wp.customize.controlConstructor["kirki-image"]=wp.customize.kirkiDynamicControl.extend({initKirkiControl:function(e){r=(e=e||this).container[0]||e.container,t=e.setting._value,i=_.isUndefined(e.params.choices)||_.isUndefined(e.params.choices.save_as)?"url":e.params.choices.save_as,a=r.querySelector(".placeholder, .thumbnail"),n="array"===i?t.url:t,l=r.querySelector(".image-upload-remove-button");var t,i,a,n,l,r,u=r.querySelector(".image-default-button"),s=function(e,t,i){e&&(e.className=i,e.innerHTML='<img src="'+t+'" alt="" />')},o=function(e,t){e&&(t?(e.classList.remove("hidden"),e.style.display=""):(e.classList.add("hidden"),e.style.display="none"))};if(t="array"===i&&_.isString(t)?{url:t}:t,("id"===i||"ID"===i)&&""!==t&&wp.media.attachment(t).fetch().then(function(){setTimeout(function(){var e=wp.media.attachment(t).get("url");s(a,e,"thumbnail thumbnail-image")},700)}),"url"===i&&""!==t||"array"===i&&!_.isUndefined(t.url)&&""!==t.url){var d=r.querySelector(".image-default-button");o(d,!1)}if(("url"===i&&""===t||"array"===i&&(_.isUndefined(t.url)||""===t.url))&&o(l,!1),t===e.params.default){var d=r.querySelector(".image-default-button");o(d,!1)}""!==n&&s(a,n,"thumbnail thumbnail-image"),r.addEventListener("click",function(t){if(t.target.closest(".image-upload-button")){t.preventDefault();var d=wp.media({multiple:!1}).open().on("select",function(){var t=d.state().get("selection").first().toJSON();n=t.url,!_.isUndefined(t.sizes)&&(n=t.sizes.full.url,_.isUndefined(t.sizes.medium)?_.isUndefined(t.sizes.thumbnail)||(n=t.sizes.thumbnail.url):n=t.sizes.medium.url),"array"===i?e.setting.set({id:t.id,url:_.isUndefined(t.sizes)?t.url:t.sizes.full.url,width:t.width,height:t.height}):"id"===i?e.setting.set(t.id):e.setting.set(_.isUndefined(t.sizes)?t.url:t.sizes.full.url),a=r.querySelector(".placeholder, .thumbnail"),l=r.querySelector(".image-upload-remove-button"),u=r.querySelector(".image-default-button"),a&&s(a,n,"thumbnail thumbnail-image"),l&&(o(l,!0),o(u,!1))})}}),r.addEventListener("click",function(t){t.target.closest(".image-upload-remove-button")&&(t.preventDefault(),e.setting.set(""),a=r.querySelector(".placeholder, .thumbnail"),l=r.querySelector(".image-upload-remove-button"),u=r.querySelector(".image-default-button"),a&&(a.className="placeholder",a.innerHTML=wp.i18n.__("No image selected","kirki")),l&&(o(l,!1),u&&u.classList.contains("button")&&o(u,!0)))}),r.addEventListener("click",function(t){t.target.closest(".image-default-button")&&(t.preventDefault(),e.setting.set(e.params.default),a=r.querySelector(".placeholder, .thumbnail"),l=r.querySelector(".image-upload-remove-button"),u=r.querySelector(".image-default-button"),a&&s(a,e.params.default,"thumbnail thumbnail-image"),l&&(o(l,!0),o(u,!1)))})}});