var Tu=Object.defineProperty;var Eu=(V,De,M)=>De in V?Tu(V,De,{enumerable:!0,configurable:!0,writable:!0,value:M}):V[De]=M;var H=(V,De,M)=>Eu(V,typeof De!="symbol"?De+"":De,M);(function(V,De,M,ie,f,Pe){"use strict";var qe;function Mr(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,i.get?i:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const T=Mr(V);var qi={exports:{}},Xt={};/**
 * @license React
 * react-jsx-runtime.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var Pr=V,Ar=Symbol.for("react.element"),Or=Symbol.for("react.fragment"),Ir=Object.prototype.hasOwnProperty,Lr=Pr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Nr={key:!0,ref:!0,__self:!0,__source:!0};function Ji(t,e,s){var i,n={},a=null,r=null;s!==void 0&&(a=""+s),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(r=e.ref);for(i in e)Ir.call(e,i)&&!Nr.hasOwnProperty(i)&&(n[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)n[i]===void 0&&(n[i]=e[i]);return{$$typeof:Ar,type:t,key:a,ref:r,props:n,_owner:Lr.current}}Xt.Fragment=Or,Xt.jsx=Ji,Xt.jsxs=Ji,qi.exports=Xt;var l=qi.exports;/**
 * @remix-run/router v1.23.2
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */function jt(){return jt=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},jt.apply(this,arguments)}var Fe;(function(t){t.Pop="POP",t.Push="PUSH",t.Replace="REPLACE"})(Fe||(Fe={}));const Qi="popstate";function Tr(t){t===void 0&&(t={});function e(n,a){let{pathname:r="/",search:o="",hash:c=""}=Qe(n.location.hash.substr(1));return!r.startsWith("/")&&!r.startsWith(".")&&(r="/"+r),zs("",{pathname:r,search:o,hash:c},a.state&&a.state.usr||null,a.state&&a.state.key||"default")}function s(n,a){let r=n.document.querySelector("base"),o="";if(r&&r.getAttribute("href")){let c=n.location.href,h=c.indexOf("#");o=h===-1?c:c.slice(0,h)}return o+"#"+(typeof a=="string"?a:Jt(a))}function i(n,a){qt(n.pathname.charAt(0)==="/","relative pathnames are not supported in hash history.push("+JSON.stringify(a)+")")}return Rr(e,s,i,t)}function Z(t,e){if(t===!1||t===null||typeof t>"u")throw new Error(e)}function qt(t,e){if(!t){typeof console<"u"&&console.warn(e);try{throw new Error(e)}catch{}}}function Er(){return Math.random().toString(36).substr(2,8)}function Zi(t,e){return{usr:t.state,key:t.key,idx:e}}function zs(t,e,s,i){return s===void 0&&(s=null),jt({pathname:typeof t=="string"?t:t.pathname,search:"",hash:""},typeof e=="string"?Qe(e):e,{state:s,key:e&&e.key||i||Er()})}function Jt(t){let{pathname:e="/",search:s="",hash:i=""}=t;return s&&s!=="?"&&(e+=s.charAt(0)==="?"?s:"?"+s),i&&i!=="#"&&(e+=i.charAt(0)==="#"?i:"#"+i),e}function Qe(t){let e={};if(t){let s=t.indexOf("#");s>=0&&(e.hash=t.substr(s),t=t.substr(0,s));let i=t.indexOf("?");i>=0&&(e.search=t.substr(i),t=t.substr(0,i)),t&&(e.pathname=t)}return e}function Rr(t,e,s,i){i===void 0&&(i={});let{window:n=document.defaultView,v5Compat:a=!1}=i,r=n.history,o=Fe.Pop,c=null,h=d();h==null&&(h=0,r.replaceState(jt({},r.state,{idx:h}),""));function d(){return(r.state||{idx:null}).idx}function u(){o=Fe.Pop;let m=d(),v=m==null?null:m-h;h=m,c&&c({action:o,location:_.location,delta:v})}function p(m,v){o=Fe.Push;let w=zs(_.location,m,v);s&&s(w,m),h=d()+1;let S=Zi(w,h),I=_.createHref(w);try{r.pushState(S,"",I)}catch(C){if(C instanceof DOMException&&C.name==="DataCloneError")throw C;n.location.assign(I)}a&&c&&c({action:o,location:_.location,delta:1})}function g(m,v){o=Fe.Replace;let w=zs(_.location,m,v);s&&s(w,m),h=d();let S=Zi(w,h),I=_.createHref(w);r.replaceState(S,"",I),a&&c&&c({action:o,location:_.location,delta:0})}function x(m){let v=n.location.origin!=="null"?n.location.origin:n.location.href,w=typeof m=="string"?m:Jt(m);return w=w.replace(/ $/,"%20"),Z(v,"No window.location.(origin|href) available to create URL for href: "+w),new URL(w,v)}let _={get action(){return o},get location(){return t(n,r)},listen(m){if(c)throw new Error("A history only accepts one active listener");return n.addEventListener(Qi,u),c=m,()=>{n.removeEventListener(Qi,u),c=null}},createHref(m){return e(n,m)},createURL:x,encodeLocation(m){let v=x(m);return{pathname:v.pathname,search:v.search,hash:v.hash}},push:p,replace:g,go(m){return r.go(m)}};return _}var en;(function(t){t.data="data",t.deferred="deferred",t.redirect="redirect",t.error="error"})(en||(en={}));function Dr(t,e,s){return s===void 0&&(s="/"),Fr(t,e,s)}function Fr(t,e,s,i){let n=typeof e=="string"?Qe(e):e,a=Bs(n.pathname||"/",s);if(a==null)return null;let r=tn(t);zr(r);let o=null;for(let c=0;o==null&&c<r.length;++c){let h=Jr(a);o=Kr(r[c],h)}return o}function tn(t,e,s,i){e===void 0&&(e=[]),s===void 0&&(s=[]),i===void 0&&(i="");let n=(a,r,o)=>{let c={relativePath:o===void 0?a.path||"":o,caseSensitive:a.caseSensitive===!0,childrenIndex:r,route:a};c.relativePath.startsWith("/")&&(Z(c.relativePath.startsWith(i),'Absolute route path "'+c.relativePath+'" nested under path '+('"'+i+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),c.relativePath=c.relativePath.slice(i.length));let h=ze([i,c.relativePath]),d=s.concat(c);a.children&&a.children.length>0&&(Z(a.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+h+'".')),tn(a.children,e,d,h)),!(a.path==null&&!a.index)&&e.push({path:h,score:Gr(h,a.index),routesMeta:d})};return t.forEach((a,r)=>{var o;if(a.path===""||!((o=a.path)!=null&&o.includes("?")))n(a,r);else for(let c of sn(a.path))n(a,r,c)}),e}function sn(t){let e=t.split("/");if(e.length===0)return[];let[s,...i]=e,n=s.endsWith("?"),a=s.replace(/\?$/,"");if(i.length===0)return n?[a,""]:[a];let r=sn(i.join("/")),o=[];return o.push(...r.map(c=>c===""?a:[a,c].join("/"))),n&&o.push(...r),o.map(c=>t.startsWith("/")&&c===""?"/":c)}function zr(t){t.sort((e,s)=>e.score!==s.score?s.score-e.score:Yr(e.routesMeta.map(i=>i.childrenIndex),s.routesMeta.map(i=>i.childrenIndex)))}const Br=/^:[\w-]+$/,Wr=3,Hr=2,Vr=1,$r=10,Ur=-2,nn=t=>t==="*";function Gr(t,e){let s=t.split("/"),i=s.length;return s.some(nn)&&(i+=Ur),e&&(i+=Hr),s.filter(n=>!nn(n)).reduce((n,a)=>n+(Br.test(a)?Wr:a===""?Vr:$r),i)}function Yr(t,e){return t.length===e.length&&t.slice(0,-1).every((i,n)=>i===e[n])?t[t.length-1]-e[e.length-1]:0}function Kr(t,e,s){let{routesMeta:i}=t,n={},a="/",r=[];for(let o=0;o<i.length;++o){let c=i[o],h=o===i.length-1,d=a==="/"?e:e.slice(a.length)||"/",u=Xr({path:c.relativePath,caseSensitive:c.caseSensitive,end:h},d),p=c.route;if(!u)return null;Object.assign(n,u.params),r.push({params:n,pathname:ze([a,u.pathname]),pathnameBase:so(ze([a,u.pathnameBase])),route:p}),u.pathnameBase!=="/"&&(a=ze([a,u.pathnameBase]))}return r}function Xr(t,e){typeof t=="string"&&(t={path:t,caseSensitive:!1,end:!0});let[s,i]=qr(t.path,t.caseSensitive,t.end),n=e.match(s);if(!n)return null;let a=n[0],r=a.replace(/(.)\/+$/,"$1"),o=n.slice(1);return{params:i.reduce((h,d,u)=>{let{paramName:p,isOptional:g}=d;if(p==="*"){let _=o[u]||"";r=a.slice(0,a.length-_.length).replace(/(.)\/+$/,"$1")}const x=o[u];return g&&!x?h[p]=void 0:h[p]=(x||"").replace(/%2F/g,"/"),h},{}),pathname:a,pathnameBase:r,pattern:t}}function qr(t,e,s){e===void 0&&(e=!1),s===void 0&&(s=!0),qt(t==="*"||!t.endsWith("*")||t.endsWith("/*"),'Route path "'+t+'" will be treated as if it were '+('"'+t.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+t.replace(/\*$/,"/*")+'".'));let i=[],n="^"+t.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(r,o,c)=>(i.push({paramName:o,isOptional:c!=null}),c?"/?([^\\/]+)?":"/([^\\/]+)"));return t.endsWith("*")?(i.push({paramName:"*"}),n+=t==="*"||t==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):s?n+="\\/*$":t!==""&&t!=="/"&&(n+="(?:(?=\\/|$))"),[new RegExp(n,e?void 0:"i"),i]}function Jr(t){try{return t.split("/").map(e=>decodeURIComponent(e).replace(/\//g,"%2F")).join("/")}catch(e){return qt(!1,'The URL path "'+t+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+e+").")),t}}function Bs(t,e){if(e==="/")return t;if(!t.toLowerCase().startsWith(e.toLowerCase()))return null;let s=e.endsWith("/")?e.length-1:e.length,i=t.charAt(s);return i&&i!=="/"?null:t.slice(s)||"/"}const Qr=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Zr=t=>Qr.test(t);function eo(t,e){e===void 0&&(e="/");let{pathname:s,search:i="",hash:n=""}=typeof t=="string"?Qe(t):t,a;if(s)if(Zr(s))a=s;else{if(s.includes("//")){let r=s;s=s.replace(/\/\/+/g,"/"),qt(!1,"Pathnames cannot have embedded double slashes - normalizing "+(r+" -> "+s))}s.startsWith("/")?a=an(s.substring(1),"/"):a=an(s,e)}else a=e;return{pathname:a,search:io(i),hash:no(n)}}function an(t,e){let s=e.replace(/\/+$/,"").split("/");return t.split("/").forEach(n=>{n===".."?s.length>1&&s.pop():n!=="."&&s.push(n)}),s.length>1?s.join("/"):"/"}function Ws(t,e,s,i){return"Cannot include a '"+t+"' character in a manually specified "+("`to."+e+"` field ["+JSON.stringify(i)+"].  Please separate it out to the ")+("`to."+s+"` field. Alternatively you may provide the full path as ")+'a string in <Link to="..."> and the router will parse it for you.'}function to(t){return t.filter((e,s)=>s===0||e.route.path&&e.route.path.length>0)}function Hs(t,e){let s=to(t);return e?s.map((i,n)=>n===s.length-1?i.pathname:i.pathnameBase):s.map(i=>i.pathnameBase)}function Vs(t,e,s,i){i===void 0&&(i=!1);let n;typeof t=="string"?n=Qe(t):(n=jt({},t),Z(!n.pathname||!n.pathname.includes("?"),Ws("?","pathname","search",n)),Z(!n.pathname||!n.pathname.includes("#"),Ws("#","pathname","hash",n)),Z(!n.search||!n.search.includes("#"),Ws("#","search","hash",n)));let a=t===""||n.pathname==="",r=a?"/":n.pathname,o;if(r==null)o=s;else{let u=e.length-1;if(!i&&r.startsWith("..")){let p=r.split("/");for(;p[0]==="..";)p.shift(),u-=1;n.pathname=p.join("/")}o=u>=0?e[u]:"/"}let c=eo(n,o),h=r&&r!=="/"&&r.endsWith("/"),d=(a||r===".")&&s.endsWith("/");return!c.pathname.endsWith("/")&&(h||d)&&(c.pathname+="/"),c}const ze=t=>t.join("/").replace(/\/\/+/g,"/"),so=t=>t.replace(/\/+$/,"").replace(/^\/*/,"/"),io=t=>!t||t==="?"?"":t.startsWith("?")?t:"?"+t,no=t=>!t||t==="#"?"":t.startsWith("#")?t:"#"+t;function ao(t){return t!=null&&typeof t.status=="number"&&typeof t.statusText=="string"&&typeof t.internal=="boolean"&&"data"in t}const rn=["post","put","patch","delete"];new Set(rn);const ro=["get",...rn];new Set(ro);/**
 * React Router v6.30.3
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */function St(){return St=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},St.apply(this,arguments)}const $s=T.createContext(null),oo=T.createContext(null),Be=T.createContext(null),Qt=T.createContext(null),We=T.createContext({outlet:null,matches:[],isDataRoute:!1}),on=T.createContext(null);function lo(t,e){let{relative:s}=e===void 0?{}:e;ct()||Z(!1);let{basename:i,navigator:n}=T.useContext(Be),{hash:a,pathname:r,search:o}=cn(t,{relative:s}),c=r;return i!=="/"&&(c=r==="/"?i:ze([i,r])),n.createHref({pathname:c,search:o,hash:a})}function ct(){return T.useContext(Qt)!=null}function ht(){return ct()||Z(!1),T.useContext(Qt).location}function ln(t){T.useContext(Be).static||T.useLayoutEffect(t)}function Us(){let{isDataRoute:t}=T.useContext(We);return t?ko():co()}function co(){ct()||Z(!1);let t=T.useContext($s),{basename:e,future:s,navigator:i}=T.useContext(Be),{matches:n}=T.useContext(We),{pathname:a}=ht(),r=JSON.stringify(Hs(n,s.v7_relativeSplatPath)),o=T.useRef(!1);return ln(()=>{o.current=!0}),T.useCallback(function(h,d){if(d===void 0&&(d={}),!o.current)return;if(typeof h=="number"){i.go(h);return}let u=Vs(h,JSON.parse(r),a,d.relative==="path");t==null&&e!=="/"&&(u.pathname=u.pathname==="/"?e:ze([e,u.pathname])),(d.replace?i.replace:i.push)(u,d.state,d)},[e,i,r,a,t])}function cn(t,e){let{relative:s}=e===void 0?{}:e,{future:i}=T.useContext(Be),{matches:n}=T.useContext(We),{pathname:a}=ht(),r=JSON.stringify(Hs(n,i.v7_relativeSplatPath));return T.useMemo(()=>Vs(t,JSON.parse(r),a,s==="path"),[t,r,a,s])}function ho(t,e){return uo(t,e)}function uo(t,e,s,i){ct()||Z(!1);let{navigator:n}=T.useContext(Be),{matches:a}=T.useContext(We),r=a[a.length-1],o=r?r.params:{};r&&r.pathname;let c=r?r.pathnameBase:"/";r&&r.route;let h=ht(),d;if(e){var u;let m=typeof e=="string"?Qe(e):e;c==="/"||(u=m.pathname)!=null&&u.startsWith(c)||Z(!1),d=m}else d=h;let p=d.pathname||"/",g=p;if(c!=="/"){let m=c.replace(/^\//,"").split("/");g="/"+p.replace(/^\//,"").split("/").slice(m.length).join("/")}let x=Dr(t,{pathname:g}),_=_o(x&&x.map(m=>Object.assign({},m,{params:Object.assign({},o,m.params),pathname:ze([c,n.encodeLocation?n.encodeLocation(m.pathname).pathname:m.pathname]),pathnameBase:m.pathnameBase==="/"?c:ze([c,n.encodeLocation?n.encodeLocation(m.pathnameBase).pathname:m.pathnameBase])})),a,s,i);return e&&_?T.createElement(Qt.Provider,{value:{location:St({pathname:"/",search:"",hash:"",state:null,key:"default"},d),navigationType:Fe.Pop}},_):_}function fo(){let t=vo(),e=ao(t)?t.status+" "+t.statusText:t instanceof Error?t.message:JSON.stringify(t),s=t instanceof Error?t.stack:null,n={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return T.createElement(T.Fragment,null,T.createElement("h2",null,"Unexpected Application Error!"),T.createElement("h3",{style:{fontStyle:"italic"}},e),s?T.createElement("pre",{style:n},s):null,null)}const po=T.createElement(fo,null);class go extends T.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,s){return s.location!==e.location||s.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:s.error,location:s.location,revalidation:e.revalidation||s.revalidation}}componentDidCatch(e,s){console.error("React Router caught the following error during render",e,s)}render(){return this.state.error!==void 0?T.createElement(We.Provider,{value:this.props.routeContext},T.createElement(on.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function mo(t){let{routeContext:e,match:s,children:i}=t,n=T.useContext($s);return n&&n.static&&n.staticContext&&(s.route.errorElement||s.route.ErrorBoundary)&&(n.staticContext._deepestRenderedBoundaryId=s.route.id),T.createElement(We.Provider,{value:e},i)}function _o(t,e,s,i){var n;if(e===void 0&&(e=[]),s===void 0&&(s=null),i===void 0&&(i=null),t==null){var a;if(!s)return null;if(s.errors)t=s.matches;else if((a=i)!=null&&a.v7_partialHydration&&e.length===0&&!s.initialized&&s.matches.length>0)t=s.matches;else return null}let r=t,o=(n=s)==null?void 0:n.errors;if(o!=null){let d=r.findIndex(u=>u.route.id&&(o==null?void 0:o[u.route.id])!==void 0);d>=0||Z(!1),r=r.slice(0,Math.min(r.length,d+1))}let c=!1,h=-1;if(s&&i&&i.v7_partialHydration)for(let d=0;d<r.length;d++){let u=r[d];if((u.route.HydrateFallback||u.route.hydrateFallbackElement)&&(h=d),u.route.id){let{loaderData:p,errors:g}=s,x=u.route.loader&&p[u.route.id]===void 0&&(!g||g[u.route.id]===void 0);if(u.route.lazy||x){c=!0,h>=0?r=r.slice(0,h+1):r=[r[0]];break}}}return r.reduceRight((d,u,p)=>{let g,x=!1,_=null,m=null;s&&(g=o&&u.route.id?o[u.route.id]:void 0,_=u.route.errorElement||po,c&&(h<0&&p===0?(wo("route-fallback"),x=!0,m=null):h===p&&(x=!0,m=u.route.hydrateFallbackElement||null)));let v=e.concat(r.slice(0,p+1)),w=()=>{let S;return g?S=_:x?S=m:u.route.Component?S=T.createElement(u.route.Component,null):u.route.element?S=u.route.element:S=d,T.createElement(mo,{match:u,routeContext:{outlet:d,matches:v,isDataRoute:s!=null},children:S})};return s&&(u.route.ErrorBoundary||u.route.errorElement||p===0)?T.createElement(go,{location:s.location,revalidation:s.revalidation,component:_,error:g,children:w(),routeContext:{outlet:null,matches:v,isDataRoute:!0}}):w()},null)}var hn=function(t){return t.UseBlocker="useBlocker",t.UseRevalidator="useRevalidator",t.UseNavigateStable="useNavigate",t}(hn||{}),dn=function(t){return t.UseBlocker="useBlocker",t.UseLoaderData="useLoaderData",t.UseActionData="useActionData",t.UseRouteError="useRouteError",t.UseNavigation="useNavigation",t.UseRouteLoaderData="useRouteLoaderData",t.UseMatches="useMatches",t.UseRevalidator="useRevalidator",t.UseNavigateStable="useNavigate",t.UseRouteId="useRouteId",t}(dn||{});function xo(t){let e=T.useContext($s);return e||Z(!1),e}function yo(t){let e=T.useContext(oo);return e||Z(!1),e}function bo(t){let e=T.useContext(We);return e||Z(!1),e}function un(t){let e=bo(),s=e.matches[e.matches.length-1];return s.route.id||Z(!1),s.route.id}function vo(){var t;let e=T.useContext(on),s=yo(),i=un();return e!==void 0?e:(t=s.errors)==null?void 0:t[i]}function ko(){let{router:t}=xo(hn.UseNavigateStable),e=un(dn.UseNavigateStable),s=T.useRef(!1);return ln(()=>{s.current=!0}),T.useCallback(function(n,a){a===void 0&&(a={}),s.current&&(typeof n=="number"?t.navigate(n):t.navigate(n,St({fromRouteId:e},a)))},[t,e])}const fn={};function wo(t,e,s){fn[t]||(fn[t]=!0)}function jo(t,e){t==null||t.v7_startTransition,t==null||t.v7_relativeSplatPath}function So(t){let{to:e,replace:s,state:i,relative:n}=t;ct()||Z(!1);let{future:a,static:r}=T.useContext(Be),{matches:o}=T.useContext(We),{pathname:c}=ht(),h=Us(),d=Vs(e,Hs(o,a.v7_relativeSplatPath),c,n==="path"),u=JSON.stringify(d);return T.useEffect(()=>h(JSON.parse(u),{replace:s,state:i,relative:n}),[h,u,n,s,i]),null}function Ze(t){Z(!1)}function Co(t){let{basename:e="/",children:s=null,location:i,navigationType:n=Fe.Pop,navigator:a,static:r=!1,future:o}=t;ct()&&Z(!1);let c=e.replace(/^\/*/,"/"),h=T.useMemo(()=>({basename:c,navigator:a,static:r,future:St({v7_relativeSplatPath:!1},o)}),[c,o,a,r]);typeof i=="string"&&(i=Qe(i));let{pathname:d="/",search:u="",hash:p="",state:g=null,key:x="default"}=i,_=T.useMemo(()=>{let m=Bs(d,c);return m==null?null:{location:{pathname:m,search:u,hash:p,state:g,key:x},navigationType:n}},[c,d,u,p,g,x,n]);return _==null?null:T.createElement(Be.Provider,{value:h},T.createElement(Qt.Provider,{children:s,value:_}))}function Mo(t){let{children:e,location:s}=t;return ho(Gs(e),s)}new Promise(()=>{});function Gs(t,e){e===void 0&&(e=[]);let s=[];return T.Children.forEach(t,(i,n)=>{if(!T.isValidElement(i))return;let a=[...e,n];if(i.type===T.Fragment){s.push.apply(s,Gs(i.props.children,a));return}i.type!==Ze&&Z(!1),!i.props.index||!i.props.children||Z(!1);let r={id:i.props.id||a.join("-"),caseSensitive:i.props.caseSensitive,element:i.props.element,Component:i.props.Component,index:i.props.index,path:i.props.path,loader:i.props.loader,action:i.props.action,errorElement:i.props.errorElement,ErrorBoundary:i.props.ErrorBoundary,hasErrorBoundary:i.props.ErrorBoundary!=null||i.props.errorElement!=null,shouldRevalidate:i.props.shouldRevalidate,handle:i.props.handle,lazy:i.props.lazy};i.props.children&&(r.children=Gs(i.props.children,a)),s.push(r)}),s}/**
 * React Router DOM v6.30.3
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */function Ys(){return Ys=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},Ys.apply(this,arguments)}function Po(t,e){if(t==null)return{};var s={},i=Object.keys(t),n,a;for(a=0;a<i.length;a++)n=i[a],!(e.indexOf(n)>=0)&&(s[n]=t[n]);return s}function Ao(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}function Oo(t,e){return t.button===0&&(!e||e==="_self")&&!Ao(t)}const Io=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],Lo="6";try{window.__reactRouterVersion=Lo}catch{}const pn=T["startTransition"];function No(t){let{basename:e,children:s,future:i,window:n}=t,a=T.useRef();a.current==null&&(a.current=Tr({window:n,v5Compat:!0}));let r=a.current,[o,c]=T.useState({action:r.action,location:r.location}),{v7_startTransition:h}=i||{},d=T.useCallback(u=>{h&&pn?pn(()=>c(u)):c(u)},[c,h]);return T.useLayoutEffect(()=>r.listen(d),[r,d]),T.useEffect(()=>jo(i),[i]),T.createElement(Co,{basename:e,children:s,location:o.location,navigationType:o.action,navigator:r,future:i})}const To=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Eo=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Ro=T.forwardRef(function(e,s){let{onClick:i,relative:n,reloadDocument:a,replace:r,state:o,target:c,to:h,preventScrollReset:d,viewTransition:u}=e,p=Po(e,Io),{basename:g}=T.useContext(Be),x,_=!1;if(typeof h=="string"&&Eo.test(h)&&(x=h,To))try{let S=new URL(window.location.href),I=h.startsWith("//")?new URL(S.protocol+h):new URL(h),C=Bs(I.pathname,g);I.origin===S.origin&&C!=null?h=C+I.search+I.hash:_=!0}catch{}let m=lo(h,{relative:n}),v=Do(h,{replace:r,state:o,target:c,preventScrollReset:d,relative:n,viewTransition:u});function w(S){i&&i(S),S.defaultPrevented||v(S)}return T.createElement("a",Ys({},p,{href:x||m,onClick:_||a?i:w,ref:s,target:c}))});var gn;(function(t){t.UseScrollRestoration="useScrollRestoration",t.UseSubmit="useSubmit",t.UseSubmitFetcher="useSubmitFetcher",t.UseFetcher="useFetcher",t.useViewTransitionState="useViewTransitionState"})(gn||(gn={}));var mn;(function(t){t.UseFetcher="useFetcher",t.UseFetchers="useFetchers",t.UseScrollRestoration="useScrollRestoration"})(mn||(mn={}));function Do(t,e){let{target:s,replace:i,state:n,preventScrollReset:a,relative:r,viewTransition:o}=e===void 0?{}:e,c=Us(),h=ht(),d=cn(t,{relative:r});return T.useCallback(u=>{if(Oo(u,s)){u.preventDefault();let p=i!==void 0?i:Jt(h)===Jt(d);c(t,{replace:p,state:n,preventScrollReset:a,relative:r,viewTransition:o})}},[h,c,d,i,n,s,t,a,r,o])}const _n=()=>{const t=window.smartypressAIAdmin||{};let e=t.apiUrl||"smartypress/v1/";if(e.startsWith("http://")||e.startsWith("https://"))try{e=new URL(e).pathname}catch{const i=e.match(/\/wp-json\/(.+)/);i&&(e=i[1])}return e.startsWith("/wp-json/")&&(e=e.replace("/wp-json/","")),e.startsWith("/")&&(e=e.substring(1)),e.endsWith("/")||(e+="/"),{restUrl:e,nonce:t.nonce||""}},Fo=async()=>{const t=_n();return await ie({path:`/${t.restUrl}modules`})},zo=async(t,e)=>{const s=_n();return await ie({path:`/${s.restUrl}modules/${t}/toggle`,method:"POST",data:{enabled:e}})},xn=M.createContext({modules:[],routes:[],refreshModules:()=>{}});function Bo(t){return t.filter(e=>e.enabled).flatMap(e=>(e.admin_routes||[]).map(s=>({...s,module:e.id})))}function Wo({children:t}){const e=(window.smartypressAIAdmin||{}).modules||[],[s,i]=M.useState(e),n=M.useMemo(()=>Bo(s),[s]),a=M.useCallback(async()=>{try{const o=await Fo();i(o)}catch(o){console.error("ModulesContext: failed to refresh modules",o)}},[]),r=M.useMemo(()=>({modules:s,routes:n,refreshModules:a}),[s,n,a]);return l.jsx(xn.Provider,{value:r,children:t})}function Ks(){return M.useContext(xn)}var yn={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},bn=V.createContext&&V.createContext(yn),Ho=["attr","size","title"];function Vo(t,e){if(t==null)return{};var s,i,n=$o(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(i=0;i<a.length;i++)s=a[i],e.indexOf(s)===-1&&{}.propertyIsEnumerable.call(t,s)&&(n[s]=t[s])}return n}function $o(t,e){if(t==null)return{};var s={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(e.indexOf(i)!==-1)continue;s[i]=t[i]}return s}function Zt(){return Zt=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)({}).hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},Zt.apply(null,arguments)}function vn(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),s.push.apply(s,i)}return s}function es(t){for(var e=1;e<arguments.length;e++){var s=arguments[e]!=null?arguments[e]:{};e%2?vn(Object(s),!0).forEach(function(i){Uo(t,i,s[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):vn(Object(s)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(s,i))})}return t}function Uo(t,e,s){return(e=Go(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function Go(t){var e=Yo(t,"string");return typeof e=="symbol"?e:e+""}function Yo(t,e){if(typeof t!="object"||!t)return t;var s=t[Symbol.toPrimitive];if(s!==void 0){var i=s.call(t,e);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function kn(t){return t&&t.map((e,s)=>V.createElement(e.tag,es({key:s},e.attr),kn(e.child)))}function Ct(t){return e=>V.createElement(Ko,Zt({attr:es({},t.attr)},e),kn(t.child))}function Ko(t){var e=s=>{var{attr:i,size:n,title:a}=t,r=Vo(t,Ho),o=n||s.size||"1em",c;return s.className&&(c=s.className),t.className&&(c=(c?c+" ":"")+t.className),V.createElement("svg",Zt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},s.attr,i,r,{className:c,style:es(es({color:t.color||s.color},s.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),a&&V.createElement("title",null,a),t.children)};return bn!==void 0?V.createElement(bn.Consumer,null,s=>e(s)):e(yn)}function Xo(t){return Ct({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"},child:[]}]})(t)}function qo(t){return Ct({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m19 9 1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25L19 9zm-7.5.5L9 4 6.5 9.5 1 12l5.5 2.5L9 20l2.5-5.5L17 12l-5.5-2.5zM19 15l-1.25 2.75L15 19l2.75 1.25L19 23l1.25-2.75L23 19l-2.75-1.25L19 15z"},child:[]}]})(t)}function Jo(t){return Ct({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"},child:[]},{tag:"path",attr:{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"},child:[]}]})(t)}function Qo(t){return Ct({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M20.5 11H19V7c0-1.1-.9-2-2-2h-4V3.5a2.5 2.5 0 0 0-5 0V5H4c-1.1 0-1.99.9-1.99 2v3.8H3.5c1.49 0 2.7 1.21 2.7 2.7s-1.21 2.7-2.7 2.7H2V20c0 1.1.9 2 2 2h3.8v-1.5c0-1.49 1.21-2.7 2.7-2.7 1.49 0 2.7 1.21 2.7 2.7V22H17c1.1 0 2-.9 2-2v-4h1.5a2.5 2.5 0 0 0 0-5z"},child:[]}]})(t)}function Zo(t){return Ct({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z"},child:[]}]})(t)}function el({items:t,currentPath:e}){const s={dashboard:Zo,"admin-plugins":Qo,"admin-settings":Jo,"admin-generic":qo,image:Xo};return l.jsx("nav",{className:"smartypress-ai-admin-nav",children:l.jsx("ul",{className:"smartypress-ai-admin-nav-list",children:t.map(i=>{const n=e===i.path||e.startsWith(i.path+"/"),a=s[i.icon]||s["admin-generic"];return l.jsx("li",{className:`smartypress-ai-admin-nav-item ${n?"is-active":""}`,children:l.jsxs(Ro,{to:i.path,className:"smartypress-ai-admin-nav-link",title:i.description||"",children:[l.jsx(a,{className:"smartypress-ai-admin-nav-icon"}),l.jsxs("div",{className:"smartypress-ai-admin-nav-text",children:[l.jsx("span",{className:"smartypress-ai-admin-nav-label",children:i.label}),i.description&&l.jsx("span",{className:"smartypress-ai-admin-nav-description",children:i.description})]})]})},i.path)})})})}const tl=()=>l.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:l.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z",fill:"currentColor"})}),sl=()=>l.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:l.jsx("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z",fill:"currentColor"})});function il(){const{pluginName:t="SmartyPress AI",pluginVersion:e="1.0.0",pluginLogo:s=""}=window.smartypressAIAdmin||{};return l.jsx("header",{className:"smartypress-ai-header",children:l.jsxs("div",{className:"smartypress-ai-header-content",children:[s&&l.jsx("div",{className:"smartypress-ai-header-logo",children:l.jsx("img",{src:s,alt:t})}),l.jsxs("div",{className:"smartypress-ai-header-info",children:[l.jsx("h1",{className:"smartypress-ai-header-title",children:t}),l.jsxs("span",{className:"smartypress-ai-header-version",children:["v",e]})]}),l.jsxs("div",{className:"smartypress-ai-header-actions",children:[l.jsxs("a",{href:"https://wp-aifactory.com/support",target:"_blank",rel:"noopener noreferrer",className:"smartypress-ai-header-button",children:[l.jsx(tl,{}),l.jsx("span",{children:f.__("Support","smartypress-ai-engine")})]}),l.jsxs("a",{href:"https://wp-aifactory.com/step-by-step-guide-to-smartypress-free-ai-engine/",target:"_blank",rel:"noopener noreferrer",className:"smartypress-ai-header-button",children:[l.jsx(sl,{}),l.jsx("span",{children:f.__("Documentation","smartypress-ai-engine")})]})]})]})})}const nl=()=>l.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:l.jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z",fill:"currentColor"})}),al=()=>l.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:l.jsx("path",{d:"M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z",fill:"currentColor"})}),rl=()=>l.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:l.jsx("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z",fill:"currentColor"})});function ol(){const{reviewUrl:t="https://wordpress.org/support/plugin/smartypress-ai-engine/reviews/"}=window.smartypressAIAdmin||{},e=[{icon:l.jsx(nl,{}),title:f.__("Leave a Review","smartypress-ai-engine"),description:f.__("Your feedback helps us improve and helps other users discover SmartyPress AI. Share your experience and help us grow!","smartypress-ai-engine"),link:t,cta:f.__("Leave Review","smartypress-ai-engine"),isReview:!0},{icon:l.jsx(al,{}),title:f.__("Join Community","smartypress-ai-engine"),description:f.__("Connect with other users, share tips, get help, and stay updated with the latest features and updates in our Telegram community.","smartypress-ai-engine"),link:"https://t.me/wpaifactory",cta:f.__("Join Now","smartypress-ai-engine")},{icon:l.jsx(rl,{}),title:f.__("Documentation","smartypress-ai-engine"),description:f.__("Comprehensive guides, tutorials, and API documentation to help you get the most out of all SmartyPress AI features and capabilities.","smartypress-ai-engine"),link:"https://wp-aifactory.com/step-by-step-guide-to-smartypress-free-ai-engine/",cta:f.__("View Docs","smartypress-ai-engine")}];return l.jsx("footer",{className:"smartypress-ai-footer",children:l.jsx("div",{className:"smartypress-ai-footer-content",children:l.jsx("div",{className:"smartypress-ai-footer-cards",children:e.map((s,i)=>l.jsxs("a",{href:s.link,target:"_blank",rel:"noopener noreferrer",className:`smartypress-ai-footer-card${s.isReview?" smartypress-ai-footer-card-review":""}`,children:[l.jsx("div",{className:"smartypress-ai-footer-card-icon",children:s.icon}),l.jsxs("div",{className:"smartypress-ai-footer-card-content",children:[l.jsx("h3",{className:"smartypress-ai-footer-card-title",children:s.title}),l.jsx("p",{className:"smartypress-ai-footer-card-description",children:s.description}),l.jsxs("span",{className:"smartypress-ai-footer-card-cta",children:[s.cta," →"]})]})]},i))})})})}function ll({children:t}){const e=ht(),{routes:s}=Ks(),i=[{path:"/dashboard",label:f.__("Dashboard","smartypress-ai-engine"),icon:"dashboard",description:f.__("Overview and quick access to all features","smartypress-ai-engine")},...s.map(n=>({path:n.path,label:n.menu_title||n.title,icon:n.icon||"admin-generic",description:n.description||""})),{path:"/settings",label:f.__("Settings","smartypress-ai-engine"),icon:"admin-settings",description:f.__("Configure AI providers and API keys","smartypress-ai-engine")},{path:"/logs",label:f.__("Logs","smartypress-ai-engine"),icon:"list-view",description:f.__("View API error logs for debugging","smartypress-ai-engine")},{path:"/components",label:f.__("Components","smartypress-ai-engine"),icon:"admin-plugins",description:f.__("Manage and activate plugin modules","smartypress-ai-engine")}];return l.jsxs("div",{className:"smartypress-ai-admin",children:[l.jsx(il,{}),l.jsxs("div",{className:"smartypress-ai-admin-main",children:[l.jsx(el,{items:i,currentPath:e.pathname}),l.jsx("div",{className:"smartypress-ai-admin-content",children:t})]}),l.jsx(ol,{})]})}const cl={content_generator:()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-module-icon",children:[l.jsx("rect",{x:"8",y:"4",width:"28",height:"38",rx:"3",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("line",{x1:"14",y1:"12",x2:"30",y2:"12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("line",{x1:"14",y1:"19",x2:"28",y2:"19",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("line",{x1:"14",y1:"26",x2:"24",y2:"26",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("path",{d:"M34 28l-4 16-2-6-6-2 16-4z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round",fill:"currentColor",opacity:"0.15"}),l.jsx("path",{d:"M34 28l-8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),image_generator:()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-module-icon",children:[l.jsx("rect",{x:"5",y:"8",width:"38",height:"32",rx:"4",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("circle",{cx:"16",cy:"19",r:"4",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("path",{d:"M5 33l10-8 7 5 8-6 13 9",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"38",cy:"12",r:"6",fill:"currentColor",opacity:"0.12"}),l.jsx("path",{d:"M36 12h4M38 10v4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),image_alt_generator:()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-module-icon",children:[l.jsx("rect",{x:"4",y:"6",width:"28",height:"22",rx:"3",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("path",{d:"M4 22l7-5 5 3 6-4 10 6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("rect",{x:"26",y:"30",width:"18",height:"13",rx:"2",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("line",{x1:"30",y1:"35",x2:"40",y2:"35",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),l.jsx("line",{x1:"30",y1:"39",x2:"37",y2:"39",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),l.jsx("text",{x:"7",y:"17",fontSize:"9",fontWeight:"700",fill:"currentColor",opacity:"0.35",children:"ALT"})]}),seo_analysis:()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-module-icon",children:[l.jsx("circle",{cx:"22",cy:"22",r:"12",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("line",{x1:"31",y1:"31",x2:"42",y2:"42",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}),l.jsx("path",{d:"M16 25l4-6 4 3 4-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"28",cy:"17",r:"3",fill:"currentColor",opacity:"0.15"})]}),seo_optimization:()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-module-icon",children:[l.jsx("rect",{x:"6",y:"6",width:"36",height:"36",rx:"4",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("path",{d:"M14 34l6-8 6 4 8-14",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("path",{d:"M30 16h4v4",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"14",cy:"34",r:"2.5",fill:"currentColor",opacity:"0.2"}),l.jsx("circle",{cx:"20",cy:"26",r:"2.5",fill:"currentColor",opacity:"0.2"}),l.jsx("circle",{cx:"26",cy:"30",r:"2.5",fill:"currentColor",opacity:"0.2"}),l.jsx("circle",{cx:"34",cy:"16",r:"2.5",fill:"currentColor",opacity:"0.2"})]})},hl=()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-module-icon",children:[l.jsx("rect",{x:"10",y:"6",width:"28",height:"36",rx:"3",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("line",{x1:"16",y1:"14",x2:"32",y2:"14",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("line",{x1:"16",y1:"22",x2:"28",y2:"22",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("line",{x1:"16",y1:"30",x2:"24",y2:"30",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]});function dl(){const{modules:t,refreshModules:e}=Ks(),[s,i]=M.useState(t),[n,a]=M.useState(!t.length),[r,o]=M.useState({});M.useEffect(()=>{t.length&&(i(t),a(!1))},[t]),M.useEffect(()=>{t.length||e().then(()=>a(!1))},[]);const c=async(h,d)=>{try{o(u=>({...u,[h]:!0})),await zo(h,d),await e()}catch(u){console.error("Failed to toggle module:",u),alert(f.__("Failed to toggle module. Please try again.","smartypress-ai-engine"))}finally{o(u=>({...u,[h]:!1}))}};return n?l.jsx("div",{className:"smartypress-ai-components-page",children:l.jsx("div",{className:"smartypress-ai-loading",children:f.__("Loading modules...","smartypress-ai-engine")})}):l.jsxs("div",{className:"smartypress-ai-components-page",children:[l.jsxs("div",{className:"smartypress-ai-page-header",children:[l.jsx("h1",{children:f.__("Plugin Components","smartypress-ai-engine")}),l.jsx("p",{children:f.__("These are components of the plugin bundle. When you activate the plugin, all the components turned on by default. If you don't need some function, you can easily turn it off on this page.","smartypress-ai-engine")})]}),l.jsx("div",{className:"smartypress-ai-components-grid",children:s.map(h=>{const d=cl[h.id]||hl;return l.jsxs("div",{className:`smartypress-ai-component-card ${h.enabled?"is-enabled":"is-disabled"}`,children:[h.build&&l.jsx("div",{className:`smartypress-ai-component-ribbon smartypress-ai-component-ribbon-${h.build}`,children:h.build}),l.jsx("div",{className:"smartypress-ai-component-icon-wrap",children:l.jsx(d,{})}),l.jsx("h3",{className:"smartypress-ai-component-title",children:h.name}),l.jsx("p",{className:"smartypress-ai-component-description",children:h.description||f.__("No description available.","smartypress-ai-engine")}),l.jsx("div",{className:"smartypress-ai-component-footer",children:l.jsx("button",{className:`smartypress-ai-component-btn ${h.enabled?"is-active":""}`,onClick:()=>c(h.id,!h.enabled),disabled:r[h.id],children:r[h.id]?f.__("Processing...","smartypress-ai-engine"):h.enabled?f.__("Deactivate","smartypress-ai-engine"):f.__("Activate","smartypress-ai-engine")})})]},h.id)})})]})}const Xs=()=>{const t=window.smartypressAIAdmin||{};let e=t.apiUrl||"smartypress/v1/";if(e.startsWith("http://")||e.startsWith("https://"))try{e=new URL(e).pathname}catch{const i=e.match(/\/wp-json\/(.+)/);i&&(e=i[1])}return e.startsWith("/wp-json/")&&(e=e.replace("/wp-json/","")),e.startsWith("/")&&(e=e.substring(1)),e.endsWith("/")||(e+="/"),{restUrl:e,nonce:t.nonce||""}},wn=async()=>{const t=Xs();return await ie({path:`/${t.restUrl}settings`})},qs=async t=>{const e=Xs();return await ie({path:`/${e.restUrl}settings`,method:"POST",data:t})},ul=async t=>{var s;const e=Xs();try{return await ie({path:`/${e.restUrl}settings/test-provider`,method:"POST",data:{provider:t}})}catch(i){throw(s=i==null?void 0:i.data)!=null&&s.message?new Error(i.data.message):i}},fl=({label:t,value:e,options:s=[],onChange:i,className:n="",placeholder:a="",ariaLabel:r=""})=>{const o=M.useRef(null),c=M.useRef(null),h=M.useMemo(()=>s.find(P=>P.value===e)||null,[s,e]),d=h?h.label:"",[u,p]=M.useState(!1),[g,x]=M.useState("");M.useEffect(()=>{const P=L=>{!o.current||o.current.contains(L.target)||(p(!1),x(""))};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[]);const _=M.useMemo(()=>{const P=g.trim().toLowerCase();return P?s.filter(L=>{const N=String(L.label||"").toLowerCase(),R=String(L.value||"").toLowerCase();return N.includes(P)||R.includes(P)}):s},[s,g]),m=P=>{i(P.value),x(""),p(!1),c.current&&c.current.blur()},v=()=>{p(!0),x("")},w=P=>{x(P.target.value),p(!0)},S=P=>{if(P.key==="Escape"){p(!1),x(""),c.current&&c.current.blur();return}P.key==="Enter"&&_.length>0&&(P.preventDefault(),m(_[0])),P.key==="ArrowDown"&&!u&&(P.preventDefault(),p(!0),x(""))},I=u?g:d,C=u&&d||a;return l.jsx("div",{ref:o,className:`components-base-control smartypress-searchable-select-control ${n}`.trim(),children:l.jsxs("div",{className:"components-base-control__field",children:[t&&l.jsx("label",{className:"components-base-control__label",children:t}),l.jsxs("div",{className:"smartypress-searchable-select-control__field",children:[l.jsx("input",{ref:c,className:"components-text-control__input smartypress-searchable-select-control__input",type:"text",value:I,"aria-label":r||t,"aria-expanded":u,"aria-haspopup":"listbox",role:"combobox",autoComplete:"off",placeholder:C,onFocus:v,onChange:w,onKeyDown:S}),l.jsx("span",{className:"smartypress-searchable-select-control__chevron","aria-hidden":"true"}),u&&_.length>0&&l.jsx("div",{className:"smartypress-searchable-select-control__list",role:"listbox",children:_.map(P=>l.jsx("button",{type:"button",role:"option","aria-selected":P.value===e,className:`smartypress-searchable-select-control__option${P.value===e?" is-selected":""}`,onMouseDown:L=>L.preventDefault(),onClick:()=>m(P),children:P.label},P.value))})]})]})})},dt="provider_connection_status",Js={writing_tone:"neutral",writing_style:"informative",number_of_sections:"3",paragraphs_per_section:"3"},Qs=Object.keys(Js),jn=t=>`{${String(t||"").trim().replace(/[^a-zA-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}}`,ts=t=>String(t||"").trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"");function pl(){var kt;const[t,e]=M.useState({}),[s,i]=M.useState(!0),[n,a]=M.useState(!1),[r,o]=M.useState(!1),[c,h]=M.useState(""),[d,u]=M.useState(null),[p,g]=M.useState({}),[x,_]=M.useState({type:"",text:""}),[m,v]=M.useState({}),[w,S]=M.useState({}),[I,C]=M.useState([]),[P,L]=M.useState("general"),[N,R]=M.useState({key:"",value:""}),B=["post","page","product"],z=((kt=window.smartypressAIAdmin)==null?void 0:kt.isRuLocale)||!1,D=y=>!!(y&&(y.startsWith("***")||y.trim().length>0)),k=[{id:"openai",label:"OpenAI",icon:"AI",description:f.__("Configure OpenAI API credentials. You can select the model when generating content.","smartypress-ai-engine"),links:[{href:"https://platform.openai.com/api-keys",label:f.__("Get your API key from OpenAI Platform","smartypress-ai-engine")},{href:"https://platform.openai.com/docs/guides/authentication",label:f.__("View instructions","smartypress-ai-engine")}],isAvailable:!0,isConfigured:()=>D(t.openai_api_key),credentialKeys:["openai_api_key"],testDisabled:()=>!1},{id:"deepseek",label:"Deepseek",icon:"DS",description:f.__("Configure Deepseek API credentials. You can select the model when generating content.","smartypress-ai-engine"),links:[{href:"https://platform.deepseek.com/api_keys",label:f.__("Get your API key from Deepseek Platform","smartypress-ai-engine")},{href:"https://platform.deepseek.com/docs",label:f.__("View documentation","smartypress-ai-engine")}],isAvailable:!0,isConfigured:()=>D(t.deepseek_api_key),credentialKeys:["deepseek_api_key"],testDisabled:()=>!1},{id:"anthropic",label:"Claude",icon:"CL",description:f.__("Configure Anthropic Claude API credentials. Claude supports text generation, JSON workflows, and image analysis for ALT metadata.","smartypress-ai-engine"),links:[{href:"https://console.anthropic.com/settings/keys",label:f.__("Get your API key from Anthropic Console","smartypress-ai-engine")},{href:"https://docs.claude.com/en/api/messages",label:f.__("View Messages API documentation","smartypress-ai-engine")}],isAvailable:!0,isConfigured:()=>D(t.anthropic_api_key),credentialKeys:["anthropic_api_key"],testDisabled:()=>!1},{id:"openrouter",label:"OpenRouter",icon:"OR",description:f.__("Configure OpenRouter as a single API key gateway to OpenAI, Anthropic, Google, DeepSeek, and other models.","smartypress-ai-engine"),links:[{href:"https://openrouter.ai/keys",label:f.__("Get your API key from OpenRouter","smartypress-ai-engine")},{href:"https://openrouter.ai/models",label:f.__("Browse OpenRouter models","smartypress-ai-engine")}],isAvailable:!0,isConfigured:()=>D(t.openrouter_api_key),credentialKeys:["openrouter_api_key"],testDisabled:()=>!1},{id:"yandex",label:"Yandex",icon:"YA",description:f.__("Configure Yandex Cloud credentials for YandexGPT (text) and YandexART (images).","smartypress-ai-engine"),links:[{href:"https://yandex.cloud/ru/docs/iam/operations/api-key/create",label:f.__("Create a service account API key","smartypress-ai-engine")},{href:"https://yandex.cloud/ru/docs/foundation-models/security/",label:f.__("View Yandex AI Studio access documentation","smartypress-ai-engine")}],isAvailable:z,isConfigured:()=>D(t.yandex_api_key)&&!!t.yandex_folder_id,credentialKeys:["yandex_api_key","yandex_folder_id"],testDisabled:()=>!t.yandex_folder_id},{id:"gigachat",label:"GigaChat",icon:"GC",description:f.__("Configure GigaChat (Sber) credentials for text and image generation.","smartypress-ai-engine"),links:[{href:"https://developers.sber.ru/studio/workspaces/",label:f.__("Get credentials","smartypress-ai-engine")},{href:"https://developers.sber.ru/docs/ru/gigachat/api/overview",label:f.__("View documentation","smartypress-ai-engine")}],isAvailable:z,isConfigured:()=>D(t.gigachat_auth_key),credentialKeys:["gigachat_auth_key","gigachat_base_url"],testDisabled:()=>!t.gigachat_auth_key}].filter(y=>y.isAvailable),F=k.filter(y=>y.isConfigured()).map(y=>({value:y.id,label:y.label}));M.useEffect(()=>{_e()},[]),M.useEffect(()=>{if(!s&&F.length>0){const y=t.default_provider;F.some(A=>A.value===y)||X("default_provider",F[0].value)}},[t.openai_api_key,t.deepseek_api_key,t.anthropic_api_key,t.openrouter_api_key,t.yandex_api_key,t.yandex_folder_id,t.gigachat_auth_key,t.gigachat_base_url,s]);const W=y=>{var j;return!!((j=t[dt])!=null&&j[y])},Q=y=>k.find(j=>j.id===y),se=(y,j,A=t)=>({...A[dt]||{},[y]:j}),we=y=>{const j=y==="image"?"openrouter_enabled_image_models":"openrouter_enabled_text_models";return Array.isArray(t[j])?t[j]:[]},je=y=>t[y==="image"?"openrouter_limit_image_models":"openrouter_limit_text_models"]===!0,Se=(y,j)=>{if(!je(j))return y;const A=we(j);return A.length?Object.fromEntries(Object.entries(y||{}).filter(([O])=>A.includes(O))):y},_e=async()=>{try{i(!0);const y=await wn();e(y),await Promise.all([xe(),ue(),de()])}catch(y){console.error("Failed to load settings:",y),_({type:"error",text:f.__("Failed to load settings.","smartypress-ai-engine")})}finally{i(!1)}},xe=async()=>{var y,j;try{const A=await fetch(`${((y=window.smartypressAIAdmin)==null?void 0:y.apiUrl)||"/wp-json/smartypress/v1/"}provider-models`,{headers:{"X-WP-Nonce":((j=window.smartypressAIAdmin)==null?void 0:j.nonce)||""}});if(A.ok){const O=await A.json();v(O)}}catch(A){console.error("Failed to load provider models:",A)}},de=async()=>{var y,j;try{const A=await fetch(`${((y=window.smartypressAIAdmin)==null?void 0:y.apiUrl)||"/wp-json/smartypress/v1/"}post-types`,{headers:{"X-WP-Nonce":((j=window.smartypressAIAdmin)==null?void 0:j.nonce)||""}});if(A.ok){const O=await A.json();C(O)}}catch(A){console.error("Failed to load post types:",A)}},ue=async()=>{var y,j;try{const A=await fetch(`${((y=window.smartypressAIAdmin)==null?void 0:y.apiUrl)||"/wp-json/smartypress/v1/"}openrouter-image-models`,{headers:{"X-WP-Nonce":((j=window.smartypressAIAdmin)==null?void 0:j.nonce)||""}});if(A.ok){const O=await A.json();S({openrouter:O||{}})}}catch(A){console.error("Failed to load image models:",A)}},ye=async()=>{try{const y=await wn(),j=[];D(y.openai_api_key)&&j.push("openai"),D(y.deepseek_api_key)&&j.push("deepseek"),D(y.anthropic_api_key)&&j.push("anthropic"),D(y.openrouter_api_key)&&j.push("openrouter"),z&&D(y.yandex_api_key)&&y.yandex_folder_id&&j.push("yandex"),z&&D(y.gigachat_auth_key)&&j.push("gigachat");const A=z?["openai","deepseek","anthropic","openrouter","yandex","gigachat"]:["openai","deepseek","anthropic","openrouter"],O=j.length>0?j:A;window.smartypressAISingle&&(window.smartypressAISingle.providers=O,window.smartypressAISingle.providerModels=m,window.smartypressAISingle.settings={...window.smartypressAISingle.settings,...y,default_provider:y.default_provider||O[0]}),window.smartypressAIBulk&&(window.smartypressAIBulk.providers=O,window.smartypressAIBulk.providerModels=m,window.smartypressAIBulk.settings={...window.smartypressAIBulk.settings,...y,default_provider:y.default_provider||O[0]}),window.smartypressAI&&(window.smartypressAI.providers=O),window.dispatchEvent(new CustomEvent("smartypressAISettingsUpdated",{detail:{settings:y,providers:O}}))}catch(y){console.error("Failed to update global providers:",y)}},ne=async()=>{try{a(!0),_({type:"",text:""}),await qs(t),await ye(),_({type:"success",text:f.__("Settings saved successfully.","smartypress-ai-engine")})}catch(y){console.error("Failed to save settings:",y),_({type:"error",text:f.__("Failed to save settings.","smartypress-ai-engine")})}finally{a(!1)}},X=(y,j)=>{const A=k.find(O=>O.credentialKeys.includes(y));e(O=>{const U={...O,[y]:j};return A&&(U[dt]=se(A.id,!1,O)),U}),A&&u(null)},Le=(y,j)=>{const A=t.enabled_post_types||B,O=j?[...A,y]:A.filter(U=>U!==y);X("enabled_post_types",O)},bt=(y,j)=>{const A=ts(y);A&&X("prompt_variables",{...Js,...t.prompt_variables||{},[A]:j})},vt=()=>({...Js,...t.prompt_variables||{}}),Gt=()=>{const y=ts(N.key);!y||Qs.includes(y)||(bt(y,N.value),R({key:"",value:""}))},Ls=y=>{const j=ts(y);if(!j||Qs.includes(j))return;const A={...vt()};delete A[j],X("prompt_variables",A)},Ei=y=>(t.enabled_post_types||B).includes(y),Yt=()=>{const y=t.default_provider;if(!y||!m[y])return[];const j=y==="openrouter"?Se(m[y],"text"):m[y];return Object.entries(j).map(([A,O])=>{const U=typeof O=="string"?O:O.name||A;let re=U!==A?`${U} (${A})`:U;return O.expensive&&(re+=" 💰"),O.reasoning&&(re+=" 🧠"),{value:A,label:re}})},Ns=()=>{const y=t.default_provider;return y==="openai"?"openai_model":y==="deepseek"?"deepseek_model":y==="anthropic"?"anthropic_model":y==="openrouter"?"openrouter_model":y==="yandex"?"yandex_model":y==="gigachat"?"gigachat_model":"default_model"},Ts=y=>{X("default_provider",y);const j=m[y];if(j){const O={openai:"openai_model",deepseek:"deepseek_model",anthropic:"anthropic_model",openrouter:"openrouter_model",yandex:"yandex_model",gigachat:"gigachat_model"}[y]||"default_model";X(O,Object.keys(j)[0]||"")}},Ri=y=>{h(y),u(null),_({type:"",text:""})},Di=()=>{h(""),u(null)},Fi=async y=>{var A;if(Q(y))try{o(!0),g(Je=>({...Je,[y]:!0})),u({type:"loading",text:f.__("Testing provider connection...","smartypress-ai-engine")}),_({type:"",text:""});const O={...t,[dt]:se(y,!1)};await qs(O),await ye();const U=await ul(y);if(!(U!=null&&U.success))throw new Error((U==null?void 0:U.message)||f.__(`Provider ${y} test failed.`,"smartypress-ai-engine"));const re={...O,[dt]:se(y,!0,O)};await qs(re),await ye(),e(re),u({type:"success",text:U.message||f.__("Provider connection successful.","smartypress-ai-engine")}),_({type:"success",text:U.message||f.__("Provider connection successful.","smartypress-ai-engine")}),window.setTimeout(()=>{h(""),u(null)},1200)}catch(O){console.error("Provider save or test failed:",O);const U=(O==null?void 0:O.message)||((A=O==null?void 0:O.data)==null?void 0:A.message)||f.__("Provider test failed.","smartypress-ai-engine"),re={...t,[dt]:se(y,!1)};e(re),u({type:"error",text:U}),_({type:"error",text:U})}finally{o(!1),g(O=>({...O,[y]:!1}))}},zi=y=>l.jsxs("p",{className:"description",children:[y.description," ",y.links.map((j,A)=>l.jsxs("span",{children:[A>0&&" ",l.jsx("a",{href:j.href,target:"_blank",rel:"noopener noreferrer",children:j.label}),A<y.links.length-1?".":""]},j.href))]}),Bi=()=>{var y;return l.jsx("table",{className:"form-table",children:l.jsxs("tbody",{children:[l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"openai_api_key",children:f.__("API Key","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"password",id:"openai_api_key",className:"regular-text",autoComplete:"new-password",value:t.openai_api_key||"",onChange:j=>X("openai_api_key",j.target.value),placeholder:(y=t.openai_api_key)!=null&&y.startsWith("***")?t.openai_api_key:f.__("Enter your OpenAI API key","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Your OpenAI API key. Keep it secure and never share it publicly.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"openai_use_proxy",children:f.__("Use Proxy","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",id:"openai_use_proxy",checked:t.openai_use_proxy||!1,onChange:j=>X("openai_use_proxy",j.target.checked)}),f.__("Enable proxy for OpenAI API requests","smartypress-ai-engine")]}),l.jsx("p",{className:"description",children:f.__("Use a proxy server to connect to OpenAI API. Useful if OpenAI is blocked in your region.","smartypress-ai-engine")})]})]}),t.openai_use_proxy&&l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"openai_proxy_url",children:f.__("Proxy URL","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"text",id:"openai_proxy_url",className:"regular-text",autoComplete:"off",value:t.openai_proxy_url||"",onChange:j=>X("openai_proxy_url",j.target.value),placeholder:"socks5://user:pass@ip:port"}),l.jsx("p",{className:"description",children:f.__("Format: socks5://USER:PASSWORD@ip:port or http://ip:port","smartypress-ai-engine")})]})]})]})})},Wi=()=>{var y;return l.jsx("table",{className:"form-table",children:l.jsx("tbody",{children:l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"deepseek_api_key",children:f.__("API Key","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"password",id:"deepseek_api_key",className:"regular-text",autoComplete:"new-password",value:t.deepseek_api_key||"",onChange:j=>X("deepseek_api_key",j.target.value),placeholder:(y=t.deepseek_api_key)!=null&&y.startsWith("***")?t.deepseek_api_key:f.__("Enter your Deepseek API key","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Your Deepseek API key. Keep it secure and never share it publicly.","smartypress-ai-engine")})]})]})})})},Es=()=>{var y;return l.jsx("table",{className:"form-table",children:l.jsx("tbody",{children:l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"anthropic_api_key",children:f.__("API Key","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"password",id:"anthropic_api_key",className:"regular-text",autoComplete:"new-password",value:t.anthropic_api_key||"",onChange:j=>X("anthropic_api_key",j.target.value),placeholder:(y=t.anthropic_api_key)!=null&&y.startsWith("***")?t.anthropic_api_key:f.__("Enter your Anthropic API key","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Your Anthropic API key for Claude. Keep it secure and never share it publicly.","smartypress-ai-engine")})]})]})})})},Ce=y=>y?Object.entries(y).map(([j,A])=>({value:j,label:typeof A=="string"?A:A.name||j})):[],Hi=(y,j,A)=>{const O=y==="image"?"openrouter_enabled_image_models":"openrouter_enabled_text_models",U=Array.isArray(t[O])?t[O]:[],re=A?[...new Set([...U,j])]:U.filter(Je=>Je!==j);X(O,re)},Rs=(y,j)=>{const A=we(y),O=je(y),U=y==="image"?"openrouter_limit_image_models":"openrouter_limit_text_models",re=y==="image"?f.__("Limit available image models","smartypress-ai-engine"):f.__("Limit available text models","smartypress-ai-engine"),Je=y==="image"?f.__("When disabled, all loaded OpenRouter image models are available. Enable this only if you want to restrict image generation to selected models.","smartypress-ai-engine"):f.__("When disabled, all loaded OpenRouter text models are available. Enable this only if you want to restrict text generation to selected models.","smartypress-ai-engine"),Xi=y==="image"?f.__("No image models loaded yet. Save the OpenRouter key and reload this page if the full list is not available.","smartypress-ai-engine"):f.__("No text models loaded yet. Save the OpenRouter key and reload this page if the full list is not available.","smartypress-ai-engine");return l.jsxs("div",{className:"smartypress-openrouter-model-limit",children:[l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:O,onChange:wt=>X(U,wt.target.checked)}),re]}),l.jsx("p",{className:"description",children:Je}),O&&!j.length&&l.jsx("p",{className:"description",children:Xi}),O&&j.length>0&&l.jsx("div",{className:"smartypress-post-types-list smartypress-openrouter-models-list",children:j.map(wt=>l.jsxs("label",{className:"smartypress-post-type-item",children:[l.jsx("input",{type:"checkbox",checked:A.includes(wt.value),onChange:Nu=>Hi(y,wt.value,Nu.target.checked)}),l.jsx("span",{children:wt.label})]},wt.value))})]})},ae=(y,j)=>{const A=we(y);return je(y)?A.length?f.sprintf(f.__("Restricted to %1$d of %2$d loaded models.","smartypress-ai-engine"),A.length,j.length):f.__("Restriction is enabled, but no models are selected.","smartypress-ai-engine"):f.__("All loaded models are available.","smartypress-ai-engine")},Ds=(y,j)=>l.jsx("p",{className:"description",children:ae(y,j)}),Vi=()=>{var Je;const y={"openai/gpt-4o-mini":{name:"GPT-4o Mini"},"anthropic/claude-sonnet-4":{name:"Claude Sonnet 4"},"google/gemini-2.5-flash":{name:"Gemini 2.5 Flash"}},j={"google/gemini-2.5-flash-image":{name:"Gemini 2.5 Flash Image"},"black-forest-labs/flux.2-pro":{name:"FLUX.2 Pro"},"black-forest-labs/flux.2-flex":{name:"FLUX.2 Flex"}},A=m.openrouter&&Object.keys(m.openrouter).length?m.openrouter:y,O=w.openrouter&&Object.keys(w.openrouter).length?w.openrouter:j,U=Ce(A),re=Ce(O);return l.jsx("table",{className:"form-table",children:l.jsxs("tbody",{children:[l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"openrouter_api_key",children:f.__("API Key","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"password",id:"openrouter_api_key",className:"regular-text",autoComplete:"new-password",value:t.openrouter_api_key||"",onChange:Xi=>X("openrouter_api_key",Xi.target.value),placeholder:(Je=t.openrouter_api_key)!=null&&Je.startsWith("***")?t.openrouter_api_key:f.__("Enter your OpenRouter API key","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("One OpenRouter key can route requests to OpenAI, Anthropic, Google, DeepSeek, and other models.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{children:f.__("Text Models","smartypress-ai-engine")})}),l.jsxs("td",{children:[Rs("text",U),Ds("text",U),l.jsx("p",{className:"description",children:f.__("Use this only when you want to hide specific OpenRouter text models from generation screens.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{children:f.__("Image Models","smartypress-ai-engine")})}),l.jsxs("td",{children:[Rs("image",re),Ds("image",re),l.jsx("p",{className:"description",children:f.__("Use this only when you want to hide specific OpenRouter image models from image generation screens.","smartypress-ai-engine")})]})]})]})})},$i=()=>{var y;return l.jsx("table",{className:"form-table",children:l.jsxs("tbody",{children:[l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"yandex_api_key",children:f.__("API Key","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"password",id:"yandex_api_key",className:"regular-text",autoComplete:"new-password",value:t.yandex_api_key||"",onChange:j=>X("yandex_api_key",j.target.value),placeholder:(y=t.yandex_api_key)!=null&&y.startsWith("***")?t.yandex_api_key:f.__("Enter your Yandex API key","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Use a Yandex Cloud service account API key with permission to execute Foundation Models requests. The key is sent as Authorization: Api-Key.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"yandex_folder_id",children:f.__("Folder ID","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"text",id:"yandex_folder_id",className:"regular-text",autoComplete:"off",value:t.yandex_folder_id||"",onChange:j=>X("yandex_folder_id",j.target.value),placeholder:f.__("Enter your Yandex Cloud Folder ID","smartypress-ai-engine")}),l.jsxs("p",{className:"description",children:[f.__("Folder ID in Yandex Cloud where AI requests will be executed. Find it in","smartypress-ai-engine")," ",l.jsx("a",{href:"https://console.cloud.yandex.ru/",target:"_blank",rel:"noopener noreferrer",children:f.__("Yandex Cloud Console","smartypress-ai-engine")}),"."]})]})]})]})})},Ui=()=>{var y;return l.jsx("table",{className:"form-table",children:l.jsxs("tbody",{children:[l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"gigachat_auth_key",children:f.__("Authorization Key","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("input",{type:"password",id:"gigachat_auth_key",className:"regular-text",autoComplete:"new-password",value:t.gigachat_auth_key||"",onChange:j=>X("gigachat_auth_key",j.target.value),placeholder:(y=t.gigachat_auth_key)!=null&&y.startsWith("***")?t.gigachat_auth_key:f.__("Enter your Authorization Key","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Copy the Authorization Key from Sber AI Studio when creating a project.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"gigachat_scope",children:f.__("API Scope","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsxs("select",{id:"gigachat_scope",value:t.gigachat_scope||"GIGACHAT_API_PERS",onChange:j=>X("gigachat_scope",j.target.value),children:[l.jsx("option",{value:"GIGACHAT_API_PERS",children:f.__("Personal (PERS)","smartypress-ai-engine")}),l.jsx("option",{value:"GIGACHAT_API_B2B",children:f.__("Business (B2B)","smartypress-ai-engine")}),l.jsx("option",{value:"GIGACHAT_API_CORP",children:f.__("Corporate (CORP)","smartypress-ai-engine")})]}),l.jsx("p",{className:"description",children:f.__("Select the API access level matching your GigaChat subscription.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"gigachat_base_url",children:f.__("API Endpoint","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsxs("select",{id:"gigachat_base_url",value:t.gigachat_base_url||"https://gigachat.devices.sberbank.ru/api/v1",onChange:j=>X("gigachat_base_url",j.target.value),children:[l.jsx("option",{value:"https://gigachat.devices.sberbank.ru/api/v1",children:f.__("Main endpoint","smartypress-ai-engine")}),l.jsx("option",{value:"https://api.giga.chat/v1",children:f.__("Salut for Business endpoint","smartypress-ai-engine")})]}),l.jsx("p",{className:"description",children:f.__("Choose the GigaChat API base endpoint. OAuth token requests always use the official Sber OAuth endpoint.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"gigachat_verify_ssl",children:f.__("SSL Verification","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",id:"gigachat_verify_ssl",checked:t.gigachat_verify_ssl===!0,onChange:j=>X("gigachat_verify_ssl",j.target.checked)}),f.__("Verify SSL certificate","smartypress-ai-engine")]}),l.jsx("p",{className:"description",children:f.__("Enable only if you have Russian CA certificates installed. Disabled by default.","smartypress-ai-engine")})]})]})]})})},Gi=y=>y==="openai"?Bi():y==="deepseek"?Wi():y==="anthropic"?Es():y==="openrouter"?Vi():y==="yandex"?$i():y==="gigachat"?Ui():null,Yi=()=>l.jsxs("div",{className:"smartypress-ai-settings-section smartypress-ai-providers-section",children:[l.jsx("h2",{children:f.__("AI Providers","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Choose a provider to configure credentials. Connected providers are highlighted and can be selected as the default provider below.","smartypress-ai-engine")}),l.jsx("div",{className:"smartypress-ai-provider-grid",children:k.map(y=>{const j=W(y.id),A=c===y.id,O=["smartypress-ai-provider-card",j?"is-connected":"is-disconnected",A?"is-active":""].filter(Boolean).join(" ");return l.jsxs("button",{type:"button",className:O,"aria-pressed":A,onClick:()=>Ri(y.id),children:[l.jsx("span",{className:"smartypress-ai-provider-card__status","aria-hidden":"true",children:"✓"}),l.jsx("span",{className:"smartypress-ai-provider-card__icon","aria-hidden":"true",children:y.icon}),l.jsx("span",{className:"smartypress-ai-provider-card__title",children:y.label}),l.jsx("span",{className:"smartypress-ai-provider-card__meta",children:j?f.__("Connected","smartypress-ai-engine"):f.__("Not connected","smartypress-ai-engine")})]},y.id)})})]}),Ki=()=>{const y=Q(c);if(!y)return null;const j=p[y.id],A=r||j||!y.isConfigured()||y.testDisabled();return l.jsxs("div",{className:"smartypress-ai-provider-panel",children:[l.jsxs("div",{className:"smartypress-ai-provider-panel__header",children:[l.jsx("button",{type:"button",className:"button smartypress-ai-provider-panel__back",onClick:Di,disabled:r||j,children:f.__("Back","smartypress-ai-engine")}),l.jsxs("div",{children:[l.jsx("h2",{children:y.label}),zi(y)]})]}),(d==null?void 0:d.type)==="loading"?l.jsxs("div",{className:"smartypress-ai-provider-testing",role:"status","aria-live":"polite",children:[l.jsx("span",{className:"smartypress-ai-provider-testing__spinner","aria-hidden":"true"}),l.jsx("h3",{children:f.__("Testing connection","smartypress-ai-engine")}),l.jsx("p",{children:d.text})]}):l.jsxs(l.Fragment,{children:[Gi(y.id),d&&l.jsxs("div",{className:`smartypress-ai-provider-result is-${d.type}`,role:"status","aria-live":"polite",children:[l.jsx("span",{"aria-hidden":"true",children:d.type==="success"?"✓":"!"}),l.jsx("p",{children:d.text})]}),l.jsx("p",{className:"submit smartypress-ai-provider-panel__actions",children:l.jsx("button",{type:"button",className:"button button-primary",onClick:()=>Fi(y.id),disabled:A,children:r?f.__("Saving...","smartypress-ai-engine"):f.__("Save Provider Settings","smartypress-ai-engine")})})]})]})},Kt=Yt(),Fs=Ns(),b=()=>{var y,j;return l.jsxs(l.Fragment,{children:[Yi(),l.jsxs("div",{className:"smartypress-ai-settings-section",children:[l.jsx("h2",{children:f.__("General Settings","smartypress-ai-engine")}),l.jsx("table",{className:"form-table",children:l.jsxs("tbody",{children:[l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"default_provider",children:f.__("Default Provider","smartypress-ai-engine")})}),l.jsx("td",{children:F.length>0?l.jsxs(l.Fragment,{children:[l.jsx("select",{id:"default_provider",value:t.default_provider||((y=F[0])==null?void 0:y.value)||"",onChange:A=>Ts(A.target.value),children:F.map(A=>l.jsx("option",{value:A.value,children:A.label},A.value))}),l.jsx("p",{className:"description",children:f.__("Select the default AI provider to use when generating content. You can override this for individual requests.","smartypress-ai-engine")})]}):l.jsx("p",{className:"description",style:{color:"#d63638"},children:f.__("Please configure at least one API key above to select a default provider.","smartypress-ai-engine")})})]}),Kt.length>0&&l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"default_model",children:f.__("Default Model","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx(fl,{label:"",ariaLabel:f.__("Default Model","smartypress-ai-engine"),className:"smartypress-default-model-control",value:t[Fs]||((j=Kt[0])==null?void 0:j.value)||"",options:Kt,onChange:A=>X(Fs,A)}),l.jsx("p",{className:"description",children:f.__("Select the default model for the selected provider. 💰 = expensive, 🧠 = reasoning model.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"default_language",children:f.__("Default Language","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsxs("select",{id:"default_language",value:t.default_language??"",onChange:A=>X("default_language",A.target.value),children:[l.jsx("option",{value:"",children:f.__("Use site language","smartypress-ai-engine")}),l.jsx("option",{value:"English",children:"English"}),l.jsx("option",{value:"Russian",children:"Russian"}),l.jsx("option",{value:"German",children:"German"}),l.jsx("option",{value:"French",children:"French"}),l.jsx("option",{value:"Spanish",children:"Spanish"}),l.jsx("option",{value:"Italian",children:"Italian"}),l.jsx("option",{value:"Portuguese",children:"Portuguese"}),l.jsx("option",{value:"Chinese",children:"Chinese"}),l.jsx("option",{value:"Japanese",children:"Japanese"}),l.jsx("option",{value:"Korean",children:"Korean"}),l.jsx("option",{value:"Arabic",children:"Arabic"}),l.jsx("option",{value:"Dutch",children:"Dutch"}),l.jsx("option",{value:"Polish",children:"Polish"}),l.jsx("option",{value:"Turkish",children:"Turkish"}),l.jsx("option",{value:"Ukrainian",children:"Ukrainian"}),l.jsx("option",{value:"Hindi",children:"Hindi"}),l.jsx("option",{value:"Indonesian",children:"Indonesian"}),l.jsx("option",{value:"Vietnamese",children:"Vietnamese"})]}),l.jsx("p",{className:"description",children:f.__("Select the default language for AI-generated content. This will be used for Magic Wand and content generation unless overridden.","smartypress-ai-engine")})]})]}),l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{children:f.__("Enabled Post Types","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsx("div",{className:"smartypress-post-types-list",children:I.map(A=>l.jsxs("label",{className:"smartypress-post-type-item",children:[l.jsx("input",{type:"checkbox",checked:Ei(A.name),onChange:O=>Le(A.name,O.target.checked)}),l.jsx("span",{children:A.label})]},A.name))}),l.jsx("p",{className:"description",children:f.__("Select which post types should have AI features enabled. Posts, Pages, and Products are enabled by default.","smartypress-ai-engine")})]})]})]})})]}),Me()]})},E=()=>{const y=vt(),j=[{key:"writing_tone",label:f.__("Writing Tone","smartypress-ai-engine"),type:"text",description:f.__("Used for {WRITING_TONE}. Example: neutral, formal, friendly, expert.","smartypress-ai-engine")},{key:"writing_style",label:f.__("Writing Style","smartypress-ai-engine"),type:"text",description:f.__("Used for {WRITING_STYLE}. Example: informative, descriptive, persuasive.","smartypress-ai-engine")},{key:"number_of_sections",label:f.__("Number of Sections","smartypress-ai-engine"),type:"number",description:f.__("Used for {NUMBER_OF_SECTIONS}. {SECTIONS_COUNT} is an alias for the same value.","smartypress-ai-engine")},{key:"paragraphs_per_section",label:f.__("Paragraphs per Section","smartypress-ai-engine"),type:"number",description:f.__("Used for {PARAGRAPHS_PER_SECTION}.","smartypress-ai-engine")}],A=Object.entries(y).filter(([O])=>!Qs.includes(O));return l.jsxs("div",{className:"smartypress-ai-settings-section",children:[l.jsx("h2",{children:f.__("Available Variables","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Configure reusable prompt variable values. These values are inserted into prompt templates when AI requests are generated.","smartypress-ai-engine")}),l.jsxs("div",{className:"smartypress-prompt-variables",children:[j.map(O=>l.jsxs("div",{className:"smartypress-prompt-variable-row is-standard",children:[l.jsxs("div",{className:"smartypress-prompt-variable-row__key",children:[l.jsx("label",{htmlFor:`prompt_variable_${O.key}`,children:O.label}),l.jsx("code",{children:jn(O.key)})]}),l.jsxs("div",{className:"smartypress-prompt-variable-row__value",children:[l.jsx("input",{type:O.type,min:O.type==="number"?"1":void 0,id:`prompt_variable_${O.key}`,value:y[O.key]??"",onChange:U=>bt(O.key,U.target.value)}),l.jsx("p",{className:"description",children:O.description})]})]},O.key)),A.map(([O,U])=>l.jsxs("div",{className:"smartypress-prompt-variable-row",children:[l.jsxs("div",{className:"smartypress-prompt-variable-row__key",children:[l.jsx("label",{htmlFor:`prompt_variable_${O}`,children:O}),l.jsx("code",{children:jn(O)})]}),l.jsx("div",{className:"smartypress-prompt-variable-row__value",children:l.jsx("input",{type:"text",id:`prompt_variable_${O}`,value:U,onChange:re=>bt(O,re.target.value)})}),l.jsx("button",{type:"button",className:"button smartypress-prompt-variable-row__remove",onClick:()=>Ls(O),children:f.__("Remove","smartypress-ai-engine")})]},O)),l.jsxs("div",{className:"smartypress-prompt-variable-row smartypress-prompt-variable-row--new",children:[l.jsx("div",{className:"smartypress-prompt-variable-row__value",children:l.jsx("input",{type:"text",value:N.key,onChange:O=>R({...N,key:O.target.value}),placeholder:f.__("Variable key, e.g. audience","smartypress-ai-engine")})}),l.jsx("div",{className:"smartypress-prompt-variable-row__value",children:l.jsx("input",{type:"text",value:N.value,onChange:O=>R({...N,value:O.target.value}),placeholder:f.__("Variable value","smartypress-ai-engine")})}),l.jsx("button",{type:"button",className:"button",onClick:Gt,disabled:!ts(N.key),children:f.__("Add Variable","smartypress-ai-engine")})]}),l.jsx("p",{className:"description",children:f.__("Use variables in prompts with braces, for example {AUDIENCE} or {BRAND_NAME}. Standard variables cannot be removed.","smartypress-ai-engine")})]})]})},J=()=>l.jsxs("div",{className:"smartypress-settings-tabs",children:[l.jsxs("nav",{className:"smartypress-settings-tabs__nav","aria-label":f.__("Settings sections","smartypress-ai-engine"),children:[l.jsx("button",{type:"button",className:`smartypress-settings-tabs__button ${P==="general"?"is-active":""}`,onClick:()=>L("general"),children:f.__("General Settings","smartypress-ai-engine")}),l.jsx("button",{type:"button",className:`smartypress-settings-tabs__button ${P==="variables"?"is-active":""}`,onClick:()=>L("variables"),children:f.__("Available Variables","smartypress-ai-engine")})]}),l.jsxs("div",{className:"smartypress-settings-tabs__content",children:[P==="general"&&b(),P==="variables"&&E()]})]}),Me=()=>l.jsxs("div",{className:"smartypress-ai-settings-section",children:[l.jsx("h2",{children:f.__("Debug Settings","smartypress-ai-engine")}),l.jsx("table",{className:"form-table",children:l.jsx("tbody",{children:l.jsxs("tr",{children:[l.jsx("th",{scope:"row",children:l.jsx("label",{htmlFor:"enable_debug",children:f.__("Enable Debug Logging","smartypress-ai-engine")})}),l.jsxs("td",{children:[l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",id:"enable_debug",checked:t.enable_debug||!1,onChange:y=>X("enable_debug",y.target.checked)}),f.__("Log API errors for debugging","smartypress-ai-engine")]}),l.jsx("p",{className:"description",children:f.__("When enabled, API errors will be logged and can be viewed in the Logs page. Useful for troubleshooting issues with AI providers.","smartypress-ai-engine")}),t.enable_debug&&l.jsxs(l.Fragment,{children:[l.jsxs("label",{style:{display:"block",marginTop:"10px"},children:[l.jsx("input",{type:"checkbox",id:"log_successful_requests",checked:t.log_successful_requests||!1,onChange:y=>X("log_successful_requests",y.target.checked)}),f.__("Also log successful requests","smartypress-ai-engine")]}),l.jsx("p",{className:"description",style:{marginTop:"10px"},children:l.jsxs("a",{href:"#/logs",children:[f.__("View API Logs","smartypress-ai-engine")," →"]})})]})]})]})})})]});return s?l.jsx("div",{className:"smartypress-ai-settings-page",children:l.jsx("div",{className:"smartypress-ai-loading",children:f.__("Loading settings...","smartypress-ai-engine")})}):l.jsxs("div",{className:"smartypress-ai-settings-page",children:[l.jsxs("div",{className:"smartypress-ai-page-header",children:[l.jsx("h1",{children:f.__("Settings","smartypress-ai-engine")}),l.jsx("p",{children:f.__("Configure AI providers and plugin settings.","smartypress-ai-engine")})]}),x.text&&l.jsx("div",{className:`notice notice-${x.type} is-dismissible`,children:l.jsx("p",{children:x.text})}),l.jsx("form",{className:"smartypress-ai-settings-form",autoComplete:"off",onSubmit:y=>y.preventDefault(),children:c?Ki():l.jsxs(l.Fragment,{children:[J(),l.jsx("p",{className:"submit",children:l.jsx("button",{type:"button",className:"button button-primary",onClick:ne,disabled:n,children:n?f.__("Saving...","smartypress-ai-engine"):f.__("Save Changes","smartypress-ai-engine")})})]})})]})}function gl(){const[t,e]=M.useState("single"),s=M.useRef(null),i=M.useRef(null),n=M.useRef(!1);return M.useEffect(()=>{if(window.smartypressAIContentGeneratorMount){const a=setTimeout(()=>{window.smartypressAIContentGeneratorMount(t),n.current=!0},50);return()=>{clearTimeout(a)}}},[t]),l.jsxs("div",{className:"smartypress-ai-content-generation-page",children:[l.jsxs("div",{className:"smartypress-ai-page-header",children:[l.jsx("h1",{children:f.__("Content Generation","smartypress-ai-engine")}),l.jsx("p",{children:f.__("Generate single posts or bulk content using AI.","smartypress-ai-engine")})]}),l.jsxs("div",{className:"spai-pill-tabs",children:[l.jsx("button",{className:t==="single"?"is-active":"",onClick:()=>e("single"),children:f.__("Single Post","smartypress-ai-engine")}),l.jsx("button",{className:t==="bulk"?"is-active":"",onClick:()=>e("bulk"),children:f.__("Bulk Generation","smartypress-ai-engine")})]}),l.jsxs("div",{className:"smartypress-ai-tab-content",children:[t==="single"&&l.jsx("div",{id:"smartypress-ai-single-generator-root",ref:s,className:"smartypress-ai-tab-panel"}),t==="bulk"&&l.jsx("div",{id:"smartypress-ai-bulk-generator-root",ref:i,className:"smartypress-ai-tab-panel"})]})]})}function ml(){const t=M.useRef(null);return M.useEffect(()=>{if(window.smartypressAIImageGeneratorMount){const e=setTimeout(()=>{window.smartypressAIImageGeneratorMount()},50);return()=>clearTimeout(e)}},[]),l.jsxs("div",{className:"smartypress-ai-image-generation-page",children:[l.jsxs("div",{className:"smartypress-ai-page-header",children:[l.jsx("h1",{children:f.__("Image Generation","smartypress-ai-engine")}),l.jsx("p",{children:f.__("Create images from text prompts. Saves to Media Library with auto-generated title, alt, and description. Regenerate any image with a correction prompt.","smartypress-ai-engine")})]}),l.jsx("div",{id:"smartypress-ai-image-generator-root",ref:t,className:"smartypress-ai-image-generation-content"})]})}const pe="/smartypress/v1/image-alt",_l=()=>ie({path:`${pe}/settings`}),xl=t=>ie({path:`${pe}/settings`,method:"POST",data:t}),yl=()=>ie({path:`${pe}/stats`}),bl=()=>ie({path:`${pe}/index`}),vl=({filter:t="missing_alt",search:e="",postTypes:s=[]}={})=>ie({path:`${pe}/index/start`,method:"POST",data:{filter:t,search:e,post_types:s}}),kl=({batchSize:t=250}={})=>ie({path:`${pe}/index/next`,method:"POST",data:{batch_size:t}}),wl=()=>ie({path:`${pe}/index/cancel`,method:"POST"}),jl=({page:t=1,perPage:e=20,filter:s="all",search:i=""}={})=>{const n=new URLSearchParams({page:String(t),per_page:String(e),filter:s,search:i});return ie({path:`${pe}/attachments?${n.toString()}`})},Sl=(t,e)=>ie({path:`${pe}/generate`,method:"POST",data:{attachment_id:t,settings:e}}),Cl=({filter:t="missing_alt",search:e="",postTypes:s=[]}={})=>ie({path:`${pe}/bulk/start`,method:"POST",data:{filter:t,search:e,post_types:s}}),Ml=t=>ie({path:`${pe}/bulk/next`,method:"POST",data:{settings:t}}),Pl=()=>ie({path:`${pe}/bulk/cancel`,method:"POST"});function Sn(t,e){if(!t||typeof t!="object")return String(e||"");let s=t.name||e;return t.reasoning&&(s=`🧠 ${s}`),t.expensive&&(s=`${s} 💰`),s}const Zs=[{label:f.__("English","smartypress-ai-engine"),value:"English"},{label:f.__("Russian","smartypress-ai-engine"),value:"Russian"},{label:f.__("German","smartypress-ai-engine"),value:"German"},{label:f.__("French","smartypress-ai-engine"),value:"French"},{label:f.__("Spanish","smartypress-ai-engine"),value:"Spanish"},{label:f.__("Italian","smartypress-ai-engine"),value:"Italian"},{label:f.__("Portuguese","smartypress-ai-engine"),value:"Portuguese"},{label:f.__("Chinese","smartypress-ai-engine"),value:"Chinese"},{label:f.__("Japanese","smartypress-ai-engine"),value:"Japanese"},{label:f.__("Korean","smartypress-ai-engine"),value:"Korean"},{label:f.__("Arabic","smartypress-ai-engine"),value:"Arabic"},{label:f.__("Dutch","smartypress-ai-engine"),value:"Dutch"},{label:f.__("Polish","smartypress-ai-engine"),value:"Polish"},{label:f.__("Turkish","smartypress-ai-engine"),value:"Turkish"},{label:f.__("Ukrainian","smartypress-ai-engine"),value:"Ukrainian"},{label:f.__("Hindi","smartypress-ai-engine"),value:"Hindi"},{label:f.__("Vietnamese","smartypress-ai-engine"),value:"Vietnamese"},{label:f.__("Custom","smartypress-ai-engine"),value:"custom"}],Al=[{value:"all",label:f.__("All images","smartypress-ai-engine")},{value:"missing_alt",label:f.__("Missing ALT","smartypress-ai-engine")},{value:"has_alt",label:f.__("Has ALT","smartypress-ai-engine")},{value:"missing_caption",label:f.__("Missing caption","smartypress-ai-engine")}],Ol={vision_two_step:f.__("Vision + text","smartypress-ai-engine"),context_post_keyword:f.__("Post + keyword","smartypress-ai-engine"),context_post:f.__("Post context","smartypress-ai-engine"),context_existing_metadata:f.__("Metadata context","smartypress-ai-engine"),poor_custom_prompt:f.__("Poor context","smartypress-ai-engine")},Cn=t=>t==="anthropic"?"Claude":t.charAt(0).toUpperCase()+t.slice(1);function Il(){const t=window.smartypressAIAdmin||{},e=t.imageAltProviderModels||{},s=t.providerModels||{},i=Object.keys(e),n=Object.keys(s).filter(b=>Object.keys(s[b]||{}).length>0),[a,r]=M.useState("bulk"),[o,c]=M.useState(null),[h,d]=M.useState(null),[u,p]=M.useState({}),[g,x]=M.useState({}),[_,m]=M.useState(!1),[v,w]=M.useState([]),[S,I]=M.useState(1),[C,P]=M.useState(1),[L,N]=M.useState("all"),[R,B]=M.useState(""),[z,D]=M.useState([]),[k,F]=M.useState([]),[W,Q]=M.useState(!0),[se,we]=M.useState(!1),[je,Se]=M.useState(null),[_e,xe]=M.useState(!1),[de,ue]=M.useState(!1),[ye,ne]=M.useState(""),[X,Le]=M.useState(""),[bt,vt]=M.useState(""),Gt=M.useRef(""),Ls=M.useRef(!1),Ei=Math.min((h==null?void 0:h.failed)||0,(h==null?void 0:h.without_alt)||0),Yt=((o==null?void 0:o.vision_mode)||"vision")==="vision",Ns=n.length>0&&(!Yt||i.length>0),Ts=L==="all"?"missing_alt":L,Ri=g!=null&&g.total_estimate?Math.round((g.processed||0)/g.total_estimate*100):0,Di=M.useMemo(()=>i.map(b=>({label:Cn(b),value:b})),[i]),Fi=M.useMemo(()=>n.map(b=>({label:Cn(b),value:b})),[n]),zi=M.useMemo(()=>{const b=(o==null?void 0:o.provider)||i[0]||"openai",E=e[b]||{};return Object.keys(E).map(J=>({value:J,label:Sn(E[J],J)}))},[e,i,o==null?void 0:o.provider]),Bi=M.useMemo(()=>{const b=(o==null?void 0:o.text_provider)||n[0]||(o==null?void 0:o.provider)||i[0]||"openai",E=s[b]||{};return Object.keys(E).map(J=>({value:J,label:Sn(E[J],J)}))},[s,n,i,o==null?void 0:o.text_provider,o==null?void 0:o.provider]),Wi=M.useCallback(async()=>{const b=await yl();d(b.stats||null),p(b.job||{}),x(b.index||{})},[]),Es=M.useCallback(async()=>{var E;const b=await bl();x(b.index||{}),(E=b.index)!=null&&E.stats&&d(b.index.stats),b.post_types&&D(b.post_types),b.default_post_types&&k.length===0&&F(b.default_post_types)},[k.length]),Ce=M.useCallback(async()=>{const b=await jl({page:S,filter:L,search:R});w(b.items||[]),P(b.total_pages||1)},[S,L,R]),Hi=M.useCallback(b=>{const E=i.includes(b.provider)?b.provider:i[0]||b.provider||"",J=e[E]||{},Me=Object.keys(J),kt=Me.includes(b.model)?b.model:Me[0]||b.model||"",y=n.includes(b.text_provider)?b.text_provider:n[0]||E,j=s[y]||{},A=Object.keys(j),O=A.includes(b.text_model)?b.text_model:A[0]||b.text_model||kt;return{...b,vision_mode:b.vision_mode==="context"?"context":"vision",provider:E,model:kt,text_provider:y,text_model:O}},[i,e,n,s]),Rs=M.useCallback(async()=>{try{Q(!0);const b=await _l(),E=Hi(b.settings||{});c(E),D(b.post_types||[]),F(b.default_post_types||[]),Gt.current=JSON.stringify(E),await Promise.all([Es(),Ce()])}catch(b){Le((b==null?void 0:b.message)||f.__("Failed to load Image ALT data.","smartypress-ai-engine"))}finally{Q(!1)}},[Es,Ce,i,e]);M.useEffect(()=>{Rs()},[]),M.useEffect(()=>{W||Ce().catch(b=>Le((b==null?void 0:b.message)||f.__("Failed to load attachments.","smartypress-ai-engine")))},[L,S]);const ae=(b,E)=>{c(J=>({...J,[b]:E}))},Ds=b=>{const E=e[b]||{},J=Object.keys(E);c(Me=>({...Me,provider:b,model:J[0]||""}))},Vi=b=>{const E=s[b]||{},J=Object.keys(E);c(Me=>({...Me,text_provider:b,text_model:J[0]||""}))},$i=async()=>{try{we(!0),vt(f.__("Saving settings...","smartypress-ai-engine"));const E=(await xl(o)).settings||o;Gt.current=JSON.stringify(E),c(E),vt(f.__("Settings saved.","smartypress-ai-engine"))}catch(b){vt(""),Le((b==null?void 0:b.message)||f.__("Failed to save settings.","smartypress-ai-engine"))}finally{we(!1)}};M.useEffect(()=>{if(!o)return;if(!Ls.current){Ls.current=!0;return}if(JSON.stringify(o)===Gt.current)return;const E=setTimeout(()=>{$i()},650);return()=>clearTimeout(E)},[o]);const Ui=async b=>{try{Se(b);const E=await Sl(b,o);if(!E.success)throw new Error(E.error||f.__("ALT generation failed.","smartypress-ai-engine"));ne(E.skipped?E.message||f.__("Image skipped.","smartypress-ai-engine"):f.__("ALT generated successfully.","smartypress-ai-engine")),await Promise.all([_?Wi():Promise.resolve(),Ce()])}catch(E){Le((E==null?void 0:E.message)||f.__("ALT generation failed.","smartypress-ai-engine"))}finally{Se(null)}},Gi=b=>{m(!1),F(E=>E.includes(b)?E.filter(J=>J!==b):[...E,b])},Yi=async()=>{try{if(k.length===0){Le(f.__("Select at least one post type for indexing.","smartypress-ai-engine"));return}xe(!0),ue(!0),Le(""),ne(f.__("Indexing media library before bulk generation...","smartypress-ai-engine")),m(!0);let E=(await vl({filter:Ts,search:R,postTypes:k})).index||{};for(x(E),d(E.stats||null);E.status==="running";)E=(await kl({batchSize:250})).index||{},x(E),d(E.stats||null);ue(!1);const J=E.queue_total||0;if(J<=0){ne(f.__("Indexing completed. No images match the current filters.","smartypress-ai-engine")),await Ce();return}if(!window.confirm(f.sprintf(f.__("Indexing completed. %d images match the current filters. Start bulk generation now?","smartypress-ai-engine"),J))){ne(f.__("Indexing completed. Bulk generation was not started.","smartypress-ai-engine")),await Ce();return}let y=(await Cl({filter:Ts,search:R,postTypes:k})).job||{};for(p(y),ne(f.__("Bulk metadata generation started.","smartypress-ai-engine"));y.status==="running";)y=(await Ml(o)).job||{},p(y);ne(f.__("Bulk ALT generation completed.","smartypress-ai-engine")),await Ce()}catch(b){Le((b==null?void 0:b.message)||f.__("Bulk ALT generation failed.","smartypress-ai-engine"))}finally{ue(!1),xe(!1)}},Ki=async()=>{const b=de?await wl():await Pl();de?x(b.index||{}):p(b.job||{}),xe(!1),ue(!1),ne(de?f.__("Indexing cancelled.","smartypress-ai-engine"):f.__("Bulk generation cancelled.","smartypress-ai-engine"))},Kt=b=>{b.preventDefault(),I(1),Ce().catch(E=>Le((E==null?void 0:E.message)||f.__("Failed to search attachments.","smartypress-ai-engine")))},Fs=b=>Ol[b]||b||f.__("Not generated","smartypress-ai-engine");return W||!o?l.jsx("div",{className:"spai-alt-page",children:l.jsx("div",{className:"spai-alt-loading",children:f.__("Loading...","smartypress-ai-engine")})}):l.jsxs("div",{className:"spai-alt-page",children:[l.jsxs("div",{className:"smartypress-ai-page-header",children:[l.jsx("h1",{children:f.__("Image ALT Generation","smartypress-ai-engine")}),l.jsx("p",{children:f.__("Generate SEO-friendly ALT text and captions for Media Library images.","smartypress-ai-engine")}),l.jsxs("div",{className:"spai-pill-tabs",children:[l.jsx("button",{className:a==="bulk"?"is-active":"",onClick:()=>r("bulk"),children:f.__("Bulk Generation","smartypress-ai-engine")}),l.jsx("button",{className:a==="upload"?"is-active":"",onClick:()=>r("upload"),children:f.__("Upload Settings","smartypress-ai-engine")})]})]}),ye&&l.jsx("div",{className:"spai-alt-notice is-success",children:ye}),X&&l.jsx("div",{className:"spai-alt-notice is-error",children:X}),l.jsxs("div",{className:"spai-alt-layout",children:[l.jsx("main",{className:"spai-alt-main",children:a==="bulk"?l.jsxs(l.Fragment,{children:[_&&l.jsxs("div",{className:"spai-alt-stats",children:[l.jsx(Mt,{label:f.__("Total indexed","smartypress-ai-engine"),value:(h==null?void 0:h.total)||0}),l.jsx(Mt,{label:f.__("With ALT","smartypress-ai-engine"),value:(h==null?void 0:h.with_alt)||0}),l.jsx(Mt,{label:f.__("Missing ALT","smartypress-ai-engine"),value:(h==null?void 0:h.without_alt)||0}),l.jsx(Mt,{label:f.__("Generated","smartypress-ai-engine"),value:(h==null?void 0:h.generated)||0}),l.jsx(Mt,{label:f.__("Failed","smartypress-ai-engine"),value:Ei})]}),l.jsxs("div",{className:"spai-alt-bulk-card",children:[l.jsxs("div",{children:[l.jsx("h2",{children:f.__("Bulk ALT generation","smartypress-ai-engine")}),l.jsx("p",{children:f.__("First indexes the Media Library in batches, then asks for confirmation before metadata generation starts.","smartypress-ai-engine")}),l.jsxs("div",{className:"spai-alt-post-types",children:[l.jsx("span",{children:f.__("Post types to index:","smartypress-ai-engine")}),z.map(b=>l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:k.includes(b.value),onChange:()=>Gi(b.value),disabled:_e}),b.label]},b.value))]}),de&&l.jsxs("div",{className:"spai-alt-progress",children:[l.jsx("div",{className:"spai-alt-progress-bar",style:{width:`${Ri}%`}}),l.jsx("span",{children:f.sprintf(f.__("Indexing: %1$d / %2$d","smartypress-ai-engine"),g.processed||0,g.total_estimate||0)})]}),!de&&(g==null?void 0:g.status)==="completed"&&_&&l.jsxs("p",{className:"spai-alt-index-summary",children:[f.sprintf(f.__("Indexed. %d images match the generation filter.","smartypress-ai-engine"),g.queue_total||0),g.stale?` ${f.__("Index is stale after media changes.","smartypress-ai-engine")}`:""]}),u!=null&&u.total?l.jsxs("div",{className:"spai-alt-progress",children:[l.jsx("div",{className:"spai-alt-progress-bar",style:{width:`${Math.round((u.processed||0)/u.total*100)}%`}}),l.jsxs("span",{children:[u.processed||0," / ",u.total]})]}):null]}),l.jsxs("div",{className:"spai-alt-bulk-actions",children:[l.jsx("button",{className:"button button-primary",onClick:Yi,disabled:_e||!Ns||k.length===0,children:de?f.__("Indexing...","smartypress-ai-engine"):_e?f.__("Generating...","smartypress-ai-engine"):f.__("Start bulk generation","smartypress-ai-engine")}),_e&&l.jsx("button",{className:"button",onClick:Ki,children:f.__("Cancel","smartypress-ai-engine")})]})]}),l.jsxs("div",{className:"spai-alt-table-card",children:[l.jsxs("div",{className:"spai-alt-toolbar",children:[l.jsxs("form",{onSubmit:Kt,children:[l.jsx("input",{type:"search",value:R,onChange:b=>{B(b.target.value),m(!1)},placeholder:f.__("Search media...","smartypress-ai-engine")}),l.jsx("button",{className:"button",type:"submit",children:f.__("Search","smartypress-ai-engine")})]}),l.jsx("select",{value:L,onChange:b=>{N(b.target.value),I(1),m(!1)},children:Al.map(b=>l.jsx("option",{value:b.value,children:b.label},b.value))})]}),l.jsxs("table",{className:"widefat striped spai-alt-table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:f.__("Image","smartypress-ai-engine")}),l.jsx("th",{children:f.__("File / Title","smartypress-ai-engine")}),l.jsx("th",{children:f.__("Metadata","smartypress-ai-engine")}),l.jsx("th",{children:f.__("Context","smartypress-ai-engine")}),l.jsx("th",{children:f.__("Actions","smartypress-ai-engine")})]})}),l.jsx("tbody",{children:v.length===0?l.jsx("tr",{children:l.jsx("td",{colSpan:"5",children:f.__("No images found.","smartypress-ai-engine")})}):v.map(b=>{var E;return l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("img",{className:"spai-alt-thumb",src:b.thumbnail_url,alt:""})}),l.jsxs("td",{children:[l.jsx("strong",{children:b.title||b.filename}),l.jsx("br",{}),l.jsx("span",{children:b.filename})]}),l.jsxs("td",{className:"spai-alt-meta-cell",children:[l.jsxs("span",{className:`spai-alt-meta-badge ${b.alt?"has-value":""}`,children:[f.__("ALT","smartypress-ai-engine"),": ",b.alt?f.__("yes","smartypress-ai-engine"):f.__("no","smartypress-ai-engine"),b.alt?l.jsx("span",{className:"spai-alt-meta-tooltip",children:b.alt}):null]}),l.jsxs("span",{className:`spai-alt-meta-badge ${b.caption?"has-value":""}`,children:[f.__("Caption","smartypress-ai-engine"),": ",b.caption?f.__("yes","smartypress-ai-engine"):f.__("no","smartypress-ai-engine"),b.caption?l.jsx("span",{className:"spai-alt-meta-tooltip",children:b.caption}):null]}),l.jsxs("span",{className:`spai-alt-meta-badge ${b.title?"has-value":""}`,children:[f.__("Title","smartypress-ai-engine"),": ",b.title?f.__("yes","smartypress-ai-engine"):f.__("no","smartypress-ai-engine"),b.title?l.jsx("span",{className:"spai-alt-meta-tooltip",children:b.title}):null]}),l.jsxs("span",{className:`spai-alt-meta-badge ${b.description?"has-value":""}`,children:[f.__("Description","smartypress-ai-engine"),": ",b.description?f.__("yes","smartypress-ai-engine"):f.__("no","smartypress-ai-engine"),b.description?l.jsx("span",{className:"spai-alt-meta-tooltip",children:b.description}):null]})]}),l.jsxs("td",{className:"spai-alt-context-cell",children:[b.primary_post?l.jsx("a",{href:b.primary_post.url||b.primary_post.edit_url,target:"_blank",rel:"noopener noreferrer",children:b.primary_post.title}):l.jsx("span",{className:"spai-alt-no-context",children:f.__("No related post","smartypress-ai-engine")}),((E=b.focus_keywords)==null?void 0:E.length)>0&&l.jsxs("span",{className:"spai-alt-keywords",children:[l.jsx("span",{className:"spai-alt-keywords-label",children:f.__("Focus keyword:","smartypress-ai-engine")}),b.focus_keywords.map((J,Me)=>l.jsx("span",{className:"spai-alt-keyword",children:J},Me))]}),b.strategy&&l.jsxs("span",{className:"spai-alt-strategy",children:[l.jsxs("span",{className:"spai-alt-strategy-badge",children:[f.__("Strategy:","smartypress-ai-engine")," ",Fs(b.strategy)]}),b.confidence&&l.jsxs("span",{className:`spai-alt-confidence is-${b.confidence}`,children:[f.__("Confidence:","smartypress-ai-engine")," ",b.confidence]}),b.needs_review&&l.jsx("span",{className:"spai-alt-review-badge",children:f.__("Review recommended","smartypress-ai-engine")})]})]}),l.jsx("td",{children:l.jsx("button",{className:"button button-small",onClick:()=>Ui(b.id),disabled:je===b.id||_e||!Ns,children:je===b.id?f.__("Generating...","smartypress-ai-engine"):f.__("Generate Metadata","smartypress-ai-engine")})})]},b.id)})})]}),l.jsxs("div",{className:"spai-alt-pagination",children:[l.jsx("button",{className:"button",onClick:()=>I(b=>Math.max(1,b-1)),disabled:S<=1,children:f.__("Previous","smartypress-ai-engine")}),l.jsxs("span",{children:[S," / ",C]}),l.jsx("button",{className:"button",onClick:()=>I(b=>Math.min(C,b+1)),disabled:S>=C,children:f.__("Next","smartypress-ai-engine")})]})]})]}):l.jsxs("div",{className:"spai-alt-upload-card",children:[l.jsx("h2",{children:f.__("Generate on upload","smartypress-ai-engine")}),l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:!!o.auto_generate_on_upload,onChange:b=>ae("auto_generate_on_upload",b.target.checked)}),f.__("Automatically generate ALT when an image is uploaded to Media Library.","smartypress-ai-engine")]}),l.jsx("p",{children:f.__("Uploads are queued with WP-Cron so the Media Library upload request is not blocked by a slow AI provider.","smartypress-ai-engine")})]})}),l.jsxs("aside",{className:"spai-alt-sidebar",children:[l.jsx("h2",{children:f.__("Generation settings","smartypress-ai-engine")}),l.jsxs("div",{className:"spai-alt-section",children:[l.jsx("h3",{children:f.__("Image Analysis","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Configure the vision model for analyzing image content.","smartypress-ai-engine")}),i.length===0&&Yt&&l.jsx("div",{className:"spai-alt-sidebar-note",children:f.__("Configure OpenAI, OpenRouter, or Claude to use image analysis for ALT generation.","smartypress-ai-engine")}),l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.SelectControl,{label:f.__("Image analysis:","smartypress-ai-engine"),value:o.vision_mode||"vision",options:[{label:f.__("Enabled","smartypress-ai-engine"),value:"vision"},{label:f.__("Disabled","smartypress-ai-engine"),value:"context"}],onChange:b=>ae("vision_mode",b)})}),Yt&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.SelectControl,{label:f.__("Vision provider:","smartypress-ai-engine"),value:o.provider,options:Di,onChange:Ds,disabled:i.length===0})}),l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.ComboboxControl,{label:f.__("Vision model:","smartypress-ai-engine"),value:o.model,options:zi,onChange:b=>ae("model",b),disabled:i.length===0,help:f.__("Used to analyze the actual image content before generating ALT, caption, title and description. Disable image analysis to generate metadata from post context, SEO keywords and file name only.","smartypress-ai-engine")})})]})]}),l.jsxs("div",{className:"spai-alt-section",children:[l.jsx("h3",{children:f.__("Text Generation","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Configure the text model for generating final metadata.","smartypress-ai-engine")}),l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.SelectControl,{label:f.__("Text provider:","smartypress-ai-engine"),value:o.text_provider,options:Fi,onChange:Vi,disabled:n.length===0})}),l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.ComboboxControl,{label:f.__("Text model:","smartypress-ai-engine"),value:o.text_model,options:Bi,onChange:b=>ae("text_model",b),disabled:n.length===0,help:f.__("Used to generate the final ALT, caption, title and description from the image analysis and SEO context.","smartypress-ai-engine")})}),l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.TextareaControl,{label:f.__("Poor context prompt:","smartypress-ai-engine"),value:o.poor_context_prompt||"",onChange:b=>ae("poor_context_prompt",b),help:f.__("Used when image analysis is disabled and the image has no related post, SEO keyword, useful title, filename, ALT or caption. Available variables: {filename}, {attachment_title}, {site_name}, {language}.","smartypress-ai-engine"),rows:5})})]}),l.jsxs("div",{className:"spai-alt-section",children:[l.jsx("h3",{children:f.__("Output Settings","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Language and formatting options for generated text.","smartypress-ai-engine")}),l.jsxs("div",{className:"spai-alt-field",children:[l.jsx(Pe.SelectControl,{label:f.__("Language:","smartypress-ai-engine"),value:Zs.some(b=>b.value===o.language&&b.value!=="custom")?o.language:"custom",options:Zs,onChange:b=>{b==="custom"?ae("language","custom"):ae("language",b)}}),!Zs.some(b=>b.value===o.language&&b.value!=="custom")&&l.jsx(Pe.TextControl,{type:"text",className:"spai-alt-custom-language",value:o.customLanguage||"",onChange:b=>ae("customLanguage",b),placeholder:f.__("Enter custom language","smartypress-ai-engine")})]}),l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.TextControl,{label:f.__("Max ALT length:","smartypress-ai-engine"),type:"number",min:"40",max:"300",value:o.max_alt_length||125,onChange:b=>ae("max_alt_length",Number(b))})}),l.jsx("div",{className:"spai-alt-field",children:l.jsx(Pe.TextControl,{label:f.__("Batch size:","smartypress-ai-engine"),type:"number",min:"1",max:"5",value:o.batch_size||1,onChange:b=>ae("batch_size",Number(b))})})]}),l.jsxs("div",{className:"spai-alt-section",children:[l.jsx("h3",{children:f.__("Generation Options","smartypress-ai-engine")}),l.jsx("p",{className:"description",children:f.__("Select which metadata fields to generate.","smartypress-ai-engine")}),l.jsxs("div",{className:"spai-alt-checks",children:[l.jsx(Pt,{label:f.__("Generate ALT","smartypress-ai-engine"),checked:o.generate_alt,onChange:b=>ae("generate_alt",b)}),l.jsx(Pt,{label:f.__("Generate caption","smartypress-ai-engine"),checked:o.generate_caption,onChange:b=>ae("generate_caption",b)}),l.jsx(Pt,{label:f.__("Generate title","smartypress-ai-engine"),checked:o.generate_title,onChange:b=>ae("generate_title",b)}),l.jsx(Pt,{label:f.__("Generate description","smartypress-ai-engine"),checked:o.generate_description,onChange:b=>ae("generate_description",b)}),l.jsx(Pt,{label:f.__("Use SEO focus keyword context","smartypress-ai-engine"),checked:o.include_seo_keyword,onChange:b=>ae("include_seo_keyword",b)})]})]}),bt&&l.jsx("p",{className:"spai-alt-save-status",children:bt})]})]})]})}function Mt({label:t,value:e}){return l.jsxs("div",{className:"spai-alt-stat",children:[l.jsx("span",{children:t}),l.jsx("strong",{children:e})]})}function Pt({label:t,checked:e,onChange:s}){return l.jsxs("label",{className:"spai-alt-checkbox",children:[l.jsx("input",{type:"checkbox",checked:!!e,onChange:i=>s(i.target.checked)}),t]})}/*!
 * @kurkle/color v0.3.4
 * https://github.com/kurkle/color#readme
 * (c) 2024 Jukka Kurkela
 * Released under the MIT License
 */function At(t){return t+.5|0}const He=(t,e,s)=>Math.max(Math.min(t,s),e);function Ot(t){return He(At(t*2.55),0,255)}function Ve(t){return He(At(t*255),0,255)}function Ne(t){return He(At(t/2.55)/100,0,1)}function Mn(t){return He(At(t*100),0,100)}const ge={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},ei=[..."0123456789ABCDEF"],Ll=t=>ei[t&15],Nl=t=>ei[(t&240)>>4]+ei[t&15],ss=t=>(t&240)>>4===(t&15),Tl=t=>ss(t.r)&&ss(t.g)&&ss(t.b)&&ss(t.a);function El(t){var e=t.length,s;return t[0]==="#"&&(e===4||e===5?s={r:255&ge[t[1]]*17,g:255&ge[t[2]]*17,b:255&ge[t[3]]*17,a:e===5?ge[t[4]]*17:255}:(e===7||e===9)&&(s={r:ge[t[1]]<<4|ge[t[2]],g:ge[t[3]]<<4|ge[t[4]],b:ge[t[5]]<<4|ge[t[6]],a:e===9?ge[t[7]]<<4|ge[t[8]]:255})),s}const Rl=(t,e)=>t<255?e(t):"";function Dl(t){var e=Tl(t)?Ll:Nl;return t?"#"+e(t.r)+e(t.g)+e(t.b)+Rl(t.a,e):void 0}const Fl=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;function Pn(t,e,s){const i=e*Math.min(s,1-s),n=(a,r=(a+t/30)%12)=>s-i*Math.max(Math.min(r-3,9-r,1),-1);return[n(0),n(8),n(4)]}function zl(t,e,s){const i=(n,a=(n+t/60)%6)=>s-s*e*Math.max(Math.min(a,4-a,1),0);return[i(5),i(3),i(1)]}function Bl(t,e,s){const i=Pn(t,1,.5);let n;for(e+s>1&&(n=1/(e+s),e*=n,s*=n),n=0;n<3;n++)i[n]*=1-e-s,i[n]+=e;return i}function Wl(t,e,s,i,n){return t===n?(e-s)/i+(e<s?6:0):e===n?(s-t)/i+2:(t-e)/i+4}function ti(t){const s=t.r/255,i=t.g/255,n=t.b/255,a=Math.max(s,i,n),r=Math.min(s,i,n),o=(a+r)/2;let c,h,d;return a!==r&&(d=a-r,h=o>.5?d/(2-a-r):d/(a+r),c=Wl(s,i,n,d,a),c=c*60+.5),[c|0,h||0,o]}function si(t,e,s,i){return(Array.isArray(e)?t(e[0],e[1],e[2]):t(e,s,i)).map(Ve)}function ii(t,e,s){return si(Pn,t,e,s)}function Hl(t,e,s){return si(Bl,t,e,s)}function Vl(t,e,s){return si(zl,t,e,s)}function An(t){return(t%360+360)%360}function $l(t){const e=Fl.exec(t);let s=255,i;if(!e)return;e[5]!==i&&(s=e[6]?Ot(+e[5]):Ve(+e[5]));const n=An(+e[2]),a=+e[3]/100,r=+e[4]/100;return e[1]==="hwb"?i=Hl(n,a,r):e[1]==="hsv"?i=Vl(n,a,r):i=ii(n,a,r),{r:i[0],g:i[1],b:i[2],a:s}}function Ul(t,e){var s=ti(t);s[0]=An(s[0]+e),s=ii(s),t.r=s[0],t.g=s[1],t.b=s[2]}function Gl(t){if(!t)return;const e=ti(t),s=e[0],i=Mn(e[1]),n=Mn(e[2]);return t.a<255?`hsla(${s}, ${i}%, ${n}%, ${Ne(t.a)})`:`hsl(${s}, ${i}%, ${n}%)`}const On={x:"dark",Z:"light",Y:"re",X:"blu",W:"gr",V:"medium",U:"slate",A:"ee",T:"ol",S:"or",B:"ra",C:"lateg",D:"ights",R:"in",Q:"turquois",E:"hi",P:"ro",O:"al",N:"le",M:"de",L:"yello",F:"en",K:"ch",G:"arks",H:"ea",I:"ightg",J:"wh"},In={OiceXe:"f0f8ff",antiquewEte:"faebd7",aqua:"ffff",aquamarRe:"7fffd4",azuY:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"0",blanKedOmond:"ffebcd",Xe:"ff",XeviTet:"8a2be2",bPwn:"a52a2a",burlywood:"deb887",caMtXe:"5f9ea0",KartYuse:"7fff00",KocTate:"d2691e",cSO:"ff7f50",cSnflowerXe:"6495ed",cSnsilk:"fff8dc",crimson:"dc143c",cyan:"ffff",xXe:"8b",xcyan:"8b8b",xgTMnPd:"b8860b",xWay:"a9a9a9",xgYF:"6400",xgYy:"a9a9a9",xkhaki:"bdb76b",xmagFta:"8b008b",xTivegYF:"556b2f",xSange:"ff8c00",xScEd:"9932cc",xYd:"8b0000",xsOmon:"e9967a",xsHgYF:"8fbc8f",xUXe:"483d8b",xUWay:"2f4f4f",xUgYy:"2f4f4f",xQe:"ced1",xviTet:"9400d3",dAppRk:"ff1493",dApskyXe:"bfff",dimWay:"696969",dimgYy:"696969",dodgerXe:"1e90ff",fiYbrick:"b22222",flSOwEte:"fffaf0",foYstWAn:"228b22",fuKsia:"ff00ff",gaRsbSo:"dcdcdc",ghostwEte:"f8f8ff",gTd:"ffd700",gTMnPd:"daa520",Way:"808080",gYF:"8000",gYFLw:"adff2f",gYy:"808080",honeyMw:"f0fff0",hotpRk:"ff69b4",RdianYd:"cd5c5c",Rdigo:"4b0082",ivSy:"fffff0",khaki:"f0e68c",lavFMr:"e6e6fa",lavFMrXsh:"fff0f5",lawngYF:"7cfc00",NmoncEffon:"fffacd",ZXe:"add8e6",ZcSO:"f08080",Zcyan:"e0ffff",ZgTMnPdLw:"fafad2",ZWay:"d3d3d3",ZgYF:"90ee90",ZgYy:"d3d3d3",ZpRk:"ffb6c1",ZsOmon:"ffa07a",ZsHgYF:"20b2aa",ZskyXe:"87cefa",ZUWay:"778899",ZUgYy:"778899",ZstAlXe:"b0c4de",ZLw:"ffffe0",lime:"ff00",limegYF:"32cd32",lRF:"faf0e6",magFta:"ff00ff",maPon:"800000",VaquamarRe:"66cdaa",VXe:"cd",VScEd:"ba55d3",VpurpN:"9370db",VsHgYF:"3cb371",VUXe:"7b68ee",VsprRggYF:"fa9a",VQe:"48d1cc",VviTetYd:"c71585",midnightXe:"191970",mRtcYam:"f5fffa",mistyPse:"ffe4e1",moccasR:"ffe4b5",navajowEte:"ffdead",navy:"80",Tdlace:"fdf5e6",Tive:"808000",TivedBb:"6b8e23",Sange:"ffa500",SangeYd:"ff4500",ScEd:"da70d6",pOegTMnPd:"eee8aa",pOegYF:"98fb98",pOeQe:"afeeee",pOeviTetYd:"db7093",papayawEp:"ffefd5",pHKpuff:"ffdab9",peru:"cd853f",pRk:"ffc0cb",plum:"dda0dd",powMrXe:"b0e0e6",purpN:"800080",YbeccapurpN:"663399",Yd:"ff0000",Psybrown:"bc8f8f",PyOXe:"4169e1",saddNbPwn:"8b4513",sOmon:"fa8072",sandybPwn:"f4a460",sHgYF:"2e8b57",sHshell:"fff5ee",siFna:"a0522d",silver:"c0c0c0",skyXe:"87ceeb",UXe:"6a5acd",UWay:"708090",UgYy:"708090",snow:"fffafa",sprRggYF:"ff7f",stAlXe:"4682b4",tan:"d2b48c",teO:"8080",tEstN:"d8bfd8",tomato:"ff6347",Qe:"40e0d0",viTet:"ee82ee",JHt:"f5deb3",wEte:"ffffff",wEtesmoke:"f5f5f5",Lw:"ffff00",LwgYF:"9acd32"};function Yl(){const t={},e=Object.keys(In),s=Object.keys(On);let i,n,a,r,o;for(i=0;i<e.length;i++){for(r=o=e[i],n=0;n<s.length;n++)a=s[n],o=o.replace(a,On[a]);a=parseInt(In[r],16),t[o]=[a>>16&255,a>>8&255,a&255]}return t}let is;function Kl(t){is||(is=Yl(),is.transparent=[0,0,0,0]);const e=is[t.toLowerCase()];return e&&{r:e[0],g:e[1],b:e[2],a:e.length===4?e[3]:255}}const Xl=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;function ql(t){const e=Xl.exec(t);let s=255,i,n,a;if(e){if(e[7]!==i){const r=+e[7];s=e[8]?Ot(r):He(r*255,0,255)}return i=+e[1],n=+e[3],a=+e[5],i=255&(e[2]?Ot(i):He(i,0,255)),n=255&(e[4]?Ot(n):He(n,0,255)),a=255&(e[6]?Ot(a):He(a,0,255)),{r:i,g:n,b:a,a:s}}}function Jl(t){return t&&(t.a<255?`rgba(${t.r}, ${t.g}, ${t.b}, ${Ne(t.a)})`:`rgb(${t.r}, ${t.g}, ${t.b})`)}const ni=t=>t<=.0031308?t*12.92:Math.pow(t,1/2.4)*1.055-.055,ut=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4);function Ql(t,e,s){const i=ut(Ne(t.r)),n=ut(Ne(t.g)),a=ut(Ne(t.b));return{r:Ve(ni(i+s*(ut(Ne(e.r))-i))),g:Ve(ni(n+s*(ut(Ne(e.g))-n))),b:Ve(ni(a+s*(ut(Ne(e.b))-a))),a:t.a+s*(e.a-t.a)}}function ns(t,e,s){if(t){let i=ti(t);i[e]=Math.max(0,Math.min(i[e]+i[e]*s,e===0?360:1)),i=ii(i),t.r=i[0],t.g=i[1],t.b=i[2]}}function Ln(t,e){return t&&Object.assign(e||{},t)}function Nn(t){var e={r:0,g:0,b:0,a:255};return Array.isArray(t)?t.length>=3&&(e={r:t[0],g:t[1],b:t[2],a:255},t.length>3&&(e.a=Ve(t[3]))):(e=Ln(t,{r:0,g:0,b:0,a:1}),e.a=Ve(e.a)),e}function Zl(t){return t.charAt(0)==="r"?ql(t):$l(t)}class It{constructor(e){if(e instanceof It)return e;const s=typeof e;let i;s==="object"?i=Nn(e):s==="string"&&(i=El(e)||Kl(e)||Zl(e)),this._rgb=i,this._valid=!!i}get valid(){return this._valid}get rgb(){var e=Ln(this._rgb);return e&&(e.a=Ne(e.a)),e}set rgb(e){this._rgb=Nn(e)}rgbString(){return this._valid?Jl(this._rgb):void 0}hexString(){return this._valid?Dl(this._rgb):void 0}hslString(){return this._valid?Gl(this._rgb):void 0}mix(e,s){if(e){const i=this.rgb,n=e.rgb;let a;const r=s===a?.5:s,o=2*r-1,c=i.a-n.a,h=((o*c===-1?o:(o+c)/(1+o*c))+1)/2;a=1-h,i.r=255&h*i.r+a*n.r+.5,i.g=255&h*i.g+a*n.g+.5,i.b=255&h*i.b+a*n.b+.5,i.a=r*i.a+(1-r)*n.a,this.rgb=i}return this}interpolate(e,s){return e&&(this._rgb=Ql(this._rgb,e._rgb,s)),this}clone(){return new It(this.rgb)}alpha(e){return this._rgb.a=Ve(e),this}clearer(e){const s=this._rgb;return s.a*=1-e,this}greyscale(){const e=this._rgb,s=At(e.r*.3+e.g*.59+e.b*.11);return e.r=e.g=e.b=s,this}opaquer(e){const s=this._rgb;return s.a*=1+e,this}negate(){const e=this._rgb;return e.r=255-e.r,e.g=255-e.g,e.b=255-e.b,this}lighten(e){return ns(this._rgb,2,e),this}darken(e){return ns(this._rgb,2,-e),this}saturate(e){return ns(this._rgb,1,e),this}desaturate(e){return ns(this._rgb,1,-e),this}rotate(e){return Ul(this._rgb,e),this}}/*!
 * Chart.js v4.5.1
 * https://www.chartjs.org
 * (c) 2025 Chart.js Contributors
 * Released under the MIT License
 */function Te(){}const ec=(()=>{let t=0;return()=>t++})();function K(t){return t==null}function te(t){if(Array.isArray&&Array.isArray(t))return!0;const e=Object.prototype.toString.call(t);return e.slice(0,7)==="[object"&&e.slice(-6)==="Array]"}function $(t){return t!==null&&Object.prototype.toString.call(t)==="[object Object]"}function me(t){return(typeof t=="number"||t instanceof Number)&&isFinite(+t)}function Ae(t,e){return me(t)?t:e}function G(t,e){return typeof t>"u"?e:t}const tc=(t,e)=>typeof t=="string"&&t.endsWith("%")?parseFloat(t)/100*e:+t;function q(t,e,s){if(t&&typeof t.call=="function")return t.apply(s,e)}function Y(t,e,s,i){let n,a,r;if(te(t))for(a=t.length,n=0;n<a;n++)e.call(s,t[n],n);else if($(t))for(r=Object.keys(t),a=r.length,n=0;n<a;n++)e.call(s,t[r[n]],r[n])}function as(t,e){let s,i,n,a;if(!t||!e||t.length!==e.length)return!1;for(s=0,i=t.length;s<i;++s)if(n=t[s],a=e[s],n.datasetIndex!==a.datasetIndex||n.index!==a.index)return!1;return!0}function rs(t){if(te(t))return t.map(rs);if($(t)){const e=Object.create(null),s=Object.keys(t),i=s.length;let n=0;for(;n<i;++n)e[s[n]]=rs(t[s[n]]);return e}return t}function Tn(t){return["__proto__","prototype","constructor"].indexOf(t)===-1}function sc(t,e,s,i){if(!Tn(t))return;const n=e[t],a=s[t];$(n)&&$(a)?Lt(n,a,i):e[t]=rs(a)}function Lt(t,e,s){const i=te(e)?e:[e],n=i.length;if(!$(t))return t;s=s||{};const a=s.merger||sc;let r;for(let o=0;o<n;++o){if(r=i[o],!$(r))continue;const c=Object.keys(r);for(let h=0,d=c.length;h<d;++h)a(c[h],t,r,s)}return t}function Nt(t,e){return Lt(t,e,{merger:ic})}function ic(t,e,s){if(!Tn(t))return;const i=e[t],n=s[t];$(i)&&$(n)?Nt(i,n):Object.prototype.hasOwnProperty.call(e,t)||(e[t]=rs(n))}const En={"":t=>t,x:t=>t.x,y:t=>t.y};function nc(t){const e=t.split("."),s=[];let i="";for(const n of e)i+=n,i.endsWith("\\")?i=i.slice(0,-1)+".":(s.push(i),i="");return s}function ac(t){const e=nc(t);return s=>{for(const i of e){if(i==="")break;s=s&&s[i]}return s}}function ft(t,e){return(En[e]||(En[e]=ac(e)))(t)}function ai(t){return t.charAt(0).toUpperCase()+t.slice(1)}const Tt=t=>typeof t<"u",$e=t=>typeof t=="function",Rn=(t,e)=>{if(t.size!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;return!0};function rc(t){return t.type==="mouseup"||t.type==="click"||t.type==="contextmenu"}const oe=Math.PI,Ue=2*oe,os=Number.POSITIVE_INFINITY,oc=oe/180,be=oe/2,et=oe/4,Dn=oe*2/3,Fn=Math.log10,Ge=Math.sign;function ls(t,e,s){return Math.abs(t-e)<s}function zn(t){const e=Math.round(t);t=ls(t,e,t/1e3)?e:t;const s=Math.pow(10,Math.floor(Fn(t))),i=t/s;return(i<=1?1:i<=2?2:i<=5?5:10)*s}function lc(t){const e=[],s=Math.sqrt(t);let i;for(i=1;i<s;i++)t%i===0&&(e.push(i),e.push(t/i));return s===(s|0)&&e.push(s),e.sort((n,a)=>n-a).pop(),e}function cc(t){return typeof t=="symbol"||typeof t=="object"&&t!==null&&!(Symbol.toPrimitive in t||"toString"in t||"valueOf"in t)}function cs(t){return!cc(t)&&!isNaN(parseFloat(t))&&isFinite(t)}function hc(t,e){const s=Math.round(t);return s-e<=t&&s+e>=t}function dc(t,e,s){let i,n,a;for(i=0,n=t.length;i<n;i++)a=t[i][s],isNaN(a)||(e.min=Math.min(e.min,a),e.max=Math.max(e.max,a))}function tt(t){return t*(oe/180)}function uc(t){return t*(180/oe)}function Bn(t){if(!me(t))return;let e=1,s=0;for(;Math.round(t*e)/e!==t;)e*=10,s++;return s}function fc(t,e){const s=e.x-t.x,i=e.y-t.y,n=Math.sqrt(s*s+i*i);let a=Math.atan2(i,s);return a<-.5*oe&&(a+=Ue),{angle:a,distance:n}}function pc(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function st(t){return(t%Ue+Ue)%Ue}function gc(t,e,s,i){const n=st(t),a=st(e),r=st(s),o=st(a-n),c=st(r-n),h=st(n-a),d=st(n-r);return n===a||n===r||i||o>c&&h<d}function ve(t,e,s){return Math.max(e,Math.min(s,t))}function mc(t){return ve(t,-32768,32767)}function pt(t,e,s,i=1e-6){return t>=Math.min(e,s)-i&&t<=Math.max(e,s)+i}function ri(t,e,s){s=s||(r=>t[r]<e);let i=t.length-1,n=0,a;for(;i-n>1;)a=n+i>>1,s(a)?n=a:i=a;return{lo:n,hi:i}}const oi=(t,e,s,i)=>ri(t,s,i?n=>{const a=t[n][e];return a<s||a===s&&t[n+1][e]===s}:n=>t[n][e]<s),_c=(t,e,s)=>ri(t,s,i=>t[i][e]>=s);function xc(t,e,s){let i=0,n=t.length;for(;i<n&&t[i]<e;)i++;for(;n>i&&t[n-1]>s;)n--;return i>0||n<t.length?t.slice(i,n):t}const Wn=["push","pop","shift","splice","unshift"];function yc(t,e){if(t._chartjs){t._chartjs.listeners.push(e);return}Object.defineProperty(t,"_chartjs",{configurable:!0,enumerable:!1,value:{listeners:[e]}}),Wn.forEach(s=>{const i="_onData"+ai(s),n=t[s];Object.defineProperty(t,s,{configurable:!0,enumerable:!1,value(...a){const r=n.apply(this,a);return t._chartjs.listeners.forEach(o=>{typeof o[i]=="function"&&o[i](...a)}),r}})})}function Hn(t,e){const s=t._chartjs;if(!s)return;const i=s.listeners,n=i.indexOf(e);n!==-1&&i.splice(n,1),!(i.length>0)&&(Wn.forEach(a=>{delete t[a]}),delete t._chartjs)}function Vn(t){const e=new Set(t);return e.size===t.length?t:Array.from(e)}const $n=function(){return typeof window>"u"?function(t){return t()}:window.requestAnimationFrame}();function Un(t,e){let s=[],i=!1;return function(...n){s=n,i||(i=!0,$n.call(window,()=>{i=!1,t.apply(e,s)}))}}function bc(t,e){let s;return function(...i){return e?(clearTimeout(s),s=setTimeout(t,e,i)):t.apply(this,i),e}}const Gn=t=>t==="start"?"left":t==="end"?"right":"center",fe=(t,e,s)=>t==="start"?e:t==="end"?s:(e+s)/2,vc=(t,e,s,i)=>t===(i?"left":"right")?s:t==="center"?(e+s)/2:e,hs=t=>t===0||t===1,Yn=(t,e,s)=>-(Math.pow(2,10*(t-=1))*Math.sin((t-e)*Ue/s)),Kn=(t,e,s)=>Math.pow(2,-10*t)*Math.sin((t-e)*Ue/s)+1,Et={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>-t*(t-2),easeInOutQuad:t=>(t/=.5)<1?.5*t*t:-.5*(--t*(t-2)-1),easeInCubic:t=>t*t*t,easeOutCubic:t=>(t-=1)*t*t+1,easeInOutCubic:t=>(t/=.5)<1?.5*t*t*t:.5*((t-=2)*t*t+2),easeInQuart:t=>t*t*t*t,easeOutQuart:t=>-((t-=1)*t*t*t-1),easeInOutQuart:t=>(t/=.5)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2),easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>(t-=1)*t*t*t*t+1,easeInOutQuint:t=>(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2),easeInSine:t=>-Math.cos(t*be)+1,easeOutSine:t=>Math.sin(t*be),easeInOutSine:t=>-.5*(Math.cos(oe*t)-1),easeInExpo:t=>t===0?0:Math.pow(2,10*(t-1)),easeOutExpo:t=>t===1?1:-Math.pow(2,-10*t)+1,easeInOutExpo:t=>hs(t)?t:t<.5?.5*Math.pow(2,10*(t*2-1)):.5*(-Math.pow(2,-10*(t*2-1))+2),easeInCirc:t=>t>=1?t:-(Math.sqrt(1-t*t)-1),easeOutCirc:t=>Math.sqrt(1-(t-=1)*t),easeInOutCirc:t=>(t/=.5)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1),easeInElastic:t=>hs(t)?t:Yn(t,.075,.3),easeOutElastic:t=>hs(t)?t:Kn(t,.075,.3),easeInOutElastic(t){return hs(t)?t:t<.5?.5*Yn(t*2,.1125,.45):.5+.5*Kn(t*2-1,.1125,.45)},easeInBack(t){return t*t*((1.70158+1)*t-1.70158)},easeOutBack(t){return(t-=1)*t*((1.70158+1)*t+1.70158)+1},easeInOutBack(t){let e=1.70158;return(t/=.5)<1?.5*(t*t*(((e*=1.525)+1)*t-e)):.5*((t-=2)*t*(((e*=1.525)+1)*t+e)+2)},easeInBounce:t=>1-Et.easeOutBounce(1-t),easeOutBounce(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},easeInOutBounce:t=>t<.5?Et.easeInBounce(t*2)*.5:Et.easeOutBounce(t*2-1)*.5+.5};function Xn(t){if(t&&typeof t=="object"){const e=t.toString();return e==="[object CanvasPattern]"||e==="[object CanvasGradient]"}return!1}function qn(t){return Xn(t)?t:new It(t)}function li(t){return Xn(t)?t:new It(t).saturate(.5).darken(.1).hexString()}const kc=["x","y","borderWidth","radius","tension"],wc=["color","borderColor","backgroundColor"];function jc(t){t.set("animation",{delay:void 0,duration:1e3,easing:"easeOutQuart",fn:void 0,from:void 0,loop:void 0,to:void 0,type:void 0}),t.describe("animation",{_fallback:!1,_indexable:!1,_scriptable:e=>e!=="onProgress"&&e!=="onComplete"&&e!=="fn"}),t.set("animations",{colors:{type:"color",properties:wc},numbers:{type:"number",properties:kc}}),t.describe("animations",{_fallback:"animation"}),t.set("transitions",{active:{animation:{duration:400}},resize:{animation:{duration:0}},show:{animations:{colors:{from:"transparent"},visible:{type:"boolean",duration:0}}},hide:{animations:{colors:{to:"transparent"},visible:{type:"boolean",easing:"linear",fn:e=>e|0}}}})}function Sc(t){t.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})}const Jn=new Map;function Cc(t,e){e=e||{};const s=t+JSON.stringify(e);let i=Jn.get(s);return i||(i=new Intl.NumberFormat(t,e),Jn.set(s,i)),i}function Qn(t,e,s){return Cc(e,s).format(t)}const Mc={values(t){return te(t)?t:""+t},numeric(t,e,s){if(t===0)return"0";const i=this.chart.options.locale;let n,a=t;if(s.length>1){const h=Math.max(Math.abs(s[0].value),Math.abs(s[s.length-1].value));(h<1e-4||h>1e15)&&(n="scientific"),a=Pc(t,s)}const r=Fn(Math.abs(a)),o=isNaN(r)?1:Math.max(Math.min(-1*Math.floor(r),20),0),c={notation:n,minimumFractionDigits:o,maximumFractionDigits:o};return Object.assign(c,this.options.ticks.format),Qn(t,i,c)}};function Pc(t,e){let s=e.length>3?e[2].value-e[1].value:e[1].value-e[0].value;return Math.abs(s)>=1&&t!==Math.floor(t)&&(s=t-Math.floor(t)),s}var Zn={formatters:Mc};function Ac(t){t.set("scale",{display:!0,offset:!1,reverse:!1,beginAtZero:!1,bounds:"ticks",clip:!0,grace:0,grid:{display:!0,lineWidth:1,drawOnChartArea:!0,drawTicks:!0,tickLength:8,tickWidth:(e,s)=>s.lineWidth,tickColor:(e,s)=>s.color,offset:!1},border:{display:!0,dash:[],dashOffset:0,width:1},title:{display:!1,text:"",padding:{top:4,bottom:4}},ticks:{minRotation:0,maxRotation:50,mirror:!1,textStrokeWidth:0,textStrokeColor:"",padding:3,display:!0,autoSkip:!0,autoSkipPadding:3,labelOffset:0,callback:Zn.formatters.values,minor:{},major:{},align:"center",crossAlign:"near",showLabelBackdrop:!1,backdropColor:"rgba(255, 255, 255, 0.75)",backdropPadding:2}}),t.route("scale.ticks","color","","color"),t.route("scale.grid","color","","borderColor"),t.route("scale.border","color","","borderColor"),t.route("scale.title","color","","color"),t.describe("scale",{_fallback:!1,_scriptable:e=>!e.startsWith("before")&&!e.startsWith("after")&&e!=="callback"&&e!=="parser",_indexable:e=>e!=="borderDash"&&e!=="tickBorderDash"&&e!=="dash"}),t.describe("scales",{_fallback:"scale"}),t.describe("scale.ticks",{_scriptable:e=>e!=="backdropPadding"&&e!=="callback",_indexable:e=>e!=="backdropPadding"})}const it=Object.create(null),ci=Object.create(null);function Rt(t,e){if(!e)return t;const s=e.split(".");for(let i=0,n=s.length;i<n;++i){const a=s[i];t=t[a]||(t[a]=Object.create(null))}return t}function hi(t,e,s){return typeof e=="string"?Lt(Rt(t,e),s):Lt(Rt(t,""),e)}class Oc{constructor(e,s){this.animation=void 0,this.backgroundColor="rgba(0,0,0,0.1)",this.borderColor="rgba(0,0,0,0.1)",this.color="#666",this.datasets={},this.devicePixelRatio=i=>i.chart.platform.getDevicePixelRatio(),this.elements={},this.events=["mousemove","mouseout","click","touchstart","touchmove"],this.font={family:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",size:12,style:"normal",lineHeight:1.2,weight:null},this.hover={},this.hoverBackgroundColor=(i,n)=>li(n.backgroundColor),this.hoverBorderColor=(i,n)=>li(n.borderColor),this.hoverColor=(i,n)=>li(n.color),this.indexAxis="x",this.interaction={mode:"nearest",intersect:!0,includeInvisible:!1},this.maintainAspectRatio=!0,this.onHover=null,this.onClick=null,this.parsing=!0,this.plugins={},this.responsive=!0,this.scale=void 0,this.scales={},this.showLine=!0,this.drawActiveElementsOnTop=!0,this.describe(e),this.apply(s)}set(e,s){return hi(this,e,s)}get(e){return Rt(this,e)}describe(e,s){return hi(ci,e,s)}override(e,s){return hi(it,e,s)}route(e,s,i,n){const a=Rt(this,e),r=Rt(this,i),o="_"+s;Object.defineProperties(a,{[o]:{value:a[s],writable:!0},[s]:{enumerable:!0,get(){const c=this[o],h=r[n];return $(c)?Object.assign({},h,c):G(c,h)},set(c){this[o]=c}}})}apply(e){e.forEach(s=>s(this))}}var ee=new Oc({_scriptable:t=>!t.startsWith("on"),_indexable:t=>t!=="events",hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[jc,Sc,Ac]);function Ic(t){return!t||K(t.size)||K(t.family)?null:(t.style?t.style+" ":"")+(t.weight?t.weight+" ":"")+t.size+"px "+t.family}function ea(t,e,s,i,n){let a=e[n];return a||(a=e[n]=t.measureText(n).width,s.push(n)),a>i&&(i=a),i}function nt(t,e,s){const i=t.currentDevicePixelRatio,n=s!==0?Math.max(s/2,.5):0;return Math.round((e-n)*i)/i+n}function ta(t,e){!e&&!t||(e=e||t.getContext("2d"),e.save(),e.resetTransform(),e.clearRect(0,0,t.width,t.height),e.restore())}function sa(t,e,s,i){ia(t,e,s,i,null)}function ia(t,e,s,i,n){let a,r,o,c,h,d,u,p;const g=e.pointStyle,x=e.rotation,_=e.radius;let m=(x||0)*oc;if(g&&typeof g=="object"&&(a=g.toString(),a==="[object HTMLImageElement]"||a==="[object HTMLCanvasElement]")){t.save(),t.translate(s,i),t.rotate(m),t.drawImage(g,-g.width/2,-g.height/2,g.width,g.height),t.restore();return}if(!(isNaN(_)||_<=0)){switch(t.beginPath(),g){default:n?t.ellipse(s,i,n/2,_,0,0,Ue):t.arc(s,i,_,0,Ue),t.closePath();break;case"triangle":d=n?n/2:_,t.moveTo(s+Math.sin(m)*d,i-Math.cos(m)*_),m+=Dn,t.lineTo(s+Math.sin(m)*d,i-Math.cos(m)*_),m+=Dn,t.lineTo(s+Math.sin(m)*d,i-Math.cos(m)*_),t.closePath();break;case"rectRounded":h=_*.516,c=_-h,r=Math.cos(m+et)*c,u=Math.cos(m+et)*(n?n/2-h:c),o=Math.sin(m+et)*c,p=Math.sin(m+et)*(n?n/2-h:c),t.arc(s-u,i-o,h,m-oe,m-be),t.arc(s+p,i-r,h,m-be,m),t.arc(s+u,i+o,h,m,m+be),t.arc(s-p,i+r,h,m+be,m+oe),t.closePath();break;case"rect":if(!x){c=Math.SQRT1_2*_,d=n?n/2:c,t.rect(s-d,i-c,2*d,2*c);break}m+=et;case"rectRot":u=Math.cos(m)*(n?n/2:_),r=Math.cos(m)*_,o=Math.sin(m)*_,p=Math.sin(m)*(n?n/2:_),t.moveTo(s-u,i-o),t.lineTo(s+p,i-r),t.lineTo(s+u,i+o),t.lineTo(s-p,i+r),t.closePath();break;case"crossRot":m+=et;case"cross":u=Math.cos(m)*(n?n/2:_),r=Math.cos(m)*_,o=Math.sin(m)*_,p=Math.sin(m)*(n?n/2:_),t.moveTo(s-u,i-o),t.lineTo(s+u,i+o),t.moveTo(s+p,i-r),t.lineTo(s-p,i+r);break;case"star":u=Math.cos(m)*(n?n/2:_),r=Math.cos(m)*_,o=Math.sin(m)*_,p=Math.sin(m)*(n?n/2:_),t.moveTo(s-u,i-o),t.lineTo(s+u,i+o),t.moveTo(s+p,i-r),t.lineTo(s-p,i+r),m+=et,u=Math.cos(m)*(n?n/2:_),r=Math.cos(m)*_,o=Math.sin(m)*_,p=Math.sin(m)*(n?n/2:_),t.moveTo(s-u,i-o),t.lineTo(s+u,i+o),t.moveTo(s+p,i-r),t.lineTo(s-p,i+r);break;case"line":r=n?n/2:Math.cos(m)*_,o=Math.sin(m)*_,t.moveTo(s-r,i-o),t.lineTo(s+r,i+o);break;case"dash":t.moveTo(s,i),t.lineTo(s+Math.cos(m)*(n?n/2:_),i+Math.sin(m)*_);break;case!1:t.closePath();break}t.fill(),e.borderWidth>0&&t.stroke()}}function na(t,e,s){return s=s||.5,!e||t&&t.x>e.left-s&&t.x<e.right+s&&t.y>e.top-s&&t.y<e.bottom+s}function di(t,e){t.save(),t.beginPath(),t.rect(e.left,e.top,e.right-e.left,e.bottom-e.top),t.clip()}function ui(t){t.restore()}function Lc(t,e){e.translation&&t.translate(e.translation[0],e.translation[1]),K(e.rotation)||t.rotate(e.rotation),e.color&&(t.fillStyle=e.color),e.textAlign&&(t.textAlign=e.textAlign),e.textBaseline&&(t.textBaseline=e.textBaseline)}function Nc(t,e,s,i,n){if(n.strikethrough||n.underline){const a=t.measureText(i),r=e-a.actualBoundingBoxLeft,o=e+a.actualBoundingBoxRight,c=s-a.actualBoundingBoxAscent,h=s+a.actualBoundingBoxDescent,d=n.strikethrough?(c+h)/2:h;t.strokeStyle=t.fillStyle,t.beginPath(),t.lineWidth=n.decorationWidth||2,t.moveTo(r,d),t.lineTo(o,d),t.stroke()}}function Tc(t,e){const s=t.fillStyle;t.fillStyle=e.color,t.fillRect(e.left,e.top,e.width,e.height),t.fillStyle=s}function ds(t,e,s,i,n,a={}){const r=te(e)?e:[e],o=a.strokeWidth>0&&a.strokeColor!=="";let c,h;for(t.save(),t.font=n.string,Lc(t,a),c=0;c<r.length;++c)h=r[c],a.backdrop&&Tc(t,a.backdrop),o&&(a.strokeColor&&(t.strokeStyle=a.strokeColor),K(a.strokeWidth)||(t.lineWidth=a.strokeWidth),t.strokeText(h,s,i,a.maxWidth)),t.fillText(h,s,i,a.maxWidth),Nc(t,s,i,h,a),i+=Number(n.lineHeight);t.restore()}function us(t,e){const{x:s,y:i,w:n,h:a,radius:r}=e;t.arc(s+r.topLeft,i+r.topLeft,r.topLeft,1.5*oe,oe,!0),t.lineTo(s,i+a-r.bottomLeft),t.arc(s+r.bottomLeft,i+a-r.bottomLeft,r.bottomLeft,oe,be,!0),t.lineTo(s+n-r.bottomRight,i+a),t.arc(s+n-r.bottomRight,i+a-r.bottomRight,r.bottomRight,be,0,!0),t.lineTo(s+n,i+r.topRight),t.arc(s+n-r.topRight,i+r.topRight,r.topRight,0,-be,!0),t.lineTo(s+r.topLeft,i)}const Ec=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,Rc=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;function Dc(t,e){const s=(""+t).match(Ec);if(!s||s[1]==="normal")return e*1.2;switch(t=+s[2],s[3]){case"px":return t;case"%":t/=100;break}return e*t}const Fc=t=>+t||0;function aa(t,e){const s={},i=$(e),n=i?Object.keys(e):e,a=$(t)?i?r=>G(t[r],t[e[r]]):r=>t[r]:()=>t;for(const r of n)s[r]=Fc(a(r));return s}function ra(t){return aa(t,{top:"y",right:"x",bottom:"y",left:"x"})}function gt(t){return aa(t,["topLeft","topRight","bottomLeft","bottomRight"])}function ke(t){const e=ra(t);return e.width=e.left+e.right,e.height=e.top+e.bottom,e}function le(t,e){t=t||{},e=e||ee.font;let s=G(t.size,e.size);typeof s=="string"&&(s=parseInt(s,10));let i=G(t.style,e.style);i&&!(""+i).match(Rc)&&(console.warn('Invalid font style specified: "'+i+'"'),i=void 0);const n={family:G(t.family,e.family),lineHeight:Dc(G(t.lineHeight,e.lineHeight),s),size:s,style:i,weight:G(t.weight,e.weight),string:""};return n.string=Ic(n),n}function fs(t,e,s,i){let n,a,r;for(n=0,a=t.length;n<a;++n)if(r=t[n],r!==void 0&&r!==void 0)return r}function zc(t,e,s){const{min:i,max:n}=t,a=tc(e,(n-i)/2),r=(o,c)=>s&&o===0?0:o+c;return{min:r(i,-Math.abs(a)),max:r(n,a)}}function mt(t,e){return Object.assign(Object.create(t),e)}function fi(t,e=[""],s,i,n=()=>t[0]){const a=s||t;typeof i>"u"&&(i=da("_fallback",t));const r={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:t,_rootScopes:a,_fallback:i,_getTarget:n,override:o=>fi([o,...t],e,a,i)};return new Proxy(r,{deleteProperty(o,c){return delete o[c],delete o._keys,delete t[0][c],!0},get(o,c){return la(o,c,()=>Yc(c,e,t,o))},getOwnPropertyDescriptor(o,c){return Reflect.getOwnPropertyDescriptor(o._scopes[0],c)},getPrototypeOf(){return Reflect.getPrototypeOf(t[0])},has(o,c){return ua(o).includes(c)},ownKeys(o){return ua(o)},set(o,c,h){const d=o._storage||(o._storage=n());return o[c]=d[c]=h,delete o._keys,!0}})}function _t(t,e,s,i){const n={_cacheable:!1,_proxy:t,_context:e,_subProxy:s,_stack:new Set,_descriptors:oa(t,i),setContext:a=>_t(t,a,s,i),override:a=>_t(t.override(a),e,s,i)};return new Proxy(n,{deleteProperty(a,r){return delete a[r],delete t[r],!0},get(a,r,o){return la(a,r,()=>Wc(a,r,o))},getOwnPropertyDescriptor(a,r){return a._descriptors.allKeys?Reflect.has(t,r)?{enumerable:!0,configurable:!0}:void 0:Reflect.getOwnPropertyDescriptor(t,r)},getPrototypeOf(){return Reflect.getPrototypeOf(t)},has(a,r){return Reflect.has(t,r)},ownKeys(){return Reflect.ownKeys(t)},set(a,r,o){return t[r]=o,delete a[r],!0}})}function oa(t,e={scriptable:!0,indexable:!0}){const{_scriptable:s=e.scriptable,_indexable:i=e.indexable,_allKeys:n=e.allKeys}=t;return{allKeys:n,scriptable:s,indexable:i,isScriptable:$e(s)?s:()=>s,isIndexable:$e(i)?i:()=>i}}const Bc=(t,e)=>t?t+ai(e):e,pi=(t,e)=>$(e)&&t!=="adapters"&&(Object.getPrototypeOf(e)===null||e.constructor===Object);function la(t,e,s){if(Object.prototype.hasOwnProperty.call(t,e)||e==="constructor")return t[e];const i=s();return t[e]=i,i}function Wc(t,e,s){const{_proxy:i,_context:n,_subProxy:a,_descriptors:r}=t;let o=i[e];return $e(o)&&r.isScriptable(e)&&(o=Hc(e,o,t,s)),te(o)&&o.length&&(o=Vc(e,o,t,r.isIndexable)),pi(e,o)&&(o=_t(o,n,a&&a[e],r)),o}function Hc(t,e,s,i){const{_proxy:n,_context:a,_subProxy:r,_stack:o}=s;if(o.has(t))throw new Error("Recursion detected: "+Array.from(o).join("->")+"->"+t);o.add(t);let c=e(a,r||i);return o.delete(t),pi(t,c)&&(c=gi(n._scopes,n,t,c)),c}function Vc(t,e,s,i){const{_proxy:n,_context:a,_subProxy:r,_descriptors:o}=s;if(typeof a.index<"u"&&i(t))return e[a.index%e.length];if($(e[0])){const c=e,h=n._scopes.filter(d=>d!==c);e=[];for(const d of c){const u=gi(h,n,t,d);e.push(_t(u,a,r&&r[t],o))}}return e}function ca(t,e,s){return $e(t)?t(e,s):t}const $c=(t,e)=>t===!0?e:typeof t=="string"?ft(e,t):void 0;function Uc(t,e,s,i,n){for(const a of e){const r=$c(s,a);if(r){t.add(r);const o=ca(r._fallback,s,n);if(typeof o<"u"&&o!==s&&o!==i)return o}else if(r===!1&&typeof i<"u"&&s!==i)return null}return!1}function gi(t,e,s,i){const n=e._rootScopes,a=ca(e._fallback,s,i),r=[...t,...n],o=new Set;o.add(i);let c=ha(o,r,s,a||s,i);return c===null||typeof a<"u"&&a!==s&&(c=ha(o,r,a,c,i),c===null)?!1:fi(Array.from(o),[""],n,a,()=>Gc(e,s,i))}function ha(t,e,s,i,n){for(;s;)s=Uc(t,e,s,i,n);return s}function Gc(t,e,s){const i=t._getTarget();e in i||(i[e]={});const n=i[e];return te(n)&&$(s)?s:n||{}}function Yc(t,e,s,i){let n;for(const a of e)if(n=da(Bc(a,t),s),typeof n<"u")return pi(t,n)?gi(s,i,t,n):n}function da(t,e){for(const s of e){if(!s)continue;const i=s[t];if(typeof i<"u")return i}}function ua(t){let e=t._keys;return e||(e=t._keys=Kc(t._scopes)),e}function Kc(t){const e=new Set;for(const s of t)for(const i of Object.keys(s).filter(n=>!n.startsWith("_")))e.add(i);return Array.from(e)}function mi(){return typeof window<"u"&&typeof document<"u"}function _i(t){let e=t.parentNode;return e&&e.toString()==="[object ShadowRoot]"&&(e=e.host),e}function ps(t,e,s){let i;return typeof t=="string"?(i=parseInt(t,10),t.indexOf("%")!==-1&&(i=i/100*e.parentNode[s])):i=t,i}const gs=t=>t.ownerDocument.defaultView.getComputedStyle(t,null);function Xc(t,e){return gs(t).getPropertyValue(e)}const qc=["top","right","bottom","left"];function at(t,e,s){const i={};s=s?"-"+s:"";for(let n=0;n<4;n++){const a=qc[n];i[a]=parseFloat(t[e+"-"+a+s])||0}return i.width=i.left+i.right,i.height=i.top+i.bottom,i}const Jc=(t,e,s)=>(t>0||e>0)&&(!s||!s.shadowRoot);function Qc(t,e){const s=t.touches,i=s&&s.length?s[0]:t,{offsetX:n,offsetY:a}=i;let r=!1,o,c;if(Jc(n,a,t.target))o=n,c=a;else{const h=e.getBoundingClientRect();o=i.clientX-h.left,c=i.clientY-h.top,r=!0}return{x:o,y:c,box:r}}function rt(t,e){if("native"in t)return t;const{canvas:s,currentDevicePixelRatio:i}=e,n=gs(s),a=n.boxSizing==="border-box",r=at(n,"padding"),o=at(n,"border","width"),{x:c,y:h,box:d}=Qc(t,s),u=r.left+(d&&o.left),p=r.top+(d&&o.top);let{width:g,height:x}=e;return a&&(g-=r.width+o.width,x-=r.height+o.height),{x:Math.round((c-u)/g*s.width/i),y:Math.round((h-p)/x*s.height/i)}}function Zc(t,e,s){let i,n;if(e===void 0||s===void 0){const a=t&&_i(t);if(!a)e=t.clientWidth,s=t.clientHeight;else{const r=a.getBoundingClientRect(),o=gs(a),c=at(o,"border","width"),h=at(o,"padding");e=r.width-h.width-c.width,s=r.height-h.height-c.height,i=ps(o.maxWidth,a,"clientWidth"),n=ps(o.maxHeight,a,"clientHeight")}}return{width:e,height:s,maxWidth:i||os,maxHeight:n||os}}const Ye=t=>Math.round(t*10)/10;function eh(t,e,s,i){const n=gs(t),a=at(n,"margin"),r=ps(n.maxWidth,t,"clientWidth")||os,o=ps(n.maxHeight,t,"clientHeight")||os,c=Zc(t,e,s);let{width:h,height:d}=c;if(n.boxSizing==="content-box"){const p=at(n,"border","width"),g=at(n,"padding");h-=g.width+p.width,d-=g.height+p.height}return h=Math.max(0,h-a.width),d=Math.max(0,i?h/i:d-a.height),h=Ye(Math.min(h,r,c.maxWidth)),d=Ye(Math.min(d,o,c.maxHeight)),h&&!d&&(d=Ye(h/2)),(e!==void 0||s!==void 0)&&i&&c.height&&d>c.height&&(d=c.height,h=Ye(Math.floor(d*i))),{width:h,height:d}}function fa(t,e,s){const i=e||1,n=Ye(t.height*i),a=Ye(t.width*i);t.height=Ye(t.height),t.width=Ye(t.width);const r=t.canvas;return r.style&&(s||!r.style.height&&!r.style.width)&&(r.style.height=`${t.height}px`,r.style.width=`${t.width}px`),t.currentDevicePixelRatio!==i||r.height!==n||r.width!==a?(t.currentDevicePixelRatio=i,r.height=n,r.width=a,t.ctx.setTransform(i,0,0,i,0,0),!0):!1}const th=function(){let t=!1;try{const e={get passive(){return t=!0,!1}};mi()&&(window.addEventListener("test",null,e),window.removeEventListener("test",null,e))}catch{}return t}();function pa(t,e){const s=Xc(t,e),i=s&&s.match(/^(\d+)(\.\d+)?px$/);return i?+i[1]:void 0}const sh=function(t,e){return{x(s){return t+t+e-s},setWidth(s){e=s},textAlign(s){return s==="center"?s:s==="right"?"left":"right"},xPlus(s,i){return s-i},leftForLtr(s,i){return s-i}}},ih=function(){return{x(t){return t},setWidth(t){},textAlign(t){return t},xPlus(t,e){return t+e},leftForLtr(t,e){return t}}};function xt(t,e,s){return t?sh(e,s):ih()}function ga(t,e){let s,i;(e==="ltr"||e==="rtl")&&(s=t.canvas.style,i=[s.getPropertyValue("direction"),s.getPropertyPriority("direction")],s.setProperty("direction",e,"important"),t.prevTextDirection=i)}function ma(t,e){e!==void 0&&(delete t.prevTextDirection,t.canvas.style.setProperty("direction",e[0],e[1]))}function ms(t,e,s){return t.options.clip?t[s]:e[s]}function nh(t,e){const{xScale:s,yScale:i}=t;return s&&i?{left:ms(s,e,"left"),right:ms(s,e,"right"),top:ms(i,e,"top"),bottom:ms(i,e,"bottom")}:e}function ah(t,e){const s=e._clip;if(s.disabled)return!1;const i=nh(e,t.chartArea);return{left:s.left===!1?0:i.left-(s.left===!0?0:s.left),right:s.right===!1?t.width:i.right+(s.right===!0?0:s.right),top:s.top===!1?0:i.top-(s.top===!0?0:s.top),bottom:s.bottom===!1?t.height:i.bottom+(s.bottom===!0?0:s.bottom)}}/*!
 * Chart.js v4.5.1
 * https://www.chartjs.org
 * (c) 2025 Chart.js Contributors
 * Released under the MIT License
 */class rh{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(e,s,i,n){const a=s.listeners[n],r=s.duration;a.forEach(o=>o({chart:e,initial:s.initial,numSteps:r,currentStep:Math.min(i-s.start,r)}))}_refresh(){this._request||(this._running=!0,this._request=$n.call(window,()=>{this._update(),this._request=null,this._running&&this._refresh()}))}_update(e=Date.now()){let s=0;this._charts.forEach((i,n)=>{if(!i.running||!i.items.length)return;const a=i.items;let r=a.length-1,o=!1,c;for(;r>=0;--r)c=a[r],c._active?(c._total>i.duration&&(i.duration=c._total),c.tick(e),o=!0):(a[r]=a[a.length-1],a.pop());o&&(n.draw(),this._notify(n,i,e,"progress")),a.length||(i.running=!1,this._notify(n,i,e,"complete"),i.initial=!1),s+=a.length}),this._lastDate=e,s===0&&(this._running=!1)}_getAnims(e){const s=this._charts;let i=s.get(e);return i||(i={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},s.set(e,i)),i}listen(e,s,i){this._getAnims(e).listeners[s].push(i)}add(e,s){!s||!s.length||this._getAnims(e).items.push(...s)}has(e){return this._getAnims(e).items.length>0}start(e){const s=this._charts.get(e);s&&(s.running=!0,s.start=Date.now(),s.duration=s.items.reduce((i,n)=>Math.max(i,n._duration),0),this._refresh())}running(e){if(!this._running)return!1;const s=this._charts.get(e);return!(!s||!s.running||!s.items.length)}stop(e){const s=this._charts.get(e);if(!s||!s.items.length)return;const i=s.items;let n=i.length-1;for(;n>=0;--n)i[n].cancel();s.items=[],this._notify(e,s,Date.now(),"complete")}remove(e){return this._charts.delete(e)}}var Ee=new rh;const _a="transparent",oh={boolean(t,e,s){return s>.5?e:t},color(t,e,s){const i=qn(t||_a),n=i.valid&&qn(e||_a);return n&&n.valid?n.mix(i,s).hexString():e},number(t,e,s){return t+(e-t)*s}};class lh{constructor(e,s,i,n){const a=s[i];n=fs([e.to,n,a,e.from]);const r=fs([e.from,a,n]);this._active=!0,this._fn=e.fn||oh[e.type||typeof r],this._easing=Et[e.easing]||Et.linear,this._start=Math.floor(Date.now()+(e.delay||0)),this._duration=this._total=Math.floor(e.duration),this._loop=!!e.loop,this._target=s,this._prop=i,this._from=r,this._to=n,this._promises=void 0}active(){return this._active}update(e,s,i){if(this._active){this._notify(!1);const n=this._target[this._prop],a=i-this._start,r=this._duration-a;this._start=i,this._duration=Math.floor(Math.max(r,e.duration)),this._total+=a,this._loop=!!e.loop,this._to=fs([e.to,s,n,e.from]),this._from=fs([e.from,n,s])}}cancel(){this._active&&(this.tick(Date.now()),this._active=!1,this._notify(!1))}tick(e){const s=e-this._start,i=this._duration,n=this._prop,a=this._from,r=this._loop,o=this._to;let c;if(this._active=a!==o&&(r||s<i),!this._active){this._target[n]=o,this._notify(!0);return}if(s<0){this._target[n]=a;return}c=s/i%2,c=r&&c>1?2-c:c,c=this._easing(Math.min(1,Math.max(0,c))),this._target[n]=this._fn(a,o,c)}wait(){const e=this._promises||(this._promises=[]);return new Promise((s,i)=>{e.push({res:s,rej:i})})}_notify(e){const s=e?"res":"rej",i=this._promises||[];for(let n=0;n<i.length;n++)i[n][s]()}}class xa{constructor(e,s){this._chart=e,this._properties=new Map,this.configure(s)}configure(e){if(!$(e))return;const s=Object.keys(ee.animation),i=this._properties;Object.getOwnPropertyNames(e).forEach(n=>{const a=e[n];if(!$(a))return;const r={};for(const o of s)r[o]=a[o];(te(a.properties)&&a.properties||[n]).forEach(o=>{(o===n||!i.has(o))&&i.set(o,r)})})}_animateOptions(e,s){const i=s.options,n=hh(e,i);if(!n)return[];const a=this._createAnimations(n,i);return i.$shared&&ch(e.options.$animations,i).then(()=>{e.options=i},()=>{}),a}_createAnimations(e,s){const i=this._properties,n=[],a=e.$animations||(e.$animations={}),r=Object.keys(s),o=Date.now();let c;for(c=r.length-1;c>=0;--c){const h=r[c];if(h.charAt(0)==="$")continue;if(h==="options"){n.push(...this._animateOptions(e,s));continue}const d=s[h];let u=a[h];const p=i.get(h);if(u)if(p&&u.active()){u.update(p,d,o);continue}else u.cancel();if(!p||!p.duration){e[h]=d;continue}a[h]=u=new lh(p,e,h,d),n.push(u)}return n}update(e,s){if(this._properties.size===0){Object.assign(e,s);return}const i=this._createAnimations(e,s);if(i.length)return Ee.add(this._chart,i),!0}}function ch(t,e){const s=[],i=Object.keys(e);for(let n=0;n<i.length;n++){const a=t[i[n]];a&&a.active()&&s.push(a.wait())}return Promise.all(s)}function hh(t,e){if(!e)return;let s=t.options;if(!s){t.options=e;return}return s.$shared&&(t.options=s=Object.assign({},s,{$shared:!1,$animations:{}})),s}function ya(t,e){const s=t&&t.options||{},i=s.reverse,n=s.min===void 0?e:0,a=s.max===void 0?e:0;return{start:i?a:n,end:i?n:a}}function dh(t,e,s){if(s===!1)return!1;const i=ya(t,s),n=ya(e,s);return{top:n.end,right:i.end,bottom:n.start,left:i.start}}function uh(t){let e,s,i,n;return $(t)?(e=t.top,s=t.right,i=t.bottom,n=t.left):e=s=i=n=t,{top:e,right:s,bottom:i,left:n,disabled:t===!1}}function ba(t,e){const s=[],i=t._getSortedDatasetMetas(e);let n,a;for(n=0,a=i.length;n<a;++n)s.push(i[n].index);return s}function va(t,e,s,i={}){const n=t.keys,a=i.mode==="single";let r,o,c,h;if(e===null)return;let d=!1;for(r=0,o=n.length;r<o;++r){if(c=+n[r],c===s){if(d=!0,i.all)continue;break}h=t.values[c],me(h)&&(a||e===0||Ge(e)===Ge(h))&&(e+=h)}return!d&&!i.all?0:e}function fh(t,e){const{iScale:s,vScale:i}=e,n=s.axis==="x"?"x":"y",a=i.axis==="x"?"x":"y",r=Object.keys(t),o=new Array(r.length);let c,h,d;for(c=0,h=r.length;c<h;++c)d=r[c],o[c]={[n]:d,[a]:t[d]};return o}function xi(t,e){const s=t&&t.options.stacked;return s||s===void 0&&e.stack!==void 0}function ph(t,e,s){return`${t.id}.${e.id}.${s.stack||s.type}`}function gh(t){const{min:e,max:s,minDefined:i,maxDefined:n}=t.getUserBounds();return{min:i?e:Number.NEGATIVE_INFINITY,max:n?s:Number.POSITIVE_INFINITY}}function mh(t,e,s){const i=t[e]||(t[e]={});return i[s]||(i[s]={})}function ka(t,e,s,i){for(const n of e.getMatchingVisibleMetas(i).reverse()){const a=t[n.index];if(s&&a>0||!s&&a<0)return n.index}return null}function wa(t,e){const{chart:s,_cachedMeta:i}=t,n=s._stacks||(s._stacks={}),{iScale:a,vScale:r,index:o}=i,c=a.axis,h=r.axis,d=ph(a,r,i),u=e.length;let p;for(let g=0;g<u;++g){const x=e[g],{[c]:_,[h]:m}=x,v=x._stacks||(x._stacks={});p=v[h]=mh(n,d,_),p[o]=m,p._top=ka(p,r,!0,i.type),p._bottom=ka(p,r,!1,i.type);const w=p._visualValues||(p._visualValues={});w[o]=m}}function yi(t,e){const s=t.scales;return Object.keys(s).filter(i=>s[i].axis===e).shift()}function _h(t,e){return mt(t,{active:!1,dataset:void 0,datasetIndex:e,index:e,mode:"default",type:"dataset"})}function xh(t,e,s){return mt(t,{active:!1,dataIndex:e,parsed:void 0,raw:void 0,element:s,index:e,mode:"default",type:"data"})}function Dt(t,e){const s=t.controller.index,i=t.vScale&&t.vScale.axis;if(i){e=e||t._parsed;for(const n of e){const a=n._stacks;if(!a||a[i]===void 0||a[i][s]===void 0)return;delete a[i][s],a[i]._visualValues!==void 0&&a[i]._visualValues[s]!==void 0&&delete a[i]._visualValues[s]}}}const bi=t=>t==="reset"||t==="none",ja=(t,e)=>e?t:Object.assign({},t),yh=(t,e,s)=>t&&!e.hidden&&e._stacked&&{keys:ba(s,!0),values:null};class Ft{constructor(e,s){this.chart=e,this._ctx=e.ctx,this.index=s,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){const e=this._cachedMeta;this.configure(),this.linkScales(),e._stacked=xi(e.vScale,e),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler")&&console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(e){this.index!==e&&Dt(this._cachedMeta),this.index=e}linkScales(){const e=this.chart,s=this._cachedMeta,i=this.getDataset(),n=(u,p,g,x)=>u==="x"?p:u==="r"?x:g,a=s.xAxisID=G(i.xAxisID,yi(e,"x")),r=s.yAxisID=G(i.yAxisID,yi(e,"y")),o=s.rAxisID=G(i.rAxisID,yi(e,"r")),c=s.indexAxis,h=s.iAxisID=n(c,a,r,o),d=s.vAxisID=n(c,r,a,o);s.xScale=this.getScaleForId(a),s.yScale=this.getScaleForId(r),s.rScale=this.getScaleForId(o),s.iScale=this.getScaleForId(h),s.vScale=this.getScaleForId(d)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(e){return this.chart.scales[e]}_getOtherScale(e){const s=this._cachedMeta;return e===s.iScale?s.vScale:s.iScale}reset(){this._update("reset")}_destroy(){const e=this._cachedMeta;this._data&&Hn(this._data,this),e._stacked&&Dt(e)}_dataCheck(){const e=this.getDataset(),s=e.data||(e.data=[]),i=this._data;if($(s)){const n=this._cachedMeta;this._data=fh(s,n)}else if(i!==s){if(i){Hn(i,this);const n=this._cachedMeta;Dt(n),n._parsed=[]}s&&Object.isExtensible(s)&&yc(s,this),this._syncList=[],this._data=s}}addElements(){const e=this._cachedMeta;this._dataCheck(),this.datasetElementType&&(e.dataset=new this.datasetElementType)}buildOrUpdateElements(e){const s=this._cachedMeta,i=this.getDataset();let n=!1;this._dataCheck();const a=s._stacked;s._stacked=xi(s.vScale,s),s.stack!==i.stack&&(n=!0,Dt(s),s.stack=i.stack),this._resyncElements(e),(n||a!==s._stacked)&&(wa(this,s._parsed),s._stacked=xi(s.vScale,s))}configure(){const e=this.chart.config,s=e.datasetScopeKeys(this._type),i=e.getOptionScopes(this.getDataset(),s,!0);this.options=e.createResolver(i,this.getContext()),this._parsing=this.options.parsing,this._cachedDataOpts={}}parse(e,s){const{_cachedMeta:i,_data:n}=this,{iScale:a,_stacked:r}=i,o=a.axis;let c=e===0&&s===n.length?!0:i._sorted,h=e>0&&i._parsed[e-1],d,u,p;if(this._parsing===!1)i._parsed=n,i._sorted=!0,p=n;else{te(n[e])?p=this.parseArrayData(i,n,e,s):$(n[e])?p=this.parseObjectData(i,n,e,s):p=this.parsePrimitiveData(i,n,e,s);const g=()=>u[o]===null||h&&u[o]<h[o];for(d=0;d<s;++d)i._parsed[d+e]=u=p[d],c&&(g()&&(c=!1),h=u);i._sorted=c}r&&wa(this,p)}parsePrimitiveData(e,s,i,n){const{iScale:a,vScale:r}=e,o=a.axis,c=r.axis,h=a.getLabels(),d=a===r,u=new Array(n);let p,g,x;for(p=0,g=n;p<g;++p)x=p+i,u[p]={[o]:d||a.parse(h[x],x),[c]:r.parse(s[x],x)};return u}parseArrayData(e,s,i,n){const{xScale:a,yScale:r}=e,o=new Array(n);let c,h,d,u;for(c=0,h=n;c<h;++c)d=c+i,u=s[d],o[c]={x:a.parse(u[0],d),y:r.parse(u[1],d)};return o}parseObjectData(e,s,i,n){const{xScale:a,yScale:r}=e,{xAxisKey:o="x",yAxisKey:c="y"}=this._parsing,h=new Array(n);let d,u,p,g;for(d=0,u=n;d<u;++d)p=d+i,g=s[p],h[d]={x:a.parse(ft(g,o),p),y:r.parse(ft(g,c),p)};return h}getParsed(e){return this._cachedMeta._parsed[e]}getDataElement(e){return this._cachedMeta.data[e]}applyStack(e,s,i){const n=this.chart,a=this._cachedMeta,r=s[e.axis],o={keys:ba(n,!0),values:s._stacks[e.axis]._visualValues};return va(o,r,a.index,{mode:i})}updateRangeFromParsed(e,s,i,n){const a=i[s.axis];let r=a===null?NaN:a;const o=n&&i._stacks[s.axis];n&&o&&(n.values=o,r=va(n,a,this._cachedMeta.index)),e.min=Math.min(e.min,r),e.max=Math.max(e.max,r)}getMinMax(e,s){const i=this._cachedMeta,n=i._parsed,a=i._sorted&&e===i.iScale,r=n.length,o=this._getOtherScale(e),c=yh(s,i,this.chart),h={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:d,max:u}=gh(o);let p,g;function x(){g=n[p];const _=g[o.axis];return!me(g[e.axis])||d>_||u<_}for(p=0;p<r&&!(!x()&&(this.updateRangeFromParsed(h,e,g,c),a));++p);if(a){for(p=r-1;p>=0;--p)if(!x()){this.updateRangeFromParsed(h,e,g,c);break}}return h}getAllParsedValues(e){const s=this._cachedMeta._parsed,i=[];let n,a,r;for(n=0,a=s.length;n<a;++n)r=s[n][e.axis],me(r)&&i.push(r);return i}getMaxOverflow(){return!1}getLabelAndValue(e){const s=this._cachedMeta,i=s.iScale,n=s.vScale,a=this.getParsed(e);return{label:i?""+i.getLabelForValue(a[i.axis]):"",value:n?""+n.getLabelForValue(a[n.axis]):""}}_update(e){const s=this._cachedMeta;this.update(e||"default"),s._clip=uh(G(this.options.clip,dh(s.xScale,s.yScale,this.getMaxOverflow())))}update(e){}draw(){const e=this._ctx,s=this.chart,i=this._cachedMeta,n=i.data||[],a=s.chartArea,r=[],o=this._drawStart||0,c=this._drawCount||n.length-o,h=this.options.drawActiveElementsOnTop;let d;for(i.dataset&&i.dataset.draw(e,a,o,c),d=o;d<o+c;++d){const u=n[d];u.hidden||(u.active&&h?r.push(u):u.draw(e,a))}for(d=0;d<r.length;++d)r[d].draw(e,a)}getStyle(e,s){const i=s?"active":"default";return e===void 0&&this._cachedMeta.dataset?this.resolveDatasetElementOptions(i):this.resolveDataElementOptions(e||0,i)}getContext(e,s,i){const n=this.getDataset();let a;if(e>=0&&e<this._cachedMeta.data.length){const r=this._cachedMeta.data[e];a=r.$context||(r.$context=xh(this.getContext(),e,r)),a.parsed=this.getParsed(e),a.raw=n.data[e],a.index=a.dataIndex=e}else a=this.$context||(this.$context=_h(this.chart.getContext(),this.index)),a.dataset=n,a.index=a.datasetIndex=this.index;return a.active=!!s,a.mode=i,a}resolveDatasetElementOptions(e){return this._resolveElementOptions(this.datasetElementType.id,e)}resolveDataElementOptions(e,s){return this._resolveElementOptions(this.dataElementType.id,s,e)}_resolveElementOptions(e,s="default",i){const n=s==="active",a=this._cachedDataOpts,r=e+"-"+s,o=a[r],c=this.enableOptionSharing&&Tt(i);if(o)return ja(o,c);const h=this.chart.config,d=h.datasetElementScopeKeys(this._type,e),u=n?[`${e}Hover`,"hover",e,""]:[e,""],p=h.getOptionScopes(this.getDataset(),d),g=Object.keys(ee.elements[e]),x=()=>this.getContext(i,n,s),_=h.resolveNamedOptions(p,g,x,u);return _.$shared&&(_.$shared=c,a[r]=Object.freeze(ja(_,c))),_}_resolveAnimations(e,s,i){const n=this.chart,a=this._cachedDataOpts,r=`animation-${s}`,o=a[r];if(o)return o;let c;if(n.options.animation!==!1){const d=this.chart.config,u=d.datasetAnimationScopeKeys(this._type,s),p=d.getOptionScopes(this.getDataset(),u);c=d.createResolver(p,this.getContext(e,i,s))}const h=new xa(n,c&&c.animations);return c&&c._cacheable&&(a[r]=Object.freeze(h)),h}getSharedOptions(e){if(e.$shared)return this._sharedOptions||(this._sharedOptions=Object.assign({},e))}includeOptions(e,s){return!s||bi(e)||this.chart._animationsDisabled}_getSharedOptions(e,s){const i=this.resolveDataElementOptions(e,s),n=this._sharedOptions,a=this.getSharedOptions(i),r=this.includeOptions(s,a)||a!==n;return this.updateSharedOptions(a,s,i),{sharedOptions:a,includeOptions:r}}updateElement(e,s,i,n){bi(n)?Object.assign(e,i):this._resolveAnimations(s,n).update(e,i)}updateSharedOptions(e,s,i){e&&!bi(s)&&this._resolveAnimations(void 0,s).update(e,i)}_setStyle(e,s,i,n){e.active=n;const a=this.getStyle(s,n);this._resolveAnimations(s,i,n).update(e,{options:!n&&this.getSharedOptions(a)||a})}removeHoverStyle(e,s,i){this._setStyle(e,i,"active",!1)}setHoverStyle(e,s,i){this._setStyle(e,i,"active",!0)}_removeDatasetHoverStyle(){const e=this._cachedMeta.dataset;e&&this._setStyle(e,void 0,"active",!1)}_setDatasetHoverStyle(){const e=this._cachedMeta.dataset;e&&this._setStyle(e,void 0,"active",!0)}_resyncElements(e){const s=this._data,i=this._cachedMeta.data;for(const[o,c,h]of this._syncList)this[o](c,h);this._syncList=[];const n=i.length,a=s.length,r=Math.min(a,n);r&&this.parse(0,r),a>n?this._insertElements(n,a-n,e):a<n&&this._removeElements(a,n-a)}_insertElements(e,s,i=!0){const n=this._cachedMeta,a=n.data,r=e+s;let o;const c=h=>{for(h.length+=s,o=h.length-1;o>=r;o--)h[o]=h[o-s]};for(c(a),o=e;o<r;++o)a[o]=new this.dataElementType;this._parsing&&c(n._parsed),this.parse(e,s),i&&this.updateElements(a,e,s,"reset")}updateElements(e,s,i,n){}_removeElements(e,s){const i=this._cachedMeta;if(this._parsing){const n=i._parsed.splice(e,s);i._stacked&&Dt(i,n)}i.data.splice(e,s)}_sync(e){if(this._parsing)this._syncList.push(e);else{const[s,i,n]=e;this[s](i,n)}this.chart._dataChanges.push([this.index,...e])}_onDataPush(){const e=arguments.length;this._sync(["_insertElements",this.getDataset().data.length-e,e])}_onDataPop(){this._sync(["_removeElements",this._cachedMeta.data.length-1,1])}_onDataShift(){this._sync(["_removeElements",0,1])}_onDataSplice(e,s){s&&this._sync(["_removeElements",e,s]);const i=arguments.length-2;i&&this._sync(["_insertElements",e,i])}_onDataUnshift(){this._sync(["_insertElements",0,arguments.length])}}H(Ft,"defaults",{}),H(Ft,"datasetElementType",null),H(Ft,"dataElementType",null);function bh(t,e){if(!t._cache.$bar){const s=t.getMatchingVisibleMetas(e);let i=[];for(let n=0,a=s.length;n<a;n++)i=i.concat(s[n].controller.getAllParsedValues(t));t._cache.$bar=Vn(i.sort((n,a)=>n-a))}return t._cache.$bar}function vh(t){const e=t.iScale,s=bh(e,t.type);let i=e._length,n,a,r,o;const c=()=>{r===32767||r===-32768||(Tt(o)&&(i=Math.min(i,Math.abs(r-o)||i)),o=r)};for(n=0,a=s.length;n<a;++n)r=e.getPixelForValue(s[n]),c();for(o=void 0,n=0,a=e.ticks.length;n<a;++n)r=e.getPixelForTick(n),c();return i}function kh(t,e,s,i){const n=s.barThickness;let a,r;return K(n)?(a=e.min*s.categoryPercentage,r=s.barPercentage):(a=n*i,r=1),{chunk:a/i,ratio:r,start:e.pixels[t]-a/2}}function wh(t,e,s,i){const n=e.pixels,a=n[t];let r=t>0?n[t-1]:null,o=t<n.length-1?n[t+1]:null;const c=s.categoryPercentage;r===null&&(r=a-(o===null?e.end-e.start:o-a)),o===null&&(o=a+a-r);const h=a-(a-Math.min(r,o))/2*c;return{chunk:Math.abs(o-r)/2*c/i,ratio:s.barPercentage,start:h}}function jh(t,e,s,i){const n=s.parse(t[0],i),a=s.parse(t[1],i),r=Math.min(n,a),o=Math.max(n,a);let c=r,h=o;Math.abs(r)>Math.abs(o)&&(c=o,h=r),e[s.axis]=h,e._custom={barStart:c,barEnd:h,start:n,end:a,min:r,max:o}}function Sa(t,e,s,i){return te(t)?jh(t,e,s,i):e[s.axis]=s.parse(t,i),e}function Ca(t,e,s,i){const n=t.iScale,a=t.vScale,r=n.getLabels(),o=n===a,c=[];let h,d,u,p;for(h=s,d=s+i;h<d;++h)p=e[h],u={},u[n.axis]=o||n.parse(r[h],h),c.push(Sa(p,u,a,h));return c}function vi(t){return t&&t.barStart!==void 0&&t.barEnd!==void 0}function Sh(t,e,s){return t!==0?Ge(t):(e.isHorizontal()?1:-1)*(e.min>=s?1:-1)}function Ch(t){let e,s,i,n,a;return t.horizontal?(e=t.base>t.x,s="left",i="right"):(e=t.base<t.y,s="bottom",i="top"),e?(n="end",a="start"):(n="start",a="end"),{start:s,end:i,reverse:e,top:n,bottom:a}}function Mh(t,e,s,i){let n=e.borderSkipped;const a={};if(!n){t.borderSkipped=a;return}if(n===!0){t.borderSkipped={top:!0,right:!0,bottom:!0,left:!0};return}const{start:r,end:o,reverse:c,top:h,bottom:d}=Ch(t);n==="middle"&&s&&(t.enableBorderRadius=!0,(s._top||0)===i?n=h:(s._bottom||0)===i?n=d:(a[Ma(d,r,o,c)]=!0,n=h)),a[Ma(n,r,o,c)]=!0,t.borderSkipped=a}function Ma(t,e,s,i){return i?(t=Ph(t,e,s),t=Pa(t,s,e)):t=Pa(t,e,s),t}function Ph(t,e,s){return t===e?s:t===s?e:t}function Pa(t,e,s){return t==="start"?e:t==="end"?s:t}function Ah(t,{inflateAmount:e},s){t.inflateAmount=e==="auto"?s===1?.33:0:e}class _s extends Ft{parsePrimitiveData(e,s,i,n){return Ca(e,s,i,n)}parseArrayData(e,s,i,n){return Ca(e,s,i,n)}parseObjectData(e,s,i,n){const{iScale:a,vScale:r}=e,{xAxisKey:o="x",yAxisKey:c="y"}=this._parsing,h=a.axis==="x"?o:c,d=r.axis==="x"?o:c,u=[];let p,g,x,_;for(p=i,g=i+n;p<g;++p)_=s[p],x={},x[a.axis]=a.parse(ft(_,h),p),u.push(Sa(ft(_,d),x,r,p));return u}updateRangeFromParsed(e,s,i,n){super.updateRangeFromParsed(e,s,i,n);const a=i._custom;a&&s===this._cachedMeta.vScale&&(e.min=Math.min(e.min,a.min),e.max=Math.max(e.max,a.max))}getMaxOverflow(){return 0}getLabelAndValue(e){const s=this._cachedMeta,{iScale:i,vScale:n}=s,a=this.getParsed(e),r=a._custom,o=vi(r)?"["+r.start+", "+r.end+"]":""+n.getLabelForValue(a[n.axis]);return{label:""+i.getLabelForValue(a[i.axis]),value:o}}initialize(){this.enableOptionSharing=!0,super.initialize();const e=this._cachedMeta;e.stack=this.getDataset().stack}update(e){const s=this._cachedMeta;this.updateElements(s.data,0,s.data.length,e)}updateElements(e,s,i,n){const a=n==="reset",{index:r,_cachedMeta:{vScale:o}}=this,c=o.getBasePixel(),h=o.isHorizontal(),d=this._getRuler(),{sharedOptions:u,includeOptions:p}=this._getSharedOptions(s,n);for(let g=s;g<s+i;g++){const x=this.getParsed(g),_=a||K(x[o.axis])?{base:c,head:c}:this._calculateBarValuePixels(g),m=this._calculateBarIndexPixels(g,d),v=(x._stacks||{})[o.axis],w={horizontal:h,base:_.base,enableBorderRadius:!v||vi(x._custom)||r===v._top||r===v._bottom,x:h?_.head:m.center,y:h?m.center:_.head,height:h?m.size:Math.abs(_.size),width:h?Math.abs(_.size):m.size};p&&(w.options=u||this.resolveDataElementOptions(g,e[g].active?"active":n));const S=w.options||e[g].options;Mh(w,S,v,r),Ah(w,S,d.ratio),this.updateElement(e[g],g,w,n)}}_getStacks(e,s){const{iScale:i}=this._cachedMeta,n=i.getMatchingVisibleMetas(this._type).filter(d=>d.controller.options.grouped),a=i.options.stacked,r=[],o=this._cachedMeta.controller.getParsed(s),c=o&&o[i.axis],h=d=>{const u=d._parsed.find(g=>g[i.axis]===c),p=u&&u[d.vScale.axis];if(K(p)||isNaN(p))return!0};for(const d of n)if(!(s!==void 0&&h(d))&&((a===!1||r.indexOf(d.stack)===-1||a===void 0&&d.stack===void 0)&&r.push(d.stack),d.index===e))break;return r.length||r.push(void 0),r}_getStackCount(e){return this._getStacks(void 0,e).length}_getAxisCount(){return this._getAxis().length}getFirstScaleIdForIndexAxis(){const e=this.chart.scales,s=this.chart.options.indexAxis;return Object.keys(e).filter(i=>e[i].axis===s).shift()}_getAxis(){const e={},s=this.getFirstScaleIdForIndexAxis();for(const i of this.chart.data.datasets)e[G(this.chart.options.indexAxis==="x"?i.xAxisID:i.yAxisID,s)]=!0;return Object.keys(e)}_getStackIndex(e,s,i){const n=this._getStacks(e,i),a=s!==void 0?n.indexOf(s):-1;return a===-1?n.length-1:a}_getRuler(){const e=this.options,s=this._cachedMeta,i=s.iScale,n=[];let a,r;for(a=0,r=s.data.length;a<r;++a)n.push(i.getPixelForValue(this.getParsed(a)[i.axis],a));const o=e.barThickness;return{min:o||vh(s),pixels:n,start:i._startPixel,end:i._endPixel,stackCount:this._getStackCount(),scale:i,grouped:e.grouped,ratio:o?1:e.categoryPercentage*e.barPercentage}}_calculateBarValuePixels(e){const{_cachedMeta:{vScale:s,_stacked:i,index:n},options:{base:a,minBarLength:r}}=this,o=a||0,c=this.getParsed(e),h=c._custom,d=vi(h);let u=c[s.axis],p=0,g=i?this.applyStack(s,c,i):u,x,_;g!==u&&(p=g-u,g=u),d&&(u=h.barStart,g=h.barEnd-h.barStart,u!==0&&Ge(u)!==Ge(h.barEnd)&&(p=0),p+=u);const m=!K(a)&&!d?a:p;let v=s.getPixelForValue(m);if(this.chart.getDataVisibility(e)?x=s.getPixelForValue(p+g):x=v,_=x-v,Math.abs(_)<r){_=Sh(_,s,o)*r,u===o&&(v-=_/2);const w=s.getPixelForDecimal(0),S=s.getPixelForDecimal(1),I=Math.min(w,S),C=Math.max(w,S);v=Math.max(Math.min(v,C),I),x=v+_,i&&!d&&(c._stacks[s.axis]._visualValues[n]=s.getValueForPixel(x)-s.getValueForPixel(v))}if(v===s.getPixelForValue(o)){const w=Ge(_)*s.getLineWidthForValue(o)/2;v+=w,_-=w}return{size:_,base:v,head:x,center:x+_/2}}_calculateBarIndexPixels(e,s){const i=s.scale,n=this.options,a=n.skipNull,r=G(n.maxBarThickness,1/0);let o,c;const h=this._getAxisCount();if(s.grouped){const d=a?this._getStackCount(e):s.stackCount,u=n.barThickness==="flex"?wh(e,s,n,d*h):kh(e,s,n,d*h),p=this.chart.options.indexAxis==="x"?this.getDataset().xAxisID:this.getDataset().yAxisID,g=this._getAxis().indexOf(G(p,this.getFirstScaleIdForIndexAxis())),x=this._getStackIndex(this.index,this._cachedMeta.stack,a?e:void 0)+g;o=u.start+u.chunk*x+u.chunk/2,c=Math.min(r,u.chunk*u.ratio)}else o=i.getPixelForValue(this.getParsed(e)[i.axis],e),c=Math.min(r,s.min*s.ratio);return{base:o-c/2,head:o+c/2,center:o,size:c}}draw(){const e=this._cachedMeta,s=e.vScale,i=e.data,n=i.length;let a=0;for(;a<n;++a)this.getParsed(a)[s.axis]!==null&&!i[a].hidden&&i[a].draw(this._ctx)}}H(_s,"id","bar"),H(_s,"defaults",{datasetElementType:!1,dataElementType:"bar",categoryPercentage:.8,barPercentage:.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}}),H(_s,"overrides",{scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}});function ot(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}class ki{constructor(e){H(this,"options");this.options=e||{}}static override(e){Object.assign(ki.prototype,e)}init(){}formats(){return ot()}parse(){return ot()}format(){return ot()}add(){return ot()}diff(){return ot()}startOf(){return ot()}endOf(){return ot()}}var Oh={_date:ki};function Ih(t,e,s,i){const{controller:n,data:a,_sorted:r}=t,o=n._cachedMeta.iScale,c=t.dataset&&t.dataset.options?t.dataset.options.spanGaps:null;if(o&&e===o.axis&&e!=="r"&&r&&a.length){const h=o._reversePixels?_c:oi;if(i){if(n._sharedOptions){const d=a[0],u=typeof d.getRange=="function"&&d.getRange(e);if(u){const p=h(a,e,s-u),g=h(a,e,s+u);return{lo:p.lo,hi:g.hi}}}}else{const d=h(a,e,s);if(c){const{vScale:u}=n._cachedMeta,{_parsed:p}=t,g=p.slice(0,d.lo+1).reverse().findIndex(_=>!K(_[u.axis]));d.lo-=Math.max(0,g);const x=p.slice(d.hi).findIndex(_=>!K(_[u.axis]));d.hi+=Math.max(0,x)}return d}}return{lo:0,hi:a.length-1}}function xs(t,e,s,i,n){const a=t.getSortedVisibleDatasetMetas(),r=s[e];for(let o=0,c=a.length;o<c;++o){const{index:h,data:d}=a[o],{lo:u,hi:p}=Ih(a[o],e,r,n);for(let g=u;g<=p;++g){const x=d[g];x.skip||i(x,h,g)}}}function Lh(t){const e=t.indexOf("x")!==-1,s=t.indexOf("y")!==-1;return function(i,n){const a=e?Math.abs(i.x-n.x):0,r=s?Math.abs(i.y-n.y):0;return Math.sqrt(Math.pow(a,2)+Math.pow(r,2))}}function wi(t,e,s,i,n){const a=[];return!n&&!t.isPointInArea(e)||xs(t,s,e,function(o,c,h){!n&&!na(o,t.chartArea,0)||o.inRange(e.x,e.y,i)&&a.push({element:o,datasetIndex:c,index:h})},!0),a}function Nh(t,e,s,i){let n=[];function a(r,o,c){const{startAngle:h,endAngle:d}=r.getProps(["startAngle","endAngle"],i),{angle:u}=fc(r,{x:e.x,y:e.y});gc(u,h,d)&&n.push({element:r,datasetIndex:o,index:c})}return xs(t,s,e,a),n}function Th(t,e,s,i,n,a){let r=[];const o=Lh(s);let c=Number.POSITIVE_INFINITY;function h(d,u,p){const g=d.inRange(e.x,e.y,n);if(i&&!g)return;const x=d.getCenterPoint(n);if(!(!!a||t.isPointInArea(x))&&!g)return;const m=o(e,x);m<c?(r=[{element:d,datasetIndex:u,index:p}],c=m):m===c&&r.push({element:d,datasetIndex:u,index:p})}return xs(t,s,e,h),r}function ji(t,e,s,i,n,a){return!a&&!t.isPointInArea(e)?[]:s==="r"&&!i?Nh(t,e,s,n):Th(t,e,s,i,n,a)}function Aa(t,e,s,i,n){const a=[],r=s==="x"?"inXRange":"inYRange";let o=!1;return xs(t,s,e,(c,h,d)=>{c[r]&&c[r](e[s],n)&&(a.push({element:c,datasetIndex:h,index:d}),o=o||c.inRange(e.x,e.y,n))}),i&&!o?[]:a}var Eh={modes:{index(t,e,s,i){const n=rt(e,t),a=s.axis||"x",r=s.includeInvisible||!1,o=s.intersect?wi(t,n,a,i,r):ji(t,n,a,!1,i,r),c=[];return o.length?(t.getSortedVisibleDatasetMetas().forEach(h=>{const d=o[0].index,u=h.data[d];u&&!u.skip&&c.push({element:u,datasetIndex:h.index,index:d})}),c):[]},dataset(t,e,s,i){const n=rt(e,t),a=s.axis||"xy",r=s.includeInvisible||!1;let o=s.intersect?wi(t,n,a,i,r):ji(t,n,a,!1,i,r);if(o.length>0){const c=o[0].datasetIndex,h=t.getDatasetMeta(c).data;o=[];for(let d=0;d<h.length;++d)o.push({element:h[d],datasetIndex:c,index:d})}return o},point(t,e,s,i){const n=rt(e,t),a=s.axis||"xy",r=s.includeInvisible||!1;return wi(t,n,a,i,r)},nearest(t,e,s,i){const n=rt(e,t),a=s.axis||"xy",r=s.includeInvisible||!1;return ji(t,n,a,s.intersect,i,r)},x(t,e,s,i){const n=rt(e,t);return Aa(t,n,"x",s.intersect,i)},y(t,e,s,i){const n=rt(e,t);return Aa(t,n,"y",s.intersect,i)}}};const Oa=["left","top","right","bottom"];function zt(t,e){return t.filter(s=>s.pos===e)}function Ia(t,e){return t.filter(s=>Oa.indexOf(s.pos)===-1&&s.box.axis===e)}function Bt(t,e){return t.sort((s,i)=>{const n=e?i:s,a=e?s:i;return n.weight===a.weight?n.index-a.index:n.weight-a.weight})}function Rh(t){const e=[];let s,i,n,a,r,o;for(s=0,i=(t||[]).length;s<i;++s)n=t[s],{position:a,options:{stack:r,stackWeight:o=1}}=n,e.push({index:s,box:n,pos:a,horizontal:n.isHorizontal(),weight:n.weight,stack:r&&a+r,stackWeight:o});return e}function Dh(t){const e={};for(const s of t){const{stack:i,pos:n,stackWeight:a}=s;if(!i||!Oa.includes(n))continue;const r=e[i]||(e[i]={count:0,placed:0,weight:0,size:0});r.count++,r.weight+=a}return e}function Fh(t,e){const s=Dh(t),{vBoxMaxWidth:i,hBoxMaxHeight:n}=e;let a,r,o;for(a=0,r=t.length;a<r;++a){o=t[a];const{fullSize:c}=o.box,h=s[o.stack],d=h&&o.stackWeight/h.weight;o.horizontal?(o.width=d?d*i:c&&e.availableWidth,o.height=n):(o.width=i,o.height=d?d*n:c&&e.availableHeight)}return s}function zh(t){const e=Rh(t),s=Bt(e.filter(h=>h.box.fullSize),!0),i=Bt(zt(e,"left"),!0),n=Bt(zt(e,"right")),a=Bt(zt(e,"top"),!0),r=Bt(zt(e,"bottom")),o=Ia(e,"x"),c=Ia(e,"y");return{fullSize:s,leftAndTop:i.concat(a),rightAndBottom:n.concat(c).concat(r).concat(o),chartArea:zt(e,"chartArea"),vertical:i.concat(n).concat(c),horizontal:a.concat(r).concat(o)}}function La(t,e,s,i){return Math.max(t[s],e[s])+Math.max(t[i],e[i])}function Na(t,e){t.top=Math.max(t.top,e.top),t.left=Math.max(t.left,e.left),t.bottom=Math.max(t.bottom,e.bottom),t.right=Math.max(t.right,e.right)}function Bh(t,e,s,i){const{pos:n,box:a}=s,r=t.maxPadding;if(!$(n)){s.size&&(t[n]-=s.size);const u=i[s.stack]||{size:0,count:1};u.size=Math.max(u.size,s.horizontal?a.height:a.width),s.size=u.size/u.count,t[n]+=s.size}a.getPadding&&Na(r,a.getPadding());const o=Math.max(0,e.outerWidth-La(r,t,"left","right")),c=Math.max(0,e.outerHeight-La(r,t,"top","bottom")),h=o!==t.w,d=c!==t.h;return t.w=o,t.h=c,s.horizontal?{same:h,other:d}:{same:d,other:h}}function Wh(t){const e=t.maxPadding;function s(i){const n=Math.max(e[i]-t[i],0);return t[i]+=n,n}t.y+=s("top"),t.x+=s("left"),s("right"),s("bottom")}function Hh(t,e){const s=e.maxPadding;function i(n){const a={left:0,top:0,right:0,bottom:0};return n.forEach(r=>{a[r]=Math.max(e[r],s[r])}),a}return i(t?["left","right"]:["top","bottom"])}function Wt(t,e,s,i){const n=[];let a,r,o,c,h,d;for(a=0,r=t.length,h=0;a<r;++a){o=t[a],c=o.box,c.update(o.width||e.w,o.height||e.h,Hh(o.horizontal,e));const{same:u,other:p}=Bh(e,s,o,i);h|=u&&n.length,d=d||p,c.fullSize||n.push(o)}return h&&Wt(n,e,s,i)||d}function ys(t,e,s,i,n){t.top=s,t.left=e,t.right=e+i,t.bottom=s+n,t.width=i,t.height=n}function Ta(t,e,s,i){const n=s.padding;let{x:a,y:r}=e;for(const o of t){const c=o.box,h=i[o.stack]||{placed:0,weight:1},d=o.stackWeight/h.weight||1;if(o.horizontal){const u=e.w*d,p=h.size||c.height;Tt(h.start)&&(r=h.start),c.fullSize?ys(c,n.left,r,s.outerWidth-n.right-n.left,p):ys(c,e.left+h.placed,r,u,p),h.start=r,h.placed+=u,r=c.bottom}else{const u=e.h*d,p=h.size||c.width;Tt(h.start)&&(a=h.start),c.fullSize?ys(c,a,n.top,p,s.outerHeight-n.bottom-n.top):ys(c,a,e.top+h.placed,p,u),h.start=a,h.placed+=u,a=c.right}}e.x=a,e.y=r}var Ke={addBox(t,e){t.boxes||(t.boxes=[]),e.fullSize=e.fullSize||!1,e.position=e.position||"top",e.weight=e.weight||0,e._layers=e._layers||function(){return[{z:0,draw(s){e.draw(s)}}]},t.boxes.push(e)},removeBox(t,e){const s=t.boxes?t.boxes.indexOf(e):-1;s!==-1&&t.boxes.splice(s,1)},configure(t,e,s){e.fullSize=s.fullSize,e.position=s.position,e.weight=s.weight},update(t,e,s,i){if(!t)return;const n=ke(t.options.layout.padding),a=Math.max(e-n.width,0),r=Math.max(s-n.height,0),o=zh(t.boxes),c=o.vertical,h=o.horizontal;Y(t.boxes,_=>{typeof _.beforeLayout=="function"&&_.beforeLayout()});const d=c.reduce((_,m)=>m.box.options&&m.box.options.display===!1?_:_+1,0)||1,u=Object.freeze({outerWidth:e,outerHeight:s,padding:n,availableWidth:a,availableHeight:r,vBoxMaxWidth:a/2/d,hBoxMaxHeight:r/2}),p=Object.assign({},n);Na(p,ke(i));const g=Object.assign({maxPadding:p,w:a,h:r,x:n.left,y:n.top},n),x=Fh(c.concat(h),u);Wt(o.fullSize,g,u,x),Wt(c,g,u,x),Wt(h,g,u,x)&&Wt(c,g,u,x),Wh(g),Ta(o.leftAndTop,g,u,x),g.x+=g.w,g.y+=g.h,Ta(o.rightAndBottom,g,u,x),t.chartArea={left:g.left,top:g.top,right:g.left+g.w,bottom:g.top+g.h,height:g.h,width:g.w},Y(o.chartArea,_=>{const m=_.box;Object.assign(m,t.chartArea),m.update(g.w,g.h,{left:0,top:0,right:0,bottom:0})})}};class Ea{acquireContext(e,s){}releaseContext(e){return!1}addEventListener(e,s,i){}removeEventListener(e,s,i){}getDevicePixelRatio(){return 1}getMaximumSize(e,s,i,n){return s=Math.max(0,s||e.width),i=i||e.height,{width:s,height:Math.max(0,n?Math.floor(s/n):i)}}isAttached(e){return!0}updateConfig(e){}}class Vh extends Ea{acquireContext(e){return e&&e.getContext&&e.getContext("2d")||null}updateConfig(e){e.options.animation=!1}}const bs="$chartjs",$h={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},Ra=t=>t===null||t==="";function Uh(t,e){const s=t.style,i=t.getAttribute("height"),n=t.getAttribute("width");if(t[bs]={initial:{height:i,width:n,style:{display:s.display,height:s.height,width:s.width}}},s.display=s.display||"block",s.boxSizing=s.boxSizing||"border-box",Ra(n)){const a=pa(t,"width");a!==void 0&&(t.width=a)}if(Ra(i))if(t.style.height==="")t.height=t.width/(e||2);else{const a=pa(t,"height");a!==void 0&&(t.height=a)}return t}const Da=th?{passive:!0}:!1;function Gh(t,e,s){t&&t.addEventListener(e,s,Da)}function Yh(t,e,s){t&&t.canvas&&t.canvas.removeEventListener(e,s,Da)}function Kh(t,e){const s=$h[t.type]||t.type,{x:i,y:n}=rt(t,e);return{type:s,chart:e,native:t,x:i!==void 0?i:null,y:n!==void 0?n:null}}function vs(t,e){for(const s of t)if(s===e||s.contains(e))return!0}function Xh(t,e,s){const i=t.canvas,n=new MutationObserver(a=>{let r=!1;for(const o of a)r=r||vs(o.addedNodes,i),r=r&&!vs(o.removedNodes,i);r&&s()});return n.observe(document,{childList:!0,subtree:!0}),n}function qh(t,e,s){const i=t.canvas,n=new MutationObserver(a=>{let r=!1;for(const o of a)r=r||vs(o.removedNodes,i),r=r&&!vs(o.addedNodes,i);r&&s()});return n.observe(document,{childList:!0,subtree:!0}),n}const Ht=new Map;let Fa=0;function za(){const t=window.devicePixelRatio;t!==Fa&&(Fa=t,Ht.forEach((e,s)=>{s.currentDevicePixelRatio!==t&&e()}))}function Jh(t,e){Ht.size||window.addEventListener("resize",za),Ht.set(t,e)}function Qh(t){Ht.delete(t),Ht.size||window.removeEventListener("resize",za)}function Zh(t,e,s){const i=t.canvas,n=i&&_i(i);if(!n)return;const a=Un((o,c)=>{const h=n.clientWidth;s(o,c),h<n.clientWidth&&s()},window),r=new ResizeObserver(o=>{const c=o[0],h=c.contentRect.width,d=c.contentRect.height;h===0&&d===0||a(h,d)});return r.observe(n),Jh(t,a),r}function Si(t,e,s){s&&s.disconnect(),e==="resize"&&Qh(t)}function ed(t,e,s){const i=t.canvas,n=Un(a=>{t.ctx!==null&&s(Kh(a,t))},t);return Gh(i,e,n),n}class td extends Ea{acquireContext(e,s){const i=e&&e.getContext&&e.getContext("2d");return i&&i.canvas===e?(Uh(e,s),i):null}releaseContext(e){const s=e.canvas;if(!s[bs])return!1;const i=s[bs].initial;["height","width"].forEach(a=>{const r=i[a];K(r)?s.removeAttribute(a):s.setAttribute(a,r)});const n=i.style||{};return Object.keys(n).forEach(a=>{s.style[a]=n[a]}),s.width=s.width,delete s[bs],!0}addEventListener(e,s,i){this.removeEventListener(e,s);const n=e.$proxies||(e.$proxies={}),r={attach:Xh,detach:qh,resize:Zh}[s]||ed;n[s]=r(e,s,i)}removeEventListener(e,s){const i=e.$proxies||(e.$proxies={}),n=i[s];if(!n)return;({attach:Si,detach:Si,resize:Si}[s]||Yh)(e,s,n),i[s]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(e,s,i,n){return eh(e,s,i,n)}isAttached(e){const s=e&&_i(e);return!!(s&&s.isConnected)}}function sd(t){return!mi()||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas?Vh:td}class lt{constructor(){H(this,"x");H(this,"y");H(this,"active",!1);H(this,"options");H(this,"$animations")}tooltipPosition(e){const{x:s,y:i}=this.getProps(["x","y"],e);return{x:s,y:i}}hasValue(){return cs(this.x)&&cs(this.y)}getProps(e,s){const i=this.$animations;if(!s||!i)return this;const n={};return e.forEach(a=>{n[a]=i[a]&&i[a].active()?i[a]._to:this[a]}),n}}H(lt,"defaults",{}),H(lt,"defaultRoutes");function id(t,e){const s=t.options.ticks,i=nd(t),n=Math.min(s.maxTicksLimit||i,i),a=s.major.enabled?rd(e):[],r=a.length,o=a[0],c=a[r-1],h=[];if(r>n)return od(e,h,a,r/n),h;const d=ad(a,e,n);if(r>0){let u,p;const g=r>1?Math.round((c-o)/(r-1)):null;for(ks(e,h,d,K(g)?0:o-g,o),u=0,p=r-1;u<p;u++)ks(e,h,d,a[u],a[u+1]);return ks(e,h,d,c,K(g)?e.length:c+g),h}return ks(e,h,d),h}function nd(t){const e=t.options.offset,s=t._tickSize(),i=t._length/s+(e?0:1),n=t._maxLength/s;return Math.floor(Math.min(i,n))}function ad(t,e,s){const i=ld(t),n=e.length/s;if(!i)return Math.max(n,1);const a=lc(i);for(let r=0,o=a.length-1;r<o;r++){const c=a[r];if(c>n)return c}return Math.max(n,1)}function rd(t){const e=[];let s,i;for(s=0,i=t.length;s<i;s++)t[s].major&&e.push(s);return e}function od(t,e,s,i){let n=0,a=s[0],r;for(i=Math.ceil(i),r=0;r<t.length;r++)r===a&&(e.push(t[r]),n++,a=s[n*i])}function ks(t,e,s,i,n){const a=G(i,0),r=Math.min(G(n,t.length),t.length);let o=0,c,h,d;for(s=Math.ceil(s),n&&(c=n-i,s=c/Math.floor(c/s)),d=a;d<0;)o++,d=Math.round(a+o*s);for(h=Math.max(a,0);h<r;h++)h===d&&(e.push(t[h]),o++,d=Math.round(a+o*s))}function ld(t){const e=t.length;let s,i;if(e<2)return!1;for(i=t[0],s=1;s<e;++s)if(t[s]-t[s-1]!==i)return!1;return i}const cd=t=>t==="left"?"right":t==="right"?"left":t,Ba=(t,e,s)=>e==="top"||e==="left"?t[e]+s:t[e]-s,Wa=(t,e)=>Math.min(e||t,t);function Ha(t,e){const s=[],i=t.length/e,n=t.length;let a=0;for(;a<n;a+=i)s.push(t[Math.floor(a)]);return s}function hd(t,e,s){const i=t.ticks.length,n=Math.min(e,i-1),a=t._startPixel,r=t._endPixel,o=1e-6;let c=t.getPixelForTick(n),h;if(!(s&&(i===1?h=Math.max(c-a,r-c):e===0?h=(t.getPixelForTick(1)-c)/2:h=(c-t.getPixelForTick(n-1))/2,c+=n<e?h:-h,c<a-o||c>r+o)))return c}function dd(t,e){Y(t,s=>{const i=s.gc,n=i.length/2;let a;if(n>e){for(a=0;a<n;++a)delete s.data[i[a]];i.splice(0,n)}})}function Vt(t){return t.drawTicks?t.tickLength:0}function Va(t,e){if(!t.display)return 0;const s=le(t.font,e),i=ke(t.padding);return(te(t.text)?t.text.length:1)*s.lineHeight+i.height}function ud(t,e){return mt(t,{scale:e,type:"scale"})}function fd(t,e,s){return mt(t,{tick:s,index:e,type:"tick"})}function pd(t,e,s){let i=Gn(t);return(s&&e!=="right"||!s&&e==="right")&&(i=cd(i)),i}function gd(t,e,s,i){const{top:n,left:a,bottom:r,right:o,chart:c}=t,{chartArea:h,scales:d}=c;let u=0,p,g,x;const _=r-n,m=o-a;if(t.isHorizontal()){if(g=fe(i,a,o),$(s)){const v=Object.keys(s)[0],w=s[v];x=d[v].getPixelForValue(w)+_-e}else s==="center"?x=(h.bottom+h.top)/2+_-e:x=Ba(t,s,e);p=o-a}else{if($(s)){const v=Object.keys(s)[0],w=s[v];g=d[v].getPixelForValue(w)-m+e}else s==="center"?g=(h.left+h.right)/2-m+e:g=Ba(t,s,e);x=fe(i,r,n),u=s==="left"?-be:be}return{titleX:g,titleY:x,maxWidth:p,rotation:u}}class yt extends lt{constructor(e){super(),this.id=e.id,this.type=e.type,this.options=void 0,this.ctx=e.ctx,this.chart=e.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(e){this.options=e.setContext(this.getContext()),this.axis=e.axis,this._userMin=this.parse(e.min),this._userMax=this.parse(e.max),this._suggestedMin=this.parse(e.suggestedMin),this._suggestedMax=this.parse(e.suggestedMax)}parse(e,s){return e}getUserBounds(){let{_userMin:e,_userMax:s,_suggestedMin:i,_suggestedMax:n}=this;return e=Ae(e,Number.POSITIVE_INFINITY),s=Ae(s,Number.NEGATIVE_INFINITY),i=Ae(i,Number.POSITIVE_INFINITY),n=Ae(n,Number.NEGATIVE_INFINITY),{min:Ae(e,i),max:Ae(s,n),minDefined:me(e),maxDefined:me(s)}}getMinMax(e){let{min:s,max:i,minDefined:n,maxDefined:a}=this.getUserBounds(),r;if(n&&a)return{min:s,max:i};const o=this.getMatchingVisibleMetas();for(let c=0,h=o.length;c<h;++c)r=o[c].controller.getMinMax(this,e),n||(s=Math.min(s,r.min)),a||(i=Math.max(i,r.max));return s=a&&s>i?i:s,i=n&&s>i?s:i,{min:Ae(s,Ae(i,s)),max:Ae(i,Ae(s,i))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){const e=this.chart.data;return this.options.labels||(this.isHorizontal()?e.xLabels:e.yLabels)||e.labels||[]}getLabelItems(e=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(e))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){q(this.options.beforeUpdate,[this])}update(e,s,i){const{beginAtZero:n,grace:a,ticks:r}=this.options,o=r.sampleSize;this.beforeUpdate(),this.maxWidth=e,this.maxHeight=s,this._margins=i=Object.assign({left:0,right:0,top:0,bottom:0},i),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+i.left+i.right:this.height+i.top+i.bottom,this._dataLimitsCached||(this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=zc(this,a,n),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();const c=o<this.ticks.length;this._convertTicksToLabels(c?Ha(this.ticks,o):this.ticks),this.configure(),this.beforeCalculateLabelRotation(),this.calculateLabelRotation(),this.afterCalculateLabelRotation(),r.display&&(r.autoSkip||r.source==="auto")&&(this.ticks=id(this,this.ticks),this._labelSizes=null,this.afterAutoSkip()),c&&this._convertTicksToLabels(this.ticks),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate()}configure(){let e=this.options.reverse,s,i;this.isHorizontal()?(s=this.left,i=this.right):(s=this.top,i=this.bottom,e=!e),this._startPixel=s,this._endPixel=i,this._reversePixels=e,this._length=i-s,this._alignToPixels=this.options.alignToPixels}afterUpdate(){q(this.options.afterUpdate,[this])}beforeSetDimensions(){q(this.options.beforeSetDimensions,[this])}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}afterSetDimensions(){q(this.options.afterSetDimensions,[this])}_callHooks(e){this.chart.notifyPlugins(e,this.getContext()),q(this.options[e],[this])}beforeDataLimits(){this._callHooks("beforeDataLimits")}determineDataLimits(){}afterDataLimits(){this._callHooks("afterDataLimits")}beforeBuildTicks(){this._callHooks("beforeBuildTicks")}buildTicks(){return[]}afterBuildTicks(){this._callHooks("afterBuildTicks")}beforeTickToLabelConversion(){q(this.options.beforeTickToLabelConversion,[this])}generateTickLabels(e){const s=this.options.ticks;let i,n,a;for(i=0,n=e.length;i<n;i++)a=e[i],a.label=q(s.callback,[a.value,i,e],this)}afterTickToLabelConversion(){q(this.options.afterTickToLabelConversion,[this])}beforeCalculateLabelRotation(){q(this.options.beforeCalculateLabelRotation,[this])}calculateLabelRotation(){const e=this.options,s=e.ticks,i=Wa(this.ticks.length,e.ticks.maxTicksLimit),n=s.minRotation||0,a=s.maxRotation;let r=n,o,c,h;if(!this._isVisible()||!s.display||n>=a||i<=1||!this.isHorizontal()){this.labelRotation=n;return}const d=this._getLabelSizes(),u=d.widest.width,p=d.highest.height,g=ve(this.chart.width-u,0,this.maxWidth);o=e.offset?this.maxWidth/i:g/(i-1),u+6>o&&(o=g/(i-(e.offset?.5:1)),c=this.maxHeight-Vt(e.grid)-s.padding-Va(e.title,this.chart.options.font),h=Math.sqrt(u*u+p*p),r=uc(Math.min(Math.asin(ve((d.highest.height+6)/o,-1,1)),Math.asin(ve(c/h,-1,1))-Math.asin(ve(p/h,-1,1)))),r=Math.max(n,Math.min(a,r))),this.labelRotation=r}afterCalculateLabelRotation(){q(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){q(this.options.beforeFit,[this])}fit(){const e={width:0,height:0},{chart:s,options:{ticks:i,title:n,grid:a}}=this,r=this._isVisible(),o=this.isHorizontal();if(r){const c=Va(n,s.options.font);if(o?(e.width=this.maxWidth,e.height=Vt(a)+c):(e.height=this.maxHeight,e.width=Vt(a)+c),i.display&&this.ticks.length){const{first:h,last:d,widest:u,highest:p}=this._getLabelSizes(),g=i.padding*2,x=tt(this.labelRotation),_=Math.cos(x),m=Math.sin(x);if(o){const v=i.mirror?0:m*u.width+_*p.height;e.height=Math.min(this.maxHeight,e.height+v+g)}else{const v=i.mirror?0:_*u.width+m*p.height;e.width=Math.min(this.maxWidth,e.width+v+g)}this._calculatePadding(h,d,m,_)}}this._handleMargins(),o?(this.width=this._length=s.width-this._margins.left-this._margins.right,this.height=e.height):(this.width=e.width,this.height=this._length=s.height-this._margins.top-this._margins.bottom)}_calculatePadding(e,s,i,n){const{ticks:{align:a,padding:r},position:o}=this.options,c=this.labelRotation!==0,h=o!=="top"&&this.axis==="x";if(this.isHorizontal()){const d=this.getPixelForTick(0)-this.left,u=this.right-this.getPixelForTick(this.ticks.length-1);let p=0,g=0;c?h?(p=n*e.width,g=i*s.height):(p=i*e.height,g=n*s.width):a==="start"?g=s.width:a==="end"?p=e.width:a!=="inner"&&(p=e.width/2,g=s.width/2),this.paddingLeft=Math.max((p-d+r)*this.width/(this.width-d),0),this.paddingRight=Math.max((g-u+r)*this.width/(this.width-u),0)}else{let d=s.height/2,u=e.height/2;a==="start"?(d=0,u=e.height):a==="end"&&(d=s.height,u=0),this.paddingTop=d+r,this.paddingBottom=u+r}}_handleMargins(){this._margins&&(this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom))}afterFit(){q(this.options.afterFit,[this])}isHorizontal(){const{axis:e,position:s}=this.options;return s==="top"||s==="bottom"||e==="x"}isFullSize(){return this.options.fullSize}_convertTicksToLabels(e){this.beforeTickToLabelConversion(),this.generateTickLabels(e);let s,i;for(s=0,i=e.length;s<i;s++)K(e[s].label)&&(e.splice(s,1),i--,s--);this.afterTickToLabelConversion()}_getLabelSizes(){let e=this._labelSizes;if(!e){const s=this.options.ticks.sampleSize;let i=this.ticks;s<i.length&&(i=Ha(i,s)),this._labelSizes=e=this._computeLabelSizes(i,i.length,this.options.ticks.maxTicksLimit)}return e}_computeLabelSizes(e,s,i){const{ctx:n,_longestTextCache:a}=this,r=[],o=[],c=Math.floor(s/Wa(s,i));let h=0,d=0,u,p,g,x,_,m,v,w,S,I,C;for(u=0;u<s;u+=c){if(x=e[u].label,_=this._resolveTickFontOptions(u),n.font=m=_.string,v=a[m]=a[m]||{data:{},gc:[]},w=_.lineHeight,S=I=0,!K(x)&&!te(x))S=ea(n,v.data,v.gc,S,x),I=w;else if(te(x))for(p=0,g=x.length;p<g;++p)C=x[p],!K(C)&&!te(C)&&(S=ea(n,v.data,v.gc,S,C),I+=w);r.push(S),o.push(I),h=Math.max(S,h),d=Math.max(I,d)}dd(a,s);const P=r.indexOf(h),L=o.indexOf(d),N=R=>({width:r[R]||0,height:o[R]||0});return{first:N(0),last:N(s-1),widest:N(P),highest:N(L),widths:r,heights:o}}getLabelForValue(e){return e}getPixelForValue(e,s){return NaN}getValueForPixel(e){}getPixelForTick(e){const s=this.ticks;return e<0||e>s.length-1?null:this.getPixelForValue(s[e].value)}getPixelForDecimal(e){this._reversePixels&&(e=1-e);const s=this._startPixel+e*this._length;return mc(this._alignToPixels?nt(this.chart,s,0):s)}getDecimalForPixel(e){const s=(e-this._startPixel)/this._length;return this._reversePixels?1-s:s}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){const{min:e,max:s}=this;return e<0&&s<0?s:e>0&&s>0?e:0}getContext(e){const s=this.ticks||[];if(e>=0&&e<s.length){const i=s[e];return i.$context||(i.$context=fd(this.getContext(),e,i))}return this.$context||(this.$context=ud(this.chart.getContext(),this))}_tickSize(){const e=this.options.ticks,s=tt(this.labelRotation),i=Math.abs(Math.cos(s)),n=Math.abs(Math.sin(s)),a=this._getLabelSizes(),r=e.autoSkipPadding||0,o=a?a.widest.width+r:0,c=a?a.highest.height+r:0;return this.isHorizontal()?c*i>o*n?o/i:c/n:c*n<o*i?c/i:o/n}_isVisible(){const e=this.options.display;return e!=="auto"?!!e:this.getMatchingVisibleMetas().length>0}_computeGridLineItems(e){const s=this.axis,i=this.chart,n=this.options,{grid:a,position:r,border:o}=n,c=a.offset,h=this.isHorizontal(),u=this.ticks.length+(c?1:0),p=Vt(a),g=[],x=o.setContext(this.getContext()),_=x.display?x.width:0,m=_/2,v=function(Q){return nt(i,Q,_)};let w,S,I,C,P,L,N,R,B,z,D,k;if(r==="top")w=v(this.bottom),L=this.bottom-p,R=w-m,z=v(e.top)+m,k=e.bottom;else if(r==="bottom")w=v(this.top),z=e.top,k=v(e.bottom)-m,L=w+m,R=this.top+p;else if(r==="left")w=v(this.right),P=this.right-p,N=w-m,B=v(e.left)+m,D=e.right;else if(r==="right")w=v(this.left),B=e.left,D=v(e.right)-m,P=w+m,N=this.left+p;else if(s==="x"){if(r==="center")w=v((e.top+e.bottom)/2+.5);else if($(r)){const Q=Object.keys(r)[0],se=r[Q];w=v(this.chart.scales[Q].getPixelForValue(se))}z=e.top,k=e.bottom,L=w+m,R=L+p}else if(s==="y"){if(r==="center")w=v((e.left+e.right)/2);else if($(r)){const Q=Object.keys(r)[0],se=r[Q];w=v(this.chart.scales[Q].getPixelForValue(se))}P=w-m,N=P-p,B=e.left,D=e.right}const F=G(n.ticks.maxTicksLimit,u),W=Math.max(1,Math.ceil(u/F));for(S=0;S<u;S+=W){const Q=this.getContext(S),se=a.setContext(Q),we=o.setContext(Q),je=se.lineWidth,Se=se.color,_e=we.dash||[],xe=we.dashOffset,de=se.tickWidth,ue=se.tickColor,ye=se.tickBorderDash||[],ne=se.tickBorderDashOffset;I=hd(this,S,c),I!==void 0&&(C=nt(i,I,je),h?P=N=B=D=C:L=R=z=k=C,g.push({tx1:P,ty1:L,tx2:N,ty2:R,x1:B,y1:z,x2:D,y2:k,width:je,color:Se,borderDash:_e,borderDashOffset:xe,tickWidth:de,tickColor:ue,tickBorderDash:ye,tickBorderDashOffset:ne}))}return this._ticksLength=u,this._borderValue=w,g}_computeLabelItems(e){const s=this.axis,i=this.options,{position:n,ticks:a}=i,r=this.isHorizontal(),o=this.ticks,{align:c,crossAlign:h,padding:d,mirror:u}=a,p=Vt(i.grid),g=p+d,x=u?-d:g,_=-tt(this.labelRotation),m=[];let v,w,S,I,C,P,L,N,R,B,z,D,k="middle";if(n==="top")P=this.bottom-x,L=this._getXAxisLabelAlignment();else if(n==="bottom")P=this.top+x,L=this._getXAxisLabelAlignment();else if(n==="left"){const W=this._getYAxisLabelAlignment(p);L=W.textAlign,C=W.x}else if(n==="right"){const W=this._getYAxisLabelAlignment(p);L=W.textAlign,C=W.x}else if(s==="x"){if(n==="center")P=(e.top+e.bottom)/2+g;else if($(n)){const W=Object.keys(n)[0],Q=n[W];P=this.chart.scales[W].getPixelForValue(Q)+g}L=this._getXAxisLabelAlignment()}else if(s==="y"){if(n==="center")C=(e.left+e.right)/2-g;else if($(n)){const W=Object.keys(n)[0],Q=n[W];C=this.chart.scales[W].getPixelForValue(Q)}L=this._getYAxisLabelAlignment(p).textAlign}s==="y"&&(c==="start"?k="top":c==="end"&&(k="bottom"));const F=this._getLabelSizes();for(v=0,w=o.length;v<w;++v){S=o[v],I=S.label;const W=a.setContext(this.getContext(v));N=this.getPixelForTick(v)+a.labelOffset,R=this._resolveTickFontOptions(v),B=R.lineHeight,z=te(I)?I.length:1;const Q=z/2,se=W.color,we=W.textStrokeColor,je=W.textStrokeWidth;let Se=L;r?(C=N,L==="inner"&&(v===w-1?Se=this.options.reverse?"left":"right":v===0?Se=this.options.reverse?"right":"left":Se="center"),n==="top"?h==="near"||_!==0?D=-z*B+B/2:h==="center"?D=-F.highest.height/2-Q*B+B:D=-F.highest.height+B/2:h==="near"||_!==0?D=B/2:h==="center"?D=F.highest.height/2-Q*B:D=F.highest.height-z*B,u&&(D*=-1),_!==0&&!W.showLabelBackdrop&&(C+=B/2*Math.sin(_))):(P=N,D=(1-z)*B/2);let _e;if(W.showLabelBackdrop){const xe=ke(W.backdropPadding),de=F.heights[v],ue=F.widths[v];let ye=D-xe.top,ne=0-xe.left;switch(k){case"middle":ye-=de/2;break;case"bottom":ye-=de;break}switch(L){case"center":ne-=ue/2;break;case"right":ne-=ue;break;case"inner":v===w-1?ne-=ue:v>0&&(ne-=ue/2);break}_e={left:ne,top:ye,width:ue+xe.width,height:de+xe.height,color:W.backdropColor}}m.push({label:I,font:R,textOffset:D,options:{rotation:_,color:se,strokeColor:we,strokeWidth:je,textAlign:Se,textBaseline:k,translation:[C,P],backdrop:_e}})}return m}_getXAxisLabelAlignment(){const{position:e,ticks:s}=this.options;if(-tt(this.labelRotation))return e==="top"?"left":"right";let n="center";return s.align==="start"?n="left":s.align==="end"?n="right":s.align==="inner"&&(n="inner"),n}_getYAxisLabelAlignment(e){const{position:s,ticks:{crossAlign:i,mirror:n,padding:a}}=this.options,r=this._getLabelSizes(),o=e+a,c=r.widest.width;let h,d;return s==="left"?n?(d=this.right+a,i==="near"?h="left":i==="center"?(h="center",d+=c/2):(h="right",d+=c)):(d=this.right-o,i==="near"?h="right":i==="center"?(h="center",d-=c/2):(h="left",d=this.left)):s==="right"?n?(d=this.left+a,i==="near"?h="right":i==="center"?(h="center",d-=c/2):(h="left",d-=c)):(d=this.left+o,i==="near"?h="left":i==="center"?(h="center",d+=c/2):(h="right",d=this.right)):h="right",{textAlign:h,x:d}}_computeLabelArea(){if(this.options.ticks.mirror)return;const e=this.chart,s=this.options.position;if(s==="left"||s==="right")return{top:0,left:this.left,bottom:e.height,right:this.right};if(s==="top"||s==="bottom")return{top:this.top,left:0,bottom:this.bottom,right:e.width}}drawBackground(){const{ctx:e,options:{backgroundColor:s},left:i,top:n,width:a,height:r}=this;s&&(e.save(),e.fillStyle=s,e.fillRect(i,n,a,r),e.restore())}getLineWidthForValue(e){const s=this.options.grid;if(!this._isVisible()||!s.display)return 0;const n=this.ticks.findIndex(a=>a.value===e);return n>=0?s.setContext(this.getContext(n)).lineWidth:0}drawGrid(e){const s=this.options.grid,i=this.ctx,n=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(e));let a,r;const o=(c,h,d)=>{!d.width||!d.color||(i.save(),i.lineWidth=d.width,i.strokeStyle=d.color,i.setLineDash(d.borderDash||[]),i.lineDashOffset=d.borderDashOffset,i.beginPath(),i.moveTo(c.x,c.y),i.lineTo(h.x,h.y),i.stroke(),i.restore())};if(s.display)for(a=0,r=n.length;a<r;++a){const c=n[a];s.drawOnChartArea&&o({x:c.x1,y:c.y1},{x:c.x2,y:c.y2},c),s.drawTicks&&o({x:c.tx1,y:c.ty1},{x:c.tx2,y:c.ty2},{color:c.tickColor,width:c.tickWidth,borderDash:c.tickBorderDash,borderDashOffset:c.tickBorderDashOffset})}}drawBorder(){const{chart:e,ctx:s,options:{border:i,grid:n}}=this,a=i.setContext(this.getContext()),r=i.display?a.width:0;if(!r)return;const o=n.setContext(this.getContext(0)).lineWidth,c=this._borderValue;let h,d,u,p;this.isHorizontal()?(h=nt(e,this.left,r)-r/2,d=nt(e,this.right,o)+o/2,u=p=c):(u=nt(e,this.top,r)-r/2,p=nt(e,this.bottom,o)+o/2,h=d=c),s.save(),s.lineWidth=a.width,s.strokeStyle=a.color,s.beginPath(),s.moveTo(h,u),s.lineTo(d,p),s.stroke(),s.restore()}drawLabels(e){if(!this.options.ticks.display)return;const i=this.ctx,n=this._computeLabelArea();n&&di(i,n);const a=this.getLabelItems(e);for(const r of a){const o=r.options,c=r.font,h=r.label,d=r.textOffset;ds(i,h,0,d,c,o)}n&&ui(i)}drawTitle(){const{ctx:e,options:{position:s,title:i,reverse:n}}=this;if(!i.display)return;const a=le(i.font),r=ke(i.padding),o=i.align;let c=a.lineHeight/2;s==="bottom"||s==="center"||$(s)?(c+=r.bottom,te(i.text)&&(c+=a.lineHeight*(i.text.length-1))):c+=r.top;const{titleX:h,titleY:d,maxWidth:u,rotation:p}=gd(this,c,s,o);ds(e,i.text,0,0,a,{color:i.color,maxWidth:u,rotation:p,textAlign:pd(o,s,n),textBaseline:"middle",translation:[h,d]})}draw(e){this._isVisible()&&(this.drawBackground(),this.drawGrid(e),this.drawBorder(),this.drawTitle(),this.drawLabels(e))}_layers(){const e=this.options,s=e.ticks&&e.ticks.z||0,i=G(e.grid&&e.grid.z,-1),n=G(e.border&&e.border.z,0);return!this._isVisible()||this.draw!==yt.prototype.draw?[{z:s,draw:a=>{this.draw(a)}}]:[{z:i,draw:a=>{this.drawBackground(),this.drawGrid(a),this.drawTitle()}},{z:n,draw:()=>{this.drawBorder()}},{z:s,draw:a=>{this.drawLabels(a)}}]}getMatchingVisibleMetas(e){const s=this.chart.getSortedVisibleDatasetMetas(),i=this.axis+"AxisID",n=[];let a,r;for(a=0,r=s.length;a<r;++a){const o=s[a];o[i]===this.id&&(!e||o.type===e)&&n.push(o)}return n}_resolveTickFontOptions(e){const s=this.options.ticks.setContext(this.getContext(e));return le(s.font)}_maxDigits(){const e=this._resolveTickFontOptions(0).lineHeight;return(this.isHorizontal()?this.width:this.height)/e}}class ws{constructor(e,s,i){this.type=e,this.scope=s,this.override=i,this.items=Object.create(null)}isForType(e){return Object.prototype.isPrototypeOf.call(this.type.prototype,e.prototype)}register(e){const s=Object.getPrototypeOf(e);let i;xd(s)&&(i=this.register(s));const n=this.items,a=e.id,r=this.scope+"."+a;if(!a)throw new Error("class does not have id: "+e);return a in n||(n[a]=e,md(e,r,i),this.override&&ee.override(e.id,e.overrides)),r}get(e){return this.items[e]}unregister(e){const s=this.items,i=e.id,n=this.scope;i in s&&delete s[i],n&&i in ee[n]&&(delete ee[n][i],this.override&&delete it[i])}}function md(t,e,s){const i=Lt(Object.create(null),[s?ee.get(s):{},ee.get(e),t.defaults]);ee.set(e,i),t.defaultRoutes&&_d(e,t.defaultRoutes),t.descriptors&&ee.describe(e,t.descriptors)}function _d(t,e){Object.keys(e).forEach(s=>{const i=s.split("."),n=i.pop(),a=[t].concat(i).join("."),r=e[s].split("."),o=r.pop(),c=r.join(".");ee.route(a,n,c,o)})}function xd(t){return"id"in t&&"defaults"in t}class yd{constructor(){this.controllers=new ws(Ft,"datasets",!0),this.elements=new ws(lt,"elements"),this.plugins=new ws(Object,"plugins"),this.scales=new ws(yt,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...e){this._each("register",e)}remove(...e){this._each("unregister",e)}addControllers(...e){this._each("register",e,this.controllers)}addElements(...e){this._each("register",e,this.elements)}addPlugins(...e){this._each("register",e,this.plugins)}addScales(...e){this._each("register",e,this.scales)}getController(e){return this._get(e,this.controllers,"controller")}getElement(e){return this._get(e,this.elements,"element")}getPlugin(e){return this._get(e,this.plugins,"plugin")}getScale(e){return this._get(e,this.scales,"scale")}removeControllers(...e){this._each("unregister",e,this.controllers)}removeElements(...e){this._each("unregister",e,this.elements)}removePlugins(...e){this._each("unregister",e,this.plugins)}removeScales(...e){this._each("unregister",e,this.scales)}_each(e,s,i){[...s].forEach(n=>{const a=i||this._getRegistryForType(n);i||a.isForType(n)||a===this.plugins&&n.id?this._exec(e,a,n):Y(n,r=>{const o=i||this._getRegistryForType(r);this._exec(e,o,r)})})}_exec(e,s,i){const n=ai(e);q(i["before"+n],[],i),s[e](i),q(i["after"+n],[],i)}_getRegistryForType(e){for(let s=0;s<this._typedRegistries.length;s++){const i=this._typedRegistries[s];if(i.isForType(e))return i}return this.plugins}_get(e,s,i){const n=s.get(e);if(n===void 0)throw new Error('"'+e+'" is not a registered '+i+".");return n}}var Oe=new yd;class bd{constructor(){this._init=void 0}notify(e,s,i,n){if(s==="beforeInit"&&(this._init=this._createDescriptors(e,!0),this._notify(this._init,e,"install")),this._init===void 0)return;const a=n?this._descriptors(e).filter(n):this._descriptors(e),r=this._notify(a,e,s,i);return s==="afterDestroy"&&(this._notify(a,e,"stop"),this._notify(this._init,e,"uninstall"),this._init=void 0),r}_notify(e,s,i,n){n=n||{};for(const a of e){const r=a.plugin,o=r[i],c=[s,n,a.options];if(q(o,c,r)===!1&&n.cancelable)return!1}return!0}invalidate(){K(this._cache)||(this._oldCache=this._cache,this._cache=void 0)}_descriptors(e){if(this._cache)return this._cache;const s=this._cache=this._createDescriptors(e);return this._notifyStateChanges(e),s}_createDescriptors(e,s){const i=e&&e.config,n=G(i.options&&i.options.plugins,{}),a=vd(i);return n===!1&&!s?[]:wd(e,a,n,s)}_notifyStateChanges(e){const s=this._oldCache||[],i=this._cache,n=(a,r)=>a.filter(o=>!r.some(c=>o.plugin.id===c.plugin.id));this._notify(n(s,i),e,"stop"),this._notify(n(i,s),e,"start")}}function vd(t){const e={},s=[],i=Object.keys(Oe.plugins.items);for(let a=0;a<i.length;a++)s.push(Oe.getPlugin(i[a]));const n=t.plugins||[];for(let a=0;a<n.length;a++){const r=n[a];s.indexOf(r)===-1&&(s.push(r),e[r.id]=!0)}return{plugins:s,localIds:e}}function kd(t,e){return!e&&t===!1?null:t===!0?{}:t}function wd(t,{plugins:e,localIds:s},i,n){const a=[],r=t.getContext();for(const o of e){const c=o.id,h=kd(i[c],n);h!==null&&a.push({plugin:o,options:jd(t.config,{plugin:o,local:s[c]},h,r)})}return a}function jd(t,{plugin:e,local:s},i,n){const a=t.pluginScopeKeys(e),r=t.getOptionScopes(i,a);return s&&e.defaults&&r.push(e.defaults),t.createResolver(r,n,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function Ci(t,e){const s=ee.datasets[t]||{};return((e.datasets||{})[t]||{}).indexAxis||e.indexAxis||s.indexAxis||"x"}function Sd(t,e){let s=t;return t==="_index_"?s=e:t==="_value_"&&(s=e==="x"?"y":"x"),s}function Cd(t,e){return t===e?"_index_":"_value_"}function $a(t){if(t==="x"||t==="y"||t==="r")return t}function Md(t){if(t==="top"||t==="bottom")return"x";if(t==="left"||t==="right")return"y"}function Mi(t,...e){if($a(t))return t;for(const s of e){const i=s.axis||Md(s.position)||t.length>1&&$a(t[0].toLowerCase());if(i)return i}throw new Error(`Cannot determine type of '${t}' axis. Please provide 'axis' or 'position' option.`)}function Ua(t,e,s){if(s[e+"AxisID"]===t)return{axis:e}}function Pd(t,e){if(e.data&&e.data.datasets){const s=e.data.datasets.filter(i=>i.xAxisID===t||i.yAxisID===t);if(s.length)return Ua(t,"x",s[0])||Ua(t,"y",s[0])}return{}}function Ad(t,e){const s=it[t.type]||{scales:{}},i=e.scales||{},n=Ci(t.type,e),a=Object.create(null);return Object.keys(i).forEach(r=>{const o=i[r];if(!$(o))return console.error(`Invalid scale configuration for scale: ${r}`);if(o._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${r}`);const c=Mi(r,o,Pd(r,t),ee.scales[o.type]),h=Cd(c,n),d=s.scales||{};a[r]=Nt(Object.create(null),[{axis:c},o,d[c],d[h]])}),t.data.datasets.forEach(r=>{const o=r.type||t.type,c=r.indexAxis||Ci(o,e),d=(it[o]||{}).scales||{};Object.keys(d).forEach(u=>{const p=Sd(u,c),g=r[p+"AxisID"]||p;a[g]=a[g]||Object.create(null),Nt(a[g],[{axis:p},i[g],d[u]])})}),Object.keys(a).forEach(r=>{const o=a[r];Nt(o,[ee.scales[o.type],ee.scale])}),a}function Ga(t){const e=t.options||(t.options={});e.plugins=G(e.plugins,{}),e.scales=Ad(t,e)}function Ya(t){return t=t||{},t.datasets=t.datasets||[],t.labels=t.labels||[],t}function Od(t){return t=t||{},t.data=Ya(t.data),Ga(t),t}const Ka=new Map,Xa=new Set;function js(t,e){let s=Ka.get(t);return s||(s=e(),Ka.set(t,s),Xa.add(s)),s}const $t=(t,e,s)=>{const i=ft(e,s);i!==void 0&&t.add(i)};class Id{constructor(e){this._config=Od(e),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(e){this._config.type=e}get data(){return this._config.data}set data(e){this._config.data=Ya(e)}get options(){return this._config.options}set options(e){this._config.options=e}get plugins(){return this._config.plugins}update(){const e=this._config;this.clearCache(),Ga(e)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(e){return js(e,()=>[[`datasets.${e}`,""]])}datasetAnimationScopeKeys(e,s){return js(`${e}.transition.${s}`,()=>[[`datasets.${e}.transitions.${s}`,`transitions.${s}`],[`datasets.${e}`,""]])}datasetElementScopeKeys(e,s){return js(`${e}-${s}`,()=>[[`datasets.${e}.elements.${s}`,`datasets.${e}`,`elements.${s}`,""]])}pluginScopeKeys(e){const s=e.id,i=this.type;return js(`${i}-plugin-${s}`,()=>[[`plugins.${s}`,...e.additionalOptionScopes||[]]])}_cachedScopes(e,s){const i=this._scopeCache;let n=i.get(e);return(!n||s)&&(n=new Map,i.set(e,n)),n}getOptionScopes(e,s,i){const{options:n,type:a}=this,r=this._cachedScopes(e,i),o=r.get(s);if(o)return o;const c=new Set;s.forEach(d=>{e&&(c.add(e),d.forEach(u=>$t(c,e,u))),d.forEach(u=>$t(c,n,u)),d.forEach(u=>$t(c,it[a]||{},u)),d.forEach(u=>$t(c,ee,u)),d.forEach(u=>$t(c,ci,u))});const h=Array.from(c);return h.length===0&&h.push(Object.create(null)),Xa.has(s)&&r.set(s,h),h}chartOptionScopes(){const{options:e,type:s}=this;return[e,it[s]||{},ee.datasets[s]||{},{type:s},ee,ci]}resolveNamedOptions(e,s,i,n=[""]){const a={$shared:!0},{resolver:r,subPrefixes:o}=qa(this._resolverCache,e,n);let c=r;if(Nd(r,s)){a.$shared=!1,i=$e(i)?i():i;const h=this.createResolver(e,i,o);c=_t(r,i,h)}for(const h of s)a[h]=c[h];return a}createResolver(e,s,i=[""],n){const{resolver:a}=qa(this._resolverCache,e,i);return $(s)?_t(a,s,void 0,n):a}}function qa(t,e,s){let i=t.get(e);i||(i=new Map,t.set(e,i));const n=s.join();let a=i.get(n);return a||(a={resolver:fi(e,s),subPrefixes:s.filter(o=>!o.toLowerCase().includes("hover"))},i.set(n,a)),a}const Ld=t=>$(t)&&Object.getOwnPropertyNames(t).some(e=>$e(t[e]));function Nd(t,e){const{isScriptable:s,isIndexable:i}=oa(t);for(const n of e){const a=s(n),r=i(n),o=(r||a)&&t[n];if(a&&($e(o)||Ld(o))||r&&te(o))return!0}return!1}var Td="4.5.1";const Ed=["top","bottom","left","right","chartArea"];function Ja(t,e){return t==="top"||t==="bottom"||Ed.indexOf(t)===-1&&e==="x"}function Qa(t,e){return function(s,i){return s[t]===i[t]?s[e]-i[e]:s[t]-i[t]}}function Za(t){const e=t.chart,s=e.options.animation;e.notifyPlugins("afterRender"),q(s&&s.onComplete,[t],e)}function Rd(t){const e=t.chart,s=e.options.animation;q(s&&s.onProgress,[t],e)}function er(t){return mi()&&typeof t=="string"?t=document.getElementById(t):t&&t.length&&(t=t[0]),t&&t.canvas&&(t=t.canvas),t}const Ss={},tr=t=>{const e=er(t);return Object.values(Ss).filter(s=>s.canvas===e).pop()};function Dd(t,e,s){const i=Object.keys(t);for(const n of i){const a=+n;if(a>=e){const r=t[n];delete t[n],(s>0||a>e)&&(t[a+s]=r)}}}function Fd(t,e,s,i){return!s||t.type==="mouseout"?null:i?e:t}let Cs=(qe=class{static register(...e){Oe.add(...e),sr()}static unregister(...e){Oe.remove(...e),sr()}constructor(e,s){const i=this.config=new Id(s),n=er(e),a=tr(n);if(a)throw new Error("Canvas is already in use. Chart with ID '"+a.id+"' must be destroyed before the canvas with ID '"+a.canvas.id+"' can be reused.");const r=i.createResolver(i.chartOptionScopes(),this.getContext());this.platform=new(i.platform||sd(n)),this.platform.updateConfig(i);const o=this.platform.acquireContext(n,r.aspectRatio),c=o&&o.canvas,h=c&&c.height,d=c&&c.width;if(this.id=ec(),this.ctx=o,this.canvas=c,this.width=d,this.height=h,this._options=r,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new bd,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=bc(u=>this.update(u),r.resizeDelay||0),this._dataChanges=[],Ss[this.id]=this,!o||!c){console.error("Failed to create chart: can't acquire context from the given item");return}Ee.listen(this,"complete",Za),Ee.listen(this,"progress",Rd),this._initialize(),this.attached&&this.update()}get aspectRatio(){const{options:{aspectRatio:e,maintainAspectRatio:s},width:i,height:n,_aspectRatio:a}=this;return K(e)?s&&a?a:n?i/n:null:e}get data(){return this.config.data}set data(e){this.config.data=e}get options(){return this._options}set options(e){this.config.options=e}get registry(){return Oe}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():fa(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return ta(this.canvas,this.ctx),this}stop(){return Ee.stop(this),this}resize(e,s){Ee.running(this)?this._resizeBeforeDraw={width:e,height:s}:this._resize(e,s)}_resize(e,s){const i=this.options,n=this.canvas,a=i.maintainAspectRatio&&this.aspectRatio,r=this.platform.getMaximumSize(n,e,s,a),o=i.devicePixelRatio||this.platform.getDevicePixelRatio(),c=this.width?"resize":"attach";this.width=r.width,this.height=r.height,this._aspectRatio=this.aspectRatio,fa(this,o,!0)&&(this.notifyPlugins("resize",{size:r}),q(i.onResize,[this,r],this),this.attached&&this._doResize(c)&&this.render())}ensureScalesHaveIDs(){const s=this.options.scales||{};Y(s,(i,n)=>{i.id=n})}buildOrUpdateScales(){const e=this.options,s=e.scales,i=this.scales,n=Object.keys(i).reduce((r,o)=>(r[o]=!1,r),{});let a=[];s&&(a=a.concat(Object.keys(s).map(r=>{const o=s[r],c=Mi(r,o),h=c==="r",d=c==="x";return{options:o,dposition:h?"chartArea":d?"bottom":"left",dtype:h?"radialLinear":d?"category":"linear"}}))),Y(a,r=>{const o=r.options,c=o.id,h=Mi(c,o),d=G(o.type,r.dtype);(o.position===void 0||Ja(o.position,h)!==Ja(r.dposition))&&(o.position=r.dposition),n[c]=!0;let u=null;if(c in i&&i[c].type===d)u=i[c];else{const p=Oe.getScale(d);u=new p({id:c,type:d,ctx:this.ctx,chart:this}),i[u.id]=u}u.init(o,e)}),Y(n,(r,o)=>{r||delete i[o]}),Y(i,r=>{Ke.configure(this,r,r.options),Ke.addBox(this,r)})}_updateMetasets(){const e=this._metasets,s=this.data.datasets.length,i=e.length;if(e.sort((n,a)=>n.index-a.index),i>s){for(let n=s;n<i;++n)this._destroyDatasetMeta(n);e.splice(s,i-s)}this._sortedMetasets=e.slice(0).sort(Qa("order","index"))}_removeUnreferencedMetasets(){const{_metasets:e,data:{datasets:s}}=this;e.length>s.length&&delete this._stacks,e.forEach((i,n)=>{s.filter(a=>a===i._dataset).length===0&&this._destroyDatasetMeta(n)})}buildOrUpdateControllers(){const e=[],s=this.data.datasets;let i,n;for(this._removeUnreferencedMetasets(),i=0,n=s.length;i<n;i++){const a=s[i];let r=this.getDatasetMeta(i);const o=a.type||this.config.type;if(r.type&&r.type!==o&&(this._destroyDatasetMeta(i),r=this.getDatasetMeta(i)),r.type=o,r.indexAxis=a.indexAxis||Ci(o,this.options),r.order=a.order||0,r.index=i,r.label=""+a.label,r.visible=this.isDatasetVisible(i),r.controller)r.controller.updateIndex(i),r.controller.linkScales();else{const c=Oe.getController(o),{datasetElementType:h,dataElementType:d}=ee.datasets[o];Object.assign(c,{dataElementType:Oe.getElement(d),datasetElementType:h&&Oe.getElement(h)}),r.controller=new c(this,i),e.push(r.controller)}}return this._updateMetasets(),e}_resetElements(){Y(this.data.datasets,(e,s)=>{this.getDatasetMeta(s).controller.reset()},this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(e){const s=this.config;s.update();const i=this._options=s.createResolver(s.chartOptionScopes(),this.getContext()),n=this._animationsDisabled=!i.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),this.notifyPlugins("beforeUpdate",{mode:e,cancelable:!0})===!1)return;const a=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let r=0;for(let h=0,d=this.data.datasets.length;h<d;h++){const{controller:u}=this.getDatasetMeta(h),p=!n&&a.indexOf(u)===-1;u.buildOrUpdateElements(p),r=Math.max(+u.getMaxOverflow(),r)}r=this._minPadding=i.layout.autoPadding?r:0,this._updateLayout(r),n||Y(a,h=>{h.reset()}),this._updateDatasets(e),this.notifyPlugins("afterUpdate",{mode:e}),this._layers.sort(Qa("z","_idx"));const{_active:o,_lastEvent:c}=this;c?this._eventHandler(c,!0):o.length&&this._updateHoverStyles(o,o,!0),this.render()}_updateScales(){Y(this.scales,e=>{Ke.removeBox(this,e)}),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){const e=this.options,s=new Set(Object.keys(this._listeners)),i=new Set(e.events);(!Rn(s,i)||!!this._responsiveListeners!==e.responsive)&&(this.unbindEvents(),this.bindEvents())}_updateHiddenIndices(){const{_hiddenIndices:e}=this,s=this._getUniformDataChanges()||[];for(const{method:i,start:n,count:a}of s){const r=i==="_removeElements"?-a:a;Dd(e,n,r)}}_getUniformDataChanges(){const e=this._dataChanges;if(!e||!e.length)return;this._dataChanges=[];const s=this.data.datasets.length,i=a=>new Set(e.filter(r=>r[0]===a).map((r,o)=>o+","+r.splice(1).join(","))),n=i(0);for(let a=1;a<s;a++)if(!Rn(n,i(a)))return;return Array.from(n).map(a=>a.split(",")).map(a=>({method:a[1],start:+a[2],count:+a[3]}))}_updateLayout(e){if(this.notifyPlugins("beforeLayout",{cancelable:!0})===!1)return;Ke.update(this,this.width,this.height,e);const s=this.chartArea,i=s.width<=0||s.height<=0;this._layers=[],Y(this.boxes,n=>{i&&n.position==="chartArea"||(n.configure&&n.configure(),this._layers.push(...n._layers()))},this),this._layers.forEach((n,a)=>{n._idx=a}),this.notifyPlugins("afterLayout")}_updateDatasets(e){if(this.notifyPlugins("beforeDatasetsUpdate",{mode:e,cancelable:!0})!==!1){for(let s=0,i=this.data.datasets.length;s<i;++s)this.getDatasetMeta(s).controller.configure();for(let s=0,i=this.data.datasets.length;s<i;++s)this._updateDataset(s,$e(e)?e({datasetIndex:s}):e);this.notifyPlugins("afterDatasetsUpdate",{mode:e})}}_updateDataset(e,s){const i=this.getDatasetMeta(e),n={meta:i,index:e,mode:s,cancelable:!0};this.notifyPlugins("beforeDatasetUpdate",n)!==!1&&(i.controller._update(s),n.cancelable=!1,this.notifyPlugins("afterDatasetUpdate",n))}render(){this.notifyPlugins("beforeRender",{cancelable:!0})!==!1&&(Ee.has(this)?this.attached&&!Ee.running(this)&&Ee.start(this):(this.draw(),Za({chart:this})))}draw(){let e;if(this._resizeBeforeDraw){const{width:i,height:n}=this._resizeBeforeDraw;this._resizeBeforeDraw=null,this._resize(i,n)}if(this.clear(),this.width<=0||this.height<=0||this.notifyPlugins("beforeDraw",{cancelable:!0})===!1)return;const s=this._layers;for(e=0;e<s.length&&s[e].z<=0;++e)s[e].draw(this.chartArea);for(this._drawDatasets();e<s.length;++e)s[e].draw(this.chartArea);this.notifyPlugins("afterDraw")}_getSortedDatasetMetas(e){const s=this._sortedMetasets,i=[];let n,a;for(n=0,a=s.length;n<a;++n){const r=s[n];(!e||r.visible)&&i.push(r)}return i}getSortedVisibleDatasetMetas(){return this._getSortedDatasetMetas(!0)}_drawDatasets(){if(this.notifyPlugins("beforeDatasetsDraw",{cancelable:!0})===!1)return;const e=this.getSortedVisibleDatasetMetas();for(let s=e.length-1;s>=0;--s)this._drawDataset(e[s]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(e){const s=this.ctx,i={meta:e,index:e.index,cancelable:!0},n=ah(this,e);this.notifyPlugins("beforeDatasetDraw",i)!==!1&&(n&&di(s,n),e.controller.draw(),n&&ui(s),i.cancelable=!1,this.notifyPlugins("afterDatasetDraw",i))}isPointInArea(e){return na(e,this.chartArea,this._minPadding)}getElementsAtEventForMode(e,s,i,n){const a=Eh.modes[s];return typeof a=="function"?a(this,e,i,n):[]}getDatasetMeta(e){const s=this.data.datasets[e],i=this._metasets;let n=i.filter(a=>a&&a._dataset===s).pop();return n||(n={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:s&&s.order||0,index:e,_dataset:s,_parsed:[],_sorted:!1},i.push(n)),n}getContext(){return this.$context||(this.$context=mt(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(e){const s=this.data.datasets[e];if(!s)return!1;const i=this.getDatasetMeta(e);return typeof i.hidden=="boolean"?!i.hidden:!s.hidden}setDatasetVisibility(e,s){const i=this.getDatasetMeta(e);i.hidden=!s}toggleDataVisibility(e){this._hiddenIndices[e]=!this._hiddenIndices[e]}getDataVisibility(e){return!this._hiddenIndices[e]}_updateVisibility(e,s,i){const n=i?"show":"hide",a=this.getDatasetMeta(e),r=a.controller._resolveAnimations(void 0,n);Tt(s)?(a.data[s].hidden=!i,this.update()):(this.setDatasetVisibility(e,i),r.update(a,{visible:i}),this.update(o=>o.datasetIndex===e?n:void 0))}hide(e,s){this._updateVisibility(e,s,!1)}show(e,s){this._updateVisibility(e,s,!0)}_destroyDatasetMeta(e){const s=this._metasets[e];s&&s.controller&&s.controller._destroy(),delete this._metasets[e]}_stop(){let e,s;for(this.stop(),Ee.remove(this),e=0,s=this.data.datasets.length;e<s;++e)this._destroyDatasetMeta(e)}destroy(){this.notifyPlugins("beforeDestroy");const{canvas:e,ctx:s}=this;this._stop(),this.config.clearCache(),e&&(this.unbindEvents(),ta(e,s),this.platform.releaseContext(s),this.canvas=null,this.ctx=null),delete Ss[this.id],this.notifyPlugins("afterDestroy")}toBase64Image(...e){return this.canvas.toDataURL(...e)}bindEvents(){this.bindUserEvents(),this.options.responsive?this.bindResponsiveEvents():this.attached=!0}bindUserEvents(){const e=this._listeners,s=this.platform,i=(a,r)=>{s.addEventListener(this,a,r),e[a]=r},n=(a,r,o)=>{a.offsetX=r,a.offsetY=o,this._eventHandler(a)};Y(this.options.events,a=>i(a,n))}bindResponsiveEvents(){this._responsiveListeners||(this._responsiveListeners={});const e=this._responsiveListeners,s=this.platform,i=(c,h)=>{s.addEventListener(this,c,h),e[c]=h},n=(c,h)=>{e[c]&&(s.removeEventListener(this,c,h),delete e[c])},a=(c,h)=>{this.canvas&&this.resize(c,h)};let r;const o=()=>{n("attach",o),this.attached=!0,this.resize(),i("resize",a),i("detach",r)};r=()=>{this.attached=!1,n("resize",a),this._stop(),this._resize(0,0),i("attach",o)},s.isAttached(this.canvas)?o():r()}unbindEvents(){Y(this._listeners,(e,s)=>{this.platform.removeEventListener(this,s,e)}),this._listeners={},Y(this._responsiveListeners,(e,s)=>{this.platform.removeEventListener(this,s,e)}),this._responsiveListeners=void 0}updateHoverStyle(e,s,i){const n=i?"set":"remove";let a,r,o,c;for(s==="dataset"&&(a=this.getDatasetMeta(e[0].datasetIndex),a.controller["_"+n+"DatasetHoverStyle"]()),o=0,c=e.length;o<c;++o){r=e[o];const h=r&&this.getDatasetMeta(r.datasetIndex).controller;h&&h[n+"HoverStyle"](r.element,r.datasetIndex,r.index)}}getActiveElements(){return this._active||[]}setActiveElements(e){const s=this._active||[],i=e.map(({datasetIndex:a,index:r})=>{const o=this.getDatasetMeta(a);if(!o)throw new Error("No dataset found at index "+a);return{datasetIndex:a,element:o.data[r],index:r}});!as(i,s)&&(this._active=i,this._lastEvent=null,this._updateHoverStyles(i,s))}notifyPlugins(e,s,i){return this._plugins.notify(this,e,s,i)}isPluginEnabled(e){return this._plugins._cache.filter(s=>s.plugin.id===e).length===1}_updateHoverStyles(e,s,i){const n=this.options.hover,a=(c,h)=>c.filter(d=>!h.some(u=>d.datasetIndex===u.datasetIndex&&d.index===u.index)),r=a(s,e),o=i?e:a(e,s);r.length&&this.updateHoverStyle(r,n.mode,!1),o.length&&n.mode&&this.updateHoverStyle(o,n.mode,!0)}_eventHandler(e,s){const i={event:e,replay:s,cancelable:!0,inChartArea:this.isPointInArea(e)},n=r=>(r.options.events||this.options.events).includes(e.native.type);if(this.notifyPlugins("beforeEvent",i,n)===!1)return;const a=this._handleEvent(e,s,i.inChartArea);return i.cancelable=!1,this.notifyPlugins("afterEvent",i,n),(a||i.changed)&&this.render(),this}_handleEvent(e,s,i){const{_active:n=[],options:a}=this,r=s,o=this._getActiveElements(e,n,i,r),c=rc(e),h=Fd(e,this._lastEvent,i,c);i&&(this._lastEvent=null,q(a.onHover,[e,o,this],this),c&&q(a.onClick,[e,o,this],this));const d=!as(o,n);return(d||s)&&(this._active=o,this._updateHoverStyles(o,n,s)),this._lastEvent=h,d}_getActiveElements(e,s,i,n){if(e.type==="mouseout")return[];if(!i)return s;const a=this.options.hover;return this.getElementsAtEventForMode(e,a.mode,a,n)}},H(qe,"defaults",ee),H(qe,"instances",Ss),H(qe,"overrides",it),H(qe,"registry",Oe),H(qe,"version",Td),H(qe,"getChart",tr),qe);function sr(){return Y(Cs.instances,t=>t._plugins.invalidate())}function ir(t,e){const{x:s,y:i,base:n,width:a,height:r}=t.getProps(["x","y","base","width","height"],e);let o,c,h,d,u;return t.horizontal?(u=r/2,o=Math.min(s,n),c=Math.max(s,n),h=i-u,d=i+u):(u=a/2,o=s-u,c=s+u,h=Math.min(i,n),d=Math.max(i,n)),{left:o,top:h,right:c,bottom:d}}function Xe(t,e,s,i){return t?0:ve(e,s,i)}function zd(t,e,s){const i=t.options.borderWidth,n=t.borderSkipped,a=ra(i);return{t:Xe(n.top,a.top,0,s),r:Xe(n.right,a.right,0,e),b:Xe(n.bottom,a.bottom,0,s),l:Xe(n.left,a.left,0,e)}}function Bd(t,e,s){const{enableBorderRadius:i}=t.getProps(["enableBorderRadius"]),n=t.options.borderRadius,a=gt(n),r=Math.min(e,s),o=t.borderSkipped,c=i||$(n);return{topLeft:Xe(!c||o.top||o.left,a.topLeft,0,r),topRight:Xe(!c||o.top||o.right,a.topRight,0,r),bottomLeft:Xe(!c||o.bottom||o.left,a.bottomLeft,0,r),bottomRight:Xe(!c||o.bottom||o.right,a.bottomRight,0,r)}}function Wd(t){const e=ir(t),s=e.right-e.left,i=e.bottom-e.top,n=zd(t,s/2,i/2),a=Bd(t,s/2,i/2);return{outer:{x:e.left,y:e.top,w:s,h:i,radius:a},inner:{x:e.left+n.l,y:e.top+n.t,w:s-n.l-n.r,h:i-n.t-n.b,radius:{topLeft:Math.max(0,a.topLeft-Math.max(n.t,n.l)),topRight:Math.max(0,a.topRight-Math.max(n.t,n.r)),bottomLeft:Math.max(0,a.bottomLeft-Math.max(n.b,n.l)),bottomRight:Math.max(0,a.bottomRight-Math.max(n.b,n.r))}}}}function Pi(t,e,s,i){const n=e===null,a=s===null,o=t&&!(n&&a)&&ir(t,i);return o&&(n||pt(e,o.left,o.right))&&(a||pt(s,o.top,o.bottom))}function Hd(t){return t.topLeft||t.topRight||t.bottomLeft||t.bottomRight}function Vd(t,e){t.rect(e.x,e.y,e.w,e.h)}function Ai(t,e,s={}){const i=t.x!==s.x?-e:0,n=t.y!==s.y?-e:0,a=(t.x+t.w!==s.x+s.w?e:0)-i,r=(t.y+t.h!==s.y+s.h?e:0)-n;return{x:t.x+i,y:t.y+n,w:t.w+a,h:t.h+r,radius:t.radius}}class Ms extends lt{constructor(e){super(),this.options=void 0,this.horizontal=void 0,this.base=void 0,this.width=void 0,this.height=void 0,this.inflateAmount=void 0,e&&Object.assign(this,e)}draw(e){const{inflateAmount:s,options:{borderColor:i,backgroundColor:n}}=this,{inner:a,outer:r}=Wd(this),o=Hd(r.radius)?us:Vd;e.save(),(r.w!==a.w||r.h!==a.h)&&(e.beginPath(),o(e,Ai(r,s,a)),e.clip(),o(e,Ai(a,-s,r)),e.fillStyle=i,e.fill("evenodd")),e.beginPath(),o(e,Ai(a,s)),e.fillStyle=n,e.fill(),e.restore()}inRange(e,s,i){return Pi(this,e,s,i)}inXRange(e,s){return Pi(this,e,null,s)}inYRange(e,s){return Pi(this,null,e,s)}getCenterPoint(e){const{x:s,y:i,base:n,horizontal:a}=this.getProps(["x","y","base","horizontal"],e);return{x:a?(s+n)/2:s,y:a?i:(i+n)/2}}getRange(e){return e==="x"?this.width/2:this.height/2}}H(Ms,"id","bar"),H(Ms,"defaults",{borderSkipped:"start",borderWidth:0,borderRadius:0,inflateAmount:"auto",pointStyle:void 0}),H(Ms,"defaultRoutes",{backgroundColor:"backgroundColor",borderColor:"borderColor"});const nr=(t,e)=>{let{boxHeight:s=e,boxWidth:i=e}=t;return t.usePointStyle&&(s=Math.min(s,e),i=t.pointStyleWidth||Math.min(i,e)),{boxWidth:i,boxHeight:s,itemHeight:Math.max(e,s)}},$d=(t,e)=>t!==null&&e!==null&&t.datasetIndex===e.datasetIndex&&t.index===e.index;class ar extends lt{constructor(e){super(),this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=e.chart,this.options=e.options,this.ctx=e.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(e,s,i){this.maxWidth=e,this.maxHeight=s,this._margins=i,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width):(this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height)}buildLabels(){const e=this.options.labels||{};let s=q(e.generateLabels,[this.chart],this)||[];e.filter&&(s=s.filter(i=>e.filter(i,this.chart.data))),e.sort&&(s=s.sort((i,n)=>e.sort(i,n,this.chart.data))),this.options.reverse&&s.reverse(),this.legendItems=s}fit(){const{options:e,ctx:s}=this;if(!e.display){this.width=this.height=0;return}const i=e.labels,n=le(i.font),a=n.size,r=this._computeTitleHeight(),{boxWidth:o,itemHeight:c}=nr(i,a);let h,d;s.font=n.string,this.isHorizontal()?(h=this.maxWidth,d=this._fitRows(r,a,o,c)+10):(d=this.maxHeight,h=this._fitCols(r,n,o,c)+10),this.width=Math.min(h,e.maxWidth||this.maxWidth),this.height=Math.min(d,e.maxHeight||this.maxHeight)}_fitRows(e,s,i,n){const{ctx:a,maxWidth:r,options:{labels:{padding:o}}}=this,c=this.legendHitBoxes=[],h=this.lineWidths=[0],d=n+o;let u=e;a.textAlign="left",a.textBaseline="middle";let p=-1,g=-d;return this.legendItems.forEach((x,_)=>{const m=i+s/2+a.measureText(x.text).width;(_===0||h[h.length-1]+m+2*o>r)&&(u+=d,h[h.length-(_>0?0:1)]=0,g+=d,p++),c[_]={left:0,top:g,row:p,width:m,height:n},h[h.length-1]+=m+o}),u}_fitCols(e,s,i,n){const{ctx:a,maxHeight:r,options:{labels:{padding:o}}}=this,c=this.legendHitBoxes=[],h=this.columnSizes=[],d=r-e;let u=o,p=0,g=0,x=0,_=0;return this.legendItems.forEach((m,v)=>{const{itemWidth:w,itemHeight:S}=Ud(i,s,a,m,n);v>0&&g+S+2*o>d&&(u+=p+o,h.push({width:p,height:g}),x+=p+o,_++,p=g=0),c[v]={left:x,top:g,col:_,width:w,height:S},p=Math.max(p,w),g+=S+o}),u+=p,h.push({width:p,height:g}),u}adjustHitBoxes(){if(!this.options.display)return;const e=this._computeTitleHeight(),{legendHitBoxes:s,options:{align:i,labels:{padding:n},rtl:a}}=this,r=xt(a,this.left,this.width);if(this.isHorizontal()){let o=0,c=fe(i,this.left+n,this.right-this.lineWidths[o]);for(const h of s)o!==h.row&&(o=h.row,c=fe(i,this.left+n,this.right-this.lineWidths[o])),h.top+=this.top+e+n,h.left=r.leftForLtr(r.x(c),h.width),c+=h.width+n}else{let o=0,c=fe(i,this.top+e+n,this.bottom-this.columnSizes[o].height);for(const h of s)h.col!==o&&(o=h.col,c=fe(i,this.top+e+n,this.bottom-this.columnSizes[o].height)),h.top=c,h.left+=this.left+n,h.left=r.leftForLtr(r.x(h.left),h.width),c+=h.height+n}}isHorizontal(){return this.options.position==="top"||this.options.position==="bottom"}draw(){if(this.options.display){const e=this.ctx;di(e,this),this._draw(),ui(e)}}_draw(){const{options:e,columnSizes:s,lineWidths:i,ctx:n}=this,{align:a,labels:r}=e,o=ee.color,c=xt(e.rtl,this.left,this.width),h=le(r.font),{padding:d}=r,u=h.size,p=u/2;let g;this.drawTitle(),n.textAlign=c.textAlign("left"),n.textBaseline="middle",n.lineWidth=.5,n.font=h.string;const{boxWidth:x,boxHeight:_,itemHeight:m}=nr(r,u),v=function(P,L,N){if(isNaN(x)||x<=0||isNaN(_)||_<0)return;n.save();const R=G(N.lineWidth,1);if(n.fillStyle=G(N.fillStyle,o),n.lineCap=G(N.lineCap,"butt"),n.lineDashOffset=G(N.lineDashOffset,0),n.lineJoin=G(N.lineJoin,"miter"),n.lineWidth=R,n.strokeStyle=G(N.strokeStyle,o),n.setLineDash(G(N.lineDash,[])),r.usePointStyle){const B={radius:_*Math.SQRT2/2,pointStyle:N.pointStyle,rotation:N.rotation,borderWidth:R},z=c.xPlus(P,x/2),D=L+p;ia(n,B,z,D,r.pointStyleWidth&&x)}else{const B=L+Math.max((u-_)/2,0),z=c.leftForLtr(P,x),D=gt(N.borderRadius);n.beginPath(),Object.values(D).some(k=>k!==0)?us(n,{x:z,y:B,w:x,h:_,radius:D}):n.rect(z,B,x,_),n.fill(),R!==0&&n.stroke()}n.restore()},w=function(P,L,N){ds(n,N.text,P,L+m/2,h,{strikethrough:N.hidden,textAlign:c.textAlign(N.textAlign)})},S=this.isHorizontal(),I=this._computeTitleHeight();S?g={x:fe(a,this.left+d,this.right-i[0]),y:this.top+d+I,line:0}:g={x:this.left+d,y:fe(a,this.top+I+d,this.bottom-s[0].height),line:0},ga(this.ctx,e.textDirection);const C=m+d;this.legendItems.forEach((P,L)=>{n.strokeStyle=P.fontColor,n.fillStyle=P.fontColor;const N=n.measureText(P.text).width,R=c.textAlign(P.textAlign||(P.textAlign=r.textAlign)),B=x+p+N;let z=g.x,D=g.y;c.setWidth(this.width),S?L>0&&z+B+d>this.right&&(D=g.y+=C,g.line++,z=g.x=fe(a,this.left+d,this.right-i[g.line])):L>0&&D+C>this.bottom&&(z=g.x=z+s[g.line].width+d,g.line++,D=g.y=fe(a,this.top+I+d,this.bottom-s[g.line].height));const k=c.x(z);if(v(k,D,P),z=vc(R,z+x+p,S?z+B:this.right,e.rtl),w(c.x(z),D,P),S)g.x+=B+d;else if(typeof P.text!="string"){const F=h.lineHeight;g.y+=rr(P,F)+d}else g.y+=C}),ma(this.ctx,e.textDirection)}drawTitle(){const e=this.options,s=e.title,i=le(s.font),n=ke(s.padding);if(!s.display)return;const a=xt(e.rtl,this.left,this.width),r=this.ctx,o=s.position,c=i.size/2,h=n.top+c;let d,u=this.left,p=this.width;if(this.isHorizontal())p=Math.max(...this.lineWidths),d=this.top+h,u=fe(e.align,u,this.right-p);else{const x=this.columnSizes.reduce((_,m)=>Math.max(_,m.height),0);d=h+fe(e.align,this.top,this.bottom-x-e.labels.padding-this._computeTitleHeight())}const g=fe(o,u,u+p);r.textAlign=a.textAlign(Gn(o)),r.textBaseline="middle",r.strokeStyle=s.color,r.fillStyle=s.color,r.font=i.string,ds(r,s.text,g,d,i)}_computeTitleHeight(){const e=this.options.title,s=le(e.font),i=ke(e.padding);return e.display?s.lineHeight+i.height:0}_getLegendItemAt(e,s){let i,n,a;if(pt(e,this.left,this.right)&&pt(s,this.top,this.bottom)){for(a=this.legendHitBoxes,i=0;i<a.length;++i)if(n=a[i],pt(e,n.left,n.left+n.width)&&pt(s,n.top,n.top+n.height))return this.legendItems[i]}return null}handleEvent(e){const s=this.options;if(!Kd(e.type,s))return;const i=this._getLegendItemAt(e.x,e.y);if(e.type==="mousemove"||e.type==="mouseout"){const n=this._hoveredItem,a=$d(n,i);n&&!a&&q(s.onLeave,[e,n,this],this),this._hoveredItem=i,i&&!a&&q(s.onHover,[e,i,this],this)}else i&&q(s.onClick,[e,i,this],this)}}function Ud(t,e,s,i,n){const a=Gd(i,t,e,s),r=Yd(n,i,e.lineHeight);return{itemWidth:a,itemHeight:r}}function Gd(t,e,s,i){let n=t.text;return n&&typeof n!="string"&&(n=n.reduce((a,r)=>a.length>r.length?a:r)),e+s.size/2+i.measureText(n).width}function Yd(t,e,s){let i=t;return typeof e.text!="string"&&(i=rr(e,s)),i}function rr(t,e){const s=t.text?t.text.length:0;return e*s}function Kd(t,e){return!!((t==="mousemove"||t==="mouseout")&&(e.onHover||e.onLeave)||e.onClick&&(t==="click"||t==="mouseup"))}var Xd={id:"legend",_element:ar,start(t,e,s){const i=t.legend=new ar({ctx:t.ctx,options:s,chart:t});Ke.configure(t,i,s),Ke.addBox(t,i)},stop(t){Ke.removeBox(t,t.legend),delete t.legend},beforeUpdate(t,e,s){const i=t.legend;Ke.configure(t,i,s),i.options=s},afterUpdate(t){const e=t.legend;e.buildLabels(),e.adjustHitBoxes()},afterEvent(t,e){e.replay||t.legend.handleEvent(e.event)},defaults:{display:!0,position:"top",align:"center",fullSize:!0,reverse:!1,weight:1e3,onClick(t,e,s){const i=e.datasetIndex,n=s.chart;n.isDatasetVisible(i)?(n.hide(i),e.hidden=!0):(n.show(i),e.hidden=!1)},onHover:null,onLeave:null,labels:{color:t=>t.chart.options.color,boxWidth:40,padding:10,generateLabels(t){const e=t.data.datasets,{labels:{usePointStyle:s,pointStyle:i,textAlign:n,color:a,useBorderRadius:r,borderRadius:o}}=t.legend.options;return t._getSortedDatasetMetas().map(c=>{const h=c.controller.getStyle(s?0:void 0),d=ke(h.borderWidth);return{text:e[c.index].label,fillStyle:h.backgroundColor,fontColor:a,hidden:!c.visible,lineCap:h.borderCapStyle,lineDash:h.borderDash,lineDashOffset:h.borderDashOffset,lineJoin:h.borderJoinStyle,lineWidth:(d.width+d.height)/4,strokeStyle:h.borderColor,pointStyle:i||h.pointStyle,rotation:h.rotation,textAlign:n||h.textAlign,borderRadius:r&&(o||h.borderRadius),datasetIndex:c.index}},this)}},title:{color:t=>t.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:t=>!t.startsWith("on"),labels:{_scriptable:t=>!["generateLabels","filter","sort"].includes(t)}}};const Ut={average(t){if(!t.length)return!1;let e,s,i=new Set,n=0,a=0;for(e=0,s=t.length;e<s;++e){const o=t[e].element;if(o&&o.hasValue()){const c=o.tooltipPosition();i.add(c.x),n+=c.y,++a}}return a===0||i.size===0?!1:{x:[...i].reduce((o,c)=>o+c)/i.size,y:n/a}},nearest(t,e){if(!t.length)return!1;let s=e.x,i=e.y,n=Number.POSITIVE_INFINITY,a,r,o;for(a=0,r=t.length;a<r;++a){const c=t[a].element;if(c&&c.hasValue()){const h=c.getCenterPoint(),d=pc(e,h);d<n&&(n=d,o=c)}}if(o){const c=o.tooltipPosition();s=c.x,i=c.y}return{x:s,y:i}}};function Ie(t,e){return e&&(te(e)?Array.prototype.push.apply(t,e):t.push(e)),t}function Re(t){return(typeof t=="string"||t instanceof String)&&t.indexOf(`
`)>-1?t.split(`
`):t}function qd(t,e){const{element:s,datasetIndex:i,index:n}=e,a=t.getDatasetMeta(i).controller,{label:r,value:o}=a.getLabelAndValue(n);return{chart:t,label:r,parsed:a.getParsed(n),raw:t.data.datasets[i].data[n],formattedValue:o,dataset:a.getDataset(),dataIndex:n,datasetIndex:i,element:s}}function or(t,e){const s=t.chart.ctx,{body:i,footer:n,title:a}=t,{boxWidth:r,boxHeight:o}=e,c=le(e.bodyFont),h=le(e.titleFont),d=le(e.footerFont),u=a.length,p=n.length,g=i.length,x=ke(e.padding);let _=x.height,m=0,v=i.reduce((I,C)=>I+C.before.length+C.lines.length+C.after.length,0);if(v+=t.beforeBody.length+t.afterBody.length,u&&(_+=u*h.lineHeight+(u-1)*e.titleSpacing+e.titleMarginBottom),v){const I=e.displayColors?Math.max(o,c.lineHeight):c.lineHeight;_+=g*I+(v-g)*c.lineHeight+(v-1)*e.bodySpacing}p&&(_+=e.footerMarginTop+p*d.lineHeight+(p-1)*e.footerSpacing);let w=0;const S=function(I){m=Math.max(m,s.measureText(I).width+w)};return s.save(),s.font=h.string,Y(t.title,S),s.font=c.string,Y(t.beforeBody.concat(t.afterBody),S),w=e.displayColors?r+2+e.boxPadding:0,Y(i,I=>{Y(I.before,S),Y(I.lines,S),Y(I.after,S)}),w=0,s.font=d.string,Y(t.footer,S),s.restore(),m+=x.width,{width:m,height:_}}function Jd(t,e){const{y:s,height:i}=e;return s<i/2?"top":s>t.height-i/2?"bottom":"center"}function Qd(t,e,s,i){const{x:n,width:a}=i,r=s.caretSize+s.caretPadding;if(t==="left"&&n+a+r>e.width||t==="right"&&n-a-r<0)return!0}function Zd(t,e,s,i){const{x:n,width:a}=s,{width:r,chartArea:{left:o,right:c}}=t;let h="center";return i==="center"?h=n<=(o+c)/2?"left":"right":n<=a/2?h="left":n>=r-a/2&&(h="right"),Qd(h,t,e,s)&&(h="center"),h}function lr(t,e,s){const i=s.yAlign||e.yAlign||Jd(t,s);return{xAlign:s.xAlign||e.xAlign||Zd(t,e,s,i),yAlign:i}}function eu(t,e){let{x:s,width:i}=t;return e==="right"?s-=i:e==="center"&&(s-=i/2),s}function tu(t,e,s){let{y:i,height:n}=t;return e==="top"?i+=s:e==="bottom"?i-=n+s:i-=n/2,i}function cr(t,e,s,i){const{caretSize:n,caretPadding:a,cornerRadius:r}=t,{xAlign:o,yAlign:c}=s,h=n+a,{topLeft:d,topRight:u,bottomLeft:p,bottomRight:g}=gt(r);let x=eu(e,o);const _=tu(e,c,h);return c==="center"?o==="left"?x+=h:o==="right"&&(x-=h):o==="left"?x-=Math.max(d,p)+n:o==="right"&&(x+=Math.max(u,g)+n),{x:ve(x,0,i.width-e.width),y:ve(_,0,i.height-e.height)}}function Ps(t,e,s){const i=ke(s.padding);return e==="center"?t.x+t.width/2:e==="right"?t.x+t.width-i.right:t.x+i.left}function hr(t){return Ie([],Re(t))}function su(t,e,s){return mt(t,{tooltip:e,tooltipItems:s,type:"tooltip"})}function dr(t,e){const s=e&&e.dataset&&e.dataset.tooltip&&e.dataset.tooltip.callbacks;return s?t.override(s):t}const ur={beforeTitle:Te,title(t){if(t.length>0){const e=t[0],s=e.chart.data.labels,i=s?s.length:0;if(this&&this.options&&this.options.mode==="dataset")return e.dataset.label||"";if(e.label)return e.label;if(i>0&&e.dataIndex<i)return s[e.dataIndex]}return""},afterTitle:Te,beforeBody:Te,beforeLabel:Te,label(t){if(this&&this.options&&this.options.mode==="dataset")return t.label+": "+t.formattedValue||t.formattedValue;let e=t.dataset.label||"";e&&(e+=": ");const s=t.formattedValue;return K(s)||(e+=s),e},labelColor(t){const s=t.chart.getDatasetMeta(t.datasetIndex).controller.getStyle(t.dataIndex);return{borderColor:s.borderColor,backgroundColor:s.backgroundColor,borderWidth:s.borderWidth,borderDash:s.borderDash,borderDashOffset:s.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(t){const s=t.chart.getDatasetMeta(t.datasetIndex).controller.getStyle(t.dataIndex);return{pointStyle:s.pointStyle,rotation:s.rotation}},afterLabel:Te,afterBody:Te,beforeFooter:Te,footer:Te,afterFooter:Te};function ce(t,e,s,i){const n=t[e].call(s,i);return typeof n>"u"?ur[e].call(s,i):n}class Oi extends lt{constructor(e){super(),this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=e.chart,this.options=e.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(e){this.options=e,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){const e=this._cachedAnimations;if(e)return e;const s=this.chart,i=this.options.setContext(this.getContext()),n=i.enabled&&s.options.animation&&i.animations,a=new xa(this.chart,n);return n._cacheable&&(this._cachedAnimations=Object.freeze(a)),a}getContext(){return this.$context||(this.$context=su(this.chart.getContext(),this,this._tooltipItems))}getTitle(e,s){const{callbacks:i}=s,n=ce(i,"beforeTitle",this,e),a=ce(i,"title",this,e),r=ce(i,"afterTitle",this,e);let o=[];return o=Ie(o,Re(n)),o=Ie(o,Re(a)),o=Ie(o,Re(r)),o}getBeforeBody(e,s){return hr(ce(s.callbacks,"beforeBody",this,e))}getBody(e,s){const{callbacks:i}=s,n=[];return Y(e,a=>{const r={before:[],lines:[],after:[]},o=dr(i,a);Ie(r.before,Re(ce(o,"beforeLabel",this,a))),Ie(r.lines,ce(o,"label",this,a)),Ie(r.after,Re(ce(o,"afterLabel",this,a))),n.push(r)}),n}getAfterBody(e,s){return hr(ce(s.callbacks,"afterBody",this,e))}getFooter(e,s){const{callbacks:i}=s,n=ce(i,"beforeFooter",this,e),a=ce(i,"footer",this,e),r=ce(i,"afterFooter",this,e);let o=[];return o=Ie(o,Re(n)),o=Ie(o,Re(a)),o=Ie(o,Re(r)),o}_createItems(e){const s=this._active,i=this.chart.data,n=[],a=[],r=[];let o=[],c,h;for(c=0,h=s.length;c<h;++c)o.push(qd(this.chart,s[c]));return e.filter&&(o=o.filter((d,u,p)=>e.filter(d,u,p,i))),e.itemSort&&(o=o.sort((d,u)=>e.itemSort(d,u,i))),Y(o,d=>{const u=dr(e.callbacks,d);n.push(ce(u,"labelColor",this,d)),a.push(ce(u,"labelPointStyle",this,d)),r.push(ce(u,"labelTextColor",this,d))}),this.labelColors=n,this.labelPointStyles=a,this.labelTextColors=r,this.dataPoints=o,o}update(e,s){const i=this.options.setContext(this.getContext()),n=this._active;let a,r=[];if(!n.length)this.opacity!==0&&(a={opacity:0});else{const o=Ut[i.position].call(this,n,this._eventPosition);r=this._createItems(i),this.title=this.getTitle(r,i),this.beforeBody=this.getBeforeBody(r,i),this.body=this.getBody(r,i),this.afterBody=this.getAfterBody(r,i),this.footer=this.getFooter(r,i);const c=this._size=or(this,i),h=Object.assign({},o,c),d=lr(this.chart,i,h),u=cr(i,h,d,this.chart);this.xAlign=d.xAlign,this.yAlign=d.yAlign,a={opacity:1,x:u.x,y:u.y,width:c.width,height:c.height,caretX:o.x,caretY:o.y}}this._tooltipItems=r,this.$context=void 0,a&&this._resolveAnimations().update(this,a),e&&i.external&&i.external.call(this,{chart:this.chart,tooltip:this,replay:s})}drawCaret(e,s,i,n){const a=this.getCaretPosition(e,i,n);s.lineTo(a.x1,a.y1),s.lineTo(a.x2,a.y2),s.lineTo(a.x3,a.y3)}getCaretPosition(e,s,i){const{xAlign:n,yAlign:a}=this,{caretSize:r,cornerRadius:o}=i,{topLeft:c,topRight:h,bottomLeft:d,bottomRight:u}=gt(o),{x:p,y:g}=e,{width:x,height:_}=s;let m,v,w,S,I,C;return a==="center"?(I=g+_/2,n==="left"?(m=p,v=m-r,S=I+r,C=I-r):(m=p+x,v=m+r,S=I-r,C=I+r),w=m):(n==="left"?v=p+Math.max(c,d)+r:n==="right"?v=p+x-Math.max(h,u)-r:v=this.caretX,a==="top"?(S=g,I=S-r,m=v-r,w=v+r):(S=g+_,I=S+r,m=v+r,w=v-r),C=S),{x1:m,x2:v,x3:w,y1:S,y2:I,y3:C}}drawTitle(e,s,i){const n=this.title,a=n.length;let r,o,c;if(a){const h=xt(i.rtl,this.x,this.width);for(e.x=Ps(this,i.titleAlign,i),s.textAlign=h.textAlign(i.titleAlign),s.textBaseline="middle",r=le(i.titleFont),o=i.titleSpacing,s.fillStyle=i.titleColor,s.font=r.string,c=0;c<a;++c)s.fillText(n[c],h.x(e.x),e.y+r.lineHeight/2),e.y+=r.lineHeight+o,c+1===a&&(e.y+=i.titleMarginBottom-o)}}_drawColorBox(e,s,i,n,a){const r=this.labelColors[i],o=this.labelPointStyles[i],{boxHeight:c,boxWidth:h}=a,d=le(a.bodyFont),u=Ps(this,"left",a),p=n.x(u),g=c<d.lineHeight?(d.lineHeight-c)/2:0,x=s.y+g;if(a.usePointStyle){const _={radius:Math.min(h,c)/2,pointStyle:o.pointStyle,rotation:o.rotation,borderWidth:1},m=n.leftForLtr(p,h)+h/2,v=x+c/2;e.strokeStyle=a.multiKeyBackground,e.fillStyle=a.multiKeyBackground,sa(e,_,m,v),e.strokeStyle=r.borderColor,e.fillStyle=r.backgroundColor,sa(e,_,m,v)}else{e.lineWidth=$(r.borderWidth)?Math.max(...Object.values(r.borderWidth)):r.borderWidth||1,e.strokeStyle=r.borderColor,e.setLineDash(r.borderDash||[]),e.lineDashOffset=r.borderDashOffset||0;const _=n.leftForLtr(p,h),m=n.leftForLtr(n.xPlus(p,1),h-2),v=gt(r.borderRadius);Object.values(v).some(w=>w!==0)?(e.beginPath(),e.fillStyle=a.multiKeyBackground,us(e,{x:_,y:x,w:h,h:c,radius:v}),e.fill(),e.stroke(),e.fillStyle=r.backgroundColor,e.beginPath(),us(e,{x:m,y:x+1,w:h-2,h:c-2,radius:v}),e.fill()):(e.fillStyle=a.multiKeyBackground,e.fillRect(_,x,h,c),e.strokeRect(_,x,h,c),e.fillStyle=r.backgroundColor,e.fillRect(m,x+1,h-2,c-2))}e.fillStyle=this.labelTextColors[i]}drawBody(e,s,i){const{body:n}=this,{bodySpacing:a,bodyAlign:r,displayColors:o,boxHeight:c,boxWidth:h,boxPadding:d}=i,u=le(i.bodyFont);let p=u.lineHeight,g=0;const x=xt(i.rtl,this.x,this.width),_=function(N){s.fillText(N,x.x(e.x+g),e.y+p/2),e.y+=p+a},m=x.textAlign(r);let v,w,S,I,C,P,L;for(s.textAlign=r,s.textBaseline="middle",s.font=u.string,e.x=Ps(this,m,i),s.fillStyle=i.bodyColor,Y(this.beforeBody,_),g=o&&m!=="right"?r==="center"?h/2+d:h+2+d:0,I=0,P=n.length;I<P;++I){for(v=n[I],w=this.labelTextColors[I],s.fillStyle=w,Y(v.before,_),S=v.lines,o&&S.length&&(this._drawColorBox(s,e,I,x,i),p=Math.max(u.lineHeight,c)),C=0,L=S.length;C<L;++C)_(S[C]),p=u.lineHeight;Y(v.after,_)}g=0,p=u.lineHeight,Y(this.afterBody,_),e.y-=a}drawFooter(e,s,i){const n=this.footer,a=n.length;let r,o;if(a){const c=xt(i.rtl,this.x,this.width);for(e.x=Ps(this,i.footerAlign,i),e.y+=i.footerMarginTop,s.textAlign=c.textAlign(i.footerAlign),s.textBaseline="middle",r=le(i.footerFont),s.fillStyle=i.footerColor,s.font=r.string,o=0;o<a;++o)s.fillText(n[o],c.x(e.x),e.y+r.lineHeight/2),e.y+=r.lineHeight+i.footerSpacing}}drawBackground(e,s,i,n){const{xAlign:a,yAlign:r}=this,{x:o,y:c}=e,{width:h,height:d}=i,{topLeft:u,topRight:p,bottomLeft:g,bottomRight:x}=gt(n.cornerRadius);s.fillStyle=n.backgroundColor,s.strokeStyle=n.borderColor,s.lineWidth=n.borderWidth,s.beginPath(),s.moveTo(o+u,c),r==="top"&&this.drawCaret(e,s,i,n),s.lineTo(o+h-p,c),s.quadraticCurveTo(o+h,c,o+h,c+p),r==="center"&&a==="right"&&this.drawCaret(e,s,i,n),s.lineTo(o+h,c+d-x),s.quadraticCurveTo(o+h,c+d,o+h-x,c+d),r==="bottom"&&this.drawCaret(e,s,i,n),s.lineTo(o+g,c+d),s.quadraticCurveTo(o,c+d,o,c+d-g),r==="center"&&a==="left"&&this.drawCaret(e,s,i,n),s.lineTo(o,c+u),s.quadraticCurveTo(o,c,o+u,c),s.closePath(),s.fill(),n.borderWidth>0&&s.stroke()}_updateAnimationTarget(e){const s=this.chart,i=this.$animations,n=i&&i.x,a=i&&i.y;if(n||a){const r=Ut[e.position].call(this,this._active,this._eventPosition);if(!r)return;const o=this._size=or(this,e),c=Object.assign({},r,this._size),h=lr(s,e,c),d=cr(e,c,h,s);(n._to!==d.x||a._to!==d.y)&&(this.xAlign=h.xAlign,this.yAlign=h.yAlign,this.width=o.width,this.height=o.height,this.caretX=r.x,this.caretY=r.y,this._resolveAnimations().update(this,d))}}_willRender(){return!!this.opacity}draw(e){const s=this.options.setContext(this.getContext());let i=this.opacity;if(!i)return;this._updateAnimationTarget(s);const n={width:this.width,height:this.height},a={x:this.x,y:this.y};i=Math.abs(i)<.001?0:i;const r=ke(s.padding),o=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;s.enabled&&o&&(e.save(),e.globalAlpha=i,this.drawBackground(a,e,n,s),ga(e,s.textDirection),a.y+=r.top,this.drawTitle(a,e,s),this.drawBody(a,e,s),this.drawFooter(a,e,s),ma(e,s.textDirection),e.restore())}getActiveElements(){return this._active||[]}setActiveElements(e,s){const i=this._active,n=e.map(({datasetIndex:o,index:c})=>{const h=this.chart.getDatasetMeta(o);if(!h)throw new Error("Cannot find a dataset at index "+o);return{datasetIndex:o,element:h.data[c],index:c}}),a=!as(i,n),r=this._positionChanged(n,s);(a||r)&&(this._active=n,this._eventPosition=s,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(e,s,i=!0){if(s&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;const n=this.options,a=this._active||[],r=this._getActiveElements(e,a,s,i),o=this._positionChanged(r,e),c=s||!as(r,a)||o;return c&&(this._active=r,(n.enabled||n.external)&&(this._eventPosition={x:e.x,y:e.y},this.update(!0,s))),c}_getActiveElements(e,s,i,n){const a=this.options;if(e.type==="mouseout")return[];if(!n)return s.filter(o=>this.chart.data.datasets[o.datasetIndex]&&this.chart.getDatasetMeta(o.datasetIndex).controller.getParsed(o.index)!==void 0);const r=this.chart.getElementsAtEventForMode(e,a.mode,a,i);return a.reverse&&r.reverse(),r}_positionChanged(e,s){const{caretX:i,caretY:n,options:a}=this,r=Ut[a.position].call(this,e,s);return r!==!1&&(i!==r.x||n!==r.y)}}H(Oi,"positioners",Ut);var iu={id:"tooltip",_element:Oi,positioners:Ut,afterInit(t,e,s){s&&(t.tooltip=new Oi({chart:t,options:s}))},beforeUpdate(t,e,s){t.tooltip&&t.tooltip.initialize(s)},reset(t,e,s){t.tooltip&&t.tooltip.initialize(s)},afterDraw(t){const e=t.tooltip;if(e&&e._willRender()){const s={tooltip:e};if(t.notifyPlugins("beforeTooltipDraw",{...s,cancelable:!0})===!1)return;e.draw(t.ctx),t.notifyPlugins("afterTooltipDraw",s)}},afterEvent(t,e){if(t.tooltip){const s=e.replay;t.tooltip.handleEvent(e.event,s,e.inChartArea)&&(e.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(t,e)=>e.bodyFont.size,boxWidth:(t,e)=>e.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:ur},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:t=>t!=="filter"&&t!=="itemSort"&&t!=="external",_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]};const nu=(t,e,s,i)=>(typeof e=="string"?(s=t.push(e)-1,i.unshift({index:s,label:e})):isNaN(e)&&(s=null),s);function au(t,e,s,i){const n=t.indexOf(e);if(n===-1)return nu(t,e,s,i);const a=t.lastIndexOf(e);return n!==a?s:n}const ru=(t,e)=>t===null?null:ve(Math.round(t),0,e);function fr(t){const e=this.getLabels();return t>=0&&t<e.length?e[t]:t}class Ii extends yt{constructor(e){super(e),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(e){const s=this._addedLabels;if(s.length){const i=this.getLabels();for(const{index:n,label:a}of s)i[n]===a&&i.splice(n,1);this._addedLabels=[]}super.init(e)}parse(e,s){if(K(e))return null;const i=this.getLabels();return s=isFinite(s)&&i[s]===e?s:au(i,e,G(s,e),this._addedLabels),ru(s,i.length-1)}determineDataLimits(){const{minDefined:e,maxDefined:s}=this.getUserBounds();let{min:i,max:n}=this.getMinMax(!0);this.options.bounds==="ticks"&&(e||(i=0),s||(n=this.getLabels().length-1)),this.min=i,this.max=n}buildTicks(){const e=this.min,s=this.max,i=this.options.offset,n=[];let a=this.getLabels();a=e===0&&s===a.length-1?a:a.slice(e,s+1),this._valueRange=Math.max(a.length-(i?0:1),1),this._startValue=this.min-(i?.5:0);for(let r=e;r<=s;r++)n.push({value:r});return n}getLabelForValue(e){return fr.call(this,e)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(e){return typeof e!="number"&&(e=this.parse(e)),e===null?NaN:this.getPixelForDecimal((e-this._startValue)/this._valueRange)}getPixelForTick(e){const s=this.ticks;return e<0||e>s.length-1?null:this.getPixelForValue(s[e].value)}getValueForPixel(e){return Math.round(this._startValue+this.getDecimalForPixel(e)*this._valueRange)}getBasePixel(){return this.bottom}}H(Ii,"id","category"),H(Ii,"defaults",{ticks:{callback:fr}});function ou(t,e){const s=[],{bounds:n,step:a,min:r,max:o,precision:c,count:h,maxTicks:d,maxDigits:u,includeBounds:p}=t,g=a||1,x=d-1,{min:_,max:m}=e,v=!K(r),w=!K(o),S=!K(h),I=(m-_)/(u+1);let C=zn((m-_)/x/g)*g,P,L,N,R;if(C<1e-14&&!v&&!w)return[{value:_},{value:m}];R=Math.ceil(m/C)-Math.floor(_/C),R>x&&(C=zn(R*C/x/g)*g),K(c)||(P=Math.pow(10,c),C=Math.ceil(C*P)/P),n==="ticks"?(L=Math.floor(_/C)*C,N=Math.ceil(m/C)*C):(L=_,N=m),v&&w&&a&&hc((o-r)/a,C/1e3)?(R=Math.round(Math.min((o-r)/C,d)),C=(o-r)/R,L=r,N=o):S?(L=v?r:L,N=w?o:N,R=h-1,C=(N-L)/R):(R=(N-L)/C,ls(R,Math.round(R),C/1e3)?R=Math.round(R):R=Math.ceil(R));const B=Math.max(Bn(C),Bn(L));P=Math.pow(10,K(c)?B:c),L=Math.round(L*P)/P,N=Math.round(N*P)/P;let z=0;for(v&&(p&&L!==r?(s.push({value:r}),L<r&&z++,ls(Math.round((L+z*C)*P)/P,r,pr(r,I,t))&&z++):L<r&&z++);z<R;++z){const D=Math.round((L+z*C)*P)/P;if(w&&D>o)break;s.push({value:D})}return w&&p&&N!==o?s.length&&ls(s[s.length-1].value,o,pr(o,I,t))?s[s.length-1].value=o:s.push({value:o}):(!w||N===o)&&s.push({value:N}),s}function pr(t,e,{horizontal:s,minRotation:i}){const n=tt(i),a=(s?Math.sin(n):Math.cos(n))||.001,r=.75*e*(""+t).length;return Math.min(e/a,r)}class lu extends yt{constructor(e){super(e),this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(e,s){return K(e)||(typeof e=="number"||e instanceof Number)&&!isFinite(+e)?null:+e}handleTickRangeOptions(){const{beginAtZero:e}=this.options,{minDefined:s,maxDefined:i}=this.getUserBounds();let{min:n,max:a}=this;const r=c=>n=s?n:c,o=c=>a=i?a:c;if(e){const c=Ge(n),h=Ge(a);c<0&&h<0?o(0):c>0&&h>0&&r(0)}if(n===a){let c=a===0?1:Math.abs(a*.05);o(a+c),e||r(n-c)}this.min=n,this.max=a}getTickLimit(){const e=this.options.ticks;let{maxTicksLimit:s,stepSize:i}=e,n;return i?(n=Math.ceil(this.max/i)-Math.floor(this.min/i)+1,n>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${i} would result generating up to ${n} ticks. Limiting to 1000.`),n=1e3)):(n=this.computeTickLimit(),s=s||11),s&&(n=Math.min(s,n)),n}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){const e=this.options,s=e.ticks;let i=this.getTickLimit();i=Math.max(2,i);const n={maxTicks:i,bounds:e.bounds,min:e.min,max:e.max,precision:s.precision,step:s.stepSize,count:s.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:s.minRotation||0,includeBounds:s.includeBounds!==!1},a=this._range||this,r=ou(n,a);return e.bounds==="ticks"&&dc(r,this,"value"),e.reverse?(r.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),r}configure(){const e=this.ticks;let s=this.min,i=this.max;if(super.configure(),this.options.offset&&e.length){const n=(i-s)/Math.max(e.length-1,1)/2;s-=n,i+=n}this._startValue=s,this._endValue=i,this._valueRange=i-s}getLabelForValue(e){return Qn(e,this.chart.options.locale,this.options.ticks.format)}}class Li extends lu{determineDataLimits(){const{min:e,max:s}=this.getMinMax(!0);this.min=me(e)?e:0,this.max=me(s)?s:1,this.handleTickRangeOptions()}computeTickLimit(){const e=this.isHorizontal(),s=e?this.width:this.height,i=tt(this.options.ticks.minRotation),n=(e?Math.sin(i):Math.cos(i))||.001,a=this._resolveTickFontOptions(0);return Math.ceil(s/Math.min(40,a.lineHeight/n))}getPixelForValue(e){return e===null?NaN:this.getPixelForDecimal((e-this._startValue)/this._valueRange)}getValueForPixel(e){return this._startValue+this.getDecimalForPixel(e)*this._valueRange}}H(Li,"id","linear"),H(Li,"defaults",{ticks:{callback:Zn.formatters.numeric}});const As={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},he=Object.keys(As);function gr(t,e){return t-e}function mr(t,e){if(K(e))return null;const s=t._adapter,{parser:i,round:n,isoWeekday:a}=t._parseOpts;let r=e;return typeof i=="function"&&(r=i(r)),me(r)||(r=typeof i=="string"?s.parse(r,i):s.parse(r)),r===null?null:(n&&(r=n==="week"&&(cs(a)||a===!0)?s.startOf(r,"isoWeek",a):s.startOf(r,n)),+r)}function _r(t,e,s,i){const n=he.length;for(let a=he.indexOf(t);a<n-1;++a){const r=As[he[a]],o=r.steps?r.steps:Number.MAX_SAFE_INTEGER;if(r.common&&Math.ceil((s-e)/(o*r.size))<=i)return he[a]}return he[n-1]}function cu(t,e,s,i,n){for(let a=he.length-1;a>=he.indexOf(s);a--){const r=he[a];if(As[r].common&&t._adapter.diff(n,i,r)>=e-1)return r}return he[s?he.indexOf(s):0]}function hu(t){for(let e=he.indexOf(t)+1,s=he.length;e<s;++e)if(As[he[e]].common)return he[e]}function xr(t,e,s){if(!s)t[e]=!0;else if(s.length){const{lo:i,hi:n}=ri(s,e),a=s[i]>=e?s[i]:s[n];t[a]=!0}}function du(t,e,s,i){const n=t._adapter,a=+n.startOf(e[0].value,i),r=e[e.length-1].value;let o,c;for(o=a;o<=r;o=+n.add(o,1,i))c=s[o],c>=0&&(e[c].major=!0);return e}function yr(t,e,s){const i=[],n={},a=e.length;let r,o;for(r=0;r<a;++r)o=e[r],n[o]=r,i.push({value:o,major:!1});return a===0||!s?i:du(t,i,n,s)}class Os extends yt{constructor(e){super(e),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(e,s={}){const i=e.time||(e.time={}),n=this._adapter=new Oh._date(e.adapters.date);n.init(s),Nt(i.displayFormats,n.formats()),this._parseOpts={parser:i.parser,round:i.round,isoWeekday:i.isoWeekday},super.init(e),this._normalized=s.normalized}parse(e,s){return e===void 0?null:mr(this,e)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){const e=this.options,s=this._adapter,i=e.time.unit||"day";let{min:n,max:a,minDefined:r,maxDefined:o}=this.getUserBounds();function c(h){!r&&!isNaN(h.min)&&(n=Math.min(n,h.min)),!o&&!isNaN(h.max)&&(a=Math.max(a,h.max))}(!r||!o)&&(c(this._getLabelBounds()),(e.bounds!=="ticks"||e.ticks.source!=="labels")&&c(this.getMinMax(!1))),n=me(n)&&!isNaN(n)?n:+s.startOf(Date.now(),i),a=me(a)&&!isNaN(a)?a:+s.endOf(Date.now(),i)+1,this.min=Math.min(n,a-1),this.max=Math.max(n+1,a)}_getLabelBounds(){const e=this.getLabelTimestamps();let s=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY;return e.length&&(s=e[0],i=e[e.length-1]),{min:s,max:i}}buildTicks(){const e=this.options,s=e.time,i=e.ticks,n=i.source==="labels"?this.getLabelTimestamps():this._generate();e.bounds==="ticks"&&n.length&&(this.min=this._userMin||n[0],this.max=this._userMax||n[n.length-1]);const a=this.min,r=this.max,o=xc(n,a,r);return this._unit=s.unit||(i.autoSkip?_r(s.minUnit,this.min,this.max,this._getLabelCapacity(a)):cu(this,o.length,s.minUnit,this.min,this.max)),this._majorUnit=!i.major.enabled||this._unit==="year"?void 0:hu(this._unit),this.initOffsets(n),e.reverse&&o.reverse(),yr(this,o,this._majorUnit)}afterAutoSkip(){this.options.offsetAfterAutoskip&&this.initOffsets(this.ticks.map(e=>+e.value))}initOffsets(e=[]){let s=0,i=0,n,a;this.options.offset&&e.length&&(n=this.getDecimalForValue(e[0]),e.length===1?s=1-n:s=(this.getDecimalForValue(e[1])-n)/2,a=this.getDecimalForValue(e[e.length-1]),e.length===1?i=a:i=(a-this.getDecimalForValue(e[e.length-2]))/2);const r=e.length<3?.5:.25;s=ve(s,0,r),i=ve(i,0,r),this._offsets={start:s,end:i,factor:1/(s+1+i)}}_generate(){const e=this._adapter,s=this.min,i=this.max,n=this.options,a=n.time,r=a.unit||_r(a.minUnit,s,i,this._getLabelCapacity(s)),o=G(n.ticks.stepSize,1),c=r==="week"?a.isoWeekday:!1,h=cs(c)||c===!0,d={};let u=s,p,g;if(h&&(u=+e.startOf(u,"isoWeek",c)),u=+e.startOf(u,h?"day":r),e.diff(i,s,r)>1e5*o)throw new Error(s+" and "+i+" are too far apart with stepSize of "+o+" "+r);const x=n.ticks.source==="data"&&this.getDataTimestamps();for(p=u,g=0;p<i;p=+e.add(p,o,r),g++)xr(d,p,x);return(p===i||n.bounds==="ticks"||g===1)&&xr(d,p,x),Object.keys(d).sort(gr).map(_=>+_)}getLabelForValue(e){const s=this._adapter,i=this.options.time;return i.tooltipFormat?s.format(e,i.tooltipFormat):s.format(e,i.displayFormats.datetime)}format(e,s){const n=this.options.time.displayFormats,a=this._unit,r=s||n[a];return this._adapter.format(e,r)}_tickFormatFunction(e,s,i,n){const a=this.options,r=a.ticks.callback;if(r)return q(r,[e,s,i],this);const o=a.time.displayFormats,c=this._unit,h=this._majorUnit,d=c&&o[c],u=h&&o[h],p=i[s],g=h&&u&&p&&p.major;return this._adapter.format(e,n||(g?u:d))}generateTickLabels(e){let s,i,n;for(s=0,i=e.length;s<i;++s)n=e[s],n.label=this._tickFormatFunction(n.value,s,e)}getDecimalForValue(e){return e===null?NaN:(e-this.min)/(this.max-this.min)}getPixelForValue(e){const s=this._offsets,i=this.getDecimalForValue(e);return this.getPixelForDecimal((s.start+i)*s.factor)}getValueForPixel(e){const s=this._offsets,i=this.getDecimalForPixel(e)/s.factor-s.end;return this.min+i*(this.max-this.min)}_getLabelSize(e){const s=this.options.ticks,i=this.ctx.measureText(e).width,n=tt(this.isHorizontal()?s.maxRotation:s.minRotation),a=Math.cos(n),r=Math.sin(n),o=this._resolveTickFontOptions(0).size;return{w:i*a+o*r,h:i*r+o*a}}_getLabelCapacity(e){const s=this.options.time,i=s.displayFormats,n=i[s.unit]||i.millisecond,a=this._tickFormatFunction(e,0,yr(this,[e],this._majorUnit),n),r=this._getLabelSize(a),o=Math.floor(this.isHorizontal()?this.width/r.w:this.height/r.h)-1;return o>0?o:1}getDataTimestamps(){let e=this._cache.data||[],s,i;if(e.length)return e;const n=this.getMatchingVisibleMetas();if(this._normalized&&n.length)return this._cache.data=n[0].controller.getAllParsedValues(this);for(s=0,i=n.length;s<i;++s)e=e.concat(n[s].controller.getAllParsedValues(this));return this._cache.data=this.normalize(e)}getLabelTimestamps(){const e=this._cache.labels||[];let s,i;if(e.length)return e;const n=this.getLabels();for(s=0,i=n.length;s<i;++s)e.push(mr(this,n[s]));return this._cache.labels=this._normalized?e:this.normalize(e)}normalize(e){return Vn(e.sort(gr))}}H(Os,"id","time"),H(Os,"defaults",{bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}});function Is(t,e,s){let i=0,n=t.length-1,a,r,o,c;s?(e>=t[i].pos&&e<=t[n].pos&&({lo:i,hi:n}=oi(t,"pos",e)),{pos:a,time:o}=t[i],{pos:r,time:c}=t[n]):(e>=t[i].time&&e<=t[n].time&&({lo:i,hi:n}=oi(t,"time",e)),{time:a,pos:o}=t[i],{time:r,pos:c}=t[n]);const h=r-a;return h?o+(c-o)*(e-a)/h:o}class br extends Os{constructor(e){super(e),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){const e=this._getTimestampsForTable(),s=this._table=this.buildLookupTable(e);this._minPos=Is(s,this.min),this._tableRange=Is(s,this.max)-this._minPos,super.initOffsets(e)}buildLookupTable(e){const{min:s,max:i}=this,n=[],a=[];let r,o,c,h,d;for(r=0,o=e.length;r<o;++r)h=e[r],h>=s&&h<=i&&n.push(h);if(n.length<2)return[{time:s,pos:0},{time:i,pos:1}];for(r=0,o=n.length;r<o;++r)d=n[r+1],c=n[r-1],h=n[r],Math.round((d+c)/2)!==h&&a.push({time:h,pos:r/(o-1)});return a}_generate(){const e=this.min,s=this.max;let i=super.getDataTimestamps();return(!i.includes(e)||!i.length)&&i.splice(0,0,e),(!i.includes(s)||i.length===1)&&i.push(s),i.sort((n,a)=>n-a)}_getTimestampsForTable(){let e=this._cache.all||[];if(e.length)return e;const s=this.getDataTimestamps(),i=this.getLabelTimestamps();return s.length&&i.length?e=this.normalize(s.concat(i)):e=s.length?s:i,e=this._cache.all=e,e}getDecimalForValue(e){return(Is(this._table,e)-this._minPos)/this._tableRange}getValueForPixel(e){const s=this._offsets,i=this.getDecimalForPixel(e)/s.factor-s.end;return Is(this._table,i*this._tableRange+this._minPos,!0)}}H(br,"id","timeseries"),H(br,"defaults",Os.defaults);const vr="label";function kr(t,e){typeof t=="function"?t(e):t&&(t.current=e)}function uu(t,e){const s=t.options;s&&e&&Object.assign(s,e)}function wr(t,e){t.labels=e}function jr(t,e,s=vr){const i=[];t.datasets=e.map(n=>{const a=t.datasets.find(r=>r[s]===n[s]);return!a||!n.data||i.includes(a)?{...n}:(i.push(a),Object.assign(a,n),a)})}function fu(t,e=vr){const s={labels:[],datasets:[]};return wr(s,t.labels),jr(s,t.datasets,e),s}function pu(t,e){const{height:s=150,width:i=300,redraw:n=!1,datasetIdKey:a,type:r,data:o,options:c,plugins:h=[],fallbackContent:d,updateMode:u,...p}=t,g=V.useRef(null),x=V.useRef(null),_=()=>{g.current&&(x.current=new Cs(g.current,{type:r,data:fu(o,a),options:c&&{...c},plugins:h}),kr(e,x.current))},m=()=>{kr(e,null),x.current&&(x.current.destroy(),x.current=null)};return V.useEffect(()=>{!n&&x.current&&c&&uu(x.current,c)},[n,c]),V.useEffect(()=>{!n&&x.current&&wr(x.current.config.data,o.labels)},[n,o.labels]),V.useEffect(()=>{!n&&x.current&&o.datasets&&jr(x.current.config.data,o.datasets,a)},[n,o.datasets]),V.useEffect(()=>{x.current&&(n?(m(),setTimeout(_)):x.current.update(u))},[n,c,o.labels,o.datasets,u]),V.useEffect(()=>{x.current&&(m(),setTimeout(_))},[r]),V.useEffect(()=>(_(),()=>m()),[]),l.jsx("canvas",{ref:g,role:"img",height:s,width:i,...p,children:d})}const gu=V.forwardRef(pu);function mu(t,e){return Cs.register(e),V.forwardRef((s,i)=>l.jsx(gu,{...s,ref:i,type:t}))}const _u=mu("bar",_s);Cs.register(Ii,Li,Ms,iu,Xd);const xu=()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-action-icon",children:[l.jsx("rect",{x:"6",y:"4",width:"36",height:"40",rx:"4",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("line",{x1:"14",y1:"14",x2:"34",y2:"14",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}),l.jsx("line",{x1:"14",y1:"22",x2:"30",y2:"22",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("line",{x1:"14",y1:"30",x2:"26",y2:"30",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("circle",{cx:"36",cy:"36",r:"8",fill:"currentColor",opacity:"0.15"}),l.jsx("path",{d:"M33 36l2 2 4-4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),yu=()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-action-icon",children:[l.jsx("rect",{x:"10",y:"2",width:"30",height:"36",rx:"3",stroke:"currentColor",strokeWidth:"2",fill:"none",opacity:"0.35"}),l.jsx("rect",{x:"6",y:"6",width:"30",height:"36",rx:"3",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("line",{x1:"13",y1:"16",x2:"29",y2:"16",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("line",{x1:"13",y1:"23",x2:"26",y2:"23",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("line",{x1:"13",y1:"30",x2:"22",y2:"30",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),l.jsx("path",{d:"M28 34l3 3 5-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),bu=()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-action-icon",children:[l.jsx("rect",{x:"5",y:"8",width:"38",height:"32",rx:"4",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("circle",{cx:"17",cy:"20",r:"4",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("path",{d:"M5 32l10-8 7 5 8-6 13 9",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"38",cy:"12",r:"6",fill:"currentColor",opacity:"0.15"}),l.jsx("path",{d:"M36 12h4M38 10v4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),vu=()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-action-icon",children:[l.jsx("rect",{x:"4",y:"6",width:"28",height:"24",rx:"3",stroke:"currentColor",strokeWidth:"2.5",fill:"none"}),l.jsx("path",{d:"M4 24l8-6 5 4 6-5 9 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("rect",{x:"26",y:"28",width:"18",height:"14",rx:"2",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("line",{x1:"30",y1:"33",x2:"40",y2:"33",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),l.jsx("line",{x1:"30",y1:"37",x2:"37",y2:"37",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),l.jsx("text",{x:"8",y:"18",fontSize:"10",fontWeight:"700",fill:"currentColor",opacity:"0.4",children:"ALT"})]}),ku=()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-action-icon",children:[l.jsx("rect",{x:"3",y:"6",width:"20",height:"16",rx:"3",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("rect",{x:"25",y:"6",width:"20",height:"16",rx:"3",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("rect",{x:"3",y:"26",width:"20",height:"16",rx:"3",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("rect",{x:"25",y:"26",width:"20",height:"16",rx:"3",stroke:"currentColor",strokeWidth:"2",fill:"none"}),l.jsx("path",{d:"M3 18l6-4 4 3 4-3 6 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("path",{d:"M25 18l6-4 4 3 4-3 6 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("path",{d:"M3 38l6-4 4 3 4-3 6 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("path",{d:"M25 38l6-4 4 3 4-3 6 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"40",cy:"40",r:"7",fill:"currentColor",opacity:"0.15"}),l.jsx("path",{d:"M37.5 40l2 2 3.5-3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),wu=()=>l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",fill:"none",className:"spai-action-icon spai-action-icon--large",children:[l.jsx("rect",{x:"4",y:"8",width:"40",height:"32",rx:"4",stroke:"currentColor",strokeWidth:"2.5",fill:"none",opacity:"0.25"}),l.jsx("polygon",{points:"20,16 34,24 20,32",fill:"currentColor",opacity:"0.3"})]}),ju=[7,14,30],Ni=["rgba(34,113,177,0.75)","rgba(46,160,67,0.75)","rgba(219,171,55,0.75)","rgba(207,79,79,0.75)","rgba(130,80,180,0.75)"],Su=[{id:"single-post",Icon:xu,title:f.__("Generate Post","smartypress-ai-engine"),description:f.__("Create a single AI-powered article with SEO optimization.","smartypress-ai-engine"),route:"/content-generation"},{id:"bulk-content",Icon:yu,title:f.__("Bulk Content","smartypress-ai-engine"),description:f.__("Generate multiple posts at once from a list of topics.","smartypress-ai-engine"),route:"/content-generation",routeState:{tab:"bulk"}},{id:"generate-image",Icon:bu,title:f.__("Generate Image","smartypress-ai-engine"),description:f.__("Create images from text prompts and save to Media Library.","smartypress-ai-engine"),route:"/image-generation"},{id:"bulk-alt",Icon:vu,title:f.__("Bulk Alt Text","smartypress-ai-engine"),description:f.__("Auto-generate alt text for all images in your library.","smartypress-ai-engine"),route:"/image-alt-generation"},{id:"bulk-thumbnails",Icon:ku,title:f.__("Bulk Thumbnails","smartypress-ai-engine"),description:f.__("Generate featured images for posts and products in bulk.","smartypress-ai-engine"),href:"/wp-admin/admin.php?page=aitm-dashboard"}];function Ti(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":String(t)}function Cu(t){return t<.01&&t>0?"$"+t.toFixed(4):"$"+t.toFixed(2)}function Mu(t){return t.includes("/")?t.split("/").pop():t}function Pu(){const[t,e]=V.useState(30),[s,i]=V.useState(null),[n,a]=V.useState(!0),[r,o]=V.useState("");V.useEffect(()=>{let u=!1;return a(!0),o(""),wp.apiFetch({path:`/smartypress/v1/token-usage/stats?days=${t}`}).then(p=>{u||(i(p),a(!1))}).catch(p=>{u||(o(p.message||f.__("Failed to load usage data.","smartypress-ai-engine")),a(!1))}),()=>{u=!0}},[t]);const c=V.useMemo(()=>{if(!(s!=null&&s.daily))return null;const u=s.daily,p=Object.keys(u).sort();if(p.length===0)return null;const g=new Map;p.forEach(w=>{var I;const S=((I=u[w])==null?void 0:I.by_model)||{};Object.keys(S).forEach(C=>{var L,N;const P=g.get(C)||0;g.set(C,P+(((L=S[C])==null?void 0:L.output)+((N=S[C])==null?void 0:N.input)||0))})});const x=[...g.entries()].sort((w,S)=>S[1]-w[1]),_=x.slice(0,4).map(([w])=>w),m=x.length>4,v=_.map((w,S)=>({label:Mu(w),data:p.map(I=>{var C,P,L,N,R,B;return((L=(P=(C=u[I])==null?void 0:C.by_model)==null?void 0:P[w])==null?void 0:L.input)+((B=(R=(N=u[I])==null?void 0:N.by_model)==null?void 0:R[w])==null?void 0:B.output)||0}),backgroundColor:Ni[S%Ni.length],borderRadius:3}));if(m){const w=x.slice(4).map(([S])=>S);v.push({label:f.__("Other","smartypress-ai-engine"),data:p.map(S=>{var C;const I=((C=u[S])==null?void 0:C.by_model)||{};return w.reduce((P,L)=>{var N,R;return P+(((N=I[L])==null?void 0:N.input)+((R=I[L])==null?void 0:R.output)||0)},0)}),backgroundColor:Ni[4],borderRadius:3})}return{labels:p.map(w=>{const S=w.split("-");return S[2]+"."+S[1]}),datasets:v}},[s]),h=V.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"bottom",labels:{boxWidth:12,padding:14,font:{size:11}}},tooltip:{callbacks:{label:u=>`${u.dataset.label}: ${Ti(u.raw)} tokens`}}},scales:{x:{stacked:!0,grid:{display:!1},ticks:{font:{size:10},maxRotation:45,minRotation:0}},y:{stacked:!0,beginAtZero:!0,ticks:{font:{size:10},callback:u=>Ti(u)}}}}),[]),d=s==null?void 0:s.summary;return l.jsxs("div",{className:"spai-token-usage",children:[l.jsxs("div",{className:"spai-token-usage__head",children:[l.jsx("h2",{children:f.__("Token Usage Statistics","smartypress-ai-engine")}),l.jsx("div",{className:"spai-token-usage__periods",children:ju.map(u=>l.jsxs("button",{type:"button",className:`spai-token-usage__period${u===t?" is-active":""}`,onClick:()=>e(u),children:[u,f.__("d","smartypress-ai-engine")]},u))})]}),n&&l.jsxs("div",{className:"spai-token-usage__loading",children:[l.jsx("div",{className:"spai-token-usage__shimmer"}),l.jsx("div",{className:"spai-token-usage__shimmer spai-token-usage__shimmer--short"})]}),r&&l.jsx("p",{className:"spai-token-usage__error",children:r}),!n&&!r&&!c&&l.jsx("div",{className:"spai-token-usage__empty",children:l.jsx("p",{children:f.__("No usage data yet. Statistics will appear after your first API call.","smartypress-ai-engine")})}),!n&&!r&&c&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"spai-token-usage__chart",children:l.jsx(_u,{data:c,options:h})}),d&&l.jsxs("div",{className:"spai-token-usage__summary",children:[l.jsxs("div",{className:"spai-token-usage__stat",children:[l.jsx("span",{className:"spai-token-usage__stat-value",children:Ti(d.total_tokens)}),l.jsx("span",{className:"spai-token-usage__stat-label",children:f.__("Total Tokens","smartypress-ai-engine")})]}),l.jsxs("div",{className:"spai-token-usage__stat",children:[l.jsx("span",{className:"spai-token-usage__stat-value",children:Cu(d.total_cost)}),l.jsx("span",{className:"spai-token-usage__stat-label",children:f.__("Est. Cost","smartypress-ai-engine")})]}),l.jsxs("div",{className:"spai-token-usage__stat",children:[l.jsx("span",{className:"spai-token-usage__stat-value",children:d.total_requests}),l.jsx("span",{className:"spai-token-usage__stat-label",children:f.__("API Calls","smartypress-ai-engine")})]})]})]})]})}function Au(){const t=Us(),e=s=>{s.href?window.location.href=window.location.origin+s.href:s.route&&t(s.route,s.routeState?{state:s.routeState}:void 0)};return l.jsxs("div",{className:"spai-dashboard",children:[l.jsxs("div",{className:"spai-dashboard__header",children:[l.jsx("h1",{children:f.__("Dashboard","smartypress-ai-engine")}),l.jsx("p",{children:f.__("Welcome to SmartyPress AI. Manage your AI-powered content generation tools.","smartypress-ai-engine")})]}),l.jsxs("div",{className:"spai-dashboard__top",children:[l.jsx(Pu,{}),l.jsxs("div",{className:"spai-dashboard__placeholder-card",children:[l.jsx("div",{className:"spai-dashboard__placeholder-icon",children:l.jsx(wu,{})}),l.jsx("h2",{children:f.__("Video Tutorial","smartypress-ai-engine")}),l.jsx("p",{children:f.__("Step-by-step guide on how to use SmartyPress AI effectively.","smartypress-ai-engine")}),l.jsx("span",{className:"spai-dashboard__badge",children:f.__("Coming soon","smartypress-ai-engine")})]})]}),l.jsx("h2",{className:"spai-dashboard__section-title",children:f.__("Quick Actions","smartypress-ai-engine")}),l.jsx("div",{className:"spai-dashboard__actions",children:Su.map(s=>l.jsxs("button",{type:"button",className:"spai-dashboard__action-card",onClick:()=>e(s),children:[l.jsx("div",{className:"spai-dashboard__action-icon",children:l.jsx(s.Icon,{})}),l.jsx("h3",{children:s.title}),l.jsx("p",{children:s.description})]},s.id))})]})}function Ou(){var z,D;const[t,e]=M.useState([]),[s,i]=M.useState(!0),[n,a]=M.useState(!1),[r,o]=M.useState({}),[c,h]=M.useState({type:"",text:""}),[d,u]=M.useState(!1),p=((z=window.smartypressAIAdmin)==null?void 0:z.apiUrl)||"/wp-json/smartypress/v1/",g=((D=window.smartypressAIAdmin)==null?void 0:D.nonce)||"",x=M.useCallback(async()=>{try{const k=await fetch(`${p}logs`,{headers:{"X-WP-Nonce":g}});if(k.ok){const F=await k.json();e(F)}else console.error("Failed to load logs:",k.statusText)}catch(k){console.error("Failed to load logs:",k)}finally{i(!1)}},[p,g]);M.useEffect(()=>{x()},[x]),M.useEffect(()=>{if(!d)return;const k=setInterval(()=>{x()},3e4);return()=>clearInterval(k)},[d,x]);const _=async()=>{if(confirm(f.__("Are you sure you want to clear all logs?","smartypress-ai-engine")))try{a(!0);const k=await fetch(`${p}logs`,{method:"DELETE",headers:{"X-WP-Nonce":g}});if(k.ok){const F=await k.json();F.success?(e([]),h({type:"success",text:f.__("Logs cleared successfully.","smartypress-ai-engine")})):h({type:"error",text:F.message||f.__("Failed to clear logs.","smartypress-ai-engine")})}else h({type:"error",text:f.__("Failed to clear logs.","smartypress-ai-engine")})}catch(k){console.error("Failed to clear logs:",k),h({type:"error",text:f.__("Failed to clear logs.","smartypress-ai-engine")})}finally{a(!1)}},m=k=>{o(F=>({...F,[k]:!F[k]}))},v=k=>{if(!k)return null;const W={api_key_invalid:{color:"#d63638",label:"API Key Invalid"},rate_limit:{color:"#dba617",label:"Rate Limit"},quota_exceeded:{color:"#d63638",label:"Quota Exceeded"},wp_error:{color:"#996800",label:"WP Error"}}[k]||{color:"#666",label:k};return l.jsx("span",{style:{backgroundColor:W.color,color:"#fff",padding:"2px 8px",borderRadius:"3px",fontSize:"11px",marginLeft:"8px"},children:W.label})},w=k=>{if(!k)return null;let F="#666";return k>=200&&k<300?F="#00a32a":k>=400&&k<500?F="#dba617":k>=500&&(F="#d63638"),l.jsx("span",{style:{backgroundColor:F,color:"#fff",padding:"2px 6px",borderRadius:"3px",fontSize:"11px"},children:k})},S=k=>k?new Date(k).toLocaleString():"",I=k=>{if(!k)return"";if(typeof k=="string")try{k=JSON.parse(k)}catch{return k}return JSON.stringify(k,null,2)},C=k=>k.type==="module_event",P=k=>({image_generator:f.__("Image Generator","smartypress-ai-engine")})[k]||k&&k.replace(/_/g," ").replace(/\b\w/g,W=>W.toUpperCase())||"",L=k=>{const F=k?"#00a32a":"#d63638",W=k?f.__("OK","smartypress-ai-engine"):f.__("Error","smartypress-ai-engine");return l.jsx("span",{style:{backgroundColor:F,color:"#fff",padding:"2px 6px",borderRadius:"3px",fontSize:"11px"},children:W})},N=k=>{var F;if(C(k)){if((F=k.data)!=null&&F.provider){const W=k.data.provider;return W?W.charAt(0).toUpperCase()+W.slice(1):""}return P(k.context)}return k.provider},R=k=>C(k)?L(k.success):w(k.response_code),B=k=>{var F;return C(k)?((F=k.data)==null?void 0:F.error)||k.stage||"":k.error_message};return s?l.jsx("div",{className:"smartypress-ai-logs-page",children:l.jsx("div",{className:"smartypress-ai-loading",children:f.__("Loading logs...","smartypress-ai-engine")})}):l.jsxs("div",{className:"smartypress-ai-logs-page",children:[l.jsxs("div",{className:"smartypress-ai-page-header",children:[l.jsx("h1",{children:f.__("API Logs","smartypress-ai-engine")}),l.jsx("p",{children:f.__("View API error logs for debugging. Enable debug logging in Settings to capture new logs.","smartypress-ai-engine")})]}),c.text&&l.jsx("div",{className:`notice notice-${c.type} is-dismissible`,children:l.jsx("p",{children:c.text})}),l.jsxs("div",{className:"smartypress-ai-logs-toolbar",style:{marginBottom:"20px",display:"flex",gap:"10px",alignItems:"center"},children:[l.jsx("button",{type:"button",className:"button",onClick:x,disabled:s,children:f.__("Refresh","smartypress-ai-engine")}),l.jsx("button",{type:"button",className:"button button-secondary",onClick:_,disabled:n||t.length===0,style:{color:t.length>0?"#d63638":void 0},children:n?f.__("Clearing...","smartypress-ai-engine"):f.__("Clear All Logs","smartypress-ai-engine")}),l.jsxs("label",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:"5px"},children:[l.jsx("input",{type:"checkbox",checked:d,onChange:k=>u(k.target.checked)}),f.__("Auto-refresh every 30s","smartypress-ai-engine")]}),l.jsxs("span",{style:{color:"#666",fontSize:"13px"},children:[t.length," ",t.length===1?f.__("log","smartypress-ai-engine"):f.__("logs","smartypress-ai-engine")]})]}),t.length===0?l.jsxs("div",{className:"smartypress-ai-no-logs",style:{padding:"40px",textAlign:"center",backgroundColor:"#f0f0f1",borderRadius:"4px"},children:[l.jsx("p",{style:{fontSize:"16px",color:"#666"},children:f.__("No logs found.","smartypress-ai-engine")}),l.jsx("p",{style:{fontSize:"14px",color:"#888"},children:f.__("API errors will appear here when debug logging is enabled in Settings.","smartypress-ai-engine")}),l.jsx("a",{href:"#/settings",className:"button button-primary",style:{marginTop:"10px"},children:f.__("Go to Settings","smartypress-ai-engine")})]}):l.jsx("div",{className:"smartypress-ai-logs-table",children:l.jsxs("table",{className:"wp-list-table widefat fixed striped",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{style:{width:"160px"},children:f.__("Timestamp","smartypress-ai-engine")}),l.jsx("th",{style:{width:"100px"},children:f.__("Provider","smartypress-ai-engine")}),l.jsx("th",{style:{width:"80px"},children:f.__("Status","smartypress-ai-engine")}),l.jsx("th",{children:f.__("Error Message","smartypress-ai-engine")}),l.jsx("th",{style:{width:"80px"},children:f.__("Actions","smartypress-ai-engine")})]})}),l.jsx("tbody",{children:t.map(k=>l.jsxs(l.Fragment,{children:[l.jsxs("tr",{children:[l.jsx("td",{children:S(k.timestamp)}),l.jsx("td",{children:l.jsx("strong",{style:{textTransform:C(k)?"none":"capitalize"},children:N(k)})}),l.jsx("td",{children:R(k)}),l.jsxs("td",{children:[B(k),!C(k)&&v(k.error_code)]}),l.jsx("td",{children:l.jsx("button",{type:"button",className:"button button-small",onClick:()=>m(k.id),children:r[k.id]?f.__("Hide","smartypress-ai-engine"):f.__("Details","smartypress-ai-engine")})})]},k.id),r[k.id]&&l.jsx("tr",{className:"smartypress-log-details",children:l.jsx("td",{colSpan:"5",style:{backgroundColor:"#f9f9f9",padding:"15px"},children:C(k)?l.jsxs("div",{children:[l.jsx("h4",{style:{margin:"0 0 10px 0"},children:f.__("Module Event Details","smartypress-ai-engine")}),l.jsxs("p",{children:[l.jsx("strong",{children:f.__("Stage:","smartypress-ai-engine")})," ",k.stage]}),l.jsxs("p",{children:[l.jsx("strong",{children:f.__("Context:","smartypress-ai-engine")})," ",k.context]}),l.jsx("p",{style:{marginBottom:"8px"},children:l.jsx("strong",{children:f.__("Data:","smartypress-ai-engine")})}),l.jsx("pre",{style:{backgroundColor:"#fff",padding:"10px",borderRadius:"4px",border:"1px solid #ddd",overflowY:"auto",overflowX:"hidden",maxHeight:"400px",fontSize:"12px",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:I(k.data)})]}):l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"20px"},children:[l.jsxs("div",{children:[l.jsx("h4",{style:{margin:"0 0 10px 0"},children:f.__("Request Details","smartypress-ai-engine")}),l.jsxs("p",{children:[l.jsx("strong",{children:f.__("Endpoint:","smartypress-ai-engine")})," ",k.endpoint]}),l.jsx("pre",{style:{backgroundColor:"#fff",padding:"10px",borderRadius:"4px",border:"1px solid #ddd",overflowY:"auto",overflowX:"hidden",maxHeight:"400px",fontSize:"12px",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:I(k.request)})]}),l.jsxs("div",{children:[l.jsx("h4",{style:{margin:"0 0 10px 0"},children:f.__("Response Body","smartypress-ai-engine")}),l.jsx("pre",{style:{backgroundColor:"#fff",padding:"10px",borderRadius:"4px",border:"1px solid #ddd",overflowY:"auto",overflowX:"hidden",maxHeight:"400px",fontSize:"12px",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:I(k.response_body)})]})]})})},`${k.id}-details`)]}))})]})})]})}const Iu={ContentGenerationPage:l.jsx(gl,{}),ImageGenerationPage:l.jsx(ml,{}),ImageALTGenerationPage:l.jsx(Il,{})};function Lu(){const{routes:t}=Ks();return l.jsx(ll,{children:l.jsxs(Mo,{children:[l.jsx(Ze,{path:"/",element:l.jsx(So,{to:"/dashboard",replace:!0})}),l.jsx(Ze,{path:"/dashboard",element:l.jsx(Au,{})}),l.jsx(Ze,{path:"/components",element:l.jsx(dl,{})}),l.jsx(Ze,{path:"/settings",element:l.jsx(pl,{})}),l.jsx(Ze,{path:"/logs",element:l.jsx(Ou,{})}),t.map(e=>l.jsx(Ze,{path:e.path,element:Iu[e.component]||l.jsxs("div",{children:["Route ",e.path," not implemented"]})},e.path))]})})}function Sr(){return l.jsx(Wo,{children:l.jsx(No,{children:l.jsx(Lu,{})})})}function Cr(){var a;const t=document.getElementById("smartypress-ai-admin-root");if(!t)return;const{createElement:e,render:s}=((a=window.wp)==null?void 0:a.element)||{},i=window.React,n=window.ReactDOM;if(!i||!e){console.error("React or WordPress element not available. Please ensure React and WordPress are loaded.");return}n!=null&&n.createRoot?n.createRoot(t).render(e(Sr)):s?s(e(Sr),t):console.error("React DOM render method not available.")}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Cr):Cr()})(React,ReactDOM,wp.element,wp.apiFetch,wp.i18n,wp.components);
