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