"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Edit=Edit;const element_1=require("@wordpress/element"),components_1=require("@wordpress/components"),block_templates_1=require("@woocommerce/block-templates"),tracks_1=require("@woocommerce/tracks"),sanitize_1=require("@woocommerce/sanitize"),core_data_1=require("@wordpress/core-data"),use_product_entity_prop_1=__importDefault(require("../../../hooks/use-product-entity-prop")),constants_1=require("../../../constants");function Edit({attributes:e,context:{postType:t}}){const o=(0,block_templates_1.useWooBlockProps)(e),{_templateBlockId:r,label:n,property:c,disabled:l,disabledCopy:s,checkedValue:i,uncheckedValue:_}=e,[a,d]=(0,use_product_entity_prop_1.default)(c,{postType:t,fallbackValue:!1}),p=(0,core_data_1.useEntityId)("postType",t),[u]=(0,core_data_1.useEntityProp)("postType",t,"parent_id");function m(){return void 0!==i?i===a:a}let k=null;return e?.help&&(k=(0,element_1.createElement)("div",{dangerouslySetInnerHTML:{__html:(0,sanitize_1.sanitizeHTML)(e.help)}})),e?.checkedHelp&&m()&&(k=(0,element_1.createElement)("div",{dangerouslySetInnerHTML:{__html:(0,sanitize_1.sanitizeHTML)(e.checkedHelp)}})),e?.uncheckedHelp&&!m()&&(k=(0,element_1.createElement)("div",{dangerouslySetInnerHTML:{__html:(0,sanitize_1.sanitizeHTML)(e.uncheckedHelp)}})),(0,element_1.createElement)("div",{...o},(0,element_1.createElement)(components_1.ToggleControl,{label:n,checked:m(),disabled:l,onChange:function(e){(0,tracks_1.recordEvent)("product_toggle_click",{block_id:r,source:constants_1.TRACKS_SOURCE,product_id:u>0?u:p}),d(e?void 0!==i?i:e:void 0!==_?_:e)},help:k}),l&&(0,element_1.createElement)("p",{className:"wp-block-woocommerce-product-toggle__disable-copy",dangerouslySetInnerHTML:{__html:(0,sanitize_1.sanitizeHTML)(s)}}))}