import{v as h,g as c,bM as m,a2 as O,aQ as E}from"./Dk4AzF7j.js";const p="sqm-policy-overrides",d=()=>{const{showDebugTools:e}=O().public;return String(e).toLowerCase()==="true"},P=()=>{if(!d())return{};try{const e=localStorage.getItem(p);return e?JSON.parse(e):{}}catch(e){return console.warn("Failed to parse policy overrides:",e),{}}},v=e=>{if(d())try{localStorage.setItem(p,JSON.stringify(e)),typeof window<"u"&&window.dispatchEvent(new CustomEvent("policy-overrides-changed",{detail:e}))}catch(o){console.warn("Failed to save policy overrides:",o)}},A=()=>{const e=h(P()),o=c(()=>d()),i=r=>o.value&&e.value[r]||null,y=r=>i(r)!==null,s=(r,n)=>{if(!o.value){console.warn("Policy overrides not allowed in this environment");return}const{apiEnv:t}=O().public,l={flagName:r,enabled:n,timestamp:Date.now(),environment:t||"unknown"};e.value[r]=l,v(e.value),console.info(`🔧 Policy override set: ${r} = ${n}`),E(()=>{console.info("🔧 Override applied, triggering policy re-evaluation")})},u=r=>{o.value&&e.value[r]&&(delete e.value[r],v(e.value),console.info(`🔧 Policy override removed: ${r}`))},f=()=>{o.value&&(e.value={},v(e.value),console.info("🔧 All policy overrides cleared"))},a=c(()=>o.value?{...e.value}:{}),g=c(()=>{const r=a.value,n=Object.keys(r).length,t=Object.values(r).filter(b=>b.enabled).length,l=n-t;return{total:n,enabled:t,disabled:l}}),w=(r,n)=>{if(!o.value)return;const t=i(r);t?t.enabled===n?s(r,!n):u(r):s(r,!n)};return{isOverrideEnabled:o,overrides:m(e),getOverride:i,hasOverride:y,setOverride:s,removeOverride:u,clearAllOverrides:f,getAllOverrides:a,getOverrideStats:g,toggleOverride:w}};export{A as u};
