"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Edit=void 0;const element_1=require("@wordpress/element"),block_templates_1=require("@woocommerce/block-templates"),i18n_1=require("@wordpress/i18n"),use_product_entity_prop_1=__importDefault(require("../../../hooks/use-product-entity-prop")),validation_context_1=require("../../../contexts/validation-context"),number_control_1=require("../../../components/number-control"),use_product_edits_1=require("../../../hooks/use-product-edits");function Edit({attributes:e,clientId:t,context:{postType:o}}){const r=(0,block_templates_1.useWooBlockProps)(e),{label:i,property:s,suffix:n,placeholder:u,help:l,min:a,max:_,required:p,tooltip:c,disabled:d,step:m}=e,[f,b]=(0,use_product_entity_prop_1.default)(s,{postType:o,fallbackValue:""}),{hasEdit:x}=(0,use_product_edits_1.useProductEdits)(),{error:h,validate:q}=(0,validation_context_1.useValidation)(s,(async function(){return"number"==typeof a&&f&&parseFloat(f)<a?{message:(0,i18n_1.sprintf)((0,i18n_1.__)("Value must be greater than or equal to %d","woocommerce"),a),context:t}:"number"==typeof _&&f&&parseFloat(f)>_?{message:(0,i18n_1.sprintf)((0,i18n_1.__)("Value must be less than or equal to %d","woocommerce"),a),context:t}:p&&!f?{message:(0,i18n_1.__)("This field is required.","woocommerce"),context:t}:void 0}),[f]);return(0,element_1.createElement)("div",{...r},(0,element_1.createElement)(number_control_1.NumberControl,{label:i,onChange:b,value:f||"",help:l,suffix:n,placeholder:u,error:h,onBlur:()=>{x(s)&&q()},required:p,tooltip:c,disabled:d,step:m,min:a,max:_}))}exports.Edit=Edit;