"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("next/head"),n=require("next/amp");function o(e){return e&&e.__esModule?e:{default:e}}var s=o(r);const i=e=>e.trim().replace(/\s/gm,"-"),a="preferred-color-scheme",c=e=>{localStorage.setItem(a,e)},l=(e="light")=>{try{if(!window)return e;return localStorage.getItem(a)||(window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches?(c("dark"),"dark"):(c("light"),"light"):(c(e),e))}catch{return e}},d="undefined"!=typeof window?t.useLayoutEffect:t.useEffect,m=(e,t)=>{if(!e)return"";const{colors:r,typography:n,spacing:o}=e,s=(e=>{let t="";if(!e)return t;const r={white:"#fff",black:"#000",...e};for(const e in r){const n=r[e];if(n)if("string"!=typeof n)for(let r=0;r{let r="",n="";if(!e)return{vars:r,outsideVars:n};if(e?.borderRadius){const o=["2xs","1xs","s","m","l","1xl","2xl"],s=e.borderRadius,i=e=>{switch(e){case 3:return 2;case 5:return 1;default:return 0}},a=s.length;switch(s[0]){case"string":try{for(let e=0;e{let r="",n="";if(!e)return{vars:r,outsideVars:n};const{fontSizes:o,fontFamilies:s}=e;if(s)for(const e in s)r+=`--font-${e}:${s[e]};`;const i=o?.length;if(!i&&"object"==typeof o)return{vars:r,outsideVars:n};const a=["4xs","3xs","2xs","1xs","s","m","l","1xl","2xl","3xl","4xl"],c=e=>{switch(e){case 7:return 2;case 9:return 1;default:return 0}};switch(typeof o[0]){case"string":try{for(let e=0;e(d((()=>{if(!document?.body)return;const e=l();let r=!0;for(const e of Array.from(document.body.classList))if(e.startsWith("kami-ui-")){r=!1;break}const n=t.findIndex((({name:t})=>t.includes(e))),o=-1===n?0:n;r&&t[o]&&t[o].name&&document.body.classList.add(`kami-ui-${i(t[o].name)}`)}),[]),e.jsx(e.Fragment,{}));exports.MultiThemeProvider=({themes:t=[],injectInBody:r=!1,disableConsole:o=!1,disableOnAmp:i=!0,autoMaintainTheme:a=!0,children:c})=>{const l=n.useAmp();(e=>{const t=[],r=[];for(const{name:n,theme:{colors:o}}of e){const s=JSON.stringify(Object.keys(o).sort());if(!0===(0===r.length?r.push(s):r[0]!==s))throw new Error("Invalid theme config: Themes have different color keys;");if(t.includes(n))throw new Error(`Theme name ${n} is duplicated`);t.push(n);for(const r in o){const n=o[r]?.length;for(const o of t){const t=e.find((({name:e})=>e===o))?.theme?.colors[r]?.length;if(t!==n)throw new Error(`Invalid theme config: Themes have different lengths of color ${r};`)}}}})(t);const d=t.map((({name:e,theme:t})=>m(t,e))).join(""),f=e.jsx("style",{id:"kami-ui-styles",dangerouslySetInnerHTML:{__html:d}}),p=r?f:e.jsx(s.default,{children:f}),x={themes:t,disableConsole:o};return e.jsxs(u.Provider,{value:x,children:[a&&e.jsx(h,{themes:t}),!(i&&l)&&p,c]})},exports.ThemeProvider=({injectInBody:t=!1,disableOnAmp:r=!0,theme:o,mode:i,children:a})=>{const c=n.useAmp(),l=m(o,i),d=e.jsx("style",{id:"kami-ui-styles",dangerouslySetInnerHTML:{__html:l}}),u=t?d:e.jsx(s.default,{children:d});return e.jsxs(e.Fragment,{children:[!(r&&c)&&u,a]})},exports.useTheme=()=>{const{themes:e,disableConsole:r}=t.useContext(u),n=e=>{r||console.warn(e)},o=t=>e.find((({name:e})=>e===t));return{updateTheme:t=>{if(!document||!t)return;if(e.find((({name:e})=>e===t))){for(const e of Array.from(document.body.classList))if(e.startsWith("kami-ui-")){document.body.classList.remove(e);break}document.body.classList.add(`kami-ui-${i(t)}`);try{t.includes("dark")?c("dark"):t.includes("light")&&c("light")}catch{r||n(`Failed to update theme ${t} in local storage`)}}else r||n(`Theme ${t} not found`)},getColor:(t,s)=>{try{const i=Array.from(document.body.classList).find((e=>e.startsWith("kami-ui-"))),a=o(i?.replace("kami-ui-","")||e?.[0]?.name);if(!a)return r||n("Current theme not found"),null;const c=a?.theme?.colors?.[t]?.[s];return t?c||null:(r||n(`--color-${c}-${s+1}00 in theme ${a?.name} not found`),null)}catch{return null}},getTheme:o,getCurrentTheme:()=>(Array.from(document.body.classList).find((e=>e.startsWith("kami-ui-")))??"").replace("kami-ui-","")||null}};