"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 i18n_1=require("@wordpress/i18n"),element_1=require("@wordpress/element"),blocks_1=require("@wordpress/blocks"),components_1=require("@wordpress/components"),block_templates_1=require("@woocommerce/block-templates"),tracks_1=require("@woocommerce/tracks"),core_data_1=require("@wordpress/core-data"),content_preview_1=require("../../../components/content-preview"),modal_editor_1=require("../../../components/modal-editor"),modal_editor_welcome_guide_1=__importDefault(require("../../../components/modal-editor-welcome-guide"));function clearDescriptionIfEmpty(e){if(1===e.length){const{content:t}=e[0].attributes;if(!t||!t.trim())return[]}return e}function Edit({attributes:e}){const t=(0,block_templates_1.useWooBlockProps)(e),[o,r]=(0,element_1.useState)(!1),[n,i]=(0,core_data_1.useEntityProp)("postType","product","description");return(0,element_1.createElement)("div",{...t},(0,element_1.createElement)(components_1.Button,{variant:"secondary",onClick:()=>{r(!0),(0,tracks_1.recordEvent)("product_add_description_click")}},n.length?(0,i18n_1.__)("Edit description","woocommerce"):(0,i18n_1.__)("Add description","woocommerce")),o&&(0,element_1.createElement)(modal_editor_1.ModalEditor,{initialBlocks:(0,blocks_1.parse)(n),onChange:e=>{const t=(0,blocks_1.serialize)(clearDescriptionIfEmpty(e));i(t)},onClose:()=>r(!1),title:(0,i18n_1.__)("Edit description","woocommerce")}),!!n.length&&(0,element_1.createElement)(content_preview_1.ContentPreview,{content:n}),o&&(0,element_1.createElement)(modal_editor_welcome_guide_1.default,null))}exports.Edit=Edit;