"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__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},__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_data=require("@woocommerce/data"),import_core_data=require("@wordpress/core-data"),import_data2=require("@wordpress/data"),import_element=require("@wordpress/element"),import_i18n=require("@wordpress/i18n"),import_shipping_dimensions_image=require("../../../components/shipping-dimensions-image"),import_validation_context=require("../../../contexts/validation-context"),import_number_control=require("../../../components/number-control");const SHIPPING_AND_WEIGHT_MIN_VALUE=0,SHIPPING_AND_WEIGHT_MAX_VALUE=1e14;function Edit({attributes:e,clientId:t,context:o}){const r=(0,import_block_templates.useWooBlockProps)(e),[i,n]=(0,import_core_data.useEntityProp)("postType",o.postType,"dimensions"),[m,_]=(0,import_core_data.useEntityProp)("postType",o.postType,"weight"),[a]=(0,import_core_data.useEntityProp)("postType",o.postType,"virtual"),[l,p]=(0,import_element.useState)(),{dimensionUnit:s,weightUnit:c}=(0,import_data2.useSelect)(e=>{const{getOption:t}=e(import_data.optionsStore);return{dimensionUnit:t("woocommerce_dimension_unit"),weightUnit:t("woocommerce_weight_unit")}},[]);function d(t,o){return{name:`dimensions.${t}`,value:(i&&i[t])??"",onChange:e=>n({...i??{},[t]:e}),onFocus:()=>p(o),onBlur:()=>p(void 0),suffix:s,disabled:e.disabled||a,min:SHIPPING_AND_WEIGHT_MIN_VALUE,max:SHIPPING_AND_WEIGHT_MAX_VALUE}}const u=`dimensions_width-${t}`,{ref:g,error:h,validate:w}=(0,import_validation_context.useValidation)(u,async function(){if(i?.width&&+i.width<=0)return{message:(0,import_i18n.__)("Width must be greater than zero.","woocommerce")}},[i?.width]),b=`dimensions_length-${t}`,{ref:f,error:E,validate:P}=(0,import_validation_context.useValidation)(b,async function(){if(i?.length&&+i.length<=0)return{message:(0,import_i18n.__)("Length must be greater than zero.","woocommerce")}},[i?.length]),v=`dimensions_height-${t}`,{ref:I,error:N,validate:y}=(0,import_validation_context.useValidation)(v,async function(){if(i?.height&&+i.height<=0)return{message:(0,import_i18n.__)("Height must be greater than zero.","woocommerce")}},[i?.height]),x=`weight-${t}`,{ref:A,error:S,validate:H}=(0,import_validation_context.useValidation)(x,async function(){if(m&&+m<=0)return{message:(0,import_i18n.__)("Weight must be greater than zero.","woocommerce")}},[m]),O={...d("width","A"),ref:g,onBlur:w,id:u},G={...d("length","B"),ref:f,onBlur:P,id:b},T={...d("height","C"),ref:I,onBlur:y,id:v},C={id:x,name:"weight",value:m??"",onChange:_,suffix:c,ref:A,onBlur:H,disabled:e.disabled||a,min:SHIPPING_AND_WEIGHT_MIN_VALUE,max:SHIPPING_AND_WEIGHT_MAX_VALUE};return(0,import_element.createElement)("div",{...r},(0,import_element.createElement)("h4",null,(0,import_i18n.__)("Dimensions","woocommerce")),(0,import_element.createElement)("div",{className:"wp-block-columns"},(0,import_element.createElement)("div",{className:"wp-block-column"},(0,import_element.createElement)(import_number_control.NumberControl,{label:(0,import_element.createInterpolateElement)((0,import_i18n.__)("Width <Side />","woocommerce"),{Side:(0,import_element.createElement)("span",null,"A")}),error:h,...O}),(0,import_element.createElement)(import_number_control.NumberControl,{label:(0,import_element.createInterpolateElement)((0,import_i18n.__)("Length <Side />","woocommerce"),{Side:(0,import_element.createElement)("span",null,"B")}),error:E,...G}),(0,import_element.createElement)(import_number_control.NumberControl,{label:(0,import_element.createInterpolateElement)((0,import_i18n.__)("Height <Side />","woocommerce"),{Side:(0,import_element.createElement)("span",null,"C")}),error:N,...T}),(0,import_element.createElement)(import_number_control.NumberControl,{label:(0,import_i18n.__)("Weight","woocommerce"),error:S,...C})),(0,import_element.createElement)("div",{className:"wp-block-column"},(0,import_element.createElement)(import_shipping_dimensions_image.ShippingDimensionsImage,{highlight:l,className:"wp-block-woocommerce-product-shipping-dimensions-fields__dimensions-image",labels:{A:O.value?.length?O.value:void 0,B:G.value?.length?G.value:void 0,C:T.value?.length?T.value:void 0}}))))}