"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 n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===o||__defProp(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||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_compose=require("@wordpress/compose"),import_core_data=require("@wordpress/core-data"),import_element=require("@wordpress/element"),import_i18n=require("@wordpress/i18n"),import_components=require("@wordpress/components"),import_validation_context=require("../../../contexts/validation-context");function Edit({attributes:e,clientId:t,context:o}){const r=(0,import_block_templates.useWooBlockProps)(e),[n]=(0,import_core_data.useEntityProp)("postType",o.postType,"manage_stock"),[p,m]=(0,import_core_data.useEntityProp)("postType",o.postType,"stock_quantity"),i=(0,import_compose.useInstanceId)(import_components.BaseControl,"product_stock_quantity"),{ref:_,error:s,validate:a}=(0,import_validation_context.useValidation)(`stock_quantity-${t}`,async function(){if(n&&p&&p<0)return{message:(0,import_i18n.__)("Stock quantity must be a positive number.","woocommerce")}},[n,p]);return(0,import_element.useEffect)(()=>{n&&null===p&&m(1)},[n,p]),(0,import_element.createElement)("div",{...r},(0,import_element.createElement)("div",{className:"wp-block-columns"},(0,import_element.createElement)("div",{className:"wp-block-column"},(0,import_element.createElement)(import_components.BaseControl,{id:i,className:s&&"has-error",help:s??""},(0,import_element.createElement)(import_components.__experimentalInputControl,{id:i,name:"stock_quantity",ref:_,label:(0,import_i18n.__)("Available stock","woocommerce"),value:p?.toString(),onChange:e=>{m(parseInt(e??"",10))},onBlur:()=>a(),type:"number",min:0}))),(0,import_element.createElement)("div",{className:"wp-block-column"})))}