"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,o)=>{for(var t in o)__defProp(e,t,{get:o[t],enumerable:!0})},__copyProps=(e,o,t,r)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let _ of __getOwnPropNames(o))__hasOwnProp.call(e,_)||_===t||__defProp(e,_,{get:()=>o[_],enumerable:!(r=__getOwnPropDesc(o,_))||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_tracks=require("@woocommerce/tracks"),import_components=require("@wordpress/components"),import_element=require("@wordpress/element"),import_block_editor=require("@wordpress/block-editor"),import_constants=require("../../../constants"),import_use_metabox_hidden_product=require("../../../hooks/use-metabox-hidden-product");const METABOX_HIDDEN_VALUE="postcustom";function Edit({attributes:e}){const{label:o,_templateBlockId:t}=e,r=(0,import_block_templates.useWooBlockProps)(e),_=(0,import_block_editor.useInnerBlocksProps)({className:"wp-block-woocommerce-product-custom-fields-toggle-field__inner-blocks"},{templateLock:"all",renderAppender:!1}),{isLoading:c,metaboxhiddenProduct:n,saveMetaboxhiddenProduct:p}=(0,import_use_metabox_hidden_product.useMetaboxHiddenProduct)(),m=(0,import_element.useMemo)(()=>n&&!n.some(e=>e===METABOX_HIDDEN_VALUE),[n]);return(0,import_element.createElement)("div",{...r},(0,import_element.createElement)("div",{className:"wp-block-woocommerce-product-custom-fields-toggle-field__content"},(0,import_element.createElement)(import_components.ToggleControl,{label:o,checked:m,disabled:c,onChange:async function(e){const o=e?n.filter(e=>e!==METABOX_HIDDEN_VALUE):[...n,METABOX_HIDDEN_VALUE];(0,import_tracks.recordEvent)("product_custom_fields_toggle_click",{block_id:t,source:import_constants.TRACKS_SOURCE,metaboxhidden_product:o}),await p(o)}}),c&&(0,import_element.createElement)(import_components.Spinner,null)),m&&(0,import_element.createElement)("div",{..._}))}