"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Edit=void 0;const i18n_1=require("@wordpress/i18n"),block_editor_1=require("@wordpress/block-editor"),element_1=require("@wordpress/element"),data_1=require("@woocommerce/data"),components_1=require("@woocommerce/components"),core_data_1=require("@wordpress/core-data"),use_product_attributes_1=require("../../hooks/use-product-attributes"),attribute_control_1=require("../../components/attribute-control"),use_product_variations_helper_1=require("../../hooks/use-product-variations-helper");function manageDefaultAttributes(e){return e.reduce(((e,t)=>t.isDefault?[...e,{id:t.id,name:t.name,option:t.options[0]}]:e),[])}function Edit(){const e=(0,block_editor_1.useBlockProps)(),{generateProductVariations:t}=(0,use_product_variations_helper_1.useProductVariationsHelper)(),{updateUserPreferences:o,product_block_variable_options_notice_dismissed:r}=(0,data_1.useUserPreferences)(),[i,a]=(0,core_data_1.useEntityProp)("postType","product","attributes"),[n,s]=(0,core_data_1.useEntityProp)("postType","product","default_attributes"),{attributes:u,handleChange:l}=(0,use_product_attributes_1.useProductAttributes)({allAttributes:i,isVariationAttributes:!0,productId:(0,core_data_1.useEntityId)("postType","product"),onChange(e){a(e),s(manageDefaultAttributes(e)),t(e)}}),c=u.filter((e=>0===e.id)).map((e=>e.name));let d="";return c.length>0&&"yes"!==r&&(d=(0,element_1.createInterpolateElement)((0,i18n_1.__)("Buyers can’t search or filter by <attributeNames /> to find the variations. Consider adding them again as <globalAttributeLink>global attributes</globalAttributeLink> to make them easier to discover.","woocommerce"),{attributeNames:(0,element_1.createElement)("span",null,2===c.length?c.join((0,i18n_1.__)(" and ","woocommerce")):c.join(", ")),globalAttributeLink:(0,element_1.createElement)(components_1.Link,{href:"https://woocommerce.com/document/variable-product/#add-attributes-to-use-for-variations",type:"external",target:"_blank"})})),(0,element_1.createElement)("div",{...e},(0,element_1.createElement)(attribute_control_1.AttributeControl,{value:(0,element_1.useMemo)((function(){return u.map((e=>({...e,isDefault:n.some((t=>t.id===e.id||t.name===e.name))})))}),[u,n]),onChange:l,createNewAttributesAsGlobal:!0,useRemoveConfirmationModal:!0,onNoticeDismiss:()=>o({product_block_variable_options_notice_dismissed:"yes"}),disabledAttributeIds:i.filter((e=>!e.variation)).map((e=>e.id)),uiStrings:{notice:d,globalAttributeHelperMessage:"",customAttributeHelperMessage:"",newAttributeModalNotice:"",newAttributeModalTitle:(0,i18n_1.__)("Add variation options","woocommerce"),newAttributeModalDescription:(0,element_1.createInterpolateElement)((0,i18n_1.__)("Select from existing <globalAttributeLink>global attributes</globalAttributeLink> or create options for buyers to choose on the product page. You can change the order later.","woocommerce"),{globalAttributeLink:(0,element_1.createElement)(components_1.Link,{href:"https://woocommerce.com/document/variable-product/#add-attributes-to-use-for-variations",type:"external",target:"_blank"})}),attributeRemoveLabel:(0,i18n_1.__)("Remove variation option","woocommerce"),attributeRemoveConfirmationModalMessage:(0,i18n_1.__)("If you continue, some variations of this product will be deleted and customers will no longer be able to purchase them.","woocommerce")}}))}exports.Edit=Edit;