"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,{Edit:()=>Edit}),module.exports=__toCommonJS(edit_exports);var import_block_templates=require("@woocommerce/block-templates"),import_compose=require("@wordpress/compose"),import_components=require("@woocommerce/components"),import_element=require("@wordpress/element"),import_i18n=require("@wordpress/i18n"),import_icons=require("@wordpress/icons"),import_text_control=require("../../../components/text-control"),import_validation_context=require("../../../contexts/validation-context"),import_use_product_edits=require("../../../hooks/use-product-edits"),import_use_product_entity_prop=__toESM(require("../../../hooks/use-product-entity-prop"));function Edit({attributes:e,context:{postType:t}}){const o=(0,import_block_templates.useWooBlockProps)(e),{property:r,label:i,placeholder:n,required:p,pattern:_,minLength:m,maxLength:l,min:s,max:a,help:c,tooltip:u,disabled:d,type:f,suffix:v}=e,[y,g]=(0,import_use_product_entity_prop.default)(r,{postType:t,fallbackValue:""}),{hasEdit:h}=(0,import_use_product_edits.useProductEdits)(),x=(0,import_element.useRef)(null),{error:w,validate:P,ref:b}=(0,import_validation_context.useValidation)(r,async function(){if(!x.current)return;const e=x.current;let t="";return e.validity.typeMismatch&&(t=f?.message??(0,import_i18n.__)("Invalid value for the field.","woocommerce")),e.validity.valueMissing&&(t="string"==typeof p?p:(0,import_i18n.__)("This field is required.","woocommerce")),e.validity.patternMismatch&&(t=_?.message??(0,import_i18n.__)("Invalid value for the field.","woocommerce")),e.validity.tooShort&&(t=(0,import_i18n.sprintf)(m?.message??(0,import_i18n.__)("The minimum length of the field is %d","woocommerce"),m?.value)),e.validity.tooLong&&(t=(0,import_i18n.sprintf)(l?.message??(0,import_i18n.__)("The maximum length of the field is %d","woocommerce"),l?.value)),e.validity.rangeUnderflow&&(t=(0,import_i18n.sprintf)(s?.message??(0,import_i18n.__)("The minimum value of the field is %d","woocommerce"),s?.value)),e.validity.rangeOverflow&&(t=(0,import_i18n.sprintf)(a?.message??(0,import_i18n.__)("The maximum value of the field is %d","woocommerce"),a?.value)),e.setCustomValidity(t),e.validity.valid?void 0:{message:t}},[f,p,_,m,l,s,a,y]);return(0,import_element.createElement)("div",{...o},(0,import_element.createElement)(import_text_control.TextControl,{ref:(0,import_compose.useMergeRefs)([x,b]),type:f?.value??"text",value:y,disabled:d,label:i,onChange:g,onBlur:()=>{h(r)&&P()},error:w,help:c,placeholder:n,tooltip:u,suffix:function(){if(!v||!y||!x.current)return;const e="url"===x.current.type&&!x.current.validity.typeMismatch;return!0===v&&e?(0,import_element.createElement)(import_components.Link,{type:"external",href:y,target:"_blank",rel:"noreferrer",className:"wp-block-woocommerce-product-text-field__suffix-link"},(0,import_element.createElement)(import_icons.Icon,{icon:import_icons.external,size:20})):"string"==typeof v?v:void 0}(),required:Boolean(p),pattern:_?.value,minLength:m?.value,maxLength:l?.value,min:s?.value,max:a?.value}))}