"use strict";var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var r in t)__defProp(e,r,{get:t[r],enumerable:!0})},__copyProps=(e,t,r,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let i of __getOwnPropNames(t))__hasOwnProp.call(e,i)||i===r||__defProp(e,i,{get:()=>t[i],enumerable:!(o=__getOwnPropDesc(t,i))||o.enumerable});return e},__toESM=(e,t,r)=>(r=null!=e?__create(__getProtoOf(e)):{},__copyProps(!t&&e&&e.__esModule?r:__defProp(r,"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_i18n=require("@wordpress/i18n"),import_data=require("@woocommerce/data"),import_block_templates=require("@woocommerce/block-templates"),import_tracks=require("@woocommerce/tracks"),import_element=require("@wordpress/element"),import_data2=require("@wordpress/data"),import_core_data=require("@wordpress/core-data"),import_variations_table=require("../../../components/variations-table"),import_validation_context=require("../../../contexts/validation-context"),import_use_product_entity_prop=__toESM(require("../../../hooks/use-product-entity-prop")),import_variable_product_tour=require("./variable-product-tour"),import_constants=require("../../../constants"),import_handle_prompt=require("../../../utils/handle-prompt"),import_empty_state=require("../../../components/empty-state");function Edit({attributes:e,context:{isInSelectedTab:t}}){const r=(0,import_element.useRef)(!1),{invalidateResolution:o}=(0,import_data2.useDispatch)(import_data.experimentalProductVariationsStore),i=(0,import_core_data.useEntityId)("postType","product"),a=(0,import_block_templates.useWooBlockProps)(e),[_]=(0,import_core_data.useEntityProp)("postType","product","status"),[p]=(0,import_core_data.useEntityProp)("postType","product","has_options"),[s]=(0,import_use_product_entity_prop.default)("attributes"),n=(0,import_element.useMemo)(function(){return s?.some(e=>e.variation)},[s]),c=(0,import_element.useMemo)(()=>({product_id:i,order:"asc",orderby:"menu_order",has_price:!1}),[i]),{totalCountWithoutPrice:m}=(0,import_data2.useSelect)(e=>{const{getProductVariationsTotalCount:t}=e(import_data.experimentalProductVariationsStore);return{totalCountWithoutPrice:p?t(c):0}},[p,c]),{updateUserPreferences:u,variable_items_without_price_notice_dismissed:d}=(0,import_data.useUserPreferences)(),{ref:l}=(0,import_validation_context.useValidation)("variations",async function(e,t){if(m>0&&!r.current&&"publish"!==_&&"publish"===t?.status)return"yes"!==d&&u({variable_items_without_price_notice_dismissed:{...d||{},[i]:"no"}}),{message:(0,import_i18n.__)("Set variation prices before adding this product.","woocommerce")}},[m]),b=!d||"yes"!==d[i],P=m>0&&b?(0,import_i18n.sprintf)((0,import_i18n.__)("%d variations do not have prices. Variations that do not have prices will not be visible to customers.","woocommerce"),m):"";return n?(0,import_element.createElement)("div",{...a},(0,import_element.createElement)(import_variations_table.VariationsTable,{isVisible:t,ref:l,noticeText:P,onNoticeDismiss:()=>{r.current=!0,u({variable_items_without_price_notice_dismissed:{...d||{},[i]:"yes"}})},noticeActions:[{label:(0,import_i18n.__)("Set prices","woocommerce"),onClick:function(e){(0,import_tracks.recordEvent)("product_variations_set_prices_select",{source:import_constants.TRACKS_SOURCE});const t=(0,import_data2.resolveSelect)(import_data.experimentalProductVariationsStore).getProductVariations({product_id:i,order:"asc",orderby:"menu_order",has_price:!1,_fields:["id"],per_page:m});(0,import_handle_prompt.handlePrompt)({onOk(r){(0,import_tracks.recordEvent)("product_variations_set_prices_update",{source:import_constants.TRACKS_SOURCE}),t.then(t=>{e(t.map(({id:e})=>({id:e,regular_price:r})))})}})},className:"is-destructive"}],onVariationTableChange:(e,t)=>{("delete"===e||"update"===e&&t&&t.find(e=>"regular_price"in e||"sale_price"in e))&&o("getProductVariationsTotalCount",[c])}}),t&&(0,import_element.createElement)(import_variable_product_tour.VariableProductTour,null)):(0,import_element.createElement)(import_empty_state.EmptyState,{names:[(0,import_i18n.__)("Variation","woocommerce"),(0,import_i18n.__)("Colors","woocommerce"),(0,import_i18n.__)("Sizes","woocommerce")]})}