File: /home/vitanhod/www/wp-content/plugins/woocommerce/assets/client/blocks/add-to-cart-with-options.js
(()=>{var t,e,o,s={7939:(t,e,o)=>{"use strict";var s=o(6645);const r=window.wp.plugins,i=window.wp.blocks,c=window.wp.data,n=window.wp.editor,a=window.wc.wcTypes;class l{blocks=new Map;initialized=!1;attemptedRegisteredBlocks=new Set;constructor(){this.initializeSubscriptions()}static getInstance(){return l.instance||(l.instance=new l),l.instance}initializeSubscriptions(){if(this.initialized)return;const t=(0,c.subscribe)(()=>{const e=(0,c.select)(n.store);if(!e)return;const o=e.getCurrentPostType();if(o)if("post"===o||"page"===o)t(),this.blocks.forEach(t=>{if(t.isAvailableOnPostEditor){const e=t.variationName||t.blockName;this.hasAttemptedRegistration(e)||this.registerBlock(t)}}),this.initialized=!0;else{t();const o=String(e.getEditedPostSlug());this.currentTemplateId=o,this.handleTemplateChange(void 0),(0,c.subscribe)(()=>{const t=this.currentTemplateId;this.currentTemplateId=String(e.getEditedPostSlug()),t!==this.currentTemplateId&&this.handleTemplateChange(t)},n.store),this.initialized=!0}})}handleTemplateChange(t){(this.currentTemplateId?.includes("single-product")||t?.includes("single-product"))&&this.blocks.forEach(t=>{this.unregisterBlock(t),this.registerBlock(t)})}hasAttemptedRegistration(t){return this.attemptedRegisteredBlocks.has(t)}unregisterBlock(t){const{blockName:e,isVariationBlock:o,variationName:s}=t;try{o&&s?((0,i.unregisterBlockVariation)(e,s),this.attemptedRegisteredBlocks.delete(s)):((0,i.unregisterBlockType)(e),this.attemptedRegisteredBlocks.delete(e))}catch(t){console.debug(`Failed to unregister block ${e}:`,t)}}registerBlock(t){const{blockName:e,settings:o,isVariationBlock:s,variationName:r,isAvailableOnPostEditor:n}=t;try{const t=r||e;if(this.hasAttemptedRegistration(t))return;const l=(0,c.select)("core/edit-site");if(!l&&!n)return;if(s)(0,i.registerBlockVariation)(e,o);else{const t=(0,a.isEmpty)(o?.ancestor)?["woocommerce/single-product"]:o?.ancestor,s=l&&this.currentTemplateId?.includes("single-product");(0,i.registerBlockType)(e,{...o,ancestor:s?void 0:t})}this.attemptedRegisteredBlocks.add(t)}catch(t){console.error(`Failed to register block ${e}:`,t)}}registerBlockConfig(t){const e=t.variationName||t.blockName;this.blocks.set(e,t),this.registerBlock(t)}}const d=window.wp.hooks;var p=o(7723);const u=window.wp.components;var h=o(1512),w=o.n(h);w()("wc-admin:tracks:stats");const m=w()("wc-admin:tracks");function g(t,e){if(m("recordevent %s %o","wcadmin_"+t,e,{_tqk:window._tkq,shouldRecord:!!window._tkq&&!!window.wcTracks&&!!window.wcTracks.isEnabled}),!window.wcTracks||"function"!=typeof window.wcTracks.recordEvent)return!1;window.wcTracks.recordEvent(t,e)}const b="woocommerce/product-type-template-state",k="SWITCH_PRODUCT_TYPE",y="SET_PRODUCT_TYPES",_="REGISTER_LISTENER",f="UNREGISTER_LISTENER",T=window.wc.wcSettings,v=(0,T.getSetting)("productTypes",{}),x=Object.keys(v).map(t=>({slug:t,label:v[t]})),j={productTypes:{list:x,current:x[0]?.slug},listeners:[]},S={switchProductType:t=>({type:k,current:t}),setProductTypes:t=>({type:y,productTypes:t}),registerListener:t=>({type:_,listener:t}),unregisterListener:t=>({type:f,listener:t})},P=(0,c.createReduxStore)(b,{reducer:(t=j,e)=>{switch(e.type){case y:return{...t,productTypes:{...t.productTypes,list:e.productTypes||[]}};case k:return{...t,productTypes:{...t.productTypes,current:e.current}};case _:return{...t,listeners:[...t.listeners,e.listener||""]};case f:return{...t,listeners:t.listeners.filter(t=>t!==e.listener)};default:return t}},actions:S,selectors:{getProductTypes:t=>t.productTypes.list,getCurrentProductType:t=>t.productTypes.list.find(e=>e.slug===t.productTypes.current),getRegisteredListeners:t=>t.listeners}});function C(){const{productTypes:t,current:e,registeredListeners:o}=(0,c.useSelect)(t=>{const{getProductTypes:e,getCurrentProductType:o,getRegisteredListeners:s}=t(P);return{productTypes:e(),current:o(),registeredListeners:s()}},[]),{switchProductType:s,registerListener:r,unregisterListener:i}=(0,c.useDispatch)(P);return{productTypes:t,current:e,set:s,registeredListeners:o,registerListener:r,unregisterListener:i}}(0,c.select)(b)||(0,c.register)(P);var B=o(790);function E(){const{productTypes:t,current:e,set:o}=C();return(0,B.jsx)(u.SelectControl,{label:(0,p.__)("Type switcher","woocommerce"),value:e?.slug,options:t.map(t=>({label:t.label,value:t.slug})),onChange:t=>{o(t),g("blocks_add_to_cart_with_options_product_type_switched",{context:"inspector",from:e?.slug,to:t})},help:(0,p.__)("Switch product type to see how the template adapts to each one.","woocommerce")})}const O=JSON.parse('{"name":"woocommerce/add-to-cart-with-options","title":"Add to Cart + Options (Beta)","description":"Use blocks to create an \\"Add to cart\\" area that\'s customized for different product types, such as variable and grouped. ","category":"woocommerce-product-elements","attributes":{"isDescendantOfAddToCartWithOptions":{"type":"boolean","default":true}},"usesContext":["postId"],"providesContext":{"woocommerce/isDescendantOfAddToCartWithOptions":"isDescendantOfAddToCartWithOptions"},"textdomain":"woocommerce","supports":{"interactivity":true},"apiVersion":3,"$schema":"https://schemas.wp.org/trunk/block.json","style":"file:../woocommerce/add-to-cart-with-options-style.css","editorStyle":"file:../woocommerce/add-to-cart-with-options-editor.css"}');var R=o(6087);const A=window.wp.blockEditor,N=window.wp.coreData;var I=o(5573);const L=(0,B.jsxs)(I.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:[(0,B.jsx)("path",{fill:"none",d:"M0 0h24v24H0V0z"}),(0,B.jsx)("path",{d:"M12 6a9.77 9.77 0 0 1 8.82 5.5C19.17 14.87 15.79 17 12 17s-7.17-2.13-8.82-5.5A9.77 9.77 0 0 1 12 6m0-2C7 4 2.73 7.11 1 11.5 2.73 15.89 7 19 12 19s9.27-3.11 11-7.5C21.27 7.11 17 4 12 4zm0 5a2.5 2.5 0 0 1 0 5 2.5 2.5 0 0 1 0-5m0-2c-2.48 0-4.5 2.02-4.5 4.5S9.52 16 12 16s4.5-2.02 4.5-4.5S14.48 7 12 7z"})]}),D=window.wc.wcBlocksSharedContext;function W(){const{current:t,productTypes:e,set:o}=C(),{product:s}=(0,D.useProductDataContext)();return s?.id||e?.length<2?null:(0,B.jsx)(u.ToolbarGroup,{children:(0,B.jsx)(u.ToolbarDropdownMenu,{icon:(0,B.jsx)(u.Icon,{icon:L}),text:t?.label||(0,p.__)("Switch product type","woocommerce"),label:(0,p.__)("Switch product type","woocommerce"),value:t?.slug,controls:e.map(e=>({title:e.label,onClick:()=>{o(e.slug),t?.slug!==e.slug&&g("blocks_add_to_cart_with_options_product_type_switched",{context:"toolbar",from:t?.slug,to:e.slug})}}))})})}var z=o(4921);function F({children:t,className:e,actionLabel:o,onActionClick:s,...r}){return(0,B.jsx)(u.Notice,{...r,className:(0,z.$)("wc-block-editor-components-upgrade-downgrade-notice",e),actions:[{label:o,onClick:s,noDefaultClasses:!0,variant:"link"}],children:(0,B.jsx)("div",{className:"wc-block-editor-components-upgrade-downgrade-notice__text",children:t})})}o(9969);const M=({blocks:t,findCondition:e})=>{for(const o of t){if(e(o))return o;if(o.innerBlocks){const t=M({blocks:o.innerBlocks,findCondition:e});if(t)return t}}},V=({blockClientId:t})=>{const e=(0,p.__)("Facing compatibility issues with extensions? You can switch back to the classic Add to Cart with Options block.","woocommerce"),o=(0,p.__)("Switch back","woocommerce");return(0,B.jsx)(F,{isDismissible:!1,actionLabel:o,onActionClick:async()=>{const e=await(t=>{const e=(0,c.select)("core/block-editor").getBlocks(),o=M({blocks:e,findCondition:e=>e.name===O.name&&e.clientId===t});if(!o)return!1;const s=(0,i.createBlock)("woocommerce/add-to-cart-form",{quantitySelectorStyle:"input"});return(0,c.dispatch)("core/block-editor").replaceBlock(o.clientId,s),!0})(t);e&&g("blocks_add_to_cart_with_options_migration",{transform_to:"legacy"})},children:e})},G=()=>{const[t,e]=(0,R.useState)(null);if((0,R.useEffect)(()=>{const t=M({blocks:(0,c.select)("core/block-editor").getBlocks(),findCondition:t=>"woocommerce/product-image-gallery"===t.name});e(t||null)},[e]),!t)return null;const o=(0,p.__)("This template contains the classic Product Image Gallery block which is not compatible with the Add to Cart + Options block. Switch to the new Product Gallery block for a better experience.","woocommerce"),s=(0,p.__)("Upgrade to the Product Gallery block","woocommerce");return(0,B.jsx)(F,{isDismissible:!1,actionLabel:s,onActionClick:()=>{(t=>{const e=(0,i.createBlock)("woocommerce/product-gallery");(0,c.dispatch)("core/block-editor").replaceBlock(t,e)})(t.clientId),e(null)},children:o})};var U=o(7871),q=o(7857);o(2405);const $=({tag:t="div",width:e="100%",height:o="8px",maxWidth:s="",className:r="",borderRadius:i="",isStatic:c=!1,ariaMessage:n})=>(0,B.jsx)(t,{className:(0,z.A)("wc-block-components-skeleton__element",{"wc-block-components-skeleton__element--static":c},r),...n?{"aria-live":"polite","aria-label":n}:{"aria-hidden":"true"},style:{width:e,height:o,borderRadius:i,maxWidth:s}}),J=({isStatic:t=!1})=>(0,B.jsxs)("div",{className:"wc-block-components-skeleton",children:[(0,B.jsx)($,{height:"16px",isStatic:t}),(0,B.jsx)($,{height:"16px",isStatic:t}),(0,B.jsx)($,{height:"16px",width:"80%",isStatic:t})]}),Y=({buttonText:t,productType:e,isLoading:o=!1})=>(0,B.jsxs)("div",{"aria-label":o?(0,p.__)("Loading the Add to Cart + Options template part","woocommerce"):(0,p.__)("Add to Cart + Options form","woocommerce"),children:[(0,B.jsx)("div",{className:"wp-block-woocommerce-add-to-cart-with-options__skeleton-wrapper",children:(0,B.jsx)(J,{isStatic:!o})}),(0,B.jsx)(u.Disabled,{children:(0,B.jsx)("button",{className:`alt wp-element-button ${e||"simple"}_add_to_cart_button`,children:t||(0,p.__)("Add to cart","woocommerce")})})]}),H=()=>(0,B.jsx)("div",{className:"wc-block-add-to-wishlist-button",children:(0,B.jsxs)("button",{type:"button",className:"wc-block-add-to-wishlist-button__toggle",disabled:!0,children:[(0,B.jsx)("span",{className:"wc-block-add-to-wishlist-button__icon wc-block-add-to-wishlist-button__icon--empty",children:(0,B.jsx)(U.A,{icon:q.A,size:24})}),(0,B.jsx)("span",{className:"wc-block-add-to-wishlist-button__label",children:(0,p.__)("Add to wishlist","woocommerce")})]})}),X=({blockProps:t,productType:e,templatePartId:o,showAddToWishlist:s})=>{const[r,i,n]=(0,N.useEntityBlockEditor)("postType","wp_template_part",{id:o}),{isLoading:a}=(0,c.useSelect)(t=>{const{hasFinishedResolution:e}=t(N.store);return{isLoading:!e("getEditedEntityRecord",["postType","wp_template_part",o])}},[o]),l=(0,A.useInnerBlocksProps)(t,{value:r,onInput:i,onChange:n,renderAppender:a||0!==r.length?null:A.InnerBlocks.ButtonBlockAppender});if(a)return(0,B.jsx)("div",{...t,children:(0,B.jsx)(Y,{productType:e,isLoading:!0})});const{children:d,...p}=l;return(0,B.jsxs)("div",{...p,children:[d,s&&(0,B.jsx)(H,{})]})},K=({productType:t,showAddToWishlist:e})=>{const o=(0,T.getSetting)("addToCartWithOptionsTemplatePartIds",{}),s=o?.[t],r=(0,A.useBlockProps)({className:"wc-block-add-to-cart-with-options"}),{canEditTemplatePart:i,isLoading:n}=(0,c.useSelect)(t=>{if(!s)return{canEditTemplatePart:!1,isLoading:!1};const{canUser:e,hasFinishedResolution:o}=t(N.store);return{canEditTemplatePart:e("update",{kind:"postType",name:"wp_template_part",id:s}),isLoading:!o("canUser",["update",{kind:"postType",name:"wp_template_part",id:s}])}},[s]);return s&&i?(0,B.jsx)(X,{blockProps:r,productType:t,templatePartId:s,showAddToWishlist:e}):(0,B.jsxs)("div",{...r,children:[(0,B.jsx)(Y,{productType:t,isLoading:n}),e&&(0,B.jsx)(H,{})]})};o(9959);const Q="document-settings-template-selector-pane";(0,r.getPlugin)(Q)||(0,r.registerPlugin)(Q,{render:function(){const{slug:t,type:e}=(0,c.useSelect)(t=>{const{slug:e,type:o}=t("core/editor").getCurrentPost();return{slug:e,type:o}},[]),{registeredListeners:o}=C();return"wp_template"===e&&"single-product"===t&&o.length>0?(0,B.jsx)(n.PluginDocumentSettingPanel,{name:"woocommerce/product-type-selector",title:(0,p.__)("Product Type","woocommerce"),children:(0,B.jsx)(E,{})}):null}}),(t=>{const e=t.name;if(!e)return void console.error("registerProductBlockType: Block name is required for registration");const o=(({name:t,...e})=>e)(t),{isVariationBlock:s,variationName:r,isAvailableOnPostEditor:i,...c}={...o,...{isAvailableOnPostEditor:!0}||{}},n={blockName:e,settings:{...c},isVariationBlock:s??!1,variationName:r??void 0,isAvailableOnPostEditor:i??!1};l.getInstance().registerBlockConfig(n)})({...O,icon:{src:({size:t})=>(0,B.jsx)("span",{className:"wp-block-woocommerce-add-to-cart-with-options__block-icon",style:{height:t,width:t},children:s.A})},edit:t=>{const e=(0,T.getSetting)("wishlistFeatureEnabled",!1),{product:o}=(s=t.context?.postId,(0,c.useSelect)(t=>{if(!s)return{product:void 0,isResolving:!1};const e="string"==typeof s?parseInt(s,10):s;return{product:t(N.store).getEditedEntityRecord("root","product",e),isResolving:t(N.store).isResolving("getEditedEntityRecord",["root","product",e]),isResolutionFinished:t(N.store).hasFinishedResolution("getEditedEntityRecord",["root","product",e])}},[s]));var s;const r=(0,A.useBlockProps)({className:"wc-block-add-to-cart-with-options"}),i=r?.id,{current:n,registerListener:a,unregisterListener:l}=C();(0,R.useEffect)(()=>(a(i),()=>{l(i)}),[i,a,l]);const d=void 0===o?.id?n?.slug:o?.type,p=d&&["simple","variable","external","grouped"].includes(d);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(A.InspectorControls,{children:[(0,B.jsx)(G,{}),(0,B.jsx)(V,{blockClientId:t?.clientId})]}),(0,B.jsx)(A.BlockControls,{children:(0,B.jsx)(W,{})}),p?(0,B.jsx)(K,{productType:d,showAddToWishlist:e}):(0,B.jsx)("div",{...r,children:(0,B.jsx)(Y,{buttonText:o?.add_to_cart?.single_text,productType:d,isLoading:!1})})]})},save:()=>null,ancestor:["woocommerce/single-product"]}),(0,d.addFilter)("blocks.registerBlockType","woocommerce/area_add-to-cart-with-options",function(t,e){return"core/template-part"===e?{...t,variations:t.variations.map(t=>"area_add-to-cart-with-options"===t.name?{...t,scope:[]}:t)}:t})},9959:()=>{},2405:()=>{},9969:()=>{},790:t=>{"use strict";t.exports=window.ReactJSXRuntime},6087:t=>{"use strict";t.exports=window.wp.element},7723:t=>{"use strict";t.exports=window.wp.i18n},5573:t=>{"use strict";t.exports=window.wp.primitives}},r={};function i(t){var e=r[t];if(void 0!==e)return e.exports;var o=r[t]={exports:{}};return s[t](o,o.exports,i),o.exports}i.m=s,t=[],i.O=(e,o,s,r)=>{if(!o){var c=1/0;for(d=0;d<t.length;d++){for(var[o,s,r]=t[d],n=!0,a=0;a<o.length;a++)(!1&r||c>=r)&&Object.keys(i.O).every(t=>i.O[t](o[a]))?o.splice(a--,1):(n=!1,r<c&&(c=r));if(n){t.splice(d--,1);var l=s();void 0!==l&&(e=l)}}return e}r=r||0;for(var d=t.length;d>0&&t[d-1][2]>r;d--)t[d]=t[d-1];t[d]=[o,s,r]},i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},o=Object.getPrototypeOf?t=>Object.getPrototypeOf(t):t=>t.__proto__,i.t=function(t,s){if(1&s&&(t=this(t)),8&s)return t;if("object"==typeof t&&t){if(4&s&&t.__esModule)return t;if(16&s&&"function"==typeof t.then)return t}var r=Object.create(null);i.r(r);var c={};e=e||[null,o({}),o([]),o(o)];for(var n=2&s&&t;"object"==typeof n&&!~e.indexOf(n);n=o(n))Object.getOwnPropertyNames(n).forEach(e=>c[e]=()=>t[e]);return c.default=()=>t,i.d(r,c),r},i.d=(t,e)=>{for(var o in e)i.o(e,o)&&!i.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.j=7435,(()=>{var t={7435:0};i.O.j=e=>0===t[e];var e=(e,o)=>{var s,r,[c,n,a]=o,l=0;if(c.some(e=>0!==t[e])){for(s in n)i.o(n,s)&&(i.m[s]=n[s]);if(a)var d=a(i)}for(e&&e(o);l<c.length;l++)r=c[l],i.o(t,r)&&t[r]&&t[r][0](),t[r]=0;return i.O(d)},o=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];o.forEach(e.bind(null,0)),o.push=e.bind(null,o.push.bind(o))})();var c=i.O(void 0,[94],()=>i(7939));c=i.O(c),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["add-to-cart-with-options"]=c})();