(()=>{"use strict";const e=window.wc.productEditor,t=window.React,o=window.wc.blockTemplates,r=window.wp.components,a=window.wp.i18n,s=window.wp.element,n=window.wp.data,i=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"woocommerce-square/sync-with-square-field","version":"0.1.0","title":"Sync with Square checkbox field","category":"widgets","icon":"flag","description":"A block to add a checkbox to set the sync with Square product setting.","attributes":{},"supports":{"html":false,"inserter":false},"textdomain":"woocommerce-square","editorScript":"file:./index.js"}'),{name:c,...u}=i,d={example:{},edit:function({attributes:i,context:{postType:c}}){const u=(0,o.useWooBlockProps)(i),[d,l]=(0,s.useState)(""),[m,p]=(0,e.__experimentalUseProductEntityProp)("is_square_synced",c),[w]=(0,e.__experimentalUseProductEntityProp)("sku",c),[_]=(0,e.__experimentalUseProductEntityProp)("sor",c),[h]=(0,e.__experimentalUseProductEntityProp)("edit_link",c),[y]=(0,e.__experimentalUseProductEntityProp)("id",c),[S]=(0,e.__experimentalUseProductEntityProp)("type",c),[g]=(0,e.__experimentalUseProductEntityProp)("is_gift_card",c),q=(0,n.useSelect)(e=>{const{getProductVariations:t}=e("wc/admin/products/variations");return t({product_id:y})});return(0,s.useEffect)(()=>{"yes"===g&&p(!1)},[g]),(0,s.useEffect)(()=>{if("simple"===S&&!w.length)return void l((0,a.sprintf)((0,a.__)("Please add an SKU to sync %s with Square. The SKU must match the item's SKU in your Square account.","woocommerce-square"),h));if("variable"!==S)return void l("");if(null===q)return;const e=q.map(e=>e.sku),t=new Set(e).size!==e.length;q.some(e=>e.sku===w)?l((0,a.__)("SKU(s) of 1 or more variations are same as the parent product.","woocommerce-square")):l(t?(0,a.__)("Variations have duplicate SKUs","woocommerce-square"):"")},[q,w]),(0,t.createElement)("div",{...u},(0,t.createElement)(r.BaseControl,{label:(0,a.__)("Sync with Square","woocommerce-square")},(0,t.createElement)(r.ToggleControl,{label:"square"===_?(0,a.__)("Update product data with Square data","woocommerce-square"):(0,a.__)("Send product data to Square","woocommerce-square"),checked:m&&!d.length,disabled:d.length,onChange:p})),d.length?(0,t.createElement)("p",{style:{color:"#a00"},dangerouslySetInnerHTML:{__html:d}}):"")}};(0,e.registerProductEditorBlockType)({name:c,metadata:u,settings:d})})();