(()=>{var e,t={4208(e,t,a){"use strict";const n=window.nab.data,i=window.ReactJSXRuntime,r=window.wp.components;Object.assign(e=>(0,i.jsx)(r.BaseControl,{__nextHasNoMarginBottom:!0,...e}),r.BaseControl),Object.assign(e=>(0,i.jsx)(r.CheckboxControl,{__nextHasNoMarginBottom:!0,...e}),r.CheckboxControl),Object.assign(e=>(0,i.jsx)(r.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,...e}),r.FormTokenField),Object.assign(e=>(0,i.jsx)(r.RangeControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,...e}),r.RangeControl);const o=Object.assign(e=>(0,i.jsx)(r.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,...e}),r.TextControl),s=Object.assign(e=>(0,i.jsx)(r.TextareaControl,{__nextHasNoMarginBottom:!0,...e}),r.TextareaControl),l=(Object.assign(e=>(0,i.jsx)(r.ToggleControl,{__nextHasNoMarginBottom:!0,...e}),r.ToggleControl),Object.assign(e=>(0,i.jsx)(r.__experimentalToggleGroupControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,...e}),r.__experimentalToggleGroupControl),window.wp.data);function c(e,t){return(0,l.useSelect)(e,t)}const d=window.wp.domReady,u=a.n(d)(),m=window.wp.element;function p(e,t){t&&(m.createRoot?(0,m.createRoot)(t).render(e):(0,m.render)(e,t))}const g=window.wp.i18n,x=window.lodash,_=window.nab.experiments,b=window.nab.utils,v=({experimentId:e,postBeingEdited:t})=>{const a=P(e);return C(e)?(0,i.jsx)("span",{className:"spinner is-active"}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(h,{icon:a,experimentId:e}),(0,i.jsx)(j,{experimentId:e,postBeingEdited:t})]})},h=({icon:e,experimentId:t})=>{const a=f(t),n=w(t);return(0,i.jsxs)(r.PanelRow,{className:"nab-test-panel",children:[(0,i.jsx)("span",{className:"nab-test-panel__icon",children:(0,i.jsx)(e,{})}),(0,i.jsx)("a",{className:"nab-test-panel__name",href:n,children:a})]})},j=({experimentId:e,postBeingEdited:t})=>{const a=y(e);return a?(0,i.jsxs)(r.PanelRow,{className:"nab-variants-panel",children:[(0,i.jsx)("h2",{className:"nab-variants-panel__title",children:(0,g._x)("Variants","text","nelio-ab-testing")}),a.map(({name:e,link:a,postId:n,index:r})=>(0,i.jsxs)("div",{className:"nab-alternative",children:[(0,i.jsx)("span",{className:"nab-alternative__letter",children:(0,b.getLetter)(r)}),(0,i.jsx)("span",{className:"nab-alternative__name",children:t!==n?(0,i.jsx)("a",{href:a,children:I(e,r)}):(0,i.jsx)("strong",{children:I(e,r)})})]},n))]}):null},f=e=>c(t=>t(n.store).getExperiment(e)?.name||(0,g._x)("Unnamed Test","text","nelio-ab-testing"),[e]),w=e=>c(t=>t(n.store).getExperiment(e)?.links.edit||"",[e]),y=e=>{const t=c(t=>t(n.store).getExperiment(e)?.alternatives,[e]);return(0,x.map)(t,(e,t)=>({index:t,postId:N(e)?e.attributes.postId:0,name:S(e)?e.attributes.name:"",link:e.links.edit}))},C=e=>c(t=>!t(n.store).hasFinishedResolution("getExperiment",[e]),[e]),P=e=>c(t=>{const{getExperiment:a}=t(n.store),{getExperimentTypes:r}=t(_.store),o=a(e)?.type??"";return r()[o]?.icon??(()=>(0,i.jsx)(i.Fragment,{}))},[e]),N=e=>!!e.attributes.postId,S=e=>!!e.attributes.name,I=(e,t)=>e||(0===t?(0,g._x)("Control Version","text","nelio-ab-testing"):(0,g.sprintf)(/* translators: %s: Letter, such as A, B, or C. */ /* translators: %s: Letter, such as A, B, or C. */
(0,g._x)("Variant %s","text","nelio-ab-testing"),(0,b.getLetter)(t))),O=window.wp.mediaUtils;function T(e){var t,a,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(a=T(e[t]))&&(n&&(n+=" "),n+=a)}else for(a in e)e[a]&&(n&&(n+=" "),n+=a);return n}const k=function(){for(var e,t,a=0,n="",i=arguments.length;a<i;a++)(e=arguments[a])&&(t=T(e))&&(n&&(n+=" "),n+=t);return n},B=window.nab.components,E=e=>{const{originalPrice:t}=e,[a,n]=(0,m.useState)(e.regularPrice),[r,o]=(0,m.useState)(e.salePrice);return(0,i.jsxs)("div",{className:"nab-product-data",children:[(0,i.jsx)(F,{originalPrice:t,regularPrice:a,salePrice:r,onRegularPriceChange:n,onSalePriceChange:o}),(0,i.jsx)(D,{name:"nab_regular_price",value:a}),(0,i.jsx)(D,{name:"nab_sale_price",value:r})]})},M=e=>(0,i.jsx)("div",{className:"nab-product-data",children:e.variations.map(t=>(0,i.jsx)(R,{isPriceTestingEnabled:e.isPriceTestingEnabled,data:t},t.id))}),R=({data:e,isPriceTestingEnabled:t})=>{const{id:a,name:n,originalPrice:r}=e,[o,l]=(0,m.useState)(e.imageId),[c,d]=(0,m.useState)(e.regularPrice),[u,p]=(0,m.useState)(e.salePrice),[x,_]=(0,m.useState)(e.description);return(0,i.jsxs)("div",{className:"nab-product-data__variation",children:[(0,i.jsxs)("div",{className:"nab-product-data__variation-name",children:[(0,i.jsxs)("strong",{children:["#",a]})," ",n]}),(0,i.jsxs)("div",{className:k({"nab-product-data__variation-data":!0,"nab-product-data__variation-data--has-pricing":t}),children:[(0,i.jsx)(z,{imageId:o,onImageIdChange:l}),t&&(0,i.jsx)(F,{originalPrice:r,regularPrice:c,salePrice:u,onRegularPriceChange:d,onSalePriceChange:p}),(0,i.jsx)("div",{className:"nab-product-data__variation-description",children:(0,i.jsx)(s,{label:(0,g._x)("Description","text","nelio-ab-testing"),value:x,onChange:_})}),(0,i.jsx)(D,{name:`nab_variation_data[${a}]`,value:{imageId:o,regularPrice:c,salePrice:u,description:x}})]})]})},F=({originalPrice:e,regularPrice:t,salePrice:a,onRegularPriceChange:n,onSalePriceChange:r})=>{const s=A(),l=U(),c=e=>e.replace(".",s),d=e=>e.replace(s,".").replace(/[^0-9.]/g,"").replace(/\./g,"#").replace("#",".").replace(/#/g,"");return(0,i.jsxs)("div",{className:"nab-product-data__pricing",children:[(0,i.jsx)(o,{label:(0,g.sprintf)(/* translators: %s: Currency. */ /* translators: %s: Currency. */
(0,g._x)("Regular price (%s)","text","nelio-ab-testing"),l),value:c(t),placeholder:c(e),onChange:e=>n(d(e))}),(0,i.jsx)(o,{label:(0,g.sprintf)(/* translators: %s: Currency. */ /* translators: %s: Currency. */
(0,g._x)("Sale price (%s)","text","nelio-ab-testing"),l),value:c(a),onChange:e=>r(d(e))})]})},z=({imageId:e,onImageIdChange:t})=>{const a=G(e),{receiveMediaUrl:o}=(0,l.useDispatch)(n.store);return(0,i.jsx)("div",{className:"nab-product-data__variation-image-wrapper",children:e?(0,i.jsx)(B.Tooltip,{text:(0,g._x)("Click to remove featured image","user","nelio-ab-testing"),children:(0,i.jsx)(r.Button,{className:"nab-product-data__variation-image-action nab-product-data__variation-image-action--is-remove",onClick:()=>t(0),children:(0,i.jsx)(H,{src:a})})}):(0,i.jsx)(O.MediaUpload,{title:(0,g._x)("Alternative Featured Image","text","nelio-ab-testing"),allowedTypes:["image"],value:e,onSelect:({id:e,url:a})=>{"string"==typeof a&&(o(e,a),t(e))},render:({open:e})=>(0,i.jsx)(B.Tooltip,{text:(0,g._x)("Click to set a featured image","user","nelio-ab-testing"),children:(0,i.jsx)(r.Button,{className:"nab-product-data__variation-image-action nab-product-data__variation-image-action--is-set",onClick:e,children:(0,i.jsx)(H,{src:a})})})})})},H=({src:e})=>e?(0,i.jsx)("img",{className:"nab-product-data__variation-image",alt:(0,g._x)("Featured Image","text","nelio-ab-testing"),src:e}):(0,i.jsx)(B.FancyIcon,{className:"nab-product-data__variation-image"}),D=({name:e,value:t})=>"string"==typeof t?(0,i.jsx)("input",{type:"hidden",name:e,value:t}):(0,i.jsx)(i.Fragment,{children:Object.keys(t).map(a=>(0,i.jsx)("input",{type:"hidden",name:`${e}[${a}]`,value:t[a]},a))}),A=()=>c(e=>e(n.store).getECommerceSetting("woocommerce","decimalSeparator"),[]),U=()=>c(e=>e(n.store).getECommerceSetting("woocommerce","currencySymbol"),[]),G=e=>c(t=>t(n.store).getMediaUrl(e),[e]),L=window.jQuery;var V,$=a.n(L);function J(){var e,t=$()("#product_image_gallery"),a=$()("#product_images_container").find("ul.product_images");$()(".add_product_images").on("click","a",function(n){var i=$()(this);n.preventDefault(),e||(e=wp.media.frames.product_gallery=wp.media({title:i.data("choose"),button:{text:i.data("update")},states:[new wp.media.controller.Library({title:i.data("choose"),filterable:"all",multiple:!0})]})).on("select",function(){var n=e.state().get("selection"),r=t.val();n.map(function(e){if((e=e.toJSON()).id){r=r?r+","+e.id:e.id;var t=e.sizes&&e.sizes.thumbnail?e.sizes.thumbnail.url:e.url;a.append('<li class="image" data-attachment_id="'+e.id+'"><img src="'+t+'" /><ul class="actions"><li><a href="#" class="delete" title="'+i.data("delete")+'">'+i.data("text")+"</a></li></ul></li>")}}),t.val(r)}),e.open()}),a.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style")},update:function(){var e="";$()("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var t=$()(this).attr("data-attachment_id");e=e+t+","}),t.val(e)}}),$()("#product_images_container").on("click","a.delete",function(){$()(this).closest("li.image").remove();var e="";return $()("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var t=$()(this).attr("data-attachment_id");e=e+t+","}),t.val(e),$()("#tiptip_holder").removeAttr("style"),$()("#tiptip_arrow").removeAttr("style"),!1})}window.nab={...(V=window,V&&"object"==typeof V&&"nab"in V?window.nab:{}),initExperimentSummary:function(e){u(()=>{const t=document.getElementById("nab-experiment-summary");t&&p((0,i.jsx)(v,{...e}),t)})},initProductDataMetabox:function(e){u(()=>{const t=document.getElementById("nab-product-data-root");t&&p("regular"===e.type?(0,i.jsx)(E,{...e}):(0,i.jsx)(M,{...e}),t)})},initProductGalleryMetabox:function(){u(J)}}}},a={};function n(e){var i=a[e];if(void 0!==i)return i.exports;var r=a[e]={exports:{}};return t[e](r,r.exports,n),r.exports}e=[],n.O=(t,a,i,r)=>{if(!a){var o=1/0;for(d=0;d<e.length;d++){for(var[a,i,r]=e[d],s=!0,l=0;l<a.length;l++)(!1&r||o>=r)&&Object.keys(n.O).every(e=>n.O[e](a[l]))?a.splice(l--,1):(s=!1,r<o&&(o=r));if(s){e.splice(d--,1);var c=i();void 0!==c&&(t=c)}}return t}r=r||0;for(var d=e.length;d>0&&e[d-1][2]>r;d--)e[d]=e[d-1];e[d]=[a,i,r]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i=n.O(void 0,[8571],()=>n(4208));i=n.O(i);var r=nab="undefined"==typeof nab?{}:nab;for(var o in i)r[o]=i[o];i.__esModule&&Object.defineProperty(r,"__esModule",{value:!0})})();