"use strict";var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,r)=>{for(var o in r)__defProp(e,o,{get:r[o],enumerable:!0})},__copyProps=(e,r,o,t)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let p of __getOwnPropNames(r))__hasOwnProp.call(e,p)||p===o||__defProp(e,p,{get:()=>r[p],enumerable:!(t=__getOwnPropDesc(r,p))||t.enumerable});return e},__toESM=(e,r,o)=>(o=null!=e?__create(__getProtoOf(e)):{},__copyProps(!r&&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_clsx=__toESM(require("clsx")),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"),import_use_currency_input_props=require("../../../hooks/use-currency-input-props"),import_label=require("../../../components/label/label");function Edit({attributes:e,clientId:r,context:o}){const t=(0,import_block_templates.useWooBlockProps)(e),{label:p,help:_,tooltip:i,disabled:n}=e,[s]=(0,import_core_data.useEntityProp)("postType",o.postType||"product","regular_price"),[a,l]=(0,import_core_data.useEntityProp)("postType",o.postType||"product","sale_price"),c=(0,import_use_currency_input_props.useCurrencyInputProps)({value:a,onChange:l}),m=(0,import_compose.useInstanceId)(import_components.BaseControl,"wp-block-woocommerce-product-sale-price-field"),{ref:u,error:d,validate:b}=(0,import_validation_context.useValidation)(`sale-price-${r}`,async function(){if(a){if(Number.parseFloat(a)<0)return{message:(0,import_i18n.__)("Sale price must be greater than or equals to zero.","woocommerce")};const e=Number.parseFloat(s);if(!e||e<=Number.parseFloat(a))return{message:(0,import_i18n.__)("Sale price must be lower than the regular price.","woocommerce")}}},[s,a]);return(0,import_element.createElement)("div",{...t},(0,import_element.createElement)(import_components.BaseControl,{id:m,help:d||_,className:(0,import_clsx.default)({"has-error":d})},(0,import_element.createElement)(import_components.__experimentalInputControl,{...c,id:m,name:"sale_price",inputMode:"decimal",ref:u,label:i?(0,import_element.createElement)(import_label.Label,{label:p,tooltip:i}):p,disabled:n,onBlur:()=>b()})))}