import e from"../../../../@babel/runtime/helpers/esm/objectWithoutProperties.js";import s from"../../../../@babel/runtime/helpers/esm/extends.js";import t from"react";import{getDynamicStyles as a}from"../../../../jss/dist/jss.esm.js";import r from"./multiKeyStore.js";import{increment as n}from"./indexCounter.js";import l from"../getStylesCreator/noopTheme.js";import o from"../getStylesCreator/getStylesCreator.js";import i from"../useTheme/useTheme.js";import{StylesContext as c}from"../StylesProvider/StylesProvider.js";import m from"../mergeClasses/mergeClasses.js";function u(e,s,t){var a=e.state;if(e.stylesOptions.disableGeneration)return s||{};a.cacheClasses||(a.cacheClasses={value:null,lastProp:null,lastJSS:{}});var r=!1;return a.classes!==a.cacheClasses.lastJSS&&(a.cacheClasses.lastJSS=a.classes,r=!0),s!==a.cacheClasses.lastProp&&(a.cacheClasses.lastProp=s,r=!0),r&&(a.cacheClasses.value=m({baseClasses:a.cacheClasses.lastJSS,newClasses:s,Component:t})),a.cacheClasses.value}function h(e,t){var n=e.state,l=e.theme,o=e.stylesOptions,i=e.stylesCreator,c=e.name;if(!o.disableGeneration){var u=r.get(o.sheetsManager,i,l);u||(u={refs:0,staticSheet:null,dynamicStyles:null},r.set(o.sheetsManager,i,l,u));var h=s({},i.options,o,{theme:l,flip:"boolean"==typeof o.flip?o.flip:"rtl"===l.direction});h.generateId=h.serverGenerateClassName||h.generateClassName;var f=o.sheetsRegistry;if(0===u.refs){var S;o.sheetsCache&&(S=r.get(o.sheetsCache,i,l));var p=i.create(l,c);S||((S=o.jss.createStyleSheet(p,s({link:!1},h))).attach(),o.sheetsCache&&r.set(o.sheetsCache,i,l,S)),f&&f.add(S),u.staticSheet=S,u.dynamicStyles=a(p)}if(u.dynamicStyles){var d=o.jss.createStyleSheet(u.dynamicStyles,s({link:!0},h));d.update(t),d.attach(),n.dynamicSheet=d,n.classes=m({baseClasses:u.staticSheet.classes,newClasses:d.classes}),f&&f.add(d)}else n.classes=u.staticSheet.classes;u.refs+=1}}function f(e,s){var t=e.state;t.dynamicSheet&&t.dynamicSheet.update(s)}function S(e){var s=e.state,t=e.theme,a=e.stylesOptions,n=e.stylesCreator;if(!a.disableGeneration){var l=r.get(a.sheetsManager,n,t);l.refs-=1;var o=a.sheetsRegistry;0===l.refs&&(r.delete(a.sheetsManager,n,t),a.jss.removeStyleSheet(l.staticSheet),o&&o.remove(l.staticSheet)),s.dynamicSheet&&(a.jss.removeStyleSheet(s.dynamicSheet),o&&o.remove(s.dynamicSheet))}}function p(e,s){var a,r=t.useRef([]),n=t.useMemo((function(){return{}}),s);r.current!==n&&(r.current=n,a=e()),t.useEffect((function(){return function(){a&&a()}}),[n])}function d(a){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},m=r.name,d=r.classNamePrefix,y=r.Component,v=r.defaultTheme,C=void 0===v?l:v,g=e(r,["name","classNamePrefix","Component","defaultTheme"]),j=o(a),b=m||d||"makeStyles";j.options={index:n(),name:m,meta:b,classNamePrefix:b};var P=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=i()||C,r=s({},t.useContext(c),g),n=t.useRef(),l=t.useRef();p((function(){var s={name:m,state:{},stylesCreator:j,stylesOptions:r,theme:a};return h(s,e),l.current=!1,n.current=s,function(){S(s)}}),[a,j]),t.useEffect((function(){l.current&&f(n.current,e),l.current=!0}));var o=u(n.current,e.classes,y);return"production"!==process.env.NODE_ENV&&t.useDebugValue(o),o};return P}export default d;
//# sourceMappingURL=makeStyles.js.map
