import{d as j,r as O}from"./vendor-BQ2R6jqo.js";import{j as w,ac as R}from"./main-CuyKCep2.js";function H(e,r){let t;try{t=e()}catch{return}return{getItem:o=>{var s;const l=m=>m===null?null:JSON.parse(m,void 0),u=(s=t.getItem(o))!=null?s:null;return u instanceof Promise?u.then(l):l(u)},setItem:(o,s)=>t.setItem(o,JSON.stringify(s,void 0)),removeItem:o=>t.removeItem(o)}}const b=e=>r=>{try{const t=e(r);return t instanceof Promise?t:{then(n){return b(n)(t)},catch(n){return this}}}catch(t){return{then(n){return this},catch(n){return b(n)(t)}}}},A=(e,r)=>(t,n,o)=>{let s={storage:H(()=>localStorage),partialize:a=>a,version:0,merge:(a,h)=>({...h,...a}),...r},l=!1;const u=new Set,m=new Set;let i=s.storage;if(!i)return e((...a)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),t(...a)},n,o);const f=()=>{const a=s.partialize({...n()});return i.setItem(s.name,{state:a,version:s.version})},$=o.setState;o.setState=(a,h)=>($(a,h),f());const d=e((...a)=>(t(...a),f()),n,o);o.getInitialState=()=>d;let y;const C=()=>{var a,h;if(!i)return;l=!1,u.forEach(c=>{var p;return c((p=n())!=null?p:d)});const _=((h=s.onRehydrateStorage)==null?void 0:h.call(s,(a=n())!=null?a:d))||void 0;return b(i.getItem.bind(i))(s.name).then(c=>{if(c)if(typeof c.version=="number"&&c.version!==s.version){if(s.migrate){const p=s.migrate(c.state,c.version);return p instanceof Promise?p.then(g=>[!0,g]):[!0,p]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,c.state];return[!1,void 0]}).then(c=>{var p;const[g,I]=c;if(y=s.merge(I,(p=n())!=null?p:d),t(y,!0),g)return f()}).then(()=>{_==null||_(y,void 0),y=n(),l=!0,m.forEach(c=>c(y))}).catch(c=>{_==null||_(void 0,c)})};return o.persist={setOptions:a=>{s={...s,...a},a.storage&&(i=a.storage)},clearStorage:()=>{i==null||i.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>C(),hasHydrated:()=>l,onHydrate:a=>(u.add(a),()=>{u.delete(a)}),onFinishHydration:a=>(m.add(a),()=>{m.delete(a)})},s.skipHydration||C(),y||d},E=A,Y=j()(E((e,r)=>({currentLayoutId:null,setCurrentLayoutId:t=>{e({currentLayoutId:t})},lastSelectedLayouts:{simple:null,sale:null,variable_simple:null,variable_sale:null},setLastSelectedLayout:(t,n)=>{e(o=>({lastSelectedLayouts:{...o.lastSelectedLayouts,[t]:n}}))},getLastSelectedLayout:t=>r().lastSelectedLayouts[t],sidebarCollapsed:{presets:!1,layouts:!1,layers:!1},setSidebarCollapsed:(t,n)=>{e(o=>({sidebarCollapsed:{...o.sidebarCollapsed,[t]:n}}))},toggleSidebarSection:t=>{e(n=>({sidebarCollapsed:{...n.sidebarCollapsed,[t]:!n.sidebarCollapsed[t]}}))}}),{name:"oppb-layout-selection",partialize:e=>({lastSelectedLayouts:e.lastSelectedLayouts,sidebarCollapsed:e.sidebarCollapsed})})),P=e=>e?Object.values(e).some(r=>r===!0):!1;function F({text:e,label:r="Copy",className:t=""}){const[n,o]=O.useState(!1),s=async()=>{try{await navigator.clipboard.writeText(e),o(!0),window.setTimeout(()=>o(!1),2e3)}catch{const l=document.createElement("textarea");l.value=e,document.body.appendChild(l),l.select(),document.execCommand("copy"),document.body.removeChild(l),o(!0),window.setTimeout(()=>o(!1),2e3)}};return React.createElement("button",{type:"button",className:`oppb-copy-btn ${t}`,onClick:s,title:n?"Copied!":r,"aria-label":r},n?React.createElement(w,{className:"w-3.5 h-3.5"}):React.createElement(R,{className:"w-3.5 h-3.5"}),React.createElement("span",null,n?"Copied":r))}const N={html:"oppb_layout_html",css:"oppb_layout_css",js:"oppb_layout_js"},L="YOUR_LAYOUT_ID";function U(e,r){return`
    if ( $layout_id !== ${r??L} ) {
        return $${e};
    }${r===null?`
    // Replace YOUR_LAYOUT_ID with your saved layout ID (shown in the editor after saving).`:""}
`}function v(e,r){return`if ( $layout_id !== ${r??L} ) {
        return $${e};
    }${r===null?`
    // Replace YOUR_LAYOUT_ID with your saved layout ID after saving.`:""}`}function S(e,r,t){const n=N[e],o=U(e,r),s="",l=e==="html"?"html":e==="css"?"css":"js";return`add_filter( '${n}', function ( $${l}, $layout_id, $context ) {${o}${s}
    // Your custom ${e.toUpperCase()} here

    return $${l};
}, 10, 3 );`}function x(e){return{html:S("html",e),css:S("css",e),js:S("js",e)}}function J(e){const r=x(e);return`<?php
/**
 * Custom layout code for Opus Price Builder
 * Add to your theme's functions.php or a custom plugin.
 */

${r.html}

${r.css}

${r.js}
`}function T(e,r,t,n){const o=v("html",e),s=v("css",e),l=v("js",e),u=r.replace(/\\/g,"\\\\").replace(/'/g,"\\'"),m=t.replace(/\\/g,"\\\\").replace(/'/g,"\\'"),i=n.replace(/\\/g,"\\\\").replace(/'/g,"\\'"),f=`add_filter( 'oppb_layout_html', function ( $html, $layout_id, $context ) {
    ${o}
    return '${u}';
}, 10, 3 );`,$=`add_filter( 'oppb_layout_css', function ( $css, $layout_id, $context ) {
    ${s}
    $css .= '\\n${m}';
    return $css;
}, 10, 3 );`,d=n?`add_filter( 'oppb_layout_js', function ( $js, $layout_id, $context ) {
    ${l}
    $js .= '\\n${i}';
    return $js;
}, 10, 3 );`:"";return{html:f,css:$,js:d,combined:`<?php

${f}

${$}${d?`

${d}`:""}
`}}export{F as C,J as a,T as b,x as g,P as h,E as p,Y as u};
