"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 l of __getOwnPropNames(t))__hasOwnProp.call(e,l)||l===o||__defProp(e,l,{get:()=>t[l],enumerable:!(r=__getOwnPropDesc(t,l))||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,{TextAreaBlockEdit:()=>TextAreaBlockEdit}),module.exports=__toCommonJS(edit_exports);var import_i18n=require("@wordpress/i18n"),import_block_templates=require("@woocommerce/block-templates"),import_element=require("@wordpress/element"),import_components=require("@wordpress/components"),import_compose=require("@wordpress/compose"),import_block_editor=require("@wordpress/block-editor"),import_clsx=__toESM(require("clsx")),import_toolbar_button_rtl=require("./toolbar/toolbar-button-rtl"),import_toolbar_button_alignment=__toESM(require("./toolbar/toolbar-button-alignment")),import_use_clear_selected_block_on_blur=require("../../../hooks/use-clear-selected-block-on-blur"),import_use_product_entity_prop=__toESM(require("../../../hooks/use-product-entity-prop")),import_label=require("../../../components/label/label");function TextAreaBlockEdit({attributes:e,setAttributes:t,context:{postType:o}}){const{property:r,label:l,placeholder:n,help:_,required:i,note:p,tooltip:a,disabled:c=!1,align:m,allowedFormats:s,direction:u,mode:d="rich-text"}=e,b=(0,import_block_templates.useWooBlockProps)(e,{className:"wp-block-woocommerce-product-text-area-field",style:{direction:u}}),f=(0,import_compose.useInstanceId)(TextAreaBlockEdit,"wp-block-woocommerce-product-content-field__content"),g=f.toString()+"__label";if(!r)throw new Error((0,import_i18n.__)("Property attribute is required.","woocommerce"));const[w,y]=(0,import_use_product_entity_prop.default)(r,{postType:o}),{handleBlur:k}=(0,import_use_clear_selected_block_on_blur.useClearSelectedBlockOnBlur)(),P=(0,import_element.useRef)(null),x=(0,import_element.useRef)(null),O="rich-text"===d,h="plain-text"===d;return(0,import_element.createElement)("div",{...b},O&&(0,import_element.createElement)(import_block_editor.BlockControls,{group:"block"},(0,import_element.createElement)(import_toolbar_button_alignment.default,{align:m,setAlignment:function(e){t({align:e})}}),(0,import_element.createElement)(import_toolbar_button_rtl.RTLToolbarButton,{direction:u,onChange:function(e){t({direction:e})}})),(0,import_element.createElement)(import_components.BaseControl,{id:f.toString(),label:(0,import_element.createElement)(import_label.Label,{label:l||"",labelId:g,required:i,note:p,tooltip:a,onClick:O?function(){P.current?.focus()}:function(){x.current?.focus()}}),help:_},O&&(0,import_element.createElement)(import_block_editor.RichText,{ref:P,id:f.toString(),"aria-labelledby":g,identifier:"content",tagName:"p",value:w||"",onChange:y,"data-empty":Boolean(w),className:(0,import_clsx.default)("components-summary-control",{[`has-text-align-${m}`]:m}),dir:u,allowedFormats:s,placeholder:n,required:i,"aria-required":i,readOnly:c,onBlur:k}),h&&(0,import_element.createElement)(import_components.TextareaControl,{ref:x,"aria-labelledby":g,value:w||"",onChange:y,placeholder:n,required:i,disabled:c,onBlur:k})))}