(()=>{"use strict";const e=window.wp.element,t=window.wp.components,n=window.ReactJSXRuntime,o=({name:e,val:o,setValue:a})=>{document.addEventListener("term-submited",()=>{s("")});const s=e=>{"string"!=typeof e?e.hasOwnProperty("hex")&&a(e.hex):a(e)};return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(t.Dropdown,{className:"sp-swatches-color",position:"bottom right",renderContent:()=>(0,n.jsx)(t.ColorPicker,{color:o,onChangeComplete:s,disableAlpha:!0}),renderToggle:({onToggle:a})=>(0,n.jsxs)("div",{className:"product-variation-color-wrapper",children:[(0,n.jsx)(t.ColorIndicator,{onClick:a,colorValue:o}),(0,n.jsx)(t.TextControl,{name:e,onChange:s,onClick:a,value:o})]})})})},a=window.wp.i18n,s=window.wp.mediaUtils,r=({name:e,val:o,setValue:r})=>{document.addEventListener("term-submited",()=>{l("")});const l=e=>{"string"!=typeof e?e.hasOwnProperty("url")&&r(e.url):r(e)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.MediaUpload,{onSelect:l,allowedTypes:["image"],render:({open:e})=>((e,o)=>e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"sp-vs-image-toggle image",style:{backgroundImage:`url(${e})`},onClick:o,onKeyDown:o,role:"button",tabIndex:0}),(0,n.jsxs)("div",{className:"sp-vs-buttons-wrapper",children:[(0,n.jsx)(t.Button,{isSecondary:!0,onClick:o,children:(0,a.__)("Replace image","sparks-for-woocommerce")}),(0,n.jsx)(t.Button,{isLink:!0,isDestructive:!0,onClick:()=>l(""),children:(0,a.__)("Remove image","sparks-for-woocommerce")})]})]}):(0,n.jsx)(t.Button,{onClick:o,className:"sp-vs-image-toggle placeholder",children:(0,a.__)("Set variation image","sparks-for-woocommerce")}))(o,e)}),(0,n.jsx)(t.TextControl,{type:"hidden",name:e,value:o||""})]})},l=({name:a,type:s,value:l})=>{const[i,c]=(0,e.useState)(l);return"color"===s?(0,n.jsx)(o,{name:a,val:i,setValue:c}):"image"===s?(0,n.jsx)(r,{name:a,val:i,setValue:c}):"label"===s?(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(t.TextControl,{name:a,onChange:e=>{c(e)},value:i})}):null},i=document.getElementById("sp-swatches-custom-fields");if(null!=i){const t=i.getAttribute("data-type"),o=i.getAttribute("data-name");let a=i.getAttribute("data-value");a=a||"",(0,e.render)((0,n.jsx)(l,{name:o,type:t,value:a}),i)}})();