import React__default,{useInsertionEffect,useState,createContext,useRef,useCallback,useEffect,useMemo}from"react";import{S as ShadowRoot}from"./ShadowRoot.component-DZn4gLKB.js";import{c as css_248z,a as css_248z$1,t as tailwindTheme}from"./ibm-plex-BUIARG2h.js";import"react-dom";import"./_commonjsHelpers-BxGi5vpY.js";var STYLE_ID="juno-style-provider-golbal-fonts",Fonts=function(a){var b,c=a.inline;return useInsertionEffect(function(){if(!c&&!document.querySelector("[id=\"".concat(STYLE_ID,"\"]"))){var a=document.createElement("style");a.setAttribute("id",STYLE_ID),a.innerHTML=css_248z.toString(),document.head.appendChild(a)}},[]),c?React__default.createElement("style",(b={},b["data-".concat(STYLE_ID)]="",b),css_248z.toString()):null},styles=css_248z$1.toString(),GLOBAL_STYLE_ID="juno-style-provider-global-styles",GlobalStyles=function(a){var b,c=a.inline;return useInsertionEffect(function(){if(!(c||document.querySelector("[id=\"".concat(GLOBAL_STYLE_ID,"\"]")))){var a=document.createElement("style");a.setAttribute("id",GLOBAL_STYLE_ID),a.appendChild(document.createTextNode(styles)),document.head.append(a)}},[]),c?React__default.createElement("style",(b={},b["data-".concat(GLOBAL_STYLE_ID)]="",b),styles):null};function useLocalStorage(a,b){var c=useState(function(){try{var c=window.localStorage.getItem(a);return c?JSON.parse(c):b}catch(a){return console.log("Juno Error: useLocalStorage error: ",a),b}}),d=c[0],e=c[1];return[d,function(c){try{var f=c instanceof Function?c(d):c;e(f),window.localStorage.setItem(a,JSON.stringify(f))}catch(a){return console.log("Juno Error: useLocalStorage error: ",a),b}}]}var StylesContext=createContext(void 0),APP_BODY_CSS_CLASS_NAME="juno-app-body",DEFAULT_THEME_NAME="theme-dark",StyleProvider=function(a){var b=a.stylesWrapper,c=void 0===b?"inline":b,d=a.theme,e=a.children,f=void 0===e?null:e,g=a.shadowRootMode,h=d||DEFAULT_THEME_NAME,i=useLocalStorage("juno-theme",h),j=i[0],k=i[1],l=useRef(j),m=useRef(APP_BODY_CSS_CLASS_NAME+" "+h),n=useRef(null),o=useCallback(function(a){var b=a.children;return"shadowRoot"===c?React__default.createElement(ShadowRoot,{mode:g},b):b},[c,g]),p=useCallback(function(a){n.current&&"string"==typeof a&&(n.current.classList.add(a),m.current=n.current.className)},[]),q=useCallback(function(a){n.current&&"string"==typeof a&&(n.current.classList.remove(a),m.current=n.current.className)},[]),r=useCallback(function(a){n.current&&"string"==typeof a&&(n.current.classList.remove(l.current),n.current.classList.add(a),l.current=a,m.current=n.current.className,k(a))},[n.current,l.current]);return useEffect(function(){n.current&&r(d||DEFAULT_THEME_NAME)},[d]),useMemo(function(){return React__default.createElement(o,null,React__default.createElement(Fonts,{inline:"head"!==c}),React__default.createElement(GlobalStyles,{inline:"head"!==c}),React__default.createElement(StylesContext.Provider,{value:{styles:styles,theme:tailwindTheme,currentTheme:l.current,setThemeClass:r,addCssClass:p,removeCssClass:q}},React__default.createElement("div",{className:m.current,ref:n},f)))},[c,f,g,m.current,r])};StyleProvider.useStyles=function(){return React__default.useContext(StylesContext)};export{StyleProvider};