"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Edit=void 0;const classnames_1=__importDefault(require("classnames")),components_1=require("@wordpress/components"),tracks_1=require("@woocommerce/tracks"),element_1=require("@wordpress/element"),i18n_1=require("@wordpress/i18n"),block_editor_1=require("@wordpress/block-editor"),core_data_1=require("@wordpress/core-data"),sanitize_html_1=require("../../utils/sanitize-html"),empty_variations_image_1=require("./empty-variations-image"),new_attribute_modal_1=require("../../components/attribute-control/new-attribute-modal"),use_product_attributes_1=require("../../hooks/use-product-attributes"),utils_1=require("../../components/attribute-control/utils"),use_product_variations_helper_1=require("../../hooks/use-product-variations-helper"),utils_2=require("../../utils"),constants_1=require("../../constants");function Edit({attributes:e}){const{description:t}=e,{generateProductVariations:r}=(0,use_product_variations_helper_1.useProductVariationsHelper)(),[o,i]=(0,element_1.useState)(!1),[a,s]=(0,core_data_1.useEntityProp)("postType","product","attributes"),[,n]=(0,core_data_1.useEntityProp)("postType","product","default_attributes"),{attributes:c,handleChange:u}=(0,use_product_attributes_1.useProductAttributes)({allAttributes:a,isVariationAttributes:!0,productId:(0,core_data_1.useEntityId)("postType","product"),onChange(e,t){s(e),n(t),r(e,t)}}),l=(0,utils_2.hasAttributesUsedForVariations)(a),_=(0,block_editor_1.useBlockProps)({className:(0,classnames_1.default)({"wp-block-woocommerce-product-variations-fields--has-attributes":l})}),d=(0,block_editor_1.useInnerBlocksProps)({className:"wp-block-woocommerce-product-variations-fields__content"},{templateLock:"all"}),m=()=>{i(!1)};return(0,element_1.createElement)("div",{..._},(0,element_1.createElement)("div",{className:"wp-block-woocommerce-product-variations-fields__heading"},(0,element_1.createElement)("div",{className:"wp-block-woocommerce-product-variations-fields__heading-image-container"},(0,element_1.createElement)(empty_variations_image_1.EmptyVariationsImage,null)),(0,element_1.createElement)("p",{className:"wp-block-woocommerce-product-variations-fields__heading-description",dangerouslySetInnerHTML:(0,sanitize_html_1.sanitizeHTML)(t)}),(0,element_1.createElement)("div",{className:"wp-block-woocommerce-product-variations-fields__heading-actions"},(0,element_1.createElement)(components_1.Button,{variant:"primary",onClick:()=>{i(!0)}},(0,i18n_1.__)("Add variation options","woocommerce")))),(0,element_1.createElement)("div",{...d}),o&&(0,element_1.createElement)(new_attribute_modal_1.NewAttributeModal,{title:(0,i18n_1.__)("Add variation options","woocommerce"),description:(0,i18n_1.__)("Select from existing attributes or create new ones to add new variations for your product. You can change the order later.","woocommerce"),createNewAttributesAsGlobal:!0,notice:"",onCancel:()=>{m()},onAdd:e=>{const t=e.filter((e=>!c.some((t=>(0,utils_1.getAttributeId)(e)===(0,utils_1.getAttributeId)(t)))));(0,tracks_1.recordEvent)("product_options_add",{source:constants_1.TRACKS_SOURCE,options:t.map((e=>({attribute:e.name,values:e.options})))}),u(t),m()},selectedAttributeIds:c.map((e=>e.id)),disabledAttributeIds:a.filter((e=>!e.variation)).map((e=>e.id)),termsAutoSelection:"all"}))}exports.Edit=Edit;