"use strict";var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var o in t)__defProp(e,o,{get:t[o],enumerable:!0})},__copyProps=(e,t,o,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let i of __getOwnPropNames(t))__hasOwnProp.call(e,i)||i===o||__defProp(e,i,{get:()=>t[i],enumerable:!(r=__getOwnPropDesc(t,i))||r.enumerable});return e},__toESM=(e,t,o)=>(o=null!=e?__create(__getProtoOf(e)):{},__copyProps(!t&&e&&e.__esModule?o:__defProp(o,"default",{value:e,enumerable:!0}),e)),__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),edit_exports={};__export(edit_exports,{DescriptionBlockEdit:()=>DescriptionBlockEdit,getContentFromFreeform:()=>getContentFromFreeform}),module.exports=__toCommonJS(edit_exports);var import_element=require("@wordpress/element"),import_blocks=require("@wordpress/blocks"),import_data=require("@wordpress/data"),import_clsx=__toESM(require("clsx")),import_block_templates=require("@woocommerce/block-templates"),import_core_data=require("@wordpress/core-data"),import_i18n=require("@wordpress/i18n"),import_block_editor=require("@wordpress/block-editor"),import_modal_editor_welcome_guide=__toESM(require("../../../components/modal-editor-welcome-guide")),import_full_editor_toolbar_button=__toESM(require("./components/full-editor-toolbar-button")),import_product_editor_ui=require("../../../store/product-editor-ui");function getContentFromFreeform(e){return!(1!==e.length||"core/freeform"!==e[0].name)&&e[0].attributes.content}function DescriptionBlockEdit({attributes:e}){const[t,o]=(0,import_core_data.useEntityProp)("postType","product","description"),[r,i]=(0,import_element.useState)([]),{isModalEditorOpen:_,modalEditorBlocks:l,hasChanged:p}=(0,import_data.useSelect)(e=>({isModalEditorOpen:e(import_product_editor_ui.wooProductEditorUiStore).isModalEditorOpen(),modalEditorBlocks:e(import_product_editor_ui.wooProductEditorUiStore).getModalEditorBlocks(),hasChanged:e(import_product_editor_ui.wooProductEditorUiStore).getModalEditorContentHasChanged()}),[]);(0,import_element.useEffect)(()=>{if(!t)return void i([]);if(-1===t.indexOf("\x3c!-- wp:"))return;const e=(0,import_blocks.parse)(t);getContentFromFreeform(e)||i(e)},[t]),(0,import_element.useEffect)(()=>{if(!p)return;const e=(0,import_blocks.serialize)(l);o(e)},[l,o,p]);const n=(0,import_block_templates.useWooBlockProps)(e,{className:(0,import_clsx.default)({"has-blocks":!!t.length}),tabIndex:0}),m=(0,import_block_editor.useInnerBlocksProps)({},{templateLock:"contentOnly",allowedBlocks:["woocommerce/product-summary-field"]});return(0,import_element.createElement)("div",{...n},r?.length?(0,import_element.createElement)(import_element.Fragment,null,(0,import_element.createElement)(import_block_editor.BlockControls,null,(0,import_element.createElement)(import_full_editor_toolbar_button.default,{text:(0,import_i18n.__)("Edit in full editor","woocommerce")})),(0,import_element.createElement)(import_block_editor.BlockPreview,{blocks:r,viewportWidth:800,additionalStyles:[{css:"body { padding: 32px; height: 10000px }"}]})):(0,import_element.createElement)("div",{...m}),_&&(0,import_element.createElement)(import_modal_editor_welcome_guide.default,null))}