"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Edit=void 0;const block_editor_1=require("@wordpress/block-editor"),compose_1=require("@wordpress/compose"),core_data_1=require("@wordpress/core-data"),element_1=require("@wordpress/element"),i18n_1=require("@wordpress/i18n"),components_1=require("@wordpress/components"),validation_context_1=require("../../contexts/validation-context");function Edit({clientId:e}){const t=(0,block_editor_1.useBlockProps)(),[o]=(0,core_data_1.useEntityProp)("postType","product","manage_stock"),[n,r]=(0,core_data_1.useEntityProp)("postType","product","stock_quantity"),c=(0,compose_1.useInstanceId)(components_1.BaseControl,"product_stock_quantity"),{ref:s,error:a,validate:i}=(0,validation_context_1.useValidation)(`stock_quantity-${e}`,(async function(){if(o&&n&&n<0)return(0,i18n_1.__)("Stock quantity must be a positive number.","woocommerce")}),[o,n]);return(0,element_1.useEffect)((()=>{o&&null===n&&r(1)}),[o,n]),(0,element_1.createElement)("div",{...t},(0,element_1.createElement)("div",{className:"wp-block-columns"},(0,element_1.createElement)("div",{className:"wp-block-column"},(0,element_1.createElement)(components_1.BaseControl,{id:c,className:a&&"has-error",help:null!=a?a:""},(0,element_1.createElement)(components_1.__experimentalInputControl,{id:c,name:"stock_quantity",ref:s,label:(0,i18n_1.__)("Available quantity","woocommerce"),value:n,onChange:r,onBlur:i,type:"number",min:0}))),(0,element_1.createElement)("div",{className:"wp-block-column"})))}exports.Edit=Edit;