190 lines
202 KiB
JavaScript
190 lines
202 KiB
JavaScript
var $i=Object.defineProperty;var Oi=(i,l,u)=>l in i?$i(i,l,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[l]=u;var xe=(i,l,u)=>(Oi(i,typeof l!="symbol"?l+"":l,u),u);import{r as R,a as Ti,u as Ai,L as Re,R as Ir,b as Mi,B as Ki,c as Ii,d as en}from"./vendor-beb84f6c.js";import{c as qn,g as Bn,a as Es,p as Ri,d as Fi,m as qi,N as Pt,b as bs,e as Bi,n as nn,f as Dr,h as Li,i as zi}from"./ndk-40656944.js";(function(){const l=document.createElement("link").relList;if(l&&l.supports&&l.supports("modulepreload"))return;for(const f of document.querySelectorAll('link[rel="modulepreload"]'))c(f);new MutationObserver(f=>{for(const d of f)if(d.type==="childList")for(const y of d.addedNodes)y.tagName==="LINK"&&y.rel==="modulepreload"&&c(y)}).observe(document,{childList:!0,subtree:!0});function u(f){const d={};return f.integrity&&(d.integrity=f.integrity),f.referrerPolicy&&(d.referrerPolicy=f.referrerPolicy),f.crossOrigin==="use-credentials"?d.credentials="include":f.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function c(f){if(f.ep)return;f.ep=!0;const d=u(f);fetch(f.href,d)}})();var Ds={exports:{}},Ln={};/**
|
||
* @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 Ui=R,Yi=Symbol.for("react.element"),Wi=Symbol.for("react.fragment"),Vi=Object.prototype.hasOwnProperty,Hi=Ui.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Zi={key:!0,ref:!0,__self:!0,__source:!0};function Ps(i,l,u){var c,f={},d=null,y=null;u!==void 0&&(d=""+u),l.key!==void 0&&(d=""+l.key),l.ref!==void 0&&(y=l.ref);for(c in l)Vi.call(l,c)&&!Zi.hasOwnProperty(c)&&(f[c]=l[c]);if(i&&i.defaultProps)for(c in l=i.defaultProps,l)f[c]===void 0&&(f[c]=l[c]);return{$$typeof:Yi,type:i,key:d,ref:y,props:f,_owner:Hi.current}}Ln.Fragment=Wi;Ln.jsx=Ps;Ln.jsxs=Ps;Ds.exports=Ln;var s=Ds.exports,Pr={},vs=Ti;Pr.createRoot=vs.createRoot,Pr.hydrateRoot=vs.hydrateRoot;let Ji={data:""},Qi=i=>typeof window=="object"?((i?i.querySelector("#_goober"):window._goober)||Object.assign((i||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:i||Ji,Gi=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,Xi=/\/\*[^]*?\*\/| +/g,xs=/\n+/g,ft=(i,l)=>{let u="",c="",f="";for(let d in i){let y=i[d];d[0]=="@"?d[1]=="i"?u=d+" "+y+";":c+=d[1]=="f"?ft(y,d):d+"{"+ft(y,d[1]=="k"?"":l)+"}":typeof y=="object"?c+=ft(y,l?l.replace(/([^,])+/g,p=>d.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,C=>/&/.test(C)?C.replace(/&/g,p):p?p+" "+C:C)):d):y!=null&&(d=/^--/.test(d)?d:d.replace(/[A-Z]/g,"-$&").toLowerCase(),f+=ft.p?ft.p(d,y):d+":"+y+";")}return u+(l&&f?l+"{"+f+"}":f)+c},st={},$s=i=>{if(typeof i=="object"){let l="";for(let u in i)l+=u+$s(i[u]);return l}return i},eo=(i,l,u,c,f)=>{let d=$s(i),y=st[d]||(st[d]=(C=>{let S=0,$=11;for(;S<C.length;)$=101*$+C.charCodeAt(S++)>>>0;return"go"+$})(d));if(!st[y]){let C=d!==i?i:(S=>{let $,A,Y=[{}];for(;$=Gi.exec(S.replace(Xi,""));)$[4]?Y.shift():$[3]?(A=$[3].replace(xs," ").trim(),Y.unshift(Y[0][A]=Y[0][A]||{})):Y[0][$[1]]=$[2].replace(xs," ").trim();return Y[0]})(i);st[y]=ft(f?{["@keyframes "+y]:C}:C,u?"":"."+y)}let p=u&&st.g?st.g:null;return u&&(st.g=st[y]),((C,S,$,A)=>{A?S.data=S.data.replace(A,C):S.data.indexOf(C)===-1&&(S.data=$?C+S.data:S.data+C)})(st[y],l,c,p),y},to=(i,l,u)=>i.reduce((c,f,d)=>{let y=l[d];if(y&&y.call){let p=y(u),C=p&&p.props&&p.props.className||/^go/.test(p)&&p;y=C?"."+C:p&&typeof p=="object"?p.props?"":ft(p,""):p===!1?"":p}return c+f+(y??"")},"");function zn(i){let l=this||{},u=i.call?i(l.p):i;return eo(u.unshift?u.raw?to(u,[].slice.call(arguments,1),l.p):u.reduce((c,f)=>Object.assign(c,f&&f.call?f(l.p):f),{}):u,Qi(l.target),l.g,l.o,l.k)}let Os,$r,Or;zn.bind({g:1});let it=zn.bind({k:1});function no(i,l,u,c){ft.p=l,Os=i,$r=u,Or=c}function pt(i,l){let u=this||{};return function(){let c=arguments;function f(d,y){let p=Object.assign({},d),C=p.className||f.className;u.p=Object.assign({theme:$r&&$r()},p),u.o=/ *go\d+/.test(C),p.className=zn.apply(u,c)+(C?" "+C:""),l&&(p.ref=y);let S=i;return i[0]&&(S=p.as||i,delete p.as),Or&&S[0]&&Or(p),Os(S,p)}return l?l(f):f}}var ro=i=>typeof i=="function",Rn=(i,l)=>ro(i)?i(l):i,so=(()=>{let i=0;return()=>(++i).toString()})(),Ts=(()=>{let i;return()=>{if(i===void 0&&typeof window<"u"){let l=matchMedia("(prefers-reduced-motion: reduce)");i=!l||l.matches}return i}})(),io=20,As=(i,l)=>{switch(l.type){case 0:return{...i,toasts:[l.toast,...i.toasts].slice(0,io)};case 1:return{...i,toasts:i.toasts.map(d=>d.id===l.toast.id?{...d,...l.toast}:d)};case 2:let{toast:u}=l;return As(i,{type:i.toasts.find(d=>d.id===u.id)?1:0,toast:u});case 3:let{toastId:c}=l;return{...i,toasts:i.toasts.map(d=>d.id===c||c===void 0?{...d,dismissed:!0,visible:!1}:d)};case 4:return l.toastId===void 0?{...i,toasts:[]}:{...i,toasts:i.toasts.filter(d=>d.id!==l.toastId)};case 5:return{...i,pausedAt:l.time};case 6:let f=l.time-(i.pausedAt||0);return{...i,pausedAt:void 0,toasts:i.toasts.map(d=>({...d,pauseDuration:d.pauseDuration+f}))}}},In=[],Dt={toasts:[],pausedAt:void 0},Ot=i=>{Dt=As(Dt,i),In.forEach(l=>{l(Dt)})},oo={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},ao=(i={})=>{let[l,u]=R.useState(Dt),c=R.useRef(Dt);R.useEffect(()=>(c.current!==Dt&&u(Dt),In.push(u),()=>{let d=In.indexOf(u);d>-1&&In.splice(d,1)}),[]);let f=l.toasts.map(d=>{var y,p,C;return{...i,...i[d.type],...d,removeDelay:d.removeDelay||((y=i[d.type])==null?void 0:y.removeDelay)||(i==null?void 0:i.removeDelay),duration:d.duration||((p=i[d.type])==null?void 0:p.duration)||(i==null?void 0:i.duration)||oo[d.type],style:{...i.style,...(C=i[d.type])==null?void 0:C.style,...d.style}}});return{...l,toasts:f}},lo=(i,l="blank",u)=>({createdAt:Date.now(),visible:!0,dismissed:!1,type:l,ariaProps:{role:"status","aria-live":"polite"},message:i,pauseDuration:0,...u,id:(u==null?void 0:u.id)||so()}),ln=i=>(l,u)=>{let c=lo(l,i,u);return Ot({type:2,toast:c}),c.id},Ue=(i,l)=>ln("blank")(i,l);Ue.error=ln("error");Ue.success=ln("success");Ue.loading=ln("loading");Ue.custom=ln("custom");Ue.dismiss=i=>{Ot({type:3,toastId:i})};Ue.remove=i=>Ot({type:4,toastId:i});Ue.promise=(i,l,u)=>{let c=Ue.loading(l.loading,{...u,...u==null?void 0:u.loading});return typeof i=="function"&&(i=i()),i.then(f=>{let d=l.success?Rn(l.success,f):void 0;return d?Ue.success(d,{id:c,...u,...u==null?void 0:u.success}):Ue.dismiss(c),f}).catch(f=>{let d=l.error?Rn(l.error,f):void 0;d?Ue.error(d,{id:c,...u,...u==null?void 0:u.error}):Ue.dismiss(c)}),i};var co=(i,l)=>{Ot({type:1,toast:{id:i,height:l}})},uo=()=>{Ot({type:5,time:Date.now()})},rn=new Map,ho=1e3,fo=(i,l=ho)=>{if(rn.has(i))return;let u=setTimeout(()=>{rn.delete(i),Ot({type:4,toastId:i})},l);rn.set(i,u)},mo=i=>{let{toasts:l,pausedAt:u}=ao(i);R.useEffect(()=>{if(u)return;let d=Date.now(),y=l.map(p=>{if(p.duration===1/0)return;let C=(p.duration||0)+p.pauseDuration-(d-p.createdAt);if(C<0){p.visible&&Ue.dismiss(p.id);return}return setTimeout(()=>Ue.dismiss(p.id),C)});return()=>{y.forEach(p=>p&&clearTimeout(p))}},[l,u]);let c=R.useCallback(()=>{u&&Ot({type:6,time:Date.now()})},[u]),f=R.useCallback((d,y)=>{let{reverseOrder:p=!1,gutter:C=8,defaultPosition:S}=y||{},$=l.filter(M=>(M.position||S)===(d.position||S)&&M.height),A=$.findIndex(M=>M.id===d.id),Y=$.filter((M,T)=>T<A&&M.visible).length;return $.filter(M=>M.visible).slice(...p?[Y+1]:[0,Y]).reduce((M,T)=>M+(T.height||0)+C,0)},[l]);return R.useEffect(()=>{l.forEach(d=>{if(d.dismissed)fo(d.id,d.removeDelay);else{let y=rn.get(d.id);y&&(clearTimeout(y),rn.delete(d.id))}})},[l]),{toasts:l,handlers:{updateHeight:co,startPause:uo,endPause:c,calculateOffset:f}}},po=it`
|
||
from {
|
||
transform: scale(0) rotate(45deg);
|
||
opacity: 0;
|
||
}
|
||
to {
|
||
transform: scale(1) rotate(45deg);
|
||
opacity: 1;
|
||
}`,yo=it`
|
||
from {
|
||
transform: scale(0);
|
||
opacity: 0;
|
||
}
|
||
to {
|
||
transform: scale(1);
|
||
opacity: 1;
|
||
}`,go=it`
|
||
from {
|
||
transform: scale(0) rotate(90deg);
|
||
opacity: 0;
|
||
}
|
||
to {
|
||
transform: scale(1) rotate(90deg);
|
||
opacity: 1;
|
||
}`,bo=pt("div")`
|
||
width: 20px;
|
||
opacity: 0;
|
||
height: 20px;
|
||
border-radius: 10px;
|
||
background: ${i=>i.primary||"#ff4b4b"};
|
||
position: relative;
|
||
transform: rotate(45deg);
|
||
|
||
animation: ${po} 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)
|
||
forwards;
|
||
animation-delay: 100ms;
|
||
|
||
&:after,
|
||
&:before {
|
||
content: '';
|
||
animation: ${yo} 0.15s ease-out forwards;
|
||
animation-delay: 150ms;
|
||
position: absolute;
|
||
border-radius: 3px;
|
||
opacity: 0;
|
||
background: ${i=>i.secondary||"#fff"};
|
||
bottom: 9px;
|
||
left: 4px;
|
||
height: 2px;
|
||
width: 12px;
|
||
}
|
||
|
||
&:before {
|
||
animation: ${go} 0.15s ease-out forwards;
|
||
animation-delay: 180ms;
|
||
transform: rotate(90deg);
|
||
}
|
||
`,vo=it`
|
||
from {
|
||
transform: rotate(0deg);
|
||
}
|
||
to {
|
||
transform: rotate(360deg);
|
||
}
|
||
`,xo=pt("div")`
|
||
width: 12px;
|
||
height: 12px;
|
||
box-sizing: border-box;
|
||
border: 2px solid;
|
||
border-radius: 100%;
|
||
border-color: ${i=>i.secondary||"#e0e0e0"};
|
||
border-right-color: ${i=>i.primary||"#616161"};
|
||
animation: ${vo} 1s linear infinite;
|
||
`,wo=it`
|
||
from {
|
||
transform: scale(0) rotate(45deg);
|
||
opacity: 0;
|
||
}
|
||
to {
|
||
transform: scale(1) rotate(45deg);
|
||
opacity: 1;
|
||
}`,jo=it`
|
||
0% {
|
||
height: 0;
|
||
width: 0;
|
||
opacity: 0;
|
||
}
|
||
40% {
|
||
height: 0;
|
||
width: 6px;
|
||
opacity: 1;
|
||
}
|
||
100% {
|
||
opacity: 1;
|
||
height: 10px;
|
||
}`,No=pt("div")`
|
||
width: 20px;
|
||
opacity: 0;
|
||
height: 20px;
|
||
border-radius: 10px;
|
||
background: ${i=>i.primary||"#61d345"};
|
||
position: relative;
|
||
transform: rotate(45deg);
|
||
|
||
animation: ${wo} 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)
|
||
forwards;
|
||
animation-delay: 100ms;
|
||
&:after {
|
||
content: '';
|
||
box-sizing: border-box;
|
||
animation: ${jo} 0.2s ease-out forwards;
|
||
opacity: 0;
|
||
animation-delay: 200ms;
|
||
position: absolute;
|
||
border-right: 2px solid;
|
||
border-bottom: 2px solid;
|
||
border-color: ${i=>i.secondary||"#fff"};
|
||
bottom: 6px;
|
||
left: 6px;
|
||
height: 10px;
|
||
width: 6px;
|
||
}
|
||
`,ko=pt("div")`
|
||
position: absolute;
|
||
`,_o=pt("div")`
|
||
position: relative;
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
min-width: 20px;
|
||
min-height: 20px;
|
||
`,Co=it`
|
||
from {
|
||
transform: scale(0.6);
|
||
opacity: 0.4;
|
||
}
|
||
to {
|
||
transform: scale(1);
|
||
opacity: 1;
|
||
}`,So=pt("div")`
|
||
position: relative;
|
||
transform: scale(0.6);
|
||
opacity: 0.4;
|
||
min-width: 20px;
|
||
animation: ${Co} 0.3s 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275)
|
||
forwards;
|
||
`,Eo=({toast:i})=>{let{icon:l,type:u,iconTheme:c}=i;return l!==void 0?typeof l=="string"?R.createElement(So,null,l):l:u==="blank"?null:R.createElement(_o,null,R.createElement(xo,{...c}),u!=="loading"&&R.createElement(ko,null,u==="error"?R.createElement(bo,{...c}):R.createElement(No,{...c})))},Do=i=>`
|
||
0% {transform: translate3d(0,${i*-200}%,0) scale(.6); opacity:.5;}
|
||
100% {transform: translate3d(0,0,0) scale(1); opacity:1;}
|
||
`,Po=i=>`
|
||
0% {transform: translate3d(0,0,-1px) scale(1); opacity:1;}
|
||
100% {transform: translate3d(0,${i*-150}%,-1px) scale(.6); opacity:0;}
|
||
`,$o="0%{opacity:0;} 100%{opacity:1;}",Oo="0%{opacity:1;} 100%{opacity:0;}",To=pt("div")`
|
||
display: flex;
|
||
align-items: center;
|
||
background: #fff;
|
||
color: #363636;
|
||
line-height: 1.3;
|
||
will-change: transform;
|
||
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05);
|
||
max-width: 350px;
|
||
pointer-events: auto;
|
||
padding: 8px 10px;
|
||
border-radius: 8px;
|
||
`,Ao=pt("div")`
|
||
display: flex;
|
||
justify-content: center;
|
||
margin: 4px 10px;
|
||
color: inherit;
|
||
flex: 1 1 auto;
|
||
white-space: pre-line;
|
||
`,Mo=(i,l)=>{let u=i.includes("top")?1:-1,[c,f]=Ts()?[$o,Oo]:[Do(u),Po(u)];return{animation:l?`${it(c)} 0.35s cubic-bezier(.21,1.02,.73,1) forwards`:`${it(f)} 0.4s forwards cubic-bezier(.06,.71,.55,1)`}},Ko=R.memo(({toast:i,position:l,style:u,children:c})=>{let f=i.height?Mo(i.position||l||"top-center",i.visible):{opacity:0},d=R.createElement(Eo,{toast:i}),y=R.createElement(Ao,{...i.ariaProps},Rn(i.message,i));return R.createElement(To,{className:i.className,style:{...f,...u,...i.style}},typeof c=="function"?c({icon:d,message:y}):R.createElement(R.Fragment,null,d,y))});no(R.createElement);var Io=({id:i,className:l,style:u,onHeightUpdate:c,children:f})=>{let d=R.useCallback(y=>{if(y){let p=()=>{let C=y.getBoundingClientRect().height;c(i,C)};p(),new MutationObserver(p).observe(y,{subtree:!0,childList:!0,characterData:!0})}},[i,c]);return R.createElement("div",{ref:d,className:l,style:u},f)},Ro=(i,l)=>{let u=i.includes("top"),c=u?{top:0}:{bottom:0},f=i.includes("center")?{justifyContent:"center"}:i.includes("right")?{justifyContent:"flex-end"}:{};return{left:0,right:0,display:"flex",position:"absolute",transition:Ts()?void 0:"all 230ms cubic-bezier(.21,1.02,.73,1)",transform:`translateY(${l*(u?1:-1)}px)`,...c,...f}},Fo=zn`
|
||
z-index: 9999;
|
||
> * {
|
||
pointer-events: auto;
|
||
}
|
||
`,Kn=16,qo=({reverseOrder:i,position:l="top-center",toastOptions:u,gutter:c,children:f,containerStyle:d,containerClassName:y})=>{let{toasts:p,handlers:C}=mo(u);return R.createElement("div",{id:"_rht_toaster",style:{position:"fixed",zIndex:9999,top:Kn,left:Kn,right:Kn,bottom:Kn,pointerEvents:"none",...d},className:y,onMouseEnter:C.startPause,onMouseLeave:C.endPause},p.map(S=>{let $=S.position||l,A=C.calculateOffset(S,{reverseOrder:i,gutter:c,defaultPosition:l}),Y=Ro($,A);return R.createElement(Io,{id:S.id,key:S.id,onHeightUpdate:C.updateHeight,className:S.visible?Fo:"",style:Y},S.type==="custom"?Rn(S.message,S):f?f(S):R.createElement(Ko,{toast:S,position:$}))}))},Le=Ue,Ms={exports:{}};(function(i,l){(function(u,c){i.exports=c()})(qn,function(){var u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])})(e,t)},c=function(){return(c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function f(e,t,n){if(n||arguments.length===2)for(var r,o=0,a=t.length;o<a;o++)!r&&o in t||((r=r||Array.prototype.slice.call(t,0,o))[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var d=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:globalThis,y=Object.keys,p=Array.isArray;function C(e,t){return typeof t!="object"||y(t).forEach(function(n){e[n]=t[n]}),e}typeof Promise>"u"||d.Promise||(d.Promise=Promise);var S=Object.getPrototypeOf,$={}.hasOwnProperty;function A(e,t){return $.call(e,t)}function Y(e,t){typeof t=="function"&&(t=t(S(e))),(typeof Reflect>"u"?y:Reflect.ownKeys)(t).forEach(function(n){T(e,n,t[n])})}var M=Object.defineProperty;function T(e,t,n,r){M(e,t,C(n&&A(n,"get")&&typeof n.get=="function"?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function ne(e){return{from:function(t){return e.prototype=Object.create(t.prototype),T(e.prototype,"constructor",e),{extend:Y.bind(null,e.prototype)}}}}var pe=Object.getOwnPropertyDescriptor,ue=[].slice;function ie(e,t,n){return ue.call(e,t,n)}function G(e,t){return t(e)}function de(e){if(!e)throw new Error("Assertion Failed")}function me(e){d.setImmediate?setImmediate(e):setTimeout(e,0)}function Q(e,t){if(typeof t=="string"&&A(e,t))return e[t];if(!t)return e;if(typeof t!="string"){for(var n=[],r=0,o=t.length;r<o;++r){var a=Q(e,t[r]);n.push(a)}return n}var h=t.indexOf(".");if(h!==-1){var m=e[t.substr(0,h)];return m==null?void 0:Q(m,t.substr(h+1))}}function F(e,t,n){if(e&&t!==void 0&&!("isFrozen"in Object&&Object.isFrozen(e)))if(typeof t!="string"&&"length"in t){de(typeof n!="string"&&"length"in n);for(var r=0,o=t.length;r<o;++r)F(e,t[r],n[r])}else{var a,h,m=t.indexOf(".");m!==-1?(a=t.substr(0,m),(h=t.substr(m+1))===""?n===void 0?p(e)&&!isNaN(parseInt(a))?e.splice(a,1):delete e[a]:e[a]=n:F(m=!(m=e[a])||!A(e,a)?e[a]={}:m,h,n)):n===void 0?p(e)&&!isNaN(parseInt(t))?e.splice(t,1):delete e[t]:e[t]=n}}function W(e){var t,n={};for(t in e)A(e,t)&&(n[t]=e[t]);return n}var le=[].concat;function X(e){return le.apply([],e)}var bt="BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(X([8,16,32,64].map(function(e){return["Int","Uint","Float"].map(function(t){return t+e+"Array"})}))).filter(function(e){return d[e]}),te=new Set(bt.map(function(e){return d[e]})),Ne=null;function ke(e){return Ne=new WeakMap,e=function t(n){if(!n||typeof n!="object")return n;var r=Ne.get(n);if(r)return r;if(p(n)){r=[],Ne.set(n,r);for(var o=0,a=n.length;o<a;++o)r.push(t(n[o]))}else if(te.has(n.constructor))r=n;else{var h,m=S(n);for(h in r=m===Object.prototype?{}:Object.create(m),Ne.set(n,r),n)A(n,h)&&(r[h]=t(n[h]))}return r}(e),Ne=null,e}var oe={}.toString;function Z(e){return oe.call(e).slice(8,-1)}var V=typeof Symbol<"u"?Symbol.iterator:"@@iterator",se=typeof V=="symbol"?function(e){var t;return e!=null&&(t=e[V])&&t.apply(e)}:function(){return null};function U(e,t){return t=e.indexOf(t),0<=t&&e.splice(t,1),0<=t}var ce={};function q(e){var t,n,r,o;if(arguments.length===1){if(p(e))return e.slice();if(this===ce&&typeof e=="string")return[e];if(o=se(e)){for(n=[];!(r=o.next()).done;)n.push(r.value);return n}if(e==null)return[e];if(typeof(t=e.length)!="number")return[e];for(n=new Array(t);t--;)n[t]=e[t];return n}for(t=arguments.length,n=new Array(t);t--;)n[t]=arguments[t];return n}var we=typeof Symbol<"u"?function(e){return e[Symbol.toStringTag]==="AsyncFunction"}:function(){return!1},Lt=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],Je=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(Lt),Se={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed",Abort:"Transaction aborted",TransactionInactive:"Transaction has already completed or failed",MissingAPI:"IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb"};function _e(e,t){this.name=e,this.message=t}function Te(e,t){return e+". Errors: "+Object.keys(t).map(function(n){return t[n].toString()}).filter(function(n,r,o){return o.indexOf(n)===r}).join(`
|
||
`)}function Ke(e,t,n,r){this.failures=t,this.failedKeys=r,this.successCount=n,this.message=Te(e,t)}function Ye(e,t){this.name="BulkError",this.failures=Object.keys(t).map(function(n){return t[n]}),this.failuresByPos=t,this.message=Te(e,this.failures)}ne(_e).from(Error).extend({toString:function(){return this.name+": "+this.message}}),ne(Ke).from(_e),ne(Ye).from(_e);var Qe=Je.reduce(function(e,t){return e[t]=t+"Error",e},{}),yt=_e,re=Je.reduce(function(e,t){var n=t+"Error";function r(o,a){this.name=n,o?typeof o=="string"?(this.message="".concat(o).concat(a?`
|
||
`+a:""),this.inner=a||null):typeof o=="object"&&(this.message="".concat(o.name," ").concat(o.message),this.inner=o):(this.message=Se[t]||n,this.inner=null)}return ne(r).from(yt),e[t]=r,e},{});re.Syntax=SyntaxError,re.Type=TypeError,re.Range=RangeError;var Ie=Lt.reduce(function(e,t){return e[t+"Error"]=re[t],e},{}),We=Je.reduce(function(e,t){return["Syntax","Type","Range"].indexOf(t)===-1&&(e[t+"Error"]=re[t]),e},{});function ve(){}function Ge(e){return e}function ti(e,t){return e==null||e===Ge?t:function(n){return t(e(n))}}function gt(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function ni(e,t){return e===ve?t:function(){var n=e.apply(this,arguments);n!==void 0&&(arguments[0]=n);var r=this.onsuccess,o=this.onerror;this.onsuccess=null,this.onerror=null;var a=t.apply(this,arguments);return r&&(this.onsuccess=this.onsuccess?gt(r,this.onsuccess):r),o&&(this.onerror=this.onerror?gt(o,this.onerror):o),a!==void 0?a:n}}function ri(e,t){return e===ve?t:function(){e.apply(this,arguments);var n=this.onsuccess,r=this.onerror;this.onsuccess=this.onerror=null,t.apply(this,arguments),n&&(this.onsuccess=this.onsuccess?gt(n,this.onsuccess):n),r&&(this.onerror=this.onerror?gt(r,this.onerror):r)}}function si(e,t){return e===ve?t:function(n){var r=e.apply(this,arguments);C(n,r);var o=this.onsuccess,a=this.onerror;return this.onsuccess=null,this.onerror=null,n=t.apply(this,arguments),o&&(this.onsuccess=this.onsuccess?gt(o,this.onsuccess):o),a&&(this.onerror=this.onerror?gt(a,this.onerror):a),r===void 0?n===void 0?void 0:n:C(r,n)}}function ii(e,t){return e===ve?t:function(){return t.apply(this,arguments)!==!1&&e.apply(this,arguments)}}function Vn(e,t){return e===ve?t:function(){var n=e.apply(this,arguments);if(n&&typeof n.then=="function"){for(var r=this,o=arguments.length,a=new Array(o);o--;)a[o]=arguments[o];return n.then(function(){return t.apply(r,a)})}return t.apply(this,arguments)}}We.ModifyError=Ke,We.DexieError=_e,We.BulkError=Ye;var Xe=typeof location<"u"&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function Fr(e){Xe=e}var Bt={},qr=100,bt=typeof Promise>"u"?[]:function(){var e=Promise.resolve();if(typeof crypto>"u"||!crypto.subtle)return[e,S(e),e];var t=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[t,S(t),e]}(),Lt=bt[0],Je=bt[1],bt=bt[2],Je=Je&&Je.then,vt=Lt&&Lt.constructor,Hn=!!bt,zt=function(e,t){Ut.push([e,t]),un&&(queueMicrotask(ai),un=!1)},Zn=!0,un=!0,xt=[],dn=[],Jn=Ge,ot={id:"globalThis",globalThis:!0,ref:0,unhandleds:[],onunhandled:ve,pgp:!1,env:{},finalize:ve},ae=ot,Ut=[],wt=0,hn=[];function J(e){if(typeof this!="object")throw new TypeError("Promises must be constructed via new");this._listeners=[],this._lib=!1;var t=this._PSD=ae;if(typeof e!="function"){if(e!==Bt)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(this._state===!1&&Gn(this,this._value))}this._state=null,this._value=null,++t.ref,function n(r,o){try{o(function(a){if(r._state===null){if(a===r)throw new TypeError("A promise cannot be resolved with itself.");var h=r._lib&&Tt();a&&typeof a.then=="function"?n(r,function(m,b){a instanceof J?a._then(m,b):a.then(m,b)}):(r._state=!0,r._value=a,Lr(r)),h&&At()}},Gn.bind(null,r))}catch(a){Gn(r,a)}}(this,e)}var Qn={get:function(){var e=ae,t=yn;function n(r,o){var a=this,h=!e.global&&(e!==ae||t!==yn),m=h&&!lt(),b=new J(function(x,N){Xn(a,new Br(Ur(r,e,h,m),Ur(o,e,h,m),x,N,e))});return this._consoleTask&&(b._consoleTask=this._consoleTask),b}return n.prototype=Bt,n},set:function(e){T(this,"then",e&&e.prototype===Bt?Qn:{get:function(){return e},set:Qn.set})}};function Br(e,t,n,r,o){this.onFulfilled=typeof e=="function"?e:null,this.onRejected=typeof t=="function"?t:null,this.resolve=n,this.reject=r,this.psd=o}function Gn(e,t){var n,r;dn.push(t),e._state===null&&(n=e._lib&&Tt(),t=Jn(t),e._state=!1,e._value=t,r=e,xt.some(function(o){return o._value===r._value})||xt.push(r),Lr(e),n&&At())}function Lr(e){var t=e._listeners;e._listeners=[];for(var n=0,r=t.length;n<r;++n)Xn(e,t[n]);var o=e._PSD;--o.ref||o.finalize(),wt===0&&(++wt,zt(function(){--wt==0&&er()},[]))}function Xn(e,t){if(e._state!==null){var n=e._state?t.onFulfilled:t.onRejected;if(n===null)return(e._state?t.resolve:t.reject)(e._value);++t.psd.ref,++wt,zt(oi,[n,e,t])}else e._listeners.push(t)}function oi(e,t,n){try{var r,o=t._value;!t._state&&dn.length&&(dn=[]),r=Xe&&t._consoleTask?t._consoleTask.run(function(){return e(o)}):e(o),t._state||dn.indexOf(o)!==-1||function(a){for(var h=xt.length;h;)if(xt[--h]._value===a._value)return xt.splice(h,1)}(t),n.resolve(r)}catch(a){n.reject(a)}finally{--wt==0&&er(),--n.psd.ref||n.psd.finalize()}}function ai(){jt(ot,function(){Tt()&&At()})}function Tt(){var e=Zn;return un=Zn=!1,e}function At(){var e,t,n;do for(;0<Ut.length;)for(e=Ut,Ut=[],n=e.length,t=0;t<n;++t){var r=e[t];r[0].apply(null,r[1])}while(0<Ut.length);un=Zn=!0}function er(){var e=xt;xt=[],e.forEach(function(r){r._PSD.onunhandled.call(null,r._value,r)});for(var t=hn.slice(0),n=t.length;n;)t[--n]()}function fn(e){return new J(Bt,!1,e)}function De(e,t){var n=ae;return function(){var r=Tt(),o=ae;try{return ct(n,!0),e.apply(this,arguments)}catch(a){t&&t(a)}finally{ct(o,!1),r&&At()}}}Y(J.prototype,{then:Qn,_then:function(e,t){Xn(this,new Br(null,null,e,t,ae))},catch:function(e){if(arguments.length===1)return this.then(null,e);var t=e,n=arguments[1];return typeof t=="function"?this.then(null,function(r){return(r instanceof t?n:fn)(r)}):this.then(null,function(r){return(r&&r.name===t?n:fn)(r)})},finally:function(e){return this.then(function(t){return J.resolve(e()).then(function(){return t})},function(t){return J.resolve(e()).then(function(){return fn(t)})})},timeout:function(e,t){var n=this;return e<1/0?new J(function(r,o){var a=setTimeout(function(){return o(new re.Timeout(t))},e);n.then(r,o).finally(clearTimeout.bind(null,a))}):this}}),typeof Symbol<"u"&&Symbol.toStringTag&&T(J.prototype,Symbol.toStringTag,"Dexie.Promise"),ot.env=zr(),Y(J,{all:function(){var e=q.apply(null,arguments).map(gn);return new J(function(t,n){e.length===0&&t([]);var r=e.length;e.forEach(function(o,a){return J.resolve(o).then(function(h){e[a]=h,--r||t(e)},n)})})},resolve:function(e){return e instanceof J?e:e&&typeof e.then=="function"?new J(function(t,n){e.then(t,n)}):new J(Bt,!0,e)},reject:fn,race:function(){var e=q.apply(null,arguments).map(gn);return new J(function(t,n){e.map(function(r){return J.resolve(r).then(t,n)})})},PSD:{get:function(){return ae},set:function(e){return ae=e}},totalEchoes:{get:function(){return yn}},newPSD:at,usePSD:jt,scheduler:{get:function(){return zt},set:function(e){zt=e}},rejectionMapper:{get:function(){return Jn},set:function(e){Jn=e}},follow:function(e,t){return new J(function(n,r){return at(function(o,a){var h=ae;h.unhandleds=[],h.onunhandled=a,h.finalize=gt(function(){var m,b=this;m=function(){b.unhandleds.length===0?o():a(b.unhandleds[0])},hn.push(function x(){m(),hn.splice(hn.indexOf(x),1)}),++wt,zt(function(){--wt==0&&er()},[])},h.finalize),e()},t,n,r)})}}),vt&&(vt.allSettled&&T(J,"allSettled",function(){var e=q.apply(null,arguments).map(gn);return new J(function(t){e.length===0&&t([]);var n=e.length,r=new Array(n);e.forEach(function(o,a){return J.resolve(o).then(function(h){return r[a]={status:"fulfilled",value:h}},function(h){return r[a]={status:"rejected",reason:h}}).then(function(){return--n||t(r)})})})}),vt.any&&typeof AggregateError<"u"&&T(J,"any",function(){var e=q.apply(null,arguments).map(gn);return new J(function(t,n){e.length===0&&n(new AggregateError([]));var r=e.length,o=new Array(r);e.forEach(function(a,h){return J.resolve(a).then(function(m){return t(m)},function(m){o[h]=m,--r||n(new AggregateError(o))})})})}),vt.withResolvers&&(J.withResolvers=vt.withResolvers));var Ae={awaits:0,echoes:0,id:0},li=0,mn=[],pn=0,yn=0,ci=0;function at(e,t,n,r){var o=ae,a=Object.create(o);return a.parent=o,a.ref=0,a.global=!1,a.id=++ci,ot.env,a.env=Hn?{Promise:J,PromiseProp:{value:J,configurable:!0,writable:!0},all:J.all,race:J.race,allSettled:J.allSettled,any:J.any,resolve:J.resolve,reject:J.reject}:{},t&&C(a,t),++o.ref,a.finalize=function(){--this.parent.ref||this.parent.finalize()},r=jt(a,e,n,r),a.ref===0&&a.finalize(),r}function Mt(){return Ae.id||(Ae.id=++li),++Ae.awaits,Ae.echoes+=qr,Ae.id}function lt(){return!!Ae.awaits&&(--Ae.awaits==0&&(Ae.id=0),Ae.echoes=Ae.awaits*qr,!0)}function gn(e){return Ae.echoes&&e&&e.constructor===vt?(Mt(),e.then(function(t){return lt(),t},function(t){return lt(),Pe(t)})):e}function ui(){var e=mn[mn.length-1];mn.pop(),ct(e,!1)}function ct(e,t){var n,r=ae;(t?!Ae.echoes||pn++&&e===ae:!pn||--pn&&e===ae)||queueMicrotask(t?(function(o){++yn,Ae.echoes&&--Ae.echoes!=0||(Ae.echoes=Ae.awaits=Ae.id=0),mn.push(ae),ct(o,!0)}).bind(null,e):ui),e!==ae&&(ae=e,r===ot&&(ot.env=zr()),Hn&&(n=ot.env.Promise,t=e.env,(r.global||e.global)&&(Object.defineProperty(d,"Promise",t.PromiseProp),n.all=t.all,n.race=t.race,n.resolve=t.resolve,n.reject=t.reject,t.allSettled&&(n.allSettled=t.allSettled),t.any&&(n.any=t.any))))}function zr(){var e=d.Promise;return Hn?{Promise:e,PromiseProp:Object.getOwnPropertyDescriptor(d,"Promise"),all:e.all,race:e.race,allSettled:e.allSettled,any:e.any,resolve:e.resolve,reject:e.reject}:{}}function jt(e,t,n,r,o){var a=ae;try{return ct(e,!0),t(n,r,o)}finally{ct(a,!1)}}function Ur(e,t,n,r){return typeof e!="function"?e:function(){var o=ae;n&&Mt(),ct(t,!0);try{return e.apply(this,arguments)}finally{ct(o,!1),r&&queueMicrotask(lt)}}}function tr(e){Promise===vt&&Ae.echoes===0?pn===0?e():enqueueNativeMicroTask(e):setTimeout(e,0)}(""+Je).indexOf("[native code]")===-1&&(Mt=lt=ve);var Pe=J.reject,Nt=String.fromCharCode(65535),nt="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",Yr="String expected.",Kt=[],bn="__dbnames",nr="readonly",rr="readwrite";function kt(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var Wr={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function vn(e){return typeof e!="string"||/\./.test(e)?function(t){return t}:function(t){return t[e]===void 0&&e in t&&delete(t=ke(t))[e],t}}function Vr(){throw re.Type()}function be(e,t){try{var n=Hr(e),r=Hr(t);if(n!==r)return n==="Array"?1:r==="Array"?-1:n==="binary"?1:r==="binary"?-1:n==="string"?1:r==="string"?-1:n==="Date"?1:r!=="Date"?NaN:-1;switch(n){case"number":case"Date":case"string":return t<e?1:e<t?-1:0;case"binary":return function(o,a){for(var h=o.length,m=a.length,b=h<m?h:m,x=0;x<b;++x)if(o[x]!==a[x])return o[x]<a[x]?-1:1;return h===m?0:h<m?-1:1}(Zr(e),Zr(t));case"Array":return function(o,a){for(var h=o.length,m=a.length,b=h<m?h:m,x=0;x<b;++x){var N=be(o[x],a[x]);if(N!==0)return N}return h===m?0:h<m?-1:1}(e,t)}}catch{}return NaN}function Hr(e){var t=typeof e;return t!="object"?t:ArrayBuffer.isView(e)?"binary":(e=Z(e),e==="ArrayBuffer"?"binary":e)}function Zr(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}var Jr=(Ee.prototype._trans=function(e,t,n){var r=this._tx||ae.trans,o=this.name,a=Xe&&typeof console<"u"&&console.createTask&&console.createTask("Dexie: ".concat(e==="readonly"?"read":"write"," ").concat(this.name));function h(x,N,g){if(!g.schema[o])throw new re.NotFound("Table "+o+" not part of transaction");return t(g.idbtrans,g)}var m=Tt();try{var b=r&&r.db._novip===this.db._novip?r===ae.trans?r._promise(e,h,n):at(function(){return r._promise(e,h,n)},{trans:r,transless:ae.transless||ae}):function x(N,g,_,v){if(N.idbdb&&(N._state.openComplete||ae.letThrough||N._vip)){var j=N._createTransaction(g,_,N._dbSchema);try{j.create(),N._state.PR1398_maxLoop=3}catch(k){return k.name===Qe.InvalidState&&N.isOpen()&&0<--N._state.PR1398_maxLoop?(console.warn("Dexie: Need to reopen db"),N.close({disableAutoOpen:!1}),N.open().then(function(){return x(N,g,_,v)})):Pe(k)}return j._promise(g,function(k,w){return at(function(){return ae.trans=j,v(k,w,j)})}).then(function(k){if(g==="readwrite")try{j.idbtrans.commit()}catch{}return g==="readonly"?k:j._completion.then(function(){return k})})}if(N._state.openComplete)return Pe(new re.DatabaseClosed(N._state.dbOpenError));if(!N._state.isBeingOpened){if(!N._state.autoOpen)return Pe(new re.DatabaseClosed);N.open().catch(ve)}return N._state.dbReadyPromise.then(function(){return x(N,g,_,v)})}(this.db,e,[this.name],h);return a&&(b._consoleTask=a,b=b.catch(function(x){return console.trace(x),Pe(x)})),b}finally{m&&At()}},Ee.prototype.get=function(e,t){var n=this;return e&&e.constructor===Object?this.where(e).first(t):e==null?Pe(new re.Type("Invalid argument to Table.get()")):this._trans("readonly",function(r){return n.core.get({trans:r,key:e}).then(function(o){return n.hook.reading.fire(o)})}).then(t)},Ee.prototype.where=function(e){if(typeof e=="string")return new this.db.WhereClause(this,e);if(p(e))return new this.db.WhereClause(this,"[".concat(e.join("+"),"]"));var t=y(e);if(t.length===1)return this.where(t[0]).equals(e[t[0]]);var n=this.schema.indexes.concat(this.schema.primKey).filter(function(m){if(m.compound&&t.every(function(x){return 0<=m.keyPath.indexOf(x)})){for(var b=0;b<t.length;++b)if(t.indexOf(m.keyPath[b])===-1)return!1;return!0}return!1}).sort(function(m,b){return m.keyPath.length-b.keyPath.length})[0];if(n&&this.db._maxKey!==Nt){var a=n.keyPath.slice(0,t.length);return this.where(a).equals(a.map(function(b){return e[b]}))}!n&&Xe&&console.warn("The query ".concat(JSON.stringify(e)," on ").concat(this.name," would benefit from a ")+"compound index [".concat(t.join("+"),"]"));var r=this.schema.idxByName;function o(m,b){return be(m,b)===0}var h=t.reduce(function(g,b){var x=g[0],N=g[1],g=r[b],_=e[b];return[x||g,x||!g?kt(N,g&&g.multi?function(v){return v=Q(v,b),p(v)&&v.some(function(j){return o(_,j)})}:function(v){return o(_,Q(v,b))}):N]},[null,null]),a=h[0],h=h[1];return a?this.where(a.name).equals(e[a.keyPath]).filter(h):n?this.filter(h):this.where(t).equals("")},Ee.prototype.filter=function(e){return this.toCollection().and(e)},Ee.prototype.count=function(e){return this.toCollection().count(e)},Ee.prototype.offset=function(e){return this.toCollection().offset(e)},Ee.prototype.limit=function(e){return this.toCollection().limit(e)},Ee.prototype.each=function(e){return this.toCollection().each(e)},Ee.prototype.toArray=function(e){return this.toCollection().toArray(e)},Ee.prototype.toCollection=function(){return new this.db.Collection(new this.db.WhereClause(this))},Ee.prototype.orderBy=function(e){return new this.db.Collection(new this.db.WhereClause(this,p(e)?"[".concat(e.join("+"),"]"):e))},Ee.prototype.reverse=function(){return this.toCollection().reverse()},Ee.prototype.mapToClass=function(e){var t,n=this.db,r=this.name;function o(){return t!==null&&t.apply(this,arguments)||this}(this.schema.mappedClass=e).prototype instanceof Vr&&(function(b,x){if(typeof x!="function"&&x!==null)throw new TypeError("Class extends value "+String(x)+" is not a constructor or null");function N(){this.constructor=b}u(b,x),b.prototype=x===null?Object.create(x):(N.prototype=x.prototype,new N)}(o,t=e),Object.defineProperty(o.prototype,"db",{get:function(){return n},enumerable:!1,configurable:!0}),o.prototype.table=function(){return r},e=o);for(var a=new Set,h=e.prototype;h;h=S(h))Object.getOwnPropertyNames(h).forEach(function(b){return a.add(b)});function m(b){if(!b)return b;var x,N=Object.create(e.prototype);for(x in b)if(!a.has(x))try{N[x]=b[x]}catch{}return N}return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=m,this.hook("reading",m),e},Ee.prototype.defineClass=function(){return this.mapToClass(function(e){C(this,e)})},Ee.prototype.add=function(e,t){var n=this,r=this.schema.primKey,o=r.auto,a=r.keyPath,h=e;return a&&o&&(h=vn(a)(e)),this._trans("readwrite",function(m){return n.core.mutate({trans:m,type:"add",keys:t!=null?[t]:null,values:[h]})}).then(function(m){return m.numFailures?J.reject(m.failures[0]):m.lastResult}).then(function(m){if(a)try{F(e,a,m)}catch{}return m})},Ee.prototype.update=function(e,t){return typeof e!="object"||p(e)?this.where(":id").equals(e).modify(t):(e=Q(e,this.schema.primKey.keyPath),e===void 0?Pe(new re.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(e).modify(t))},Ee.prototype.put=function(e,t){var n=this,r=this.schema.primKey,o=r.auto,a=r.keyPath,h=e;return a&&o&&(h=vn(a)(e)),this._trans("readwrite",function(m){return n.core.mutate({trans:m,type:"put",values:[h],keys:t!=null?[t]:null})}).then(function(m){return m.numFailures?J.reject(m.failures[0]):m.lastResult}).then(function(m){if(a)try{F(e,a,m)}catch{}return m})},Ee.prototype.delete=function(e){var t=this;return this._trans("readwrite",function(n){return t.core.mutate({trans:n,type:"delete",keys:[e]})}).then(function(n){return n.numFailures?J.reject(n.failures[0]):void 0})},Ee.prototype.clear=function(){var e=this;return this._trans("readwrite",function(t){return e.core.mutate({trans:t,type:"deleteRange",range:Wr})}).then(function(t){return t.numFailures?J.reject(t.failures[0]):void 0})},Ee.prototype.bulkGet=function(e){var t=this;return this._trans("readonly",function(n){return t.core.getMany({keys:e,trans:n}).then(function(r){return r.map(function(o){return t.hook.reading.fire(o)})})})},Ee.prototype.bulkAdd=function(e,t,n){var r=this,o=Array.isArray(t)?t:void 0,a=(n=n||(o?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",function(h){var x=r.schema.primKey,m=x.auto,x=x.keyPath;if(x&&o)throw new re.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(o&&o.length!==e.length)throw new re.InvalidArgument("Arguments objects and keys must have the same length");var b=e.length,x=x&&m?e.map(vn(x)):e;return r.core.mutate({trans:h,type:"add",keys:o,values:x,wantResults:a}).then(function(j){var g=j.numFailures,_=j.results,v=j.lastResult,j=j.failures;if(g===0)return a?_:v;throw new Ye("".concat(r.name,".bulkAdd(): ").concat(g," of ").concat(b," operations failed"),j)})})},Ee.prototype.bulkPut=function(e,t,n){var r=this,o=Array.isArray(t)?t:void 0,a=(n=n||(o?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",function(h){var x=r.schema.primKey,m=x.auto,x=x.keyPath;if(x&&o)throw new re.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(o&&o.length!==e.length)throw new re.InvalidArgument("Arguments objects and keys must have the same length");var b=e.length,x=x&&m?e.map(vn(x)):e;return r.core.mutate({trans:h,type:"put",keys:o,values:x,wantResults:a}).then(function(j){var g=j.numFailures,_=j.results,v=j.lastResult,j=j.failures;if(g===0)return a?_:v;throw new Ye("".concat(r.name,".bulkPut(): ").concat(g," of ").concat(b," operations failed"),j)})})},Ee.prototype.bulkUpdate=function(e){var t=this,n=this.core,r=e.map(function(h){return h.key}),o=e.map(function(h){return h.changes}),a=[];return this._trans("readwrite",function(h){return n.getMany({trans:h,keys:r,cache:"clone"}).then(function(m){var b=[],x=[];e.forEach(function(g,_){var v=g.key,j=g.changes,k=m[_];if(k){for(var w=0,E=Object.keys(j);w<E.length;w++){var D=E[w],P=j[D];if(D===t.schema.primKey.keyPath){if(be(P,v)!==0)throw new re.Constraint("Cannot update primary key in bulkUpdate()")}else F(k,D,P)}a.push(_),b.push(v),x.push(k)}});var N=b.length;return n.mutate({trans:h,type:"put",keys:b,values:x,updates:{keys:r,changeSpecs:o}}).then(function(g){var _=g.numFailures,v=g.failures;if(_===0)return N;for(var j=0,k=Object.keys(v);j<k.length;j++){var w,E=k[j],D=a[Number(E)];D!=null&&(w=v[E],delete v[E],v[D]=w)}throw new Ye("".concat(t.name,".bulkUpdate(): ").concat(_," of ").concat(N," operations failed"),v)})})})},Ee.prototype.bulkDelete=function(e){var t=this,n=e.length;return this._trans("readwrite",function(r){return t.core.mutate({trans:r,type:"delete",keys:e})}).then(function(h){var o=h.numFailures,a=h.lastResult,h=h.failures;if(o===0)return a;throw new Ye("".concat(t.name,".bulkDelete(): ").concat(o," of ").concat(n," operations failed"),h)})},Ee);function Ee(){}function Yt(e){function t(h,m){if(m){for(var b=arguments.length,x=new Array(b-1);--b;)x[b-1]=arguments[b];return n[h].subscribe.apply(null,x),e}if(typeof h=="string")return n[h]}var n={};t.addEventType=a;for(var r=1,o=arguments.length;r<o;++r)a(arguments[r]);return t;function a(h,m,b){if(typeof h!="object"){var x;m=m||ii;var N={subscribers:[],fire:b=b||ve,subscribe:function(g){N.subscribers.indexOf(g)===-1&&(N.subscribers.push(g),N.fire=m(N.fire,g))},unsubscribe:function(g){N.subscribers=N.subscribers.filter(function(_){return _!==g}),N.fire=N.subscribers.reduce(m,b)}};return n[h]=t[h]=N}y(x=h).forEach(function(g){var _=x[g];if(p(_))a(g,x[g][0],x[g][1]);else{if(_!=="asap")throw new re.InvalidArgument("Invalid event config");var v=a(g,Ge,function(){for(var j=arguments.length,k=new Array(j);j--;)k[j]=arguments[j];v.subscribers.forEach(function(w){me(function(){w.apply(null,k)})})})}})}}function Wt(e,t){return ne(t).from({prototype:e}),t}function It(e,t){return!(e.filter||e.algorithm||e.or)&&(t?e.justLimit:!e.replayFilter)}function sr(e,t){e.filter=kt(e.filter,t)}function ir(e,t,n){var r=e.replayFilter;e.replayFilter=r?function(){return kt(r(),t())}:t,e.justLimit=n&&!r}function xn(e,t){if(e.isPrimKey)return t.primaryKey;var n=t.getIndexByKeyPath(e.index);if(!n)throw new re.Schema("KeyPath "+e.index+" on object store "+t.name+" is not indexed");return n}function Qr(e,t,n){var r=xn(e,t.schema);return t.openCursor({trans:n,values:!e.keysOnly,reverse:e.dir==="prev",unique:!!e.unique,query:{index:r,range:e.range}})}function wn(e,t,n,r){var o=e.replayFilter?kt(e.filter,e.replayFilter()):e.filter;if(e.or){var a={},h=function(m,b,x){var N,g;o&&!o(b,x,function(_){return b.stop(_)},function(_){return b.fail(_)})||((g=""+(N=b.primaryKey))=="[object ArrayBuffer]"&&(g=""+new Uint8Array(N)),A(a,g)||(a[g]=!0,t(m,b,x)))};return Promise.all([e.or._iterate(h,n),Gr(Qr(e,r,n),e.algorithm,h,!e.keysOnly&&e.valueMapper)])}return Gr(Qr(e,r,n),kt(e.algorithm,o),t,!e.keysOnly&&e.valueMapper)}function Gr(e,t,n,r){var o=De(r?function(a,h,m){return n(r(a),h,m)}:n);return e.then(function(a){if(a)return a.start(function(){var h=function(){return a.continue()};t&&!t(a,function(m){return h=m},function(m){a.stop(m),h=ve},function(m){a.fail(m),h=ve})||o(a.value,a,function(m){return h=m}),h()})})}var Vt=(Xr.prototype.execute=function(e){var t=this["@@propmod"];if(t.add!==void 0){var n=t.add;if(p(n))return f(f([],p(e)?e:[],!0),n,!0).sort();if(typeof n=="number")return(Number(e)||0)+n;if(typeof n=="bigint")try{return BigInt(e)+n}catch{return BigInt(0)+n}throw new TypeError("Invalid term ".concat(n))}if(t.remove!==void 0){var r=t.remove;if(p(r))return p(e)?e.filter(function(o){return!r.includes(o)}).sort():[];if(typeof r=="number")return Number(e)-r;if(typeof r=="bigint")try{return BigInt(e)-r}catch{return BigInt(0)-r}throw new TypeError("Invalid subtrahend ".concat(r))}return n=(n=t.replacePrefix)===null||n===void 0?void 0:n[0],n&&typeof e=="string"&&e.startsWith(n)?t.replacePrefix[1]+e.substring(n.length):e},Xr);function Xr(e){this["@@propmod"]=e}var di=(je.prototype._read=function(e,t){var n=this._ctx;return n.error?n.table._trans(null,Pe.bind(null,n.error)):n.table._trans("readonly",e).then(t)},je.prototype._write=function(e){var t=this._ctx;return t.error?t.table._trans(null,Pe.bind(null,t.error)):t.table._trans("readwrite",e,"locked")},je.prototype._addAlgorithm=function(e){var t=this._ctx;t.algorithm=kt(t.algorithm,e)},je.prototype._iterate=function(e,t){return wn(this._ctx,e,t,this._ctx.table.core)},je.prototype.clone=function(e){var t=Object.create(this.constructor.prototype),n=Object.create(this._ctx);return e&&C(n,e),t._ctx=n,t},je.prototype.raw=function(){return this._ctx.valueMapper=null,this},je.prototype.each=function(e){var t=this._ctx;return this._read(function(n){return wn(t,e,n,t.table.core)})},je.prototype.count=function(e){var t=this;return this._read(function(n){var r=t._ctx,o=r.table.core;if(It(r,!0))return o.count({trans:n,query:{index:xn(r,o.schema),range:r.range}}).then(function(h){return Math.min(h,r.limit)});var a=0;return wn(r,function(){return++a,!1},n,o).then(function(){return a})}).then(e)},je.prototype.sortBy=function(e,t){var n=e.split(".").reverse(),r=n[0],o=n.length-1;function a(b,x){return x?a(b[n[x]],x-1):b[r]}var h=this._ctx.dir==="next"?1:-1;function m(b,x){return be(a(b,o),a(x,o))*h}return this.toArray(function(b){return b.sort(m)}).then(t)},je.prototype.toArray=function(e){var t=this;return this._read(function(n){var r=t._ctx;if(r.dir==="next"&&It(r,!0)&&0<r.limit){var o=r.valueMapper,a=xn(r,r.table.core.schema);return r.table.core.query({trans:n,limit:r.limit,values:!0,query:{index:a,range:r.range}}).then(function(m){return m=m.result,o?m.map(o):m})}var h=[];return wn(r,function(m){return h.push(m)},n,r.table.core).then(function(){return h})},e)},je.prototype.offset=function(e){var t=this._ctx;return e<=0||(t.offset+=e,It(t)?ir(t,function(){var n=e;return function(r,o){return n===0||(n===1?--n:o(function(){r.advance(n),n=0}),!1)}}):ir(t,function(){var n=e;return function(){return--n<0}})),this},je.prototype.limit=function(e){return this._ctx.limit=Math.min(this._ctx.limit,e),ir(this._ctx,function(){var t=e;return function(n,r,o){return--t<=0&&r(o),0<=t}},!0),this},je.prototype.until=function(e,t){return sr(this._ctx,function(n,r,o){return!e(n.value)||(r(o),t)}),this},je.prototype.first=function(e){return this.limit(1).toArray(function(t){return t[0]}).then(e)},je.prototype.last=function(e){return this.reverse().first(e)},je.prototype.filter=function(e){var t;return sr(this._ctx,function(n){return e(n.value)}),(t=this._ctx).isMatch=kt(t.isMatch,e),this},je.prototype.and=function(e){return this.filter(e)},je.prototype.or=function(e){return new this.db.WhereClause(this._ctx.table,e,this)},je.prototype.reverse=function(){return this._ctx.dir=this._ctx.dir==="prev"?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},je.prototype.desc=function(){return this.reverse()},je.prototype.eachKey=function(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each(function(n,r){e(r.key,r)})},je.prototype.eachUniqueKey=function(e){return this._ctx.unique="unique",this.eachKey(e)},je.prototype.eachPrimaryKey=function(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each(function(n,r){e(r.primaryKey,r)})},je.prototype.keys=function(e){var t=this._ctx;t.keysOnly=!t.isMatch;var n=[];return this.each(function(r,o){n.push(o.key)}).then(function(){return n}).then(e)},je.prototype.primaryKeys=function(e){var t=this._ctx;if(t.dir==="next"&&It(t,!0)&&0<t.limit)return this._read(function(r){var o=xn(t,t.table.core.schema);return t.table.core.query({trans:r,values:!1,limit:t.limit,query:{index:o,range:t.range}})}).then(function(r){return r.result}).then(e);t.keysOnly=!t.isMatch;var n=[];return this.each(function(r,o){n.push(o.primaryKey)}).then(function(){return n}).then(e)},je.prototype.uniqueKeys=function(e){return this._ctx.unique="unique",this.keys(e)},je.prototype.firstKey=function(e){return this.limit(1).keys(function(t){return t[0]}).then(e)},je.prototype.lastKey=function(e){return this.reverse().firstKey(e)},je.prototype.distinct=function(){var e=this._ctx,e=e.index&&e.table.schema.idxByName[e.index];if(!e||!e.multi)return this;var t={};return sr(this._ctx,function(o){var r=o.primaryKey.toString(),o=A(t,r);return t[r]=!0,!o}),this},je.prototype.modify=function(e){var t=this,n=this._ctx;return this._write(function(r){var o,a,h;h=typeof e=="function"?e:(o=y(e),a=o.length,function(w){for(var E=!1,D=0;D<a;++D){var P=o[D],O=e[P],K=Q(w,P);O instanceof Vt?(F(w,P,O.execute(K)),E=!0):K!==O&&(F(w,P,O),E=!0)}return E});var m=n.table.core,g=m.schema.primaryKey,b=g.outbound,x=g.extractKey,N=200,g=t.db._options.modifyChunkSize;g&&(N=typeof g=="object"?g[m.name]||g["*"]||200:g);function _(w,P){var D=P.failures,P=P.numFailures;j+=w-P;for(var O=0,K=y(D);O<K.length;O++){var z=K[O];v.push(D[z])}}var v=[],j=0,k=[];return t.clone().primaryKeys().then(function(w){function E(P){var O=Math.min(N,w.length-P);return m.getMany({trans:r,keys:w.slice(P,P+O),cache:"immutable"}).then(function(K){for(var z=[],I=[],B=b?[]:null,H=[],L=0;L<O;++L){var ee=K[L],fe={value:ke(ee),primKey:w[P+L]};h.call(fe,fe.value,fe)!==!1&&(fe.value==null?H.push(w[P+L]):b||be(x(ee),x(fe.value))===0?(I.push(fe.value),b&&B.push(w[P+L])):(H.push(w[P+L]),z.push(fe.value)))}return Promise.resolve(0<z.length&&m.mutate({trans:r,type:"add",values:z}).then(function(ye){for(var ge in ye.failures)H.splice(parseInt(ge),1);_(z.length,ye)})).then(function(){return(0<I.length||D&&typeof e=="object")&&m.mutate({trans:r,type:"put",keys:B,values:I,criteria:D,changeSpec:typeof e!="function"&&e,isAdditionalChunk:0<P}).then(function(ye){return _(I.length,ye)})}).then(function(){return(0<H.length||D&&e===or)&&m.mutate({trans:r,type:"delete",keys:H,criteria:D,isAdditionalChunk:0<P}).then(function(ye){return _(H.length,ye)})}).then(function(){return w.length>P+O&&E(P+N)})})}var D=It(n)&&n.limit===1/0&&(typeof e!="function"||e===or)&&{index:n.index,range:n.range};return E(0).then(function(){if(0<v.length)throw new Ke("Error modifying one or more objects",v,j,k);return w.length})})})},je.prototype.delete=function(){var e=this._ctx,t=e.range;return It(e)&&(e.isPrimKey||t.type===3)?this._write(function(n){var r=e.table.core.schema.primaryKey,o=t;return e.table.core.count({trans:n,query:{index:r,range:o}}).then(function(a){return e.table.core.mutate({trans:n,type:"deleteRange",range:o}).then(function(h){var m=h.failures;if(h.lastResult,h.results,h=h.numFailures,h)throw new Ke("Could not delete some values",Object.keys(m).map(function(b){return m[b]}),a-h);return a-h})})}):this.modify(or)},je);function je(){}var or=function(e,t){return t.value=null};function hi(e,t){return e<t?-1:e===t?0:1}function fi(e,t){return t<e?-1:e===t?0:1}function Ve(e,t,n){return e=e instanceof ts?new e.Collection(e):e,e._ctx.error=new(n||TypeError)(t),e}function Rt(e){return new e.Collection(e,function(){return es("")}).limit(0)}function jn(e,t,n,r){var o,a,h,m,b,x,N,g=n.length;if(!n.every(function(j){return typeof j=="string"}))return Ve(e,Yr);function _(j){o=j==="next"?function(w){return w.toUpperCase()}:function(w){return w.toLowerCase()},a=j==="next"?function(w){return w.toLowerCase()}:function(w){return w.toUpperCase()},h=j==="next"?hi:fi;var k=n.map(function(w){return{lower:a(w),upper:o(w)}}).sort(function(w,E){return h(w.lower,E.lower)});m=k.map(function(w){return w.upper}),b=k.map(function(w){return w.lower}),N=(x=j)==="next"?"":r}_("next"),e=new e.Collection(e,function(){return ut(m[0],b[g-1]+r)}),e._ondirectionchange=function(j){_(j)};var v=0;return e._addAlgorithm(function(j,k,w){var E=j.key;if(typeof E!="string")return!1;var D=a(E);if(t(D,b,v))return!0;for(var P=null,O=v;O<g;++O){var K=function(z,I,B,H,L,ee){for(var fe=Math.min(z.length,H.length),ye=-1,ge=0;ge<fe;++ge){var He=I[ge];if(He!==H[ge])return L(z[ge],B[ge])<0?z.substr(0,ge)+B[ge]+B.substr(ge+1):L(z[ge],H[ge])<0?z.substr(0,ge)+H[ge]+B.substr(ge+1):0<=ye?z.substr(0,ye)+I[ye]+B.substr(ye+1):null;L(z[ge],He)<0&&(ye=ge)}return fe<H.length&&ee==="next"?z+B.substr(z.length):fe<z.length&&ee==="prev"?z.substr(0,B.length):ye<0?null:z.substr(0,ye)+H[ye]+B.substr(ye+1)}(E,D,m[O],b[O],h,x);K===null&&P===null?v=O+1:(P===null||0<h(P,K))&&(P=K)}return k(P!==null?function(){j.continue(P+N)}:w),!1}),e}function ut(e,t,n,r){return{type:2,lower:e,upper:t,lowerOpen:n,upperOpen:r}}function es(e){return{type:1,lower:e,upper:e}}var ts=(Object.defineProperty(Me.prototype,"Collection",{get:function(){return this._ctx.table.db.Collection},enumerable:!1,configurable:!0}),Me.prototype.between=function(e,t,n,r){n=n!==!1,r=r===!0;try{return 0<this._cmp(e,t)||this._cmp(e,t)===0&&(n||r)&&(!n||!r)?Rt(this):new this.Collection(this,function(){return ut(e,t,!n,!r)})}catch{return Ve(this,nt)}},Me.prototype.equals=function(e){return e==null?Ve(this,nt):new this.Collection(this,function(){return es(e)})},Me.prototype.above=function(e){return e==null?Ve(this,nt):new this.Collection(this,function(){return ut(e,void 0,!0)})},Me.prototype.aboveOrEqual=function(e){return e==null?Ve(this,nt):new this.Collection(this,function(){return ut(e,void 0,!1)})},Me.prototype.below=function(e){return e==null?Ve(this,nt):new this.Collection(this,function(){return ut(void 0,e,!1,!0)})},Me.prototype.belowOrEqual=function(e){return e==null?Ve(this,nt):new this.Collection(this,function(){return ut(void 0,e)})},Me.prototype.startsWith=function(e){return typeof e!="string"?Ve(this,Yr):this.between(e,e+Nt,!0,!0)},Me.prototype.startsWithIgnoreCase=function(e){return e===""?this.startsWith(e):jn(this,function(t,n){return t.indexOf(n[0])===0},[e],Nt)},Me.prototype.equalsIgnoreCase=function(e){return jn(this,function(t,n){return t===n[0]},[e],"")},Me.prototype.anyOfIgnoreCase=function(){var e=q.apply(ce,arguments);return e.length===0?Rt(this):jn(this,function(t,n){return n.indexOf(t)!==-1},e,"")},Me.prototype.startsWithAnyOfIgnoreCase=function(){var e=q.apply(ce,arguments);return e.length===0?Rt(this):jn(this,function(t,n){return n.some(function(r){return t.indexOf(r)===0})},e,Nt)},Me.prototype.anyOf=function(){var e=this,t=q.apply(ce,arguments),n=this._cmp;try{t.sort(n)}catch{return Ve(this,nt)}if(t.length===0)return Rt(this);var r=new this.Collection(this,function(){return ut(t[0],t[t.length-1])});r._ondirectionchange=function(a){n=a==="next"?e._ascending:e._descending,t.sort(n)};var o=0;return r._addAlgorithm(function(a,h,m){for(var b=a.key;0<n(b,t[o]);)if(++o===t.length)return h(m),!1;return n(b,t[o])===0||(h(function(){a.continue(t[o])}),!1)}),r},Me.prototype.notEqual=function(e){return this.inAnyRange([[-1/0,e],[e,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})},Me.prototype.noneOf=function(){var e=q.apply(ce,arguments);if(e.length===0)return new this.Collection(this);try{e.sort(this._ascending)}catch{return Ve(this,nt)}var t=e.reduce(function(n,r){return n?n.concat([[n[n.length-1][1],r]]):[[-1/0,r]]},null);return t.push([e[e.length-1],this.db._maxKey]),this.inAnyRange(t,{includeLowers:!1,includeUppers:!1})},Me.prototype.inAnyRange=function(E,t){var n=this,r=this._cmp,o=this._ascending,a=this._descending,h=this._min,m=this._max;if(E.length===0)return Rt(this);if(!E.every(function(D){return D[0]!==void 0&&D[1]!==void 0&&o(D[0],D[1])<=0}))return Ve(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",re.InvalidArgument);var b=!t||t.includeLowers!==!1,x=t&&t.includeUppers===!0,N,g=o;function _(D,P){return g(D[0],P[0])}try{(N=E.reduce(function(D,P){for(var O=0,K=D.length;O<K;++O){var z=D[O];if(r(P[0],z[1])<0&&0<r(P[1],z[0])){z[0]=h(z[0],P[0]),z[1]=m(z[1],P[1]);break}}return O===K&&D.push(P),D},[])).sort(_)}catch{return Ve(this,nt)}var v=0,j=x?function(D){return 0<o(D,N[v][1])}:function(D){return 0<=o(D,N[v][1])},k=b?function(D){return 0<a(D,N[v][0])}:function(D){return 0<=a(D,N[v][0])},w=j,E=new this.Collection(this,function(){return ut(N[0][0],N[N.length-1][1],!b,!x)});return E._ondirectionchange=function(D){g=D==="next"?(w=j,o):(w=k,a),N.sort(_)},E._addAlgorithm(function(D,P,O){for(var K,z=D.key;w(z);)if(++v===N.length)return P(O),!1;return!j(K=z)&&!k(K)||(n._cmp(z,N[v][1])===0||n._cmp(z,N[v][0])===0||P(function(){g===o?D.continue(N[v][0]):D.continue(N[v][1])}),!1)}),E},Me.prototype.startsWithAnyOf=function(){var e=q.apply(ce,arguments);return e.every(function(t){return typeof t=="string"})?e.length===0?Rt(this):this.inAnyRange(e.map(function(t){return[t,t+Nt]})):Ve(this,"startsWithAnyOf() only works with strings")},Me);function Me(){}function et(e){return De(function(t){return Ht(t),e(t.target.error),!1})}function Ht(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()}var Zt="storagemutated",ar="x-storagemutated-1",dt=Yt(null,Zt),mi=(tt.prototype._lock=function(){return de(!ae.global),++this._reculock,this._reculock!==1||ae.global||(ae.lockOwnerFor=this),this},tt.prototype._unlock=function(){if(de(!ae.global),--this._reculock==0)for(ae.global||(ae.lockOwnerFor=null);0<this._blockedFuncs.length&&!this._locked();){var e=this._blockedFuncs.shift();try{jt(e[1],e[0])}catch{}}return this},tt.prototype._locked=function(){return this._reculock&&ae.lockOwnerFor!==this},tt.prototype.create=function(e){var t=this;if(!this.mode)return this;var n=this.db.idbdb,r=this.db._state.dbOpenError;if(de(!this.idbtrans),!e&&!n)switch(r&&r.name){case"DatabaseClosedError":throw new re.DatabaseClosed(r);case"MissingAPIError":throw new re.MissingAPI(r.message,r);default:throw new re.OpenFailed(r)}if(!this.active)throw new re.TransactionInactive;return de(this._completion._state===null),(e=this.idbtrans=e||(this.db.core||n).transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability})).onerror=De(function(o){Ht(o),t._reject(e.error)}),e.onabort=De(function(o){Ht(o),t.active&&t._reject(new re.Abort(e.error)),t.active=!1,t.on("abort").fire(o)}),e.oncomplete=De(function(){t.active=!1,t._resolve(),"mutatedParts"in e&&dt.storagemutated.fire(e.mutatedParts)}),this},tt.prototype._promise=function(e,t,n){var r=this;if(e==="readwrite"&&this.mode!=="readwrite")return Pe(new re.ReadOnly("Transaction is readonly"));if(!this.active)return Pe(new re.TransactionInactive);if(this._locked())return new J(function(a,h){r._blockedFuncs.push([function(){r._promise(e,t,n).then(a,h)},ae])});if(n)return at(function(){var a=new J(function(h,m){r._lock();var b=t(h,m,r);b&&b.then&&b.then(h,m)});return a.finally(function(){return r._unlock()}),a._lib=!0,a});var o=new J(function(a,h){var m=t(a,h,r);m&&m.then&&m.then(a,h)});return o._lib=!0,o},tt.prototype._root=function(){return this.parent?this.parent._root():this},tt.prototype.waitFor=function(e){var t,n=this._root(),r=J.resolve(e);n._waitingFor?n._waitingFor=n._waitingFor.then(function(){return r}):(n._waitingFor=r,n._waitingQueue=[],t=n.idbtrans.objectStore(n.storeNames[0]),function a(){for(++n._spinCount;n._waitingQueue.length;)n._waitingQueue.shift()();n._waitingFor&&(t.get(-1/0).onsuccess=a)}());var o=n._waitingFor;return new J(function(a,h){r.then(function(m){return n._waitingQueue.push(De(a.bind(null,m)))},function(m){return n._waitingQueue.push(De(h.bind(null,m)))}).finally(function(){n._waitingFor===o&&(n._waitingFor=null)})})},tt.prototype.abort=function(){this.active&&(this.active=!1,this.idbtrans&&this.idbtrans.abort(),this._reject(new re.Abort))},tt.prototype.table=function(e){var t=this._memoizedTables||(this._memoizedTables={});if(A(t,e))return t[e];var n=this.schema[e];if(!n)throw new re.NotFound("Table "+e+" not part of transaction");return n=new this.db.Table(e,n,this),n.core=this.db.core.table(e),t[e]=n},tt);function tt(){}function lr(e,t,n,r,o,a,h){return{name:e,keyPath:t,unique:n,multi:r,auto:o,compound:a,src:(n&&!h?"&":"")+(r?"*":"")+(o?"++":"")+ns(t)}}function ns(e){return typeof e=="string"?e:e?"["+[].join.call(e,"+")+"]":""}function cr(e,t,n){return{name:e,primKey:t,indexes:n,mappedClass:null,idxByName:(r=function(o){return[o.name,o]},n.reduce(function(o,a,h){return h=r(a,h),h&&(o[h[0]]=h[1]),o},{}))};var r}var Jt=function(e){try{return e.only([[]]),Jt=function(){return[[]]},[[]]}catch{return Jt=function(){return Nt},Nt}};function ur(e){return e==null?function(){}:typeof e=="string"?(t=e).split(".").length===1?function(n){return n[t]}:function(n){return Q(n,t)}:function(n){return Q(n,e)};var t}function rs(e){return[].slice.call(e)}var pi=0;function Qt(e){return e==null?":id":typeof e=="string"?e:"[".concat(e.join("+"),"]")}function yi(e,t,b){function r(w){if(w.type===3)return null;if(w.type===4)throw new Error("Cannot convert never type to IDBKeyRange");var v=w.lower,j=w.upper,k=w.lowerOpen,w=w.upperOpen;return v===void 0?j===void 0?null:t.upperBound(j,!!w):j===void 0?t.lowerBound(v,!!k):t.bound(v,j,!!k,!!w)}function o(_){var v,j=_.name;return{name:j,schema:_,mutate:function(k){var w=k.trans,E=k.type,D=k.keys,P=k.values,O=k.range;return new Promise(function(K,z){K=De(K);var I=w.objectStore(j),B=I.keyPath==null,H=E==="put"||E==="add";if(!H&&E!=="delete"&&E!=="deleteRange")throw new Error("Invalid operation type: "+E);var L,ee=(D||P||{length:1}).length;if(D&&P&&D.length!==P.length)throw new Error("Given keys array must have same length as given values array.");if(ee===0)return K({numFailures:0,failures:{},results:[],lastResult:void 0});function fe(ze){++He,Ht(ze)}var ye=[],ge=[],He=0;if(E==="deleteRange"){if(O.type===4)return K({numFailures:He,failures:ge,results:[],lastResult:void 0});O.type===3?ye.push(L=I.clear()):ye.push(L=I.delete(r(O)))}else{var B=H?B?[P,D]:[P,null]:[D,null],he=B[0],qe=B[1];if(H)for(var Be=0;Be<ee;++Be)ye.push(L=qe&&qe[Be]!==void 0?I[E](he[Be],qe[Be]):I[E](he[Be])),L.onerror=fe;else for(Be=0;Be<ee;++Be)ye.push(L=I[E](he[Be])),L.onerror=fe}function Mn(ze){ze=ze.target.result,ye.forEach(function(St,Er){return St.error!=null&&(ge[Er]=St.error)}),K({numFailures:He,failures:ge,results:E==="delete"?D:ye.map(function(St){return St.result}),lastResult:ze})}L.onerror=function(ze){fe(ze),Mn(ze)},L.onsuccess=Mn})},getMany:function(k){var w=k.trans,E=k.keys;return new Promise(function(D,P){D=De(D);for(var O,K=w.objectStore(j),z=E.length,I=new Array(z),B=0,H=0,L=function(ye){ye=ye.target,I[ye._pos]=ye.result,++H===B&&D(I)},ee=et(P),fe=0;fe<z;++fe)E[fe]!=null&&((O=K.get(E[fe]))._pos=fe,O.onsuccess=L,O.onerror=ee,++B);B===0&&D(I)})},get:function(k){var w=k.trans,E=k.key;return new Promise(function(D,P){D=De(D);var O=w.objectStore(j).get(E);O.onsuccess=function(K){return D(K.target.result)},O.onerror=et(P)})},query:(v=x,function(k){return new Promise(function(w,E){w=De(w);var D,P,O,B=k.trans,K=k.values,z=k.limit,L=k.query,I=z===1/0?void 0:z,H=L.index,L=L.range,B=B.objectStore(j),H=H.isPrimaryKey?B:B.index(H.name),L=r(L);if(z===0)return w({result:[]});v?((I=K?H.getAll(L,I):H.getAllKeys(L,I)).onsuccess=function(ee){return w({result:ee.target.result})},I.onerror=et(E)):(D=0,P=!K&&"openKeyCursor"in H?H.openKeyCursor(L):H.openCursor(L),O=[],P.onsuccess=function(ee){var fe=P.result;return fe?(O.push(K?fe.value:fe.primaryKey),++D===z?w({result:O}):void fe.continue()):w({result:O})},P.onerror=et(E))})}),openCursor:function(k){var w=k.trans,E=k.values,D=k.query,P=k.reverse,O=k.unique;return new Promise(function(K,z){K=De(K);var H=D.index,I=D.range,B=w.objectStore(j),B=H.isPrimaryKey?B:B.index(H.name),H=P?O?"prevunique":"prev":O?"nextunique":"next",L=!E&&"openKeyCursor"in B?B.openKeyCursor(r(I),H):B.openCursor(r(I),H);L.onerror=et(z),L.onsuccess=De(function(ee){var fe,ye,ge,He,he=L.result;he?(he.___id=++pi,he.done=!1,fe=he.continue.bind(he),ye=(ye=he.continuePrimaryKey)&&ye.bind(he),ge=he.advance.bind(he),He=function(){throw new Error("Cursor not stopped")},he.trans=w,he.stop=he.continue=he.continuePrimaryKey=he.advance=function(){throw new Error("Cursor not started")},he.fail=De(z),he.next=function(){var qe=this,Be=1;return this.start(function(){return Be--?qe.continue():qe.stop()}).then(function(){return qe})},he.start=function(qe){function Be(){if(L.result)try{qe()}catch(ze){he.fail(ze)}else he.done=!0,he.start=function(){throw new Error("Cursor behind last entry")},he.stop()}var Mn=new Promise(function(ze,St){ze=De(ze),L.onerror=et(St),he.fail=St,he.stop=function(Er){he.stop=he.continue=he.continuePrimaryKey=he.advance=He,ze(Er)}});return L.onsuccess=De(function(ze){L.onsuccess=Be,Be()}),he.continue=fe,he.continuePrimaryKey=ye,he.advance=ge,Be(),Mn},K(he)):K(null)},z)})},count:function(k){var w=k.query,E=k.trans,D=w.index,P=w.range;return new Promise(function(O,K){var z=E.objectStore(j),I=D.isPrimaryKey?z:z.index(D.name),z=r(P),I=z?I.count(z):I.count();I.onsuccess=De(function(B){return O(B.target.result)}),I.onerror=et(K)})}}}var a,h,m,N=(h=b,m=rs((a=e).objectStoreNames),{schema:{name:a.name,tables:m.map(function(_){return h.objectStore(_)}).map(function(_){var v=_.keyPath,w=_.autoIncrement,j=p(v),k={},w={name:_.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:v==null,compound:j,keyPath:v,autoIncrement:w,unique:!0,extractKey:ur(v)},indexes:rs(_.indexNames).map(function(E){return _.index(E)}).map(function(O){var D=O.name,P=O.unique,K=O.multiEntry,O=O.keyPath,K={name:D,compound:p(O),keyPath:O,unique:P,multiEntry:K,extractKey:ur(O)};return k[Qt(O)]=K}),getIndexByKeyPath:function(E){return k[Qt(E)]}};return k[":id"]=w.primaryKey,v!=null&&(k[Qt(v)]=w.primaryKey),w})},hasGetAll:0<m.length&&"getAll"in h.objectStore(m[0])&&!(typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}),b=N.schema,x=N.hasGetAll,N=b.tables.map(o),g={};return N.forEach(function(_){return g[_.name]=_}),{stack:"dbcore",transaction:e.transaction.bind(e),table:function(_){if(!g[_])throw new Error("Table '".concat(_,"' not found"));return g[_]},MIN_KEY:-1/0,MAX_KEY:Jt(t),schema:b}}function gi(e,t,n,r){var o=n.IDBKeyRange;return n.indexedDB,{dbcore:(r=yi(t,o,r),e.dbcore.reduce(function(a,h){return h=h.create,c(c({},a),h(a))},r))}}function Nn(e,r){var n=r.db,r=gi(e._middlewares,n,e._deps,r);e.core=r.dbcore,e.tables.forEach(function(o){var a=o.name;e.core.schema.tables.some(function(h){return h.name===a})&&(o.core=e.core.table(a),e[a]instanceof e.Table&&(e[a].core=o.core))})}function kn(e,t,n,r){n.forEach(function(o){var a=r[o];t.forEach(function(h){var m=function b(x,N){return pe(x,N)||(x=S(x))&&b(x,N)}(h,o);(!m||"value"in m&&m.value===void 0)&&(h===e.Transaction.prototype||h instanceof e.Transaction?T(h,o,{get:function(){return this.table(o)},set:function(b){M(this,o,{value:b,writable:!0,configurable:!0,enumerable:!0})}}):h[o]=new e.Table(o,a))})})}function dr(e,t){t.forEach(function(n){for(var r in n)n[r]instanceof e.Table&&delete n[r]})}function bi(e,t){return e._cfg.version-t._cfg.version}function vi(e,t,n,r){var o=e._dbSchema;n.objectStoreNames.contains("$meta")&&!o.$meta&&(o.$meta=cr("$meta",is("")[0],[]),e._storeNames.push("$meta"));var a=e._createTransaction("readwrite",e._storeNames,o);a.create(n),a._completion.catch(r);var h=a._reject.bind(a),m=ae.transless||ae;at(function(){return ae.trans=a,ae.transless=m,t!==0?(Nn(e,n),x=t,((b=a).storeNames.includes("$meta")?b.table("$meta").get("version").then(function(N){return N??x}):J.resolve(x)).then(function(N){return _=N,v=a,j=n,k=[],N=(g=e)._versions,w=g._dbSchema=Cn(0,g.idbdb,j),(N=N.filter(function(E){return E._cfg.version>=_})).length!==0?(N.forEach(function(E){k.push(function(){var D=w,P=E._cfg.dbschema;Sn(g,D,j),Sn(g,P,j),w=g._dbSchema=P;var O=hr(D,P);O.add.forEach(function(H){fr(j,H[0],H[1].primKey,H[1].indexes)}),O.change.forEach(function(H){if(H.recreate)throw new re.Upgrade("Not yet support for changing primary key");var L=j.objectStore(H.name);H.add.forEach(function(ee){return _n(L,ee)}),H.change.forEach(function(ee){L.deleteIndex(ee.name),_n(L,ee)}),H.del.forEach(function(ee){return L.deleteIndex(ee)})});var K=E._cfg.contentUpgrade;if(K&&E._cfg.version>_){Nn(g,j),v._memoizedTables={};var z=W(P);O.del.forEach(function(H){z[H]=D[H]}),dr(g,[g.Transaction.prototype]),kn(g,[g.Transaction.prototype],y(z),z),v.schema=z;var I,B=we(K);return B&&Mt(),O=J.follow(function(){var H;(I=K(v))&&B&&(H=lt.bind(null,null),I.then(H,H))}),I&&typeof I.then=="function"?J.resolve(I):O.then(function(){return I})}}),k.push(function(D){var P,O,K=E._cfg.dbschema;P=K,O=D,[].slice.call(O.db.objectStoreNames).forEach(function(z){return P[z]==null&&O.db.deleteObjectStore(z)}),dr(g,[g.Transaction.prototype]),kn(g,[g.Transaction.prototype],g._storeNames,g._dbSchema),v.schema=g._dbSchema}),k.push(function(D){g.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(g.idbdb.version/10)===E._cfg.version?(g.idbdb.deleteObjectStore("$meta"),delete g._dbSchema.$meta,g._storeNames=g._storeNames.filter(function(P){return P!=="$meta"})):D.objectStore("$meta").put(E._cfg.version,"version"))})}),function E(){return k.length?J.resolve(k.shift()(v.idbtrans)).then(E):J.resolve()}().then(function(){ss(w,j)})):J.resolve();var g,_,v,j,k,w}).catch(h)):(y(o).forEach(function(N){fr(n,N,o[N].primKey,o[N].indexes)}),Nn(e,n),void J.follow(function(){return e.on.populate.fire(a)}).catch(h));var b,x})}function xi(e,t){ss(e._dbSchema,t),t.db.version%10!=0||t.objectStoreNames.contains("$meta")||t.db.createObjectStore("$meta").add(Math.ceil(t.db.version/10-1),"version");var n=Cn(0,e.idbdb,t);Sn(e,e._dbSchema,t);for(var r=0,o=hr(n,e._dbSchema).change;r<o.length;r++){var a=function(h){if(h.change.length||h.recreate)return console.warn("Unable to patch indexes of table ".concat(h.name," because it has changes on the type of index or primary key.")),{value:void 0};var m=t.objectStore(h.name);h.add.forEach(function(b){Xe&&console.debug("Dexie upgrade patch: Creating missing index ".concat(h.name,".").concat(b.src)),_n(m,b)})}(o[r]);if(typeof a=="object")return a.value}}function hr(e,t){var n,r={del:[],add:[],change:[]};for(n in e)t[n]||r.del.push(n);for(n in t){var o=e[n],a=t[n];if(o){var h={name:n,def:a,recreate:!1,del:[],add:[],change:[]};if(""+(o.primKey.keyPath||"")!=""+(a.primKey.keyPath||"")||o.primKey.auto!==a.primKey.auto)h.recreate=!0,r.change.push(h);else{var m=o.idxByName,b=a.idxByName,x=void 0;for(x in m)b[x]||h.del.push(x);for(x in b){var N=m[x],g=b[x];N?N.src!==g.src&&h.change.push(g):h.add.push(g)}(0<h.del.length||0<h.add.length||0<h.change.length)&&r.change.push(h)}}else r.add.push([n,a])}return r}function fr(e,t,n,r){var o=e.db.createObjectStore(t,n.keyPath?{keyPath:n.keyPath,autoIncrement:n.auto}:{autoIncrement:n.auto});return r.forEach(function(a){return _n(o,a)}),o}function ss(e,t){y(e).forEach(function(n){t.db.objectStoreNames.contains(n)||(Xe&&console.debug("Dexie: Creating missing table",n),fr(t,n,e[n].primKey,e[n].indexes))})}function _n(e,t){e.createIndex(t.name,t.keyPath,{unique:t.unique,multiEntry:t.multi})}function Cn(e,t,n){var r={};return ie(t.objectStoreNames,0).forEach(function(o){for(var a=n.objectStore(o),h=lr(ns(x=a.keyPath),x||"",!0,!1,!!a.autoIncrement,x&&typeof x!="string",!0),m=[],b=0;b<a.indexNames.length;++b){var N=a.index(a.indexNames[b]),x=N.keyPath,N=lr(N.name,x,!!N.unique,!!N.multiEntry,!1,x&&typeof x!="string",!1);m.push(N)}r[o]=cr(o,h,m)}),r}function Sn(e,t,n){for(var r=n.db.objectStoreNames,o=0;o<r.length;++o){var a=r[o],h=n.objectStore(a);e._hasGetAll="getAll"in h;for(var m=0;m<h.indexNames.length;++m){var b=h.indexNames[m],x=h.index(b).keyPath,N=typeof x=="string"?x:"["+ie(x).join("+")+"]";!t[a]||(x=t[a].idxByName[N])&&(x.name=b,delete t[a].idxByName[N],t[a].idxByName[b]=x)}}typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&d.WorkerGlobalScope&&d instanceof d.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(e._hasGetAll=!1)}function is(e){return e.split(",").map(function(t,n){var r=(t=t.trim()).replace(/([&*]|\+\+)/g,""),o=/^\[/.test(r)?r.match(/^\[(.*)\]$/)[1].split("+"):r;return lr(r,o||null,/\&/.test(t),/\*/.test(t),/\+\+/.test(t),p(o),n===0)})}var wi=(En.prototype._parseStoresSpec=function(e,t){y(e).forEach(function(n){if(e[n]!==null){var r=is(e[n]),o=r.shift();if(o.unique=!0,o.multi)throw new re.Schema("Primary key cannot be multi-valued");r.forEach(function(a){if(a.auto)throw new re.Schema("Only primary key can be marked as autoIncrement (++)");if(!a.keyPath)throw new re.Schema("Index must have a name and cannot be an empty string")}),t[n]=cr(n,o,r)}})},En.prototype.stores=function(n){var t=this.db;this._cfg.storesSource=this._cfg.storesSource?C(this._cfg.storesSource,n):n;var n=t._versions,r={},o={};return n.forEach(function(a){C(r,a._cfg.storesSource),o=a._cfg.dbschema={},a._parseStoresSpec(r,o)}),t._dbSchema=o,dr(t,[t._allTables,t,t.Transaction.prototype]),kn(t,[t._allTables,t,t.Transaction.prototype,this._cfg.tables],y(o),o),t._storeNames=y(o),this},En.prototype.upgrade=function(e){return this._cfg.contentUpgrade=Vn(this._cfg.contentUpgrade||ve,e),this},En);function En(){}function mr(e,t){var n=e._dbNamesDB;return n||(n=e._dbNamesDB=new rt(bn,{addons:[],indexedDB:e,IDBKeyRange:t})).version(1).stores({dbnames:"name"}),n.table("dbnames")}function pr(e){return e&&typeof e.databases=="function"}function yr(e){return at(function(){return ae.letThrough=!0,e()})}function gr(e){return!("from"in e)}var Fe=function(e,t){if(!this){var n=new Fe;return e&&"d"in e&&C(n,e),n}C(this,arguments.length?{d:1,from:e,to:1<arguments.length?t:e}:{d:0})};function Gt(e,t,n){var r=be(t,n);if(!isNaN(r)){if(0<r)throw RangeError();if(gr(e))return C(e,{from:t,to:n,d:1});var o=e.l,r=e.r;if(be(n,e.from)<0)return o?Gt(o,t,n):e.l={from:t,to:n,d:1,l:null,r:null},as(e);if(0<be(t,e.to))return r?Gt(r,t,n):e.r={from:t,to:n,d:1,l:null,r:null},as(e);be(t,e.from)<0&&(e.from=t,e.l=null,e.d=r?r.d+1:1),0<be(n,e.to)&&(e.to=n,e.r=null,e.d=e.l?e.l.d+1:1),n=!e.r,o&&!e.l&&Xt(e,o),r&&n&&Xt(e,r)}}function Xt(e,t){gr(t)||function n(r,b){var a=b.from,h=b.to,m=b.l,b=b.r;Gt(r,a,h),m&&n(r,m),b&&n(r,b)}(e,t)}function os(e,t){var n=Dn(t),r=n.next();if(r.done)return!1;for(var o=r.value,a=Dn(e),h=a.next(o.from),m=h.value;!r.done&&!h.done;){if(be(m.from,o.to)<=0&&0<=be(m.to,o.from))return!0;be(o.from,m.from)<0?o=(r=n.next(m.from)).value:m=(h=a.next(o.from)).value}return!1}function Dn(e){var t=gr(e)?null:{s:0,n:e};return{next:function(n){for(var r=0<arguments.length;t;)switch(t.s){case 0:if(t.s=1,r)for(;t.n.l&&be(n,t.n.from)<0;)t={up:t,n:t.n.l,s:1};else for(;t.n.l;)t={up:t,n:t.n.l,s:1};case 1:if(t.s=2,!r||be(n,t.n.to)<=0)return{value:t.n,done:!1};case 2:if(t.n.r){t.s=3,t={up:t,n:t.n.r,s:0};continue}case 3:t=t.up}return{done:!0}}}}function as(e){var t,n,r=(((t=e.r)===null||t===void 0?void 0:t.d)||0)-(((n=e.l)===null||n===void 0?void 0:n.d)||0),o=1<r?"r":r<-1?"l":"";o&&(t=o=="r"?"l":"r",n=c({},e),r=e[o],e.from=r.from,e.to=r.to,e[o]=r[o],n[o]=r[t],(e[t]=n).d=ls(n)),e.d=ls(e)}function ls(n){var t=n.r,n=n.l;return(t?n?Math.max(t.d,n.d):t.d:n?n.d:0)+1}function Pn(e,t){return y(t).forEach(function(n){e[n]?Xt(e[n],t[n]):e[n]=function r(o){var a,h,m={};for(a in o)A(o,a)&&(h=o[a],m[a]=!h||typeof h!="object"||te.has(h.constructor)?h:r(h));return m}(t[n])}),e}function br(e,t){return e.all||t.all||Object.keys(e).some(function(n){return t[n]&&os(t[n],e[n])})}Y(Fe.prototype,((Je={add:function(e){return Xt(this,e),this},addKey:function(e){return Gt(this,e,e),this},addKeys:function(e){var t=this;return e.forEach(function(n){return Gt(t,n,n)}),this},hasKey:function(e){var t=Dn(this).next(e).value;return t&&be(t.from,e)<=0&&0<=be(t.to,e)}})[V]=function(){return Dn(this)},Je));var _t={},vr={},xr=!1;function $n(e){Pn(vr,e),xr||(xr=!0,setTimeout(function(){xr=!1,wr(vr,!(vr={}))},0))}function wr(e,t){t===void 0&&(t=!1);var n=new Set;if(e.all)for(var r=0,o=Object.values(_t);r<o.length;r++)cs(h=o[r],e,n,t);else for(var a in e){var h,m=/^idb\:\/\/(.*)\/(.*)\//.exec(a);m&&(a=m[1],m=m[2],(h=_t["idb://".concat(a,"/").concat(m)])&&cs(h,e,n,t))}n.forEach(function(b){return b()})}function cs(e,t,n,r){for(var o=[],a=0,h=Object.entries(e.queries.query);a<h.length;a++){for(var m=h[a],b=m[0],x=[],N=0,g=m[1];N<g.length;N++){var _=g[N];br(t,_.obsSet)?_.subscribers.forEach(function(w){return n.add(w)}):r&&x.push(_)}r&&o.push([b,x])}if(r)for(var v=0,j=o;v<j.length;v++){var k=j[v],b=k[0],x=k[1];e.queries.query[b]=x}}function ji(e){var t=e._state,n=e._deps.indexedDB;if(t.isBeingOpened||e.idbdb)return t.dbReadyPromise.then(function(){return t.dbOpenError?Pe(t.dbOpenError):e});t.isBeingOpened=!0,t.dbOpenError=null,t.openComplete=!1;var r=t.openCanceller,o=Math.round(10*e.verno),a=!1;function h(){if(t.openCanceller!==r)throw new re.DatabaseClosed("db.open() was cancelled")}function m(){return new J(function(_,v){if(h(),!n)throw new re.MissingAPI;var j=e.name,k=t.autoSchema||!o?n.open(j):n.open(j,o);if(!k)throw new re.MissingAPI;k.onerror=et(v),k.onblocked=De(e._fireOnBlocked),k.onupgradeneeded=De(function(w){var E;N=k.transaction,t.autoSchema&&!e._options.allowEmptyDB?(k.onerror=Ht,N.abort(),k.result.close(),(E=n.deleteDatabase(j)).onsuccess=E.onerror=De(function(){v(new re.NoSuchDatabase("Database ".concat(j," doesnt exist")))})):(N.onerror=et(v),w=w.oldVersion>Math.pow(2,62)?0:w.oldVersion,g=w<1,e.idbdb=k.result,a&&xi(e,N),vi(e,w/10,N,v))},v),k.onsuccess=De(function(){N=null;var w,E,D,P,O,K=e.idbdb=k.result,z=ie(K.objectStoreNames);if(0<z.length)try{var I=K.transaction((P=z).length===1?P[0]:P,"readonly");if(t.autoSchema)E=K,D=I,(w=e).verno=E.version/10,D=w._dbSchema=Cn(0,E,D),w._storeNames=ie(E.objectStoreNames,0),kn(w,[w._allTables],y(D),D);else if(Sn(e,e._dbSchema,I),((O=hr(Cn(0,(O=e).idbdb,I),O._dbSchema)).add.length||O.change.some(function(B){return B.add.length||B.change.length}))&&!a)return console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this."),K.close(),o=K.version+1,a=!0,_(m());Nn(e,I)}catch{}Kt.push(e),K.onversionchange=De(function(B){t.vcFired=!0,e.on("versionchange").fire(B)}),K.onclose=De(function(B){e.on("close").fire(B)}),g&&(O=e._deps,I=j,K=O.indexedDB,O=O.IDBKeyRange,pr(K)||I===bn||mr(K,O).put({name:I}).catch(ve)),_()},v)}).catch(function(_){switch(_==null?void 0:_.name){case"UnknownError":if(0<t.PR1398_maxLoop)return t.PR1398_maxLoop--,console.warn("Dexie: Workaround for Chrome UnknownError on open()"),m();break;case"VersionError":if(0<o)return o=0,m()}return J.reject(_)})}var b,x=t.dbReadyResolve,N=null,g=!1;return J.race([r,(typeof navigator>"u"?J.resolve():!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise(function(_){function v(){return indexedDB.databases().finally(_)}b=setInterval(v,100),v()}).finally(function(){return clearInterval(b)}):Promise.resolve()).then(m)]).then(function(){return h(),t.onReadyBeingFired=[],J.resolve(yr(function(){return e.on.ready.fire(e.vip)})).then(function _(){if(0<t.onReadyBeingFired.length){var v=t.onReadyBeingFired.reduce(Vn,ve);return t.onReadyBeingFired=[],J.resolve(yr(function(){return v(e.vip)})).then(_)}})}).finally(function(){t.openCanceller===r&&(t.onReadyBeingFired=null,t.isBeingOpened=!1)}).catch(function(_){t.dbOpenError=_;try{N&&N.abort()}catch{}return r===t.openCanceller&&e._close(),Pe(_)}).finally(function(){t.openComplete=!0,x()}).then(function(){var _;return g&&(_={},e.tables.forEach(function(v){v.schema.indexes.forEach(function(j){j.name&&(_["idb://".concat(e.name,"/").concat(v.name,"/").concat(j.name)]=new Fe(-1/0,[[[]]]))}),_["idb://".concat(e.name,"/").concat(v.name,"/")]=_["idb://".concat(e.name,"/").concat(v.name,"/:dels")]=new Fe(-1/0,[[[]]])}),dt(Zt).fire(_),wr(_,!0)),e})}function jr(e){function t(a){return e.next(a)}var n=o(t),r=o(function(a){return e.throw(a)});function o(a){return function(b){var m=a(b),b=m.value;return m.done?b:b&&typeof b.then=="function"?b.then(n,r):p(b)?Promise.all(b).then(n,r):n(b)}}return o(t)()}function On(e,t,n){for(var r=p(e)?e.slice():[e],o=0;o<n;++o)r.push(t);return r}var Ni={stack:"dbcore",name:"VirtualIndexMiddleware",level:1,create:function(e){return c(c({},e),{table:function(t){var n=e.table(t),r=n.schema,o={},a=[];function h(g,_,v){var j=Qt(g),k=o[j]=o[j]||[],w=g==null?0:typeof g=="string"?1:g.length,E=0<_,E=c(c({},v),{name:E?"".concat(j,"(virtual-from:").concat(v.name,")"):v.name,lowLevelIndex:v,isVirtual:E,keyTail:_,keyLength:w,extractKey:ur(g),unique:!E&&v.unique});return k.push(E),E.isPrimaryKey||a.push(E),1<w&&h(w===2?g[0]:g.slice(0,w-1),_+1,v),k.sort(function(D,P){return D.keyTail-P.keyTail}),E}t=h(r.primaryKey.keyPath,0,r.primaryKey),o[":id"]=[t];for(var m=0,b=r.indexes;m<b.length;m++){var x=b[m];h(x.keyPath,0,x)}function N(g){var _,v=g.query.index;return v.isVirtual?c(c({},g),{query:{index:v.lowLevelIndex,range:(_=g.query.range,v=v.keyTail,{type:_.type===1?2:_.type,lower:On(_.lower,_.lowerOpen?e.MAX_KEY:e.MIN_KEY,v),lowerOpen:!0,upper:On(_.upper,_.upperOpen?e.MIN_KEY:e.MAX_KEY,v),upperOpen:!0})}}):g}return c(c({},n),{schema:c(c({},r),{primaryKey:t,indexes:a,getIndexByKeyPath:function(g){return(g=o[Qt(g)])&&g[0]}}),count:function(g){return n.count(N(g))},query:function(g){return n.query(N(g))},openCursor:function(g){var _=g.query.index,v=_.keyTail,j=_.isVirtual,k=_.keyLength;return j?n.openCursor(N(g)).then(function(E){return E&&w(E)}):n.openCursor(g);function w(E){return Object.create(E,{continue:{value:function(D){D!=null?E.continue(On(D,g.reverse?e.MAX_KEY:e.MIN_KEY,v)):g.unique?E.continue(E.key.slice(0,k).concat(g.reverse?e.MIN_KEY:e.MAX_KEY,v)):E.continue()}},continuePrimaryKey:{value:function(D,P){E.continuePrimaryKey(On(D,e.MAX_KEY,v),P)}},primaryKey:{get:function(){return E.primaryKey}},key:{get:function(){var D=E.key;return k===1?D[0]:D.slice(0,k)}},value:{get:function(){return E.value}}})}}})}})}};function Nr(e,t,n,r){return n=n||{},r=r||"",y(e).forEach(function(o){var a,h,m;A(t,o)?(a=e[o],h=t[o],typeof a=="object"&&typeof h=="object"&&a&&h?(m=Z(a))!==Z(h)?n[r+o]=t[o]:m==="Object"?Nr(a,h,n,r+o+"."):a!==h&&(n[r+o]=t[o]):a!==h&&(n[r+o]=t[o])):n[r+o]=void 0}),y(t).forEach(function(o){A(e,o)||(n[r+o]=t[o])}),n}function kr(e,t){return t.type==="delete"?t.keys:t.keys||t.values.map(e.extractKey)}var ki={stack:"dbcore",name:"HooksMiddleware",level:2,create:function(e){return c(c({},e),{table:function(t){var n=e.table(t),r=n.schema.primaryKey;return c(c({},n),{mutate:function(o){var a=ae.trans,h=a.table(t).hook,m=h.deleting,b=h.creating,x=h.updating;switch(o.type){case"add":if(b.fire===ve)break;return a._promise("readwrite",function(){return N(o)},!0);case"put":if(b.fire===ve&&x.fire===ve)break;return a._promise("readwrite",function(){return N(o)},!0);case"delete":if(m.fire===ve)break;return a._promise("readwrite",function(){return N(o)},!0);case"deleteRange":if(m.fire===ve)break;return a._promise("readwrite",function(){return function g(_,v,j){return n.query({trans:_,values:!1,query:{index:r,range:v},limit:j}).then(function(k){var w=k.result;return N({type:"delete",keys:w,trans:_}).then(function(E){return 0<E.numFailures?Promise.reject(E.failures[0]):w.length<j?{failures:[],numFailures:0,lastResult:void 0}:g(_,c(c({},v),{lower:w[w.length-1],lowerOpen:!0}),j)})})}(o.trans,o.range,1e4)},!0)}return n.mutate(o);function N(g){var _,v,j,k=ae.trans,w=g.keys||kr(r,g);if(!w)throw new Error("Keys missing");return(g=g.type==="add"||g.type==="put"?c(c({},g),{keys:w}):c({},g)).type!=="delete"&&(g.values=f([],g.values,!0)),g.keys&&(g.keys=f([],g.keys,!0)),_=n,j=w,((v=g).type==="add"?Promise.resolve([]):_.getMany({trans:v.trans,keys:j,cache:"immutable"})).then(function(E){var D=w.map(function(P,O){var K,z,I,B=E[O],H={onerror:null,onsuccess:null};return g.type==="delete"?m.fire.call(H,P,B,k):g.type==="add"||B===void 0?(K=b.fire.call(H,P,g.values[O],k),P==null&&K!=null&&(g.keys[O]=P=K,r.outbound||F(g.values[O],r.keyPath,P))):(K=Nr(B,g.values[O]),(z=x.fire.call(H,K,P,B,k))&&(I=g.values[O],Object.keys(z).forEach(function(L){A(I,L)?I[L]=z[L]:F(I,L,z[L])}))),H});return n.mutate(g).then(function(P){for(var O=P.failures,K=P.results,z=P.numFailures,P=P.lastResult,I=0;I<w.length;++I){var B=(K||w)[I],H=D[I];B==null?H.onerror&&H.onerror(O[I]):H.onsuccess&&H.onsuccess(g.type==="put"&&E[I]?g.values[I]:B)}return{failures:O,results:K,numFailures:z,lastResult:P}}).catch(function(P){return D.forEach(function(O){return O.onerror&&O.onerror(P)}),Promise.reject(P)})})}}})}})}};function us(e,t,n){try{if(!t||t.keys.length<e.length)return null;for(var r=[],o=0,a=0;o<t.keys.length&&a<e.length;++o)be(t.keys[o],e[a])===0&&(r.push(n?ke(t.values[o]):t.values[o]),++a);return r.length===e.length?r:null}catch{return null}}var _i={stack:"dbcore",level:-1,create:function(e){return{table:function(t){var n=e.table(t);return c(c({},n),{getMany:function(r){if(!r.cache)return n.getMany(r);var o=us(r.keys,r.trans._cache,r.cache==="clone");return o?J.resolve(o):n.getMany(r).then(function(a){return r.trans._cache={keys:r.keys,values:r.cache==="clone"?ke(a):a},a})},mutate:function(r){return r.type!=="add"&&(r.trans._cache=null),n.mutate(r)}})}}}};function ds(e,t){return e.trans.mode==="readonly"&&!!e.subscr&&!e.trans.explicit&&e.trans.db._options.cache!=="disabled"&&!t.schema.primaryKey.outbound}function hs(e,t){switch(e){case"query":return t.values&&!t.unique;case"get":case"getMany":case"count":case"openCursor":return!1}}var Ci={stack:"dbcore",level:0,name:"Observability",create:function(e){var t=e.schema.name,n=new Fe(e.MIN_KEY,e.MAX_KEY);return c(c({},e),{transaction:function(r,o,a){if(ae.subscr&&o!=="readonly")throw new re.ReadOnly("Readwrite transaction in liveQuery context. Querier source: ".concat(ae.querier));return e.transaction(r,o,a)},table:function(r){var o=e.table(r),a=o.schema,h=a.primaryKey,g=a.indexes,m=h.extractKey,b=h.outbound,x=h.autoIncrement&&g.filter(function(v){return v.compound&&v.keyPath.includes(h.keyPath)}),N=c(c({},o),{mutate:function(v){function j(L){return L="idb://".concat(t,"/").concat(r,"/").concat(L),P[L]||(P[L]=new Fe)}var k,w,E,D=v.trans,P=v.mutatedParts||(v.mutatedParts={}),O=j(""),K=j(":dels"),z=v.type,H=v.type==="deleteRange"?[v.range]:v.type==="delete"?[v.keys]:v.values.length<50?[kr(h,v).filter(function(L){return L}),v.values]:[],I=H[0],B=H[1],H=v.trans._cache;return p(I)?(O.addKeys(I),(H=z==="delete"||I.length===B.length?us(I,H):null)||K.addKeys(I),(H||B)&&(k=j,w=H,E=B,a.indexes.forEach(function(L){var ee=k(L.name||"");function fe(ge){return ge!=null?L.extractKey(ge):null}function ye(ge){return L.multiEntry&&p(ge)?ge.forEach(function(He){return ee.addKey(He)}):ee.addKey(ge)}(w||E).forEach(function(ge,qe){var he=w&&fe(w[qe]),qe=E&&fe(E[qe]);be(he,qe)!==0&&(he!=null&&ye(he),qe!=null&&ye(qe))})}))):I?(B={from:(B=I.lower)!==null&&B!==void 0?B:e.MIN_KEY,to:(B=I.upper)!==null&&B!==void 0?B:e.MAX_KEY},K.add(B),O.add(B)):(O.add(n),K.add(n),a.indexes.forEach(function(L){return j(L.name).add(n)})),o.mutate(v).then(function(L){return!I||v.type!=="add"&&v.type!=="put"||(O.addKeys(L.results),x&&x.forEach(function(ee){for(var fe=v.values.map(function(he){return ee.extractKey(he)}),ye=ee.keyPath.findIndex(function(he){return he===h.keyPath}),ge=0,He=L.results.length;ge<He;++ge)fe[ge][ye]=L.results[ge];j(ee.name).addKeys(fe)})),D.mutatedParts=Pn(D.mutatedParts||{},P),L})}}),g=function(j){var k=j.query,j=k.index,k=k.range;return[j,new Fe((j=k.lower)!==null&&j!==void 0?j:e.MIN_KEY,(k=k.upper)!==null&&k!==void 0?k:e.MAX_KEY)]},_={get:function(v){return[h,new Fe(v.key)]},getMany:function(v){return[h,new Fe().addKeys(v.keys)]},count:g,query:g,openCursor:g};return y(_).forEach(function(v){N[v]=function(j){var k=ae.subscr,w=!!k,E=ds(ae,o)&&hs(v,j)?j.obsSet={}:k;if(w){var D=function(B){return B="idb://".concat(t,"/").concat(r,"/").concat(B),E[B]||(E[B]=new Fe)},P=D(""),O=D(":dels"),k=_[v](j),w=k[0],k=k[1];if((v==="query"&&w.isPrimaryKey&&!j.values?O:D(w.name||"")).add(k),!w.isPrimaryKey){if(v!=="count"){var K=v==="query"&&b&&j.values&&o.query(c(c({},j),{values:!1}));return o[v].apply(this,arguments).then(function(B){if(v==="query"){if(b&&j.values)return K.then(function(fe){return fe=fe.result,P.addKeys(fe),B});var H=j.values?B.result.map(m):B.result;(j.values?P:O).addKeys(H)}else if(v==="openCursor"){var L=B,ee=j.values;return L&&Object.create(L,{key:{get:function(){return O.addKey(L.primaryKey),L.key}},primaryKey:{get:function(){var fe=L.primaryKey;return O.addKey(fe),fe}},value:{get:function(){return ee&&P.addKey(L.primaryKey),L.value}}})}return B})}O.add(n)}}return o[v].apply(this,arguments)}}),N}})}};function fs(e,t,n){if(n.numFailures===0)return t;if(t.type==="deleteRange")return null;var r=t.keys?t.keys.length:"values"in t&&t.values?t.values.length:1;return n.numFailures===r?null:(t=c({},t),p(t.keys)&&(t.keys=t.keys.filter(function(o,a){return!(a in n.failures)})),"values"in t&&p(t.values)&&(t.values=t.values.filter(function(o,a){return!(a in n.failures)})),t)}function _r(e,t){return n=e,((r=t).lower===void 0||(r.lowerOpen?0<be(n,r.lower):0<=be(n,r.lower)))&&(e=e,(t=t).upper===void 0||(t.upperOpen?be(e,t.upper)<0:be(e,t.upper)<=0));var n,r}function ms(e,t,_,r,o,a){if(!_||_.length===0)return e;var h=t.query.index,m=h.multiEntry,b=t.query.range,x=r.schema.primaryKey.extractKey,N=h.extractKey,g=(h.lowLevelIndex||h).extractKey,_=_.reduce(function(v,j){var k=v,w=[];if(j.type==="add"||j.type==="put")for(var E=new Fe,D=j.values.length-1;0<=D;--D){var P,O=j.values[D],K=x(O);E.hasKey(K)||(P=N(O),(m&&p(P)?P.some(function(L){return _r(L,b)}):_r(P,b))&&(E.addKey(K),w.push(O)))}switch(j.type){case"add":var z=new Fe().addKeys(t.values?v.map(function(ee){return x(ee)}):v),k=v.concat(t.values?w.filter(function(ee){return ee=x(ee),!z.hasKey(ee)&&(z.addKey(ee),!0)}):w.map(function(ee){return x(ee)}).filter(function(ee){return!z.hasKey(ee)&&(z.addKey(ee),!0)}));break;case"put":var I=new Fe().addKeys(j.values.map(function(ee){return x(ee)}));k=v.filter(function(ee){return!I.hasKey(t.values?x(ee):ee)}).concat(t.values?w:w.map(function(ee){return x(ee)}));break;case"delete":var B=new Fe().addKeys(j.keys);k=v.filter(function(ee){return!B.hasKey(t.values?x(ee):ee)});break;case"deleteRange":var H=j.range;k=v.filter(function(ee){return!_r(x(ee),H)})}return k},e);return _===e?e:(_.sort(function(v,j){return be(g(v),g(j))||be(x(v),x(j))}),t.limit&&t.limit<1/0&&(_.length>t.limit?_.length=t.limit:e.length===t.limit&&_.length<t.limit&&(o.dirty=!0)),a?Object.freeze(_):_)}function ps(e,t){return be(e.lower,t.lower)===0&&be(e.upper,t.upper)===0&&!!e.lowerOpen==!!t.lowerOpen&&!!e.upperOpen==!!t.upperOpen}function Si(e,t){return function(n,r,o,a){if(n===void 0)return r!==void 0?-1:0;if(r===void 0)return 1;if((r=be(n,r))===0){if(o&&a)return 0;if(o)return 1;if(a)return-1}return r}(e.lower,t.lower,e.lowerOpen,t.lowerOpen)<=0&&0<=function(n,r,o,a){if(n===void 0)return r!==void 0?1:0;if(r===void 0)return-1;if((r=be(n,r))===0){if(o&&a)return 0;if(o)return-1;if(a)return 1}return r}(e.upper,t.upper,e.upperOpen,t.upperOpen)}function Ei(e,t,n,r){e.subscribers.add(n),r.addEventListener("abort",function(){var o,a;e.subscribers.delete(n),e.subscribers.size===0&&(o=e,a=t,setTimeout(function(){o.subscribers.size===0&&U(a,o)},3e3))})}var Di={stack:"dbcore",level:0,name:"Cache",create:function(e){var t=e.schema.name;return c(c({},e),{transaction:function(n,r,o){var a,h,m=e.transaction(n,r,o);return r==="readwrite"&&(h=(a=new AbortController).signal,o=function(b){return function(){if(a.abort(),r==="readwrite"){for(var x=new Set,N=0,g=n;N<g.length;N++){var _=g[N],v=_t["idb://".concat(t,"/").concat(_)];if(v){var j=e.table(_),k=v.optimisticOps.filter(function(ee){return ee.trans===m});if(m._explicit&&b&&m.mutatedParts)for(var w=0,E=Object.values(v.queries.query);w<E.length;w++)for(var D=0,P=(z=E[w]).slice();D<P.length;D++)br((I=P[D]).obsSet,m.mutatedParts)&&(U(z,I),I.subscribers.forEach(function(ee){return x.add(ee)}));else if(0<k.length){v.optimisticOps=v.optimisticOps.filter(function(ee){return ee.trans!==m});for(var O=0,K=Object.values(v.queries.query);O<K.length;O++)for(var z,I,B,H=0,L=(z=K[O]).slice();H<L.length;H++)(I=L[H]).res!=null&&m.mutatedParts&&(b&&!I.dirty?(B=Object.isFrozen(I.res),B=ms(I.res,I.req,k,j,I,B),I.dirty?(U(z,I),I.subscribers.forEach(function(ee){return x.add(ee)})):B!==I.res&&(I.res=B,I.promise=J.resolve({result:B}))):(I.dirty&&U(z,I),I.subscribers.forEach(function(ee){return x.add(ee)})))}}}x.forEach(function(ee){return ee()})}}},m.addEventListener("abort",o(!1),{signal:h}),m.addEventListener("error",o(!1),{signal:h}),m.addEventListener("complete",o(!0),{signal:h})),m},table:function(n){var r=e.table(n),o=r.schema.primaryKey;return c(c({},r),{mutate:function(a){var h=ae.trans;if(o.outbound||h.db._options.cache==="disabled"||h.explicit||h.idbtrans.mode!=="readwrite")return r.mutate(a);var m=_t["idb://".concat(t,"/").concat(n)];return m?(h=r.mutate(a),a.type!=="add"&&a.type!=="put"||!(50<=a.values.length||kr(o,a).some(function(b){return b==null}))?(m.optimisticOps.push(a),a.mutatedParts&&$n(a.mutatedParts),h.then(function(b){0<b.numFailures&&(U(m.optimisticOps,a),(b=fs(0,a,b))&&m.optimisticOps.push(b),a.mutatedParts&&$n(a.mutatedParts))}),h.catch(function(){U(m.optimisticOps,a),a.mutatedParts&&$n(a.mutatedParts)})):h.then(function(b){var x=fs(0,c(c({},a),{values:a.values.map(function(N,g){var _;return b.failures[g]?N:(N=(_=o.keyPath)!==null&&_!==void 0&&_.includes(".")?ke(N):c({},N),F(N,o.keyPath,b.results[g]),N)})}),b);m.optimisticOps.push(x),queueMicrotask(function(){return a.mutatedParts&&$n(a.mutatedParts)})}),h):r.mutate(a)},query:function(a){if(!ds(ae,r)||!hs("query",a))return r.query(a);var h=((x=ae.trans)===null||x===void 0?void 0:x.db._options.cache)==="immutable",g=ae,m=g.requery,b=g.signal,x=function(j,k,w,E){var D=_t["idb://".concat(j,"/").concat(k)];if(!D)return[];if(!(k=D.queries[w]))return[null,!1,D,null];var P=k[(E.query?E.query.index.name:null)||""];if(!P)return[null,!1,D,null];switch(w){case"query":var O=P.find(function(K){return K.req.limit===E.limit&&K.req.values===E.values&&ps(K.req.query.range,E.query.range)});return O?[O,!0,D,P]:[P.find(function(K){return("limit"in K.req?K.req.limit:1/0)>=E.limit&&(!E.values||K.req.values)&&Si(K.req.query.range,E.query.range)}),!1,D,P];case"count":return O=P.find(function(K){return ps(K.req.query.range,E.query.range)}),[O,!!O,D,P]}}(t,n,"query",a),N=x[0],g=x[1],_=x[2],v=x[3];return N&&g?N.obsSet=a.obsSet:(g=r.query(a).then(function(j){var k=j.result;if(N&&(N.res=k),h){for(var w=0,E=k.length;w<E;++w)Object.freeze(k[w]);Object.freeze(k)}else j.result=ke(k);return j}).catch(function(j){return v&&N&&U(v,N),Promise.reject(j)}),N={obsSet:a.obsSet,promise:g,subscribers:new Set,type:"query",req:a,dirty:!1},v?v.push(N):(v=[N],(_=_||(_t["idb://".concat(t,"/").concat(n)]={queries:{query:{},count:{}},objs:new Map,optimisticOps:[],unsignaledParts:{}})).queries.query[a.query.index.name||""]=v)),Ei(N,v,m,b),N.promise.then(function(j){return{result:ms(j.result,a,_==null?void 0:_.optimisticOps,r,N,h)}})}})}})}};function Tn(e,t){return new Proxy(e,{get:function(n,r,o){return r==="db"?t:Reflect.get(n,r,o)}})}var rt=($e.prototype.version=function(e){if(isNaN(e)||e<.1)throw new re.Type("Given version is not a positive number");if(e=Math.round(10*e)/10,this.idbdb||this._state.isBeingOpened)throw new re.Schema("Cannot add version when database is open");this.verno=Math.max(this.verno,e);var t=this._versions,n=t.filter(function(r){return r._cfg.version===e})[0];return n||(n=new this.Version(e),t.push(n),t.sort(bi),n.stores({}),this._state.autoSchema=!1,n)},$e.prototype._whenReady=function(e){var t=this;return this.idbdb&&(this._state.openComplete||ae.letThrough||this._vip)?e():new J(function(n,r){if(t._state.openComplete)return r(new re.DatabaseClosed(t._state.dbOpenError));if(!t._state.isBeingOpened){if(!t._state.autoOpen)return void r(new re.DatabaseClosed);t.open().catch(ve)}t._state.dbReadyPromise.then(n,r)}).then(e)},$e.prototype.use=function(e){var t=e.stack,n=e.create,r=e.level,o=e.name;return o&&this.unuse({stack:t,name:o}),e=this._middlewares[t]||(this._middlewares[t]=[]),e.push({stack:t,create:n,level:r??10,name:o}),e.sort(function(a,h){return a.level-h.level}),this},$e.prototype.unuse=function(e){var t=e.stack,n=e.name,r=e.create;return t&&this._middlewares[t]&&(this._middlewares[t]=this._middlewares[t].filter(function(o){return r?o.create!==r:!!n&&o.name!==n})),this},$e.prototype.open=function(){var e=this;return jt(ot,function(){return ji(e)})},$e.prototype._close=function(){var e=this._state,t=Kt.indexOf(this);if(0<=t&&Kt.splice(t,1),this.idbdb){try{this.idbdb.close()}catch{}this.idbdb=null}e.isBeingOpened||(e.dbReadyPromise=new J(function(n){e.dbReadyResolve=n}),e.openCanceller=new J(function(n,r){e.cancelOpen=r}))},$e.prototype.close=function(n){var t=(n===void 0?{disableAutoOpen:!0}:n).disableAutoOpen,n=this._state;t?(n.isBeingOpened&&n.cancelOpen(new re.DatabaseClosed),this._close(),n.autoOpen=!1,n.dbOpenError=new re.DatabaseClosed):(this._close(),n.autoOpen=this._options.autoOpen||n.isBeingOpened,n.openComplete=!1,n.dbOpenError=null)},$e.prototype.delete=function(e){var t=this;e===void 0&&(e={disableAutoOpen:!0});var n=0<arguments.length&&typeof arguments[0]!="object",r=this._state;return new J(function(o,a){function h(){t.close(e);var m=t._deps.indexedDB.deleteDatabase(t.name);m.onsuccess=De(function(){var b,x,N;b=t._deps,x=t.name,N=b.indexedDB,b=b.IDBKeyRange,pr(N)||x===bn||mr(N,b).delete(x).catch(ve),o()}),m.onerror=et(a),m.onblocked=t._fireOnBlocked}if(n)throw new re.InvalidArgument("Invalid closeOptions argument to db.delete()");r.isBeingOpened?r.dbReadyPromise.then(h):h()})},$e.prototype.backendDB=function(){return this.idbdb},$e.prototype.isOpen=function(){return this.idbdb!==null},$e.prototype.hasBeenClosed=function(){var e=this._state.dbOpenError;return e&&e.name==="DatabaseClosed"},$e.prototype.hasFailed=function(){return this._state.dbOpenError!==null},$e.prototype.dynamicallyOpened=function(){return this._state.autoSchema},Object.defineProperty($e.prototype,"tables",{get:function(){var e=this;return y(this._allTables).map(function(t){return e._allTables[t]})},enumerable:!1,configurable:!0}),$e.prototype.transaction=function(){var e=(function(t,n,r){var o=arguments.length;if(o<2)throw new re.InvalidArgument("Too few arguments");for(var a=new Array(o-1);--o;)a[o-1]=arguments[o];return r=a.pop(),[t,X(a),r]}).apply(this,arguments);return this._transaction.apply(this,e)},$e.prototype._transaction=function(e,t,n){var r=this,o=ae.trans;o&&o.db===this&&e.indexOf("!")===-1||(o=null);var a,h,m=e.indexOf("?")!==-1;e=e.replace("!","").replace("?","");try{if(h=t.map(function(x){if(x=x instanceof r.Table?x.name:x,typeof x!="string")throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return x}),e=="r"||e===nr)a=nr;else{if(e!="rw"&&e!=rr)throw new re.InvalidArgument("Invalid transaction mode: "+e);a=rr}if(o){if(o.mode===nr&&a===rr){if(!m)throw new re.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");o=null}o&&h.forEach(function(x){if(o&&o.storeNames.indexOf(x)===-1){if(!m)throw new re.SubTransaction("Table "+x+" not included in parent transaction.");o=null}}),m&&o&&!o.active&&(o=null)}}catch(x){return o?o._promise(null,function(N,g){g(x)}):Pe(x)}var b=(function x(N,g,_,v,j){return J.resolve().then(function(){var k=ae.transless||ae,w=N._createTransaction(g,_,N._dbSchema,v);if(w.explicit=!0,k={trans:w,transless:k},v)w.idbtrans=v.idbtrans;else try{w.create(),w.idbtrans._explicit=!0,N._state.PR1398_maxLoop=3}catch(P){return P.name===Qe.InvalidState&&N.isOpen()&&0<--N._state.PR1398_maxLoop?(console.warn("Dexie: Need to reopen db"),N.close({disableAutoOpen:!1}),N.open().then(function(){return x(N,g,_,null,j)})):Pe(P)}var E,D=we(j);return D&&Mt(),k=J.follow(function(){var P;(E=j.call(w,w))&&(D?(P=lt.bind(null,null),E.then(P,P)):typeof E.next=="function"&&typeof E.throw=="function"&&(E=jr(E)))},k),(E&&typeof E.then=="function"?J.resolve(E).then(function(P){return w.active?P:Pe(new re.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn"))}):k.then(function(){return E})).then(function(P){return v&&w._resolve(),w._completion.then(function(){return P})}).catch(function(P){return w._reject(P),Pe(P)})})}).bind(null,this,a,h,o,n);return o?o._promise(a,b,"lock"):ae.trans?jt(ae.transless,function(){return r._whenReady(b)}):this._whenReady(b)},$e.prototype.table=function(e){if(!A(this._allTables,e))throw new re.InvalidTable("Table ".concat(e," does not exist"));return this._allTables[e]},$e);function $e(e,t){var n=this;this._middlewares={},this.verno=0;var r=$e.dependencies;this._options=t=c({addons:$e.addons,autoOpen:!0,indexedDB:r.indexedDB,IDBKeyRange:r.IDBKeyRange,cache:"cloned"},t),this._deps={indexedDB:t.indexedDB,IDBKeyRange:t.IDBKeyRange},r=t.addons,this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null,this._novip=this;var o,a,h,m,b,x={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:ve,dbReadyPromise:null,cancelOpen:ve,openCanceller:null,autoSchema:!0,PR1398_maxLoop:3,autoOpen:t.autoOpen};x.dbReadyPromise=new J(function(g){x.dbReadyResolve=g}),x.openCanceller=new J(function(g,_){x.cancelOpen=_}),this._state=x,this.name=e,this.on=Yt(this,"populate","blocked","versionchange","close",{ready:[Vn,ve]}),this.on.ready.subscribe=G(this.on.ready.subscribe,function(g){return function(_,v){$e.vip(function(){var j,k=n._state;k.openComplete?(k.dbOpenError||J.resolve().then(_),v&&g(_)):k.onReadyBeingFired?(k.onReadyBeingFired.push(_),v&&g(_)):(g(_),j=n,v||g(function w(){j.on.ready.unsubscribe(_),j.on.ready.unsubscribe(w)}))})}}),this.Collection=(o=this,Wt(di.prototype,function(E,w){this.db=o;var v=Wr,j=null;if(w)try{v=w()}catch(D){j=D}var k=E._ctx,w=k.table,E=w.hook.reading.fire;this._ctx={table:w,index:k.index,isPrimKey:!k.index||w.schema.primKey.keyPath&&k.index===w.schema.primKey.name,range:v,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:j,or:k.or,valueMapper:E!==Ge?E:null}})),this.Table=(a=this,Wt(Jr.prototype,function(g,_,v){this.db=a,this._tx=v,this.name=g,this.schema=_,this.hook=a._allTables[g]?a._allTables[g].hook:Yt(null,{creating:[ni,ve],reading:[ti,Ge],updating:[si,ve],deleting:[ri,ve]})})),this.Transaction=(h=this,Wt(mi.prototype,function(g,_,v,j,k){var w=this;this.db=h,this.mode=g,this.storeNames=_,this.schema=v,this.chromeTransactionDurability=j,this.idbtrans=null,this.on=Yt(this,"complete","error","abort"),this.parent=k||null,this.active=!0,this._reculock=0,this._blockedFuncs=[],this._resolve=null,this._reject=null,this._waitingFor=null,this._waitingQueue=null,this._spinCount=0,this._completion=new J(function(E,D){w._resolve=E,w._reject=D}),this._completion.then(function(){w.active=!1,w.on.complete.fire()},function(E){var D=w.active;return w.active=!1,w.on.error.fire(E),w.parent?w.parent._reject(E):D&&w.idbtrans&&w.idbtrans.abort(),Pe(E)})})),this.Version=(m=this,Wt(wi.prototype,function(g){this.db=m,this._cfg={version:g,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}})),this.WhereClause=(b=this,Wt(ts.prototype,function(g,_,v){if(this.db=b,this._ctx={table:g,index:_===":id"?null:_,or:v},this._cmp=this._ascending=be,this._descending=function(j,k){return be(k,j)},this._max=function(j,k){return 0<be(j,k)?j:k},this._min=function(j,k){return be(j,k)<0?j:k},this._IDBKeyRange=b._deps.IDBKeyRange,!this._IDBKeyRange)throw new re.MissingAPI})),this.on("versionchange",function(g){0<g.newVersion?console.warn("Another connection wants to upgrade database '".concat(n.name,"'. Closing db now to resume the upgrade.")):console.warn("Another connection wants to delete database '".concat(n.name,"'. Closing db now to resume the delete request.")),n.close({disableAutoOpen:!1})}),this.on("blocked",function(g){!g.newVersion||g.newVersion<g.oldVersion?console.warn("Dexie.delete('".concat(n.name,"') was blocked")):console.warn("Upgrade '".concat(n.name,"' blocked by other connection holding version ").concat(g.oldVersion/10))}),this._maxKey=Jt(t.IDBKeyRange),this._createTransaction=function(g,_,v,j){return new n.Transaction(g,_,v,n._options.chromeTransactionDurability,j)},this._fireOnBlocked=function(g){n.on("blocked").fire(g),Kt.filter(function(_){return _.name===n.name&&_!==n&&!_._state.vcFired}).map(function(_){return _.on("versionchange").fire(g)})},this.use(_i),this.use(Di),this.use(Ci),this.use(Ni),this.use(ki);var N=new Proxy(this,{get:function(g,_,v){if(_==="_vip")return!0;if(_==="table")return function(k){return Tn(n.table(k),N)};var j=Reflect.get(g,_,v);return j instanceof Jr?Tn(j,N):_==="tables"?j.map(function(k){return Tn(k,N)}):_==="_createTransaction"?function(){return Tn(j.apply(this,arguments),N)}:j}});this.vip=N,r.forEach(function(g){return g(n)})}var An,Je=typeof Symbol<"u"&&"observable"in Symbol?Symbol.observable:"@@observable",Pi=(Cr.prototype.subscribe=function(e,t,n){return this._subscribe(e&&typeof e!="function"?e:{next:e,error:t,complete:n})},Cr.prototype[Je]=function(){return this},Cr);function Cr(e){this._subscribe=e}try{An={indexedDB:d.indexedDB||d.mozIndexedDB||d.webkitIndexedDB||d.msIndexedDB,IDBKeyRange:d.IDBKeyRange||d.webkitIDBKeyRange}}catch{An={indexedDB:null,IDBKeyRange:null}}function ys(e){var t,n=!1,r=new Pi(function(o){var a=we(e),h,m=!1,b={},x={},N={get closed(){return m},unsubscribe:function(){m||(m=!0,h&&h.abort(),g&&dt.storagemutated.unsubscribe(v))}};o.start&&o.start(N);var g=!1,_=function(){return tr(j)},v=function(k){Pn(b,k),br(x,b)&&_()},j=function(){var k,w,E;!m&&An.indexedDB&&(b={},k={},h&&h.abort(),h=new AbortController,E=function(D){var P=Tt();try{a&&Mt();var O=at(e,D);return O=a?O.finally(lt):O}finally{P&&At()}}(w={subscr:k,signal:h.signal,requery:_,querier:e,trans:null}),Promise.resolve(E).then(function(D){n=!0,t=D,m||w.signal.aborted||(b={},function(P){for(var O in P)if(A(P,O))return;return 1}(x=k)||g||(dt(Zt,v),g=!0),tr(function(){return!m&&o.next&&o.next(D)}))},function(D){n=!1,["DatabaseClosedError","AbortError"].includes(D==null?void 0:D.name)||m||tr(function(){m||o.error&&o.error(D)})}))};return setTimeout(_,0),N});return r.hasValue=function(){return n},r.getValue=function(){return t},r}var Ct=rt;function Sr(e){var t=ht;try{ht=!0,dt.storagemutated.fire(e),wr(e,!0)}finally{ht=t}}Y(Ct,c(c({},We),{delete:function(e){return new Ct(e,{addons:[]}).delete()},exists:function(e){return new Ct(e,{addons:[]}).open().then(function(t){return t.close(),!0}).catch("NoSuchDatabaseError",function(){return!1})},getDatabaseNames:function(e){try{return t=Ct.dependencies,n=t.indexedDB,t=t.IDBKeyRange,(pr(n)?Promise.resolve(n.databases()).then(function(r){return r.map(function(o){return o.name}).filter(function(o){return o!==bn})}):mr(n,t).toCollection().primaryKeys()).then(e)}catch{return Pe(new re.MissingAPI)}var t,n},defineClass:function(){return function(e){C(this,e)}},ignoreTransaction:function(e){return ae.trans?jt(ae.transless,e):e()},vip:yr,async:function(e){return function(){try{var t=jr(e.apply(this,arguments));return t&&typeof t.then=="function"?t:J.resolve(t)}catch(n){return Pe(n)}}},spawn:function(e,t,n){try{var r=jr(e.apply(n,t||[]));return r&&typeof r.then=="function"?r:J.resolve(r)}catch(o){return Pe(o)}},currentTransaction:{get:function(){return ae.trans||null}},waitFor:function(e,t){return t=J.resolve(typeof e=="function"?Ct.ignoreTransaction(e):e).timeout(t||6e4),ae.trans?ae.trans.waitFor(t):t},Promise:J,debug:{get:function(){return Xe},set:function(e){Fr(e)}},derive:ne,extend:C,props:Y,override:G,Events:Yt,on:dt,liveQuery:ys,extendObservabilitySet:Pn,getByKeyPath:Q,setByKeyPath:F,delByKeyPath:function(e,t){typeof t=="string"?F(e,t,void 0):"length"in t&&[].map.call(t,function(n){F(e,n,void 0)})},shallowClone:W,deepClone:ke,getObjectDiff:Nr,cmp:be,asap:me,minKey:-1/0,addons:[],connections:Kt,errnames:Qe,dependencies:An,cache:_t,semVer:"4.0.11",version:"4.0.11".split(".").map(function(e){return parseInt(e)}).reduce(function(e,t,n){return e+t/Math.pow(10,2*n)})})),Ct.maxKey=Jt(Ct.dependencies.IDBKeyRange),typeof dispatchEvent<"u"&&typeof addEventListener<"u"&&(dt(Zt,function(e){ht||(e=new CustomEvent(ar,{detail:e}),ht=!0,dispatchEvent(e),ht=!1)}),addEventListener(ar,function(e){e=e.detail,ht||Sr(e)}));var Ft,ht=!1,gs=function(){};return typeof BroadcastChannel<"u"&&((gs=function(){(Ft=new BroadcastChannel(ar)).onmessage=function(e){return e.data&&Sr(e.data)}})(),typeof Ft.unref=="function"&&Ft.unref(),dt(Zt,function(e){ht||Ft.postMessage(e)})),typeof addEventListener<"u"&&(addEventListener("pagehide",function(e){if(!rt.disableBfCache&&e.persisted){Xe&&console.debug("Dexie: handling persisted pagehide"),Ft!=null&&Ft.close();for(var t=0,n=Kt;t<n.length;t++)n[t].close({disableAutoOpen:!1})}}),addEventListener("pageshow",function(e){!rt.disableBfCache&&e.persisted&&(Xe&&console.debug("Dexie: handling persisted pageshow"),gs(),Sr({all:new Fe(-1/0,[[]])}))})),J.rejectionMapper=function(e,t){return!e||e instanceof _e||e instanceof TypeError||e instanceof SyntaxError||!e.name||!Ie[e.name]?e:(t=new Ie[e.name](t||e.message,e),"stack"in e&&T(t,"stack",{get:function(){return this.inner.stack}}),t)},Fr(Xe),c(rt,Object.freeze({__proto__:null,Dexie:rt,liveQuery:ys,Entity:Vr,cmp:be,PropModification:Vt,replacePrefix:function(e,t){return new Vt({replacePrefix:[e,t]})},add:function(e){return new Vt({add:e})},remove:function(e){return new Vt({remove:e})},default:rt,RangeSet:Fe,mergeRanges:Xt,rangesOverlap:os}),{default:rt}),rt})})(Ms);var Bo=Ms.exports;const Tr=Bn(Bo),ws=Symbol.for("Dexie"),Ar=globalThis[ws]||(globalThis[ws]=Tr);if(Tr.semVer!==Ar.semVer)throw new Error(`Two different versions of Dexie loaded in the same app: ${Tr.semVer} and ${Ar.semVer}`);async function Lo(i,l){const u=await l.limit(i.maxSize).toArray();for(const c of u)i.add(c.tagValue,c.eventId,!1)}var zo=(i,l)=>async(u,c)=>{const f=[];for(const d of u){const y=c.get(d);if(y)for(const p of y)f.push({tagValue:d,eventId:p})}f.length>0&&(l(`Saving ${f.length} events cache entries to database`),await i.bulkPut(f)),u.clear()};async function Uo(i,l){const u=await l.limit(i.maxSize).toArray();for(const c of u)i.set(c.id,c,!1)}var Yo=(i,l)=>async(u,c)=>{const f=[];for(const d of u){const y=c.get(d);y&&f.push(y)}f.length>0&&(l(`Saving ${f.length} events cache entries to database`),await i.bulkPut(f)),u.clear()};async function Wo(i,l){const u=await l.limit(i.maxSize).toArray();for(const c of u)i.set(c.nip05,c,!1)}var Vo=(i,l)=>async(u,c)=>{const f=[];for(const d of u){const y=c.get(d);y&&f.push({nip05:d,...y})}f.length&&(l(`Saving ${f.length} NIP-05 cache entries to database`),await i.bulkPut(f)),u.clear()},Ho=class extends Ar{constructor(l){super(l);xe(this,"profiles");xe(this,"events");xe(this,"eventTags");xe(this,"nip05");xe(this,"lnurl");xe(this,"relayStatus");xe(this,"unpublishedEvents");this.version(15).stores({profiles:"&pubkey",events:"&id, kind",eventTags:"&tagValue",nip05:"&nip05",lnurl:"&pubkey",relayStatus:"&url",unpublishedEvents:"&id"})}},Oe;function Zo(i){Oe=new Ho(i)}var Jo=Es("ndk:dexie-adapter:profiles");async function Qo(i,l){const u=await l.limit(i.maxSize).toArray();for(const c of u){const f=c;i.set(c.pubkey,f,!1)}Jo("Loaded %d profiles from database",i.size())}var Go=(i,l)=>async(u,c)=>{const f=[];for(const d of u){const y=c.get(d);y&&f.push(y)}f.length&&(l(`Saving ${f.length} users to database`),await i.bulkPut(f)),u.clear()};async function Xo(i,l){const u=await l.limit(i.maxSize).toArray();for(const c of u)i.set(c.url,{url:c.url,updatedAt:c.updatedAt,lastConnectedAt:c.lastConnectedAt,dontConnectBefore:c.dontConnectBefore},!1)}var ea=(i,l)=>async(u,c)=>{const f=[];for(const d of u){const y=c.get(d);y&&f.push({url:d,updatedAt:y.updatedAt,lastConnectedAt:y.lastConnectedAt,dontConnectBefore:y.dontConnectBefore})}f.length>0&&(l(`Saving ${f.length} relay status cache entries to database`),await i.bulkPut(f)),u.clear()},ta=3;async function na(i,l){await l.each(u=>{i.set(u.event.id,u,!1)})}function ra(i,l){return async(u,c)=>{const f=[];for(const d of u){const y=c.get(d);y&&f.push(y)}f.length>0&&(l(`Saving ${f.length} unpublished events cache entries to database`),await i.bulkPut(f)),u.clear()}}async function sa(i,l){await i.delete(l)}async function ia(i){const l=[];return await i.each(u=>{l.push({event:new Pt(void 0,u.event),relays:Object.keys(u.relays),lastTryAt:u.lastTryAt})}),l}function oa(i,l){const u={};l.forEach(f=>u[f]=!1),this.unpublishedEvents.set(i.id,{id:i.id,event:i.rawEvent(),relays:u});const c=f=>{const d=f.url,y=this.unpublishedEvents.get(i.id);if(!y){i.off("publushed",c);return}y.relays[d]=!0,this.unpublishedEvents.set(i.id,y);const p=Object.values(y.relays).filter(S=>S).length,C=Object.values(y.relays).length-p;(p>=ta||C===0)&&(this.unpublishedEvents.delete(i.id),i.off("published",c))};i.on("published",c)}async function aa(i,l){const u=await l.limit(i.maxSize).toArray();for(const c of u)i.set(c.pubkey,{document:c.document,fetchedAt:c.fetchedAt},!1)}var la=(i,l)=>async(u,c)=>{const f=[];for(const d of u){const y=c.get(d);y&&f.push({pubkey:d,...y})}f.length&&(l(`Saving ${f.length} zapper cache entries to database`),await i.bulkPut(f)),u.clear()},Et=class{constructor(i){xe(this,"cache");xe(this,"dirtyKeys",new Set);xe(this,"options");xe(this,"debug");xe(this,"indexes");xe(this,"isSet",!1);xe(this,"maxSize",0);this.debug=i.debug,this.options=i,this.maxSize=i.maxSize,i.maxSize>0&&(this.cache=new bs.LRUCache({maxSize:i.maxSize}),setInterval(()=>this.dump().catch(console.error),1e3*10)),this.indexes=new Map}getSet(i){var l;return(l=this.cache)==null?void 0:l.get(i)}getAllWithFilter(i){var u;const l=new Map;return(u=this.cache)==null||u.forEach((c,f)=>{i(f,c)&&l.set(f,c)}),l}get(i){var l;return(l=this.cache)==null?void 0:l.get(i)}async getWithFallback(i,l){let u=this.get(i);return u||(u=await l.get(i),u&&this.set(i,u)),u}async getManyWithFallback(i,l){const u=[],c=[];for(const f of i){const d=this.get(f);d?u.push(d):c.push(f)}if(u.length>0&&this.debug(`Cache hit for keys ${u.length} and miss for ${c.length} keys`),c.length>0){const f=Date.now(),d=await l.bulkGet(c),y=Date.now();let p=0;for(const C of d)C&&(this.set(C.id,C),u.push(C),p++);this.debug(`Time spent querying database: ${y-f}ms for ${c.length} keys, which added ${p} entries to the cache`)}return u}add(i,l,u=!0){var f;const c=this.get(i)??new Set;c.add(l),(f=this.cache)==null||f.set(i,c),u&&this.dirtyKeys.add(i)}set(i,l,u=!0){var c;(c=this.cache)==null||c.set(i,l),u&&this.dirtyKeys.add(i);for(const[f,d]of this.indexes.entries()){const y=l[f];if(y){const p=d.get(y)||new Set;p.add(i),d.set(y,p)}}}size(){var i;return((i=this.cache)==null?void 0:i.size)||0}delete(i){var l;(l=this.cache)==null||l.delete(i),this.dirtyKeys.add(i)}async dump(){this.dirtyKeys.size>0&&this.cache&&(await this.options.dump(this.dirtyKeys,this.cache),this.dirtyKeys.clear())}addIndex(i){this.indexes.set(i,new bs.LRUCache({maxSize:this.options.maxSize}))}getFromIndex(i,l){const u=new Set,c=this.indexes.get(i);if(c){const f=c.get(l);if(f)for(const d of f.values()){const y=this.get(d);y&&u.add(y)}}return u}},ca=10,ua=class{constructor(i={}){xe(this,"debug");xe(this,"locking",!1);xe(this,"ready",!1);xe(this,"profiles");xe(this,"zappers");xe(this,"nip05s");xe(this,"events");xe(this,"eventTags");xe(this,"relayInfo");xe(this,"unpublishedEvents");xe(this,"warmedUp",!1);xe(this,"warmUpPromise");xe(this,"devMode",!1);xe(this,"saveSig");xe(this,"_onReady");xe(this,"addUnpublishedEvent",oa.bind(this));xe(this,"getUnpublishedEvents",()=>ia(Oe.unpublishedEvents));xe(this,"discardUnpublishedEvent",i=>sa(Oe.unpublishedEvents,i));Zo(i.dbName||"ndk"),this.debug=i.debug||Es("ndk:dexie-adapter"),this.saveSig=i.saveSig||!1,this.profiles=new Et({maxSize:i.profileCacheSize||1e5,dump:Go(Oe.profiles,this.debug),debug:this.debug}),this.zappers=new Et({maxSize:i.zapperCacheSize||200,dump:la(Oe.lnurl,this.debug),debug:this.debug}),this.nip05s=new Et({maxSize:i.nip05CacheSize||1e3,dump:Vo(Oe.nip05,this.debug),debug:this.debug}),this.events=new Et({maxSize:i.eventCacheSize||5e4,dump:Yo(Oe.events,this.debug),debug:this.debug}),this.events.addIndex("pubkey"),this.events.addIndex("kind"),this.eventTags=new Et({maxSize:i.eventTagsCacheSize||1e5,dump:zo(Oe.eventTags,this.debug),debug:this.debug}),this.relayInfo=new Et({maxSize:500,debug:this.debug,dump:ea(Oe.relayStatus,this.debug)}),this.unpublishedEvents=new Et({maxSize:5e3,debug:this.debug,dump:ra(Oe.unpublishedEvents,this.debug)});const l=(c,f)=>{const d=Date.now();return f().then(()=>{const y=Date.now();this.debug(c,"took",y-d,"ms")})},u=Date.now();this.warmUpPromise=Promise.allSettled([l("profilesWarmUp",()=>Qo(this.profiles,Oe.profiles)),l("zapperWarmUp",()=>aa(this.zappers,Oe.lnurl)),l("nip05WarmUp",()=>Wo(this.nip05s,Oe.nip05)),l("relayInfoWarmUp",()=>Xo(this.relayInfo,Oe.relayStatus)),l("unpublishedEventsWarmUp",()=>na(this.unpublishedEvents,Oe.unpublishedEvents)),l("eventsWarmUp",()=>Uo(this.events,Oe.events)),l("eventTagsWarmUp",()=>Lo(this.eventTags,Oe.eventTags))]),this.warmUpPromise.then(()=>{const c=Date.now();this.warmedUp=!0,this.ready=!0,this.locking=!0,this.debug("Warm up completed, time",c-u,"ms"),this._onReady&&this._onReady()})}onReady(i){this._onReady=i}async query(i){if(!this.warmedUp){const c=Date.now();await this.warmUpPromise,this.debug("froze query for",Date.now()-c,"ms",i.filters)}const l=Date.now();i.filters.map(c=>this.processFilter(c,i));const u=Date.now()-l;return u>100&&this.debug("query took",u,"ms",i.filter),[]}async fetchProfile(i){return this.profiles?await this.profiles.getWithFallback(i,Oe.profiles):null}fetchProfileSync(i){return this.profiles?this.profiles.get(i):null}async getProfiles(i){if(this.profiles)return this.profiles.getAllWithFilter(i)}saveProfile(i,l){const u=this.profiles.get(i);if(u!=null&&u.created_at&&l.created_at&&u.created_at>=l.created_at)return;const c=Math.floor(Date.now()/1e3);this.profiles.set(i,{pubkey:i,...l,cachedAt:c}),this.debug("Saved profile for pubkey",i,l)}async loadNip05(i,l=3600){var d;const u=(d=this.nip05s)==null?void 0:d.get(i);if(u){if(u.profile===null)return u.fetchedAt+l*1e3<Date.now()?"missing":null;try{return JSON.parse(u.profile)}catch{return"missing"}}const c=await Oe.nip05.get({nip05:i});if(!c)return"missing";const f=Date.now();if(c.profile===null)return c.fetchedAt+l*1e3<f?"missing":null;try{return JSON.parse(c.profile)}catch{return"missing"}}async saveNip05(i,l){try{const u=l?JSON.stringify(l):null;this.nip05s.set(i,{profile:u,fetchedAt:Date.now()})}catch(u){console.error("Failed to save NIP-05 profile for nip05:",i,u)}}async loadUsersLNURLDoc(i,l=86400,u=3600){var y;const c=(y=this.zappers)==null?void 0:y.get(i);if(c){if(c.document===null)return c.fetchedAt+u*1e3<Date.now()?"missing":null;try{return JSON.parse(c.document)}catch{return"missing"}}const f=await Oe.lnurl.get({pubkey:i});if(!f)return"missing";const d=Date.now();if(f.fetchedAt+l*1e3<d)return"missing";if(f.document===null)return f.fetchedAt+u*1e3<d?"missing":null;try{return JSON.parse(f.document)}catch{return"missing"}}async saveUsersLNURLDoc(i,l){var u;try{const c=l?JSON.stringify(l):null;(u=this.zappers)==null||u.set(i,{document:c,fetchedAt:Date.now()})}catch(c){console.error("Failed to save LNURL document for pubkey:",i,c)}}processFilter(i,l){const u={...i};u.limit=void 0;const c=new Set(Object.keys(u||{}));c.delete("since"),c.delete("limit"),c.delete("until");try{if(this.byNip33Query(c,i,l)||this.byAuthors(i,l)||this.byIdsQuery(i,l)||this.byTags(i,l)||this.byKinds(c,i,l))return}catch(f){console.error(f)}}async deleteEventIds(i){i.forEach(l=>this.events.delete(l)),await Oe.events.where({id:i}).delete()}async setEvent(i,l,u){if(i.kind===0){if(!this.profiles)return;try{const f=Ri(i);this.saveProfile(i.pubkey,f)}catch{this.debug(`Failed to save profile for pubkey: ${i.pubkey}`)}}let c=!0;if(i.isParamReplaceable()){const f=this.events.get(i.tagId());f&&i.created_at&&f.createdAt>i.created_at&&(c=!1)}if(c){const f={id:i.tagId(),pubkey:i.pubkey,kind:i.kind,createdAt:i.created_at??Date.now(),relay:u==null?void 0:u.url,event:i.serialize(this.saveSig,!0)};this.saveSig&&i.sig&&(f.sig=i.sig),this.events.set(i.tagId(),f);const d=ha(i);for(const y of d)this.eventTags.add(y[0]+y[1],i.tagId())}}updateRelayStatus(i,l){const u={url:i,updatedAt:Date.now(),...l};this.relayInfo.set(i,u)}getRelayStatus(i){const l=this.relayInfo.get(i);if(l)return{lastConnectedAt:l.lastConnectedAt,dontConnectBefore:l.dontConnectBefore}}byAuthors(i,l){if(!i.authors)return!1;let u=0;for(const c of i.authors){let f=Array.from(this.events.getFromIndex("pubkey",c));i.kinds&&(f=f.filter(d=>{var y;return(y=i.kinds)==null?void 0:y.includes(d.kind)})),da(l,f,i),u+=f.length}return!0}byIdsQuery(i,l){if(i.ids){for(const u of i.ids){const c=this.events.get(u);c&&tn(l,c,c.relay,i)}return!0}return!1}byNip33Query(i,l,u){const c=["#d","authors","kinds"];if(i.size===c.length&&c.every(d=>i.has(d))&&l.kinds&&l.authors){for(const d of l.kinds)if(d>=3e4&&d<4e4)for(const p of l.authors)for(const C of l["#d"]){const S=`${d}:${p}:${C}`,$=this.events.get(S);$&&tn(u,$,$.relay,l)}return!0}return!1}byTags(i,l){const u=Object.entries(i).filter(([c])=>c.startsWith("#")&&c.length===2).map(([c,f])=>[c[1],f]);if(u.length===0)return!1;for(const[c,f]of u)for(const d of f){const y=c+d,p=this.eventTags.getSet(y);p&&p.forEach(C=>{const S=this.events.get(C);S&&(!i.kinds||i.kinds.includes(S.kind))&&tn(l,S,S.relay,i)})}return!0}byKinds(i,l,u){if(!l.kinds||i.size!==1||!i.has("kinds"))return!1;const c=l.limit||500;let f=0;const d=new Set,y=[...l.kinds].sort((p,C)=>{var S,$,A,Y;return((($=(S=this.events.indexes.get("kind"))==null?void 0:S.get(p))==null?void 0:$.size)||0)-(((Y=(A=this.events.indexes.get("kind"))==null?void 0:A.get(C))==null?void 0:Y.size)||0)});for(const p of y){const C=this.events.getFromIndex("kind",p);for(const S of C)if(!d.has(S.id)&&(d.add(S.id),tn(u,S,S.relay,l),f++,f>=c))break;if(f>=c)break}return!0}};function da(i,l,u){u!=null&&u.limit&&l.length>u.limit&&(l=l.sort((c,f)=>f.createdAt-c.createdAt).slice(0,u.limit));for(const c of l)tn(i,c,c.relay,u)}function tn(i,l,u,c){try{const f=Fi(l.event);if(c&&!qi(c,f))return;const d=new Pt(void 0,f),y=u?i.pool.getRelay(u,!1):void 0;d.relay=y,i.eventReceived(d,y,!0)}catch(f){console.error("failed to deserialize event",f)}}function ha(i){const l=[];if(i.kind===3)return[];for(const u of i.tags)if(u[0].length===1&&(l.push(u),l.length>=ca))return[];return l}function sn(i){const l=new Date;return new Date(i)<=l?"since":"until"}function Ks(i,l=!1){const u=i.tags,c=u.some(p=>p[0]==="type"&&(p[1]==="since"||p[1]==="until")),f=u.some(p=>p[0]==="title"&&p[1]&&p[1].length>0),d=u.some(p=>p[0]==="date"&&p[1]&&/^\d{4}-\d{2}-\d{2}$/.test(p[1]));return c&&f&&d?l?u.some(C=>C[0]==="visibility"&&C[1]==="public"):!0:!1}function Un(i,l=!1){var u,c,f,d;try{console.log("Parsing event:",i);const y=i.tags;console.log("Event tags:",y),y.forEach((M,T)=>{console.log(`Tag ${T}:`,M)});let p=(u=y.find(M=>M[0]==="type"))==null?void 0:u[1],C=(c=y.find(M=>M[0]==="title"))==null?void 0:c[1],S=(f=y.find(M=>M[0]==="date"))==null?void 0:f[1],$=(d=y.find(M=>M[0]==="visibility"))==null?void 0:d[1];if(!p||!C||!S){console.log("Standard tags not found, trying alternative parsing...");for(const M of y)M[0]==="d"&&M[1]&&(C||(C=M[1])),M[0]==="t"&&M[1]&&(p||(p=M[1]));if(i.content&&i.content.trim()!=="")try{const M=JSON.parse(i.content);console.log("Parsed content:",M),!C&&M.title&&(C=M.title),!p&&M.type&&(p=M.type),!S&&M.date&&(S=M.date),!$&&M.visibility&&($=M.visibility)}catch{console.log("Content is not JSON:",i.content)}}if(console.log("Parsed tags:",{typeTag:p,titleTag:C,dateTag:S,visibilityTag:$}),!C||!S)return console.log("Missing required title or date, skipping event"),null;if(p||(p="since"),$||($="public"),p!=="since"&&p!=="until")return console.log("Invalid type tag:",p),null;if($!=="public"&&$!=="private")return console.log("Invalid visibility tag:",$),null;if(!/^\d{4}-\d{2}-\d{2}$/.test(S))return console.log("Invalid date format:",S),null;if(C.length<2||C.length>100)return console.log("Invalid title length:",C.length),null;if(l&&$!=="public")return console.log("Counter is not public, skipping:",$),null;const Y={id:i.id,title:C,date:S,type:p,visibility:$,pubkey:i.pubkey,createdAt:i.created_at||0,slug:i.id};return console.log("Created counter:",Y),Y}catch(y){return console.error("Error parsing counter event:",y),null}}function Is(i,l){const u={kinds:[30078],limit:100};return i&&(u.authors=[i]),console.log("getCounterFilter: Created filter:",u,{pubkey:i,isPublic:l}),u}const Rs=["wss://relay.azzamo.net","wss://relay.damus.io","wss://nostr.oxtr.dev","wss://nos.lol","wss://relay.snort.social"];function fa(i){if(!i||!i.includes("@"))return null;const[l,u]=i.split("@");return{name:l,domain:u}}function Fs(i){return i.lud16?i.lud16:i.lud06?i.lud06:null}const ma=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_RELAYS:Rs,deriveCounterType:sn,eventToCounter:Un,extractLightningAddress:Fs,getCounterFilter:Is,isValidCounterEvent:Ks,parseNip05:fa},Symbol.toStringTag,{value:"Module"})),qs=R.createContext(null),Ze=()=>{const i=R.useContext(qs);if(!i)throw new Error("useNDK must be used within NDKProvider");return i},pa=({children:i})=>{const[l,u]=R.useState(null),[c,f]=R.useState(null),[d,y]=R.useState(null),[p,C]=R.useState(!1),[S,$]=R.useState(!0);R.useEffect(()=>{(async()=>{try{console.log("Initializing NDK with Dexie cache...");const G=new ua({dbName:"nostrcount-cache"}),de=new Bi({explicitRelayUrls:Rs,cacheAdapter:G});console.log("Connecting to relays..."),await de.connect(),console.log("NDK connected successfully with cache"),u(de),$(!1)}catch(G){console.error("Failed to initialize NDK:",G),$(!1)}})()},[]);const A=async()=>{if(l)try{if($(!0),console.log("Attempting login with NIP-07 extension..."),window.nostr){console.log("Nostr extension found, getting public key...");const ie=await window.nostr.getPublicKey();console.log("Got public key:",ie);const G=l.getUser({pubkey:ie});l.signer={user:async()=>G,sign:async me=>{if(console.log("Signing event with NIP-07 extension..."),!window.nostr)throw new Error("Nostr extension not available");const Q={kind:me.kind,created_at:me.created_at||Math.floor(Date.now()/1e3),tags:me.tags,content:me.content,pubkey:me.pubkey};console.log("Raw event to sign:",Q);const F=await window.nostr.signEvent(Q);return console.log("Event signed successfully:",F),me.sig=F.sig,me.sig},blockUntilReady:async()=>!0},f(G),C(!0),console.log("Login successful with NIP-07");const de=await pe(ie);y(de)}else throw new Error("No Nostr extension found")}catch(ie){throw console.error("Login failed:",ie),ie}finally{$(!1)}},Y=async(ie,G)=>{if(l)try{$(!0),console.log("Attempting login with keys...");let de,me;if(G&&!ie)try{const te=nn.decode(G).data;de=Dr(te),me=te,console.log("Derived public key from private key:",de)}catch{throw new Error("Invalid nsec format")}else if(ie&&G){try{de=nn.decode(ie).data}catch{throw new Error("Invalid npub format")}try{me=nn.decode(G).data}catch{throw new Error("Invalid nsec format")}if(Dr(me)!==de)throw new Error("Public key does not match private key")}else throw new Error("Please provide a valid private key");console.log("Keys verified successfully");const Q=l.getUser({pubkey:de}),F=Array.from(me).map(X=>X.toString(16).padStart(2,"0")).join(""),W=new Li(F);l.signer=W,console.log("Signer set successfully"),f(Q),C(!0),console.log("Login successful with keys");const le=await pe(de);y(le)}catch(de){throw console.error("Keys login failed:",de),de}finally{$(!1)}},M=async ie=>{if(l)try{throw $(!0),console.log("Attempting NIP-55 login with URL:",ie),new Error("NIP-55 login not yet implemented")}catch(G){throw console.error("NIP-55 login failed:",G),G}finally{$(!1)}},T=()=>{console.log("Logging out..."),f(null),y(null),C(!1),l&&(l.signer=void 0)},ne=async ie=>{if(!l||!c)throw new Error("NDK not initialized or user not logged in");try{console.log("Creating NDK event with data:",ie);const G=new Pt(l,{...ie,pubkey:c.pubkey});return console.log("Signing event..."),await G.sign(),console.log("Event signed successfully"),console.log("Publishing event..."),await G.publish(),console.log("Event published successfully"),G}catch(G){throw console.error("Error in publishEvent:",G),G}},pe=async ie=>{if(!l)return null;try{console.log("Fetching user profile for:",ie);const G=l.getUser({pubkey:ie});return await G.fetchProfile(),G.profile?(console.log("User profile fetched:",G.profile),{pubkey:ie,name:G.profile.name,display_name:G.profile.display_name,about:G.profile.about,picture:G.profile.picture,nip05:G.profile.nip05,lud16:G.profile.lud16,lud06:G.profile.lud06}):(console.log("No profile found for user"),null)}catch(G){return console.error("Error fetching user profile:",G),null}},ue=async ie=>{if(!l||!c)throw new Error("NDK not initialized or user not logged in");try{console.log("Updating user profile:",ie);const G=new Pt(l);G.kind=0,G.content=JSON.stringify(ie),console.log("Publishing profile update..."),await G.sign(),await G.publish(),console.log("Profile updated successfully");const de=await pe(c.pubkey);y(de)}catch(G){throw console.error("Error updating user profile:",G),G}};return s.jsx(qs.Provider,{value:{ndk:l,user:c,userProfile:d,isConnected:p,isLoading:S,login:A,loginWithKeys:Y,loginWithNip55:M,logout:T,publishEvent:ne,fetchUserProfile:pe,updateUserProfile:ue},children:i})};var ya={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const ga=i=>i.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ce=(i,l)=>{const u=R.forwardRef(({color:c="currentColor",size:f=24,strokeWidth:d=2,absoluteStrokeWidth:y,children:p,...C},S)=>R.createElement("svg",{ref:S,...ya,width:f,height:f,stroke:c,strokeWidth:y?Number(d)*24/Number(f):d,className:`lucide lucide-${ga(i)}`,...C},[...l.map(([$,A])=>R.createElement($,A)),...(Array.isArray(p)?p:[p])||[]]));return u.displayName=`${i}`,u},js=Ce("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]),ba=Ce("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),Ns=Ce("BarChart3",[["path",{d:"M3 3v18h18",key:"1s2lah"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]]),mt=Ce("Calendar",[["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",ry:"2",key:"eu3xkr"}],["line",{x1:"16",x2:"16",y1:"2",y2:"6",key:"m3sa8f"}],["line",{x1:"8",x2:"8",y1:"2",y2:"6",key:"18kwsl"}],["line",{x1:"3",x2:"21",y1:"10",y2:"10",key:"xt86sb"}]]),Bs=Ce("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]),Mr=Ce("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),Ls=Ce("ExternalLink",[["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}],["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["line",{x1:"10",x2:"21",y1:"14",y2:"3",key:"18c3s4"}]]),zs=Ce("EyeOff",[["path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24",key:"1jxqfv"}],["path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68",key:"9wicm4"}],["path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61",key:"1jreej"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]),cn=Ce("Eye",[["path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z",key:"rwhkz3"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),va=Ce("Home",[["path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"y5dka4"}],["polyline",{points:"9 22 9 12 15 12 15 22",key:"e2us08"}]]),xa=Ce("Key",[["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["path",{d:"m15.5 7.5 3 3L22 7l-3-3",key:"1rn1fs"}]]),Us=Ce("Loader2",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]),wa=Ce("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]),ja=Ce("MessageCircle",[["path",{d:"m3 21 1.9-5.7a8.5 8.5 0 1 1 3.8 3.8z",key:"v2veuj"}]]),Ys=Ce("PenSquare",[["path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1qinfi"}],["path",{d:"M18.5 2.5a2.12 2.12 0 0 1 3 3L12 15l-4 1 1-4Z",key:"w2jsv5"}]]),qt=Ce("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),ks=Ce("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]),Na=Ce("Save",[["path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z",key:"1owoqh"}],["polyline",{points:"17 21 17 13 7 13 7 21",key:"1md35c"}],["polyline",{points:"7 3 7 8 15 8",key:"8nz8an"}]]),Kr=Ce("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]),ka=Ce("Send",[["path",{d:"m22 2-7 20-4-9-9-4Z",key:"1q3vgg"}],["path",{d:"M22 2 11 13",key:"nzbqef"}]]),_a=Ce("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]),Ca=Ce("Shield",[["path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",key:"1irkt0"}]]),Ws=Ce("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]),Vs=Ce("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]),Sa=Ce("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]),Yn=Ce("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),Fn=Ce("Zap",[["polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2",key:"45s27k"}]]),Ea=({isOpen:i,onClose:l})=>{const{login:u,loginWithKeys:c,loginWithNip55:f,updateUserProfile:d}=Ze(),[y,p]=R.useState("extension"),[C,S]=R.useState("username"),[$,A]=R.useState(""),[Y,M]=R.useState("unknown"),[T,ne]=R.useState(""),[pe,ue]=R.useState(""),[ie,G]=R.useState(""),[de,me]=R.useState(""),[Q,F]=R.useState(!1),[W,le]=R.useState(null),X=q=>q.startsWith("npub")?"npub":q.startsWith("nsec")?"nsec":"unknown",te=q=>{A(q),M(X(q))},Ne=async()=>{try{F(!0),le(null),await u(),l()}catch(q){console.error("Extension login failed:",q),le(q instanceof Error?q.message:"Login failed")}finally{F(!1)}},ke=async()=>{if(!$.trim()){le("Please enter a public or private key");return}try{if(F(!0),le(null),Y==="nsec")await c("",$.trim());else if(Y==="npub"){le("Public key only provides read-only access. Please provide a private key for full access.");return}else{le("Please enter a valid npub or nsec key");return}l()}catch(q){console.error("Keys login failed:",q),le(q instanceof Error?q.message:"Login failed")}finally{F(!1)}},oe=async()=>{if(!T.trim()){le("Please enter a username");return}try{F(!0),le(null);const q=zi(),we=Dr(q),Se=nn.nsecEncode(q),_e=nn.npubEncode(we);ue(Se),G(_e),S("keys")}catch(q){console.error("Account creation failed:",q),le("Failed to create account")}finally{F(!1)}},Z=async()=>{try{F(!0),le(null),await c(ie,pe),await d({name:T,display_name:T}),l()}catch(q){console.error("Login with new keys failed:",q),le(q instanceof Error?q.message:"Login failed")}finally{F(!1)}},V=async()=>{if(!de.trim()){le("Please enter a NIP-55 URL");return}try{F(!0),le(null),await f(de),l()}catch(q){console.error("NIP-55 login failed:",q),le(q instanceof Error?q.message:"Login failed")}finally{F(!1)}},se=q=>{navigator.clipboard.writeText(q)},U=()=>{A(""),M("unknown"),ne(""),ue(""),G(""),me(""),le(null),S("username")},ce=()=>{U(),l()};return i?s.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-white rounded-lg max-w-md w-full max-h-[90vh] overflow-y-auto",children:[s.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[s.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:"Connect to Nostr"}),s.jsx("button",{onClick:ce,className:"p-2 hover:bg-gray-100 rounded-full transition-colors",disabled:Q,children:s.jsx(Yn,{className:"w-5 h-5 text-gray-500"})})]}),s.jsxs("div",{className:"p-6",children:[s.jsxs("div",{className:"flex gap-2 mb-6",children:[s.jsxs("button",{onClick:()=>p("extension"),className:`flex-1 px-3 py-2 rounded-md font-medium transition-colors text-sm ${y==="extension"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[s.jsx(Fn,{className:"w-4 h-4 inline mr-1"}),"Extension"]}),s.jsxs("button",{onClick:()=>p("keys"),className:`flex-1 px-3 py-2 rounded-md font-medium transition-colors text-sm ${y==="keys"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[s.jsx(xa,{className:"w-4 h-4 inline mr-1"}),"Keys"]}),s.jsxs("button",{onClick:()=>p("create"),className:`flex-1 px-3 py-2 rounded-md font-medium transition-colors text-sm ${y==="create"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[s.jsx(qt,{className:"w-4 h-4 inline mr-1"}),"Create"]}),s.jsxs("button",{onClick:()=>p("nip55"),className:`flex-1 px-3 py-2 rounded-md font-medium transition-colors text-sm ${y==="nip55"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[s.jsx(Ls,{className:"w-4 h-4 inline mr-1"}),"NIP-55"]})]}),y==="extension"&&s.jsxs("div",{children:[s.jsx("p",{className:"text-gray-600 mb-4",children:"Connect using your Nostr browser extension (Alby, nos2x, etc.)"}),s.jsx("button",{onClick:Ne,disabled:Q,className:"w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors font-medium disabled:opacity-50",children:Q?"Connecting...":"Connect Extension"})]}),y==="keys"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Public or Private Key"}),s.jsx("input",{type:"password",value:$,onChange:q=>te(q.target.value),placeholder:"npub1... or nsec1...",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:Q}),Y!=="unknown"&&s.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Detected: ",Y==="npub"?"Public Key (Read-only)":"Private Key (Full Access)"]})]}),s.jsx("button",{onClick:ke,disabled:Q||Y==="unknown",className:"w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors font-medium disabled:opacity-50",children:Q?"Connecting...":"Connect with Keys"})]}),y==="create"&&C==="username"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Choose a Username"}),s.jsx("input",{type:"text",value:T,onChange:q=>ne(q.target.value),placeholder:"your-username",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:Q}),s.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"This will be used to identify your account"})]}),s.jsx("button",{onClick:oe,disabled:Q||!T.trim(),className:"w-full px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 transition-colors font-medium disabled:opacity-50",children:Q?"Creating...":"Create Account"})]}),y==="create"&&C==="keys"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"bg-yellow-50 border border-yellow-200 rounded-md p-4",children:[s.jsx("h3",{className:"font-semibold text-yellow-800 mb-2",children:"Save Your Keys!"}),s.jsx("p",{className:"text-sm text-yellow-700 mb-3",children:"Store these keys safely. You'll need them to access your account."})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Private Key (nsec) - Keep Secret!"}),s.jsxs("div",{className:"relative",children:[s.jsx("input",{type:"password",value:pe,readOnly:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md bg-gray-50"}),s.jsx("button",{onClick:()=>se(pe),className:"absolute right-2 top-2 p-1 hover:bg-gray-200 rounded",children:s.jsx(Mr,{className:"w-4 h-4 text-gray-500"})})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Public Key (npub)"}),s.jsxs("div",{className:"relative",children:[s.jsx("input",{type:"text",value:ie,readOnly:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md bg-gray-50"}),s.jsx("button",{onClick:()=>se(ie),className:"absolute right-2 top-2 p-1 hover:bg-gray-200 rounded",children:s.jsx(Mr,{className:"w-4 h-4 text-gray-500"})})]})]}),s.jsx("button",{onClick:Z,disabled:Q,className:"w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors font-medium disabled:opacity-50",children:Q?"Connecting...":"Use These Keys"})]}),y==="nip55"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"NIP-55 URL"}),s.jsx("input",{type:"url",value:de,onChange:q=>me(q.target.value),placeholder:"https://example.com/.well-known/nostr.json",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:Q}),s.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Enter a NIP-55 compatible URL to connect with an external signer"})]}),s.jsx("button",{onClick:V,disabled:Q||!de.trim(),className:"w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors font-medium disabled:opacity-50",children:Q?"Connecting...":"Connect with NIP-55"})]}),W&&s.jsx("div",{className:"mt-4 p-3 bg-red-50 border border-red-200 rounded-md",children:s.jsx("p",{className:"text-red-600 text-sm",children:W})})]})]})}):null},Da=()=>{const{userProfile:i,isConnected:l,logout:u}=Ze(),c=Ai(),[f,d]=R.useState(!1),y=C=>c.pathname===C,p=()=>{l?u():d(!0)};return s.jsxs("header",{className:"bg-white shadow-sm border-b border-gray-200",children:[s.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:s.jsxs("div",{className:"flex justify-between items-center h-16",children:[s.jsxs("div",{className:"flex items-center gap-8",children:[s.jsxs(Re,{to:"/",className:"flex items-center gap-2",children:[s.jsx(Ns,{className:"w-8 h-8 text-blue-600"}),s.jsx("span",{className:"text-xl font-bold text-gray-900",children:"NostrCount"})]}),s.jsxs("nav",{className:"hidden md:flex items-center gap-6",children:[s.jsxs(Re,{to:"/",className:`flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${y("/")?"bg-blue-100 text-blue-700":"text-gray-600 hover:text-gray-900 hover:bg-gray-100"}`,children:[s.jsx(va,{className:"w-4 h-4"}),"Home"]}),s.jsxs(Re,{to:"/browse",className:`flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${y("/browse")?"bg-blue-100 text-blue-700":"text-gray-600 hover:text-gray-900 hover:bg-gray-100"}`,children:[s.jsx(cn,{className:"w-4 h-4"}),"Browse"]}),l&&s.jsxs(Re,{to:"/dashboard",className:`flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${y("/dashboard")?"bg-blue-100 text-blue-700":"text-gray-600 hover:text-gray-900 hover:bg-gray-100"}`,children:[s.jsx(Ns,{className:"w-4 h-4"}),"Dashboard"]})]})]}),s.jsxs("div",{className:"flex items-center gap-4",children:[l&&i&&s.jsxs("div",{className:"flex items-center gap-2",children:[i.picture&&s.jsx("img",{src:i.picture,alt:i.name||"User",className:"w-8 h-8 rounded-full"}),s.jsx("span",{className:"text-sm font-medium text-gray-700",children:i.display_name||i.name||"Anonymous"})]}),s.jsx("button",{onClick:p,className:`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-colors ${l?"text-gray-600 hover:text-gray-900 hover:bg-gray-100":"bg-blue-600 text-white hover:bg-blue-700"}`,children:l?s.jsxs(s.Fragment,{children:[s.jsx(wa,{className:"w-4 h-4"}),"Logout"]}):s.jsxs(s.Fragment,{children:[s.jsx(Vs,{className:"w-4 h-4"}),"Login"]})})]})]})}),s.jsx(Ea,{isOpen:f,onClose:()=>d(!1)})]})};var Hs={exports:{}};(function(i,l){(function(u,c){i.exports=c()})(qn,function(){var u=1e3,c=6e4,f=36e5,d="millisecond",y="second",p="minute",C="hour",S="day",$="week",A="month",Y="quarter",M="year",T="date",ne="Invalid Date",pe=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,ue=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,ie={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(oe){var Z=["th","st","nd","rd"],V=oe%100;return"["+oe+(Z[(V-20)%10]||Z[V]||Z[0])+"]"}},G=function(oe,Z,V){var se=String(oe);return!se||se.length>=Z?oe:""+Array(Z+1-se.length).join(V)+oe},de={s:G,z:function(oe){var Z=-oe.utcOffset(),V=Math.abs(Z),se=Math.floor(V/60),U=V%60;return(Z<=0?"+":"-")+G(se,2,"0")+":"+G(U,2,"0")},m:function oe(Z,V){if(Z.date()<V.date())return-oe(V,Z);var se=12*(V.year()-Z.year())+(V.month()-Z.month()),U=Z.clone().add(se,A),ce=V-U<0,q=Z.clone().add(se+(ce?-1:1),A);return+(-(se+(V-U)/(ce?U-q:q-U))||0)},a:function(oe){return oe<0?Math.ceil(oe)||0:Math.floor(oe)},p:function(oe){return{M:A,y:M,w:$,d:S,D:T,h:C,m:p,s:y,ms:d,Q:Y}[oe]||String(oe||"").toLowerCase().replace(/s$/,"")},u:function(oe){return oe===void 0}},me="en",Q={};Q[me]=ie;var F="$isDayjsObject",W=function(oe){return oe instanceof Ne||!(!oe||!oe[F])},le=function oe(Z,V,se){var U;if(!Z)return me;if(typeof Z=="string"){var ce=Z.toLowerCase();Q[ce]&&(U=ce),V&&(Q[ce]=V,U=ce);var q=Z.split("-");if(!U&&q.length>1)return oe(q[0])}else{var we=Z.name;Q[we]=Z,U=we}return!se&&U&&(me=U),U||!se&&me},X=function(oe,Z){if(W(oe))return oe.clone();var V=typeof Z=="object"?Z:{};return V.date=oe,V.args=arguments,new Ne(V)},te=de;te.l=le,te.i=W,te.w=function(oe,Z){return X(oe,{locale:Z.$L,utc:Z.$u,x:Z.$x,$offset:Z.$offset})};var Ne=function(){function oe(V){this.$L=le(V.locale,null,!0),this.parse(V),this.$x=this.$x||V.x||{},this[F]=!0}var Z=oe.prototype;return Z.parse=function(V){this.$d=function(se){var U=se.date,ce=se.utc;if(U===null)return new Date(NaN);if(te.u(U))return new Date;if(U instanceof Date)return new Date(U);if(typeof U=="string"&&!/Z$/i.test(U)){var q=U.match(pe);if(q){var we=q[2]-1||0,Se=(q[7]||"0").substring(0,3);return ce?new Date(Date.UTC(q[1],we,q[3]||1,q[4]||0,q[5]||0,q[6]||0,Se)):new Date(q[1],we,q[3]||1,q[4]||0,q[5]||0,q[6]||0,Se)}}return new Date(U)}(V),this.init()},Z.init=function(){var V=this.$d;this.$y=V.getFullYear(),this.$M=V.getMonth(),this.$D=V.getDate(),this.$W=V.getDay(),this.$H=V.getHours(),this.$m=V.getMinutes(),this.$s=V.getSeconds(),this.$ms=V.getMilliseconds()},Z.$utils=function(){return te},Z.isValid=function(){return this.$d.toString()!==ne},Z.isSame=function(V,se){var U=X(V);return this.startOf(se)<=U&&U<=this.endOf(se)},Z.isAfter=function(V,se){return X(V)<this.startOf(se)},Z.isBefore=function(V,se){return this.endOf(se)<X(V)},Z.$g=function(V,se,U){return te.u(V)?this[se]:this.set(U,V)},Z.unix=function(){return Math.floor(this.valueOf()/1e3)},Z.valueOf=function(){return this.$d.getTime()},Z.startOf=function(V,se){var U=this,ce=!!te.u(se)||se,q=te.p(V),we=function(re,Ie){var We=te.w(U.$u?Date.UTC(U.$y,Ie,re):new Date(U.$y,Ie,re),U);return ce?We:We.endOf(S)},Se=function(re,Ie){return te.w(U.toDate()[re].apply(U.toDate("s"),(ce?[0,0,0,0]:[23,59,59,999]).slice(Ie)),U)},_e=this.$W,Te=this.$M,Ke=this.$D,Ye="set"+(this.$u?"UTC":"");switch(q){case M:return ce?we(1,0):we(31,11);case A:return ce?we(1,Te):we(0,Te+1);case $:var Qe=this.$locale().weekStart||0,yt=(_e<Qe?_e+7:_e)-Qe;return we(ce?Ke-yt:Ke+(6-yt),Te);case S:case T:return Se(Ye+"Hours",0);case C:return Se(Ye+"Minutes",1);case p:return Se(Ye+"Seconds",2);case y:return Se(Ye+"Milliseconds",3);default:return this.clone()}},Z.endOf=function(V){return this.startOf(V,!1)},Z.$set=function(V,se){var U,ce=te.p(V),q="set"+(this.$u?"UTC":""),we=(U={},U[S]=q+"Date",U[T]=q+"Date",U[A]=q+"Month",U[M]=q+"FullYear",U[C]=q+"Hours",U[p]=q+"Minutes",U[y]=q+"Seconds",U[d]=q+"Milliseconds",U)[ce],Se=ce===S?this.$D+(se-this.$W):se;if(ce===A||ce===M){var _e=this.clone().set(T,1);_e.$d[we](Se),_e.init(),this.$d=_e.set(T,Math.min(this.$D,_e.daysInMonth())).$d}else we&&this.$d[we](Se);return this.init(),this},Z.set=function(V,se){return this.clone().$set(V,se)},Z.get=function(V){return this[te.p(V)]()},Z.add=function(V,se){var U,ce=this;V=Number(V);var q=te.p(se),we=function(Te){var Ke=X(ce);return te.w(Ke.date(Ke.date()+Math.round(Te*V)),ce)};if(q===A)return this.set(A,this.$M+V);if(q===M)return this.set(M,this.$y+V);if(q===S)return we(1);if(q===$)return we(7);var Se=(U={},U[p]=c,U[C]=f,U[y]=u,U)[q]||1,_e=this.$d.getTime()+V*Se;return te.w(_e,this)},Z.subtract=function(V,se){return this.add(-1*V,se)},Z.format=function(V){var se=this,U=this.$locale();if(!this.isValid())return U.invalidDate||ne;var ce=V||"YYYY-MM-DDTHH:mm:ssZ",q=te.z(this),we=this.$H,Se=this.$m,_e=this.$M,Te=U.weekdays,Ke=U.months,Ye=U.meridiem,Qe=function(Ie,We,ve,Ge){return Ie&&(Ie[We]||Ie(se,ce))||ve[We].slice(0,Ge)},yt=function(Ie){return te.s(we%12||12,Ie,"0")},re=Ye||function(Ie,We,ve){var Ge=Ie<12?"AM":"PM";return ve?Ge.toLowerCase():Ge};return ce.replace(ue,function(Ie,We){return We||function(ve){switch(ve){case"YY":return String(se.$y).slice(-2);case"YYYY":return te.s(se.$y,4,"0");case"M":return _e+1;case"MM":return te.s(_e+1,2,"0");case"MMM":return Qe(U.monthsShort,_e,Ke,3);case"MMMM":return Qe(Ke,_e);case"D":return se.$D;case"DD":return te.s(se.$D,2,"0");case"d":return String(se.$W);case"dd":return Qe(U.weekdaysMin,se.$W,Te,2);case"ddd":return Qe(U.weekdaysShort,se.$W,Te,3);case"dddd":return Te[se.$W];case"H":return String(we);case"HH":return te.s(we,2,"0");case"h":return yt(1);case"hh":return yt(2);case"a":return re(we,Se,!0);case"A":return re(we,Se,!1);case"m":return String(Se);case"mm":return te.s(Se,2,"0");case"s":return String(se.$s);case"ss":return te.s(se.$s,2,"0");case"SSS":return te.s(se.$ms,3,"0");case"Z":return q}return null}(Ie)||q.replace(":","")})},Z.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},Z.diff=function(V,se,U){var ce,q=this,we=te.p(se),Se=X(V),_e=(Se.utcOffset()-this.utcOffset())*c,Te=this-Se,Ke=function(){return te.m(q,Se)};switch(we){case M:ce=Ke()/12;break;case A:ce=Ke();break;case Y:ce=Ke()/3;break;case $:ce=(Te-_e)/6048e5;break;case S:ce=(Te-_e)/864e5;break;case C:ce=Te/f;break;case p:ce=Te/c;break;case y:ce=Te/u;break;default:ce=Te}return U?ce:te.a(ce)},Z.daysInMonth=function(){return this.endOf(A).$D},Z.$locale=function(){return Q[this.$L]},Z.locale=function(V,se){if(!V)return this.$L;var U=this.clone(),ce=le(V,se,!0);return ce&&(U.$L=ce),U},Z.clone=function(){return te.w(this.$d,this)},Z.toDate=function(){return new Date(this.valueOf())},Z.toJSON=function(){return this.isValid()?this.toISOString():null},Z.toISOString=function(){return this.$d.toISOString()},Z.toString=function(){return this.$d.toUTCString()},oe}(),ke=Ne.prototype;return X.prototype=ke,[["$ms",d],["$s",y],["$m",p],["$H",C],["$W",S],["$M",A],["$y",M],["$D",T]].forEach(function(oe){ke[oe[1]]=function(Z){return this.$g(Z,oe[0],oe[1])}}),X.extend=function(oe,Z){return oe.$i||(oe(Z,Ne,X),oe.$i=!0),X},X.locale=le,X.isDayjs=W,X.unix=function(oe){return X(1e3*oe)},X.en=Q[me],X.Ls=Q,X.p={},X})})(Hs);var Pa=Hs.exports;const $t=Bn(Pa);var Zs={exports:{}};(function(i,l){(function(u,c){i.exports=c()})(qn,function(){return function(u,c,f){u=u||{};var d=c.prototype,y={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function p(S,$,A,Y){return d.fromToBase(S,$,A,Y)}f.en.relativeTime=y,d.fromToBase=function(S,$,A,Y,M){for(var T,ne,pe,ue=A.$locale().relativeTime||y,ie=u.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],G=ie.length,de=0;de<G;de+=1){var me=ie[de];me.d&&(T=Y?f(S).diff(A,me.d,!0):A.diff(S,me.d,!0));var Q=(u.rounding||Math.round)(Math.abs(T));if(pe=T>0,Q<=me.r||!me.r){Q<=1&&de>0&&(me=ie[de-1]);var F=ue[me.l];M&&(Q=M(""+Q)),ne=typeof F=="string"?F.replace("%d",Q):F(Q,$,me.l,pe);break}}if($)return ne;var W=pe?ue.future:ue.past;return typeof W=="function"?W(ne):W.replace("%s",ne)},d.to=function(S,$){return p(S,$,this,!0)},d.from=function(S,$){return p(S,$,this)};var C=function(S){return S.$u?f.utc():f()};d.toNow=function(S){return this.to(C(this),S)},d.fromNow=function(S){return this.from(C(this),S)}}})})(Zs);var $a=Zs.exports;const Oa=Bn($a);var Js={exports:{}};(function(i,l){(function(u,c){i.exports=c()})(qn,function(){var u,c,f=1e3,d=6e4,y=36e5,p=864e5,C=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,S=31536e6,$=2628e6,A=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,Y={years:S,months:$,days:p,hours:y,minutes:d,seconds:f,milliseconds:1,weeks:6048e5},M=function(Q){return Q instanceof de},T=function(Q,F,W){return new de(Q,W,F.$l)},ne=function(Q){return c.p(Q)+"s"},pe=function(Q){return Q<0},ue=function(Q){return pe(Q)?Math.ceil(Q):Math.floor(Q)},ie=function(Q){return Math.abs(Q)},G=function(Q,F){return Q?pe(Q)?{negative:!0,format:""+ie(Q)+F}:{negative:!1,format:""+Q+F}:{negative:!1,format:""}},de=function(){function Q(W,le,X){var te=this;if(this.$d={},this.$l=X,W===void 0&&(this.$ms=0,this.parseFromMilliseconds()),le)return T(W*Y[ne(le)],this);if(typeof W=="number")return this.$ms=W,this.parseFromMilliseconds(),this;if(typeof W=="object")return Object.keys(W).forEach(function(oe){te.$d[ne(oe)]=W[oe]}),this.calMilliseconds(),this;if(typeof W=="string"){var Ne=W.match(A);if(Ne){var ke=Ne.slice(2).map(function(oe){return oe!=null?Number(oe):0});return this.$d.years=ke[0],this.$d.months=ke[1],this.$d.weeks=ke[2],this.$d.days=ke[3],this.$d.hours=ke[4],this.$d.minutes=ke[5],this.$d.seconds=ke[6],this.calMilliseconds(),this}}return this}var F=Q.prototype;return F.calMilliseconds=function(){var W=this;this.$ms=Object.keys(this.$d).reduce(function(le,X){return le+(W.$d[X]||0)*Y[X]},0)},F.parseFromMilliseconds=function(){var W=this.$ms;this.$d.years=ue(W/S),W%=S,this.$d.months=ue(W/$),W%=$,this.$d.days=ue(W/p),W%=p,this.$d.hours=ue(W/y),W%=y,this.$d.minutes=ue(W/d),W%=d,this.$d.seconds=ue(W/f),W%=f,this.$d.milliseconds=W},F.toISOString=function(){var W=G(this.$d.years,"Y"),le=G(this.$d.months,"M"),X=+this.$d.days||0;this.$d.weeks&&(X+=7*this.$d.weeks);var te=G(X,"D"),Ne=G(this.$d.hours,"H"),ke=G(this.$d.minutes,"M"),oe=this.$d.seconds||0;this.$d.milliseconds&&(oe+=this.$d.milliseconds/1e3,oe=Math.round(1e3*oe)/1e3);var Z=G(oe,"S"),V=W.negative||le.negative||te.negative||Ne.negative||ke.negative||Z.negative,se=Ne.format||ke.format||Z.format?"T":"",U=(V?"-":"")+"P"+W.format+le.format+te.format+se+Ne.format+ke.format+Z.format;return U==="P"||U==="-P"?"P0D":U},F.toJSON=function(){return this.toISOString()},F.format=function(W){var le=W||"YYYY-MM-DDTHH:mm:ss",X={Y:this.$d.years,YY:c.s(this.$d.years,2,"0"),YYYY:c.s(this.$d.years,4,"0"),M:this.$d.months,MM:c.s(this.$d.months,2,"0"),D:this.$d.days,DD:c.s(this.$d.days,2,"0"),H:this.$d.hours,HH:c.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:c.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:c.s(this.$d.seconds,2,"0"),SSS:c.s(this.$d.milliseconds,3,"0")};return le.replace(C,function(te,Ne){return Ne||String(X[te])})},F.as=function(W){return this.$ms/Y[ne(W)]},F.get=function(W){var le=this.$ms,X=ne(W);return X==="milliseconds"?le%=1e3:le=X==="weeks"?ue(le/Y[X]):this.$d[X],le||0},F.add=function(W,le,X){var te;return te=le?W*Y[ne(le)]:M(W)?W.$ms:T(W,this).$ms,T(this.$ms+te*(X?-1:1),this)},F.subtract=function(W,le){return this.add(W,le,!0)},F.locale=function(W){var le=this.clone();return le.$l=W,le},F.clone=function(){return T(this.$ms,this)},F.humanize=function(W){return u().add(this.$ms,"ms").locale(this.$l).fromNow(!W)},F.valueOf=function(){return this.asMilliseconds()},F.milliseconds=function(){return this.get("milliseconds")},F.asMilliseconds=function(){return this.as("milliseconds")},F.seconds=function(){return this.get("seconds")},F.asSeconds=function(){return this.as("seconds")},F.minutes=function(){return this.get("minutes")},F.asMinutes=function(){return this.as("minutes")},F.hours=function(){return this.get("hours")},F.asHours=function(){return this.as("hours")},F.days=function(){return this.get("days")},F.asDays=function(){return this.as("days")},F.weeks=function(){return this.get("weeks")},F.asWeeks=function(){return this.as("weeks")},F.months=function(){return this.get("months")},F.asMonths=function(){return this.as("months")},F.years=function(){return this.get("years")},F.asYears=function(){return this.as("years")},Q}(),me=function(Q,F,W){return Q.add(F.years()*W,"y").add(F.months()*W,"M").add(F.days()*W,"d").add(F.hours()*W,"h").add(F.minutes()*W,"m").add(F.seconds()*W,"s").add(F.milliseconds()*W,"ms")};return function(Q,F,W){u=W,c=W().$utils(),W.duration=function(te,Ne){var ke=W.locale();return T(te,{$l:ke},Ne)},W.isDuration=M;var le=F.prototype.add,X=F.prototype.subtract;F.prototype.add=function(te,Ne){return M(te)?me(this,te,1):le.bind(this)(te,Ne)},F.prototype.subtract=function(te,Ne){return M(te)?me(this,te,-1):X.bind(this)(te,Ne)}}})})(Js);var Ta=Js.exports;const Aa=Bn(Ta);$t.extend(Oa);$t.extend(Aa);function on(i,l){const u=$t(i),c=$t();return l==="since"?c.diff(u,"day"):u.diff(c,"day")}function _s(i){return $t(i).format("MMMM D, YYYY")}function Ma(i){return $t(i).isValid()}function Cs(){return $t().format("YYYY-MM-DD")}const Wn=({counter:i,onDelete:l,onEdit:u,onShare:c,showActions:f=!1})=>{const{user:d}=Ze(),y=(d==null?void 0:d.pubkey)===i.pubkey,p=on(i.date,i.type),C=i.type==="until"&&p<0,S=()=>i.type==="since"?p===0?"Today":`${p} days`:p===0?"Today":p>0?`${p} days`:`${Math.abs(p)} days ago`,$=()=>i.type==="since"||C?"since":"until";return s.jsx("div",{className:"bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow duration-200 border border-gray-200",children:s.jsxs("div",{className:"p-6",children:[s.jsxs("div",{className:"flex items-start justify-between mb-4",children:[s.jsx(Re,{to:`/counter/${i.slug}`,className:"text-lg font-semibold text-gray-900 leading-tight hover:text-blue-600 transition-colors",children:i.title}),s.jsxs("div",{className:"flex items-center gap-2",children:[i.visibility==="private"?s.jsx(zs,{className:"w-4 h-4 text-gray-400"}):s.jsx(cn,{className:"w-4 h-4 text-gray-400"}),f&&s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(Re,{to:`/counter/${i.slug}`,className:"p-1 text-gray-400 hover:text-blue-600 transition-colors",title:"View counter",children:s.jsx(Ls,{className:"w-4 h-4"})}),c&&s.jsx("button",{onClick:()=>c(i),className:"p-1 text-gray-400 hover:text-blue-600 transition-colors",title:"Share counter",children:s.jsx(_a,{className:"w-4 h-4"})}),y&&u&&s.jsx("button",{onClick:()=>u(i),className:"p-1 text-gray-400 hover:text-green-600 transition-colors",title:"Edit counter",children:s.jsx(Ys,{className:"w-4 h-4"})}),y&&l&&s.jsx("button",{onClick:()=>l(i.slug),className:"p-1 text-gray-400 hover:text-red-600 transition-colors",title:"Delete counter",children:s.jsx(Ws,{className:"w-4 h-4"})})]})]})]}),s.jsxs("div",{className:"text-center py-4",children:[s.jsx("div",{className:`text-4xl font-bold mb-2 ${C?"text-red-600":"text-blue-600"}`,children:S()}),s.jsxs("div",{className:"text-gray-600 text-sm",children:[$()," ",_s(i.date)]})]}),s.jsxs("div",{className:"flex items-center justify-between text-sm text-gray-500 pt-4 border-t border-gray-100",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(mt,{className:"w-4 h-4"}),s.jsx("span",{children:_s(i.date)})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(Bs,{className:"w-4 h-4"}),s.jsxs("span",{children:["Created ",new Date(i.createdAt*1e3).toLocaleDateString()]})]})]})]})})},an=({size:i="md",className:l=""})=>{const u={sm:"w-4 h-4",md:"w-8 h-8",lg:"w-12 h-12"};return s.jsx("div",{className:`animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 ${u[i]} ${l}`})};function Rr(i,l){const{ndk:u}=Ze(),[c,f]=R.useState([]),[d,y]=R.useState(!0),[p,C]=R.useState(null),S=R.useCallback(async()=>{if(console.log("useCounters: fetchCounters called",{pubkey:i,isPublic:l,ndk:!!u}),!u){console.log("useCounters: NDK not initialized, skipping fetch"),y(!1);return}try{y(!0),C(null);const A={kinds:[5],limit:100};i&&(A.authors=[i]),console.log("useCounters: Fetching deletion events...");const Y=await u.fetchEvents(A);console.log("useCounters: Fetched deletion events:",Y.size);const M=new Set;for(const ue of Y)for(const ie of ue.tags)if(ie[0]==="a"&&ie[1]){const G=ie[1].split(":");G.length===2&&G[0]==="30078"&&M.add(G[1])}console.log("useCounters: Deleted event IDs:",Array.from(M));const T=Is(i,l);console.log("useCounters: Using filter:",T),console.log("useCounters: Fetching counter events...");const ne=await u.fetchEvents(T);console.log("useCounters: Fetched events:",ne.size);const pe=[];for(const ue of ne){if(console.log("useCounters: Processing event:",ue.id),M.has(ue.id)){console.log("useCounters: Skipping deleted event:",ue.id);continue}if(!Ks(ue,l)){console.log("useCounters: Skipping invalid counter event:",ue.id);continue}const ie=Un(ue,l);ie?(console.log("useCounters: Valid counter found:",ie.title),pe.push(ie)):console.log("useCounters: Invalid counter event:",ue.id)}console.log("useCounters: Total valid counters:",pe.length),pe.sort((ue,ie)=>ie.createdAt-ue.createdAt),f(pe)}catch(A){console.error("useCounters: Error fetching counters:",A),C("Failed to fetch counters")}finally{y(!1)}},[u,i,l]);R.useEffect(()=>{console.log("useCounters: useEffect triggered",{pubkey:i,isPublic:l,ndk:!!u}),S()},[S]);const $=R.useCallback(()=>{console.log("useCounters: Manual refetch triggered"),S()},[S]);return{counters:c,loading:d,error:p,refetch:$}}function Ka(i){const{ndk:l}=Ze(),[u,c]=R.useState(null),[f,d]=R.useState(!0),[y,p]=R.useState(null);return R.useEffect(()=>{(async()=>{if(!(!l||!i))try{d(!0),p(null);const S={kinds:[30078],ids:[i]},$=await l.fetchEvents(S);if($.size===0){p("Counter not found");return}const Y=Array.from($).sort((T,ne)=>ne.created_at-T.created_at)[0],M=Un(Y);M?c(M):p("Invalid counter data")}catch(S){console.error("Error fetching counter:",S),p("Failed to fetch counter")}finally{d(!1)}})()},[l,i]),{counter:u,loading:f,error:y}}function Qs(){const{ndk:i,user:l}=Ze(),[u,c]=R.useState(!1),[f,d]=R.useState(null);return{createCounter:async p=>{if(!i||!l)throw new Error("NDK not initialized or user not logged in");try{c(!0),d(null),console.log("Creating counter with form data:",p);const C=sn(p.date);console.log("Derived type from date:",C);const S={kind:30078,content:"",tags:[["type",C],["title",p.title],["date",p.date],["visibility",p.visibility]],created_at:Math.floor(Date.now()/1e3),pubkey:l.pubkey};console.log("Event data:",S);const $=new Pt(i,S);console.log("NDK event created:",$),console.log("Signing event..."),await $.sign(),console.log("Event signed successfully"),console.log("Publishing event..."),await $.publish(),console.log("Event published successfully");const A=Un($);if(!A)throw new Error("Failed to parse created counter");return console.log("Counter created successfully:",A),A}catch(C){console.error("Error creating counter:",C);const S=C instanceof Error?C.message:"Failed to create counter";throw d(S),C}finally{c(!1)}},loading:u,error:f}}function Gs(){const{publishEvent:i}=Ze(),[l,u]=R.useState(!1),[c,f]=R.useState(null);return{deleteCounter:async y=>{try{u(!0),f(null);const p={kind:5,content:"Deleted counter",tags:[["a",`30078:${y}`]],created_at:Math.floor(Date.now()/1e3)};return await i(p)}catch(p){throw console.error("Error deleting counter:",p),f("Failed to delete counter"),p}finally{u(!1)}},loading:l,error:c}}const Ia=()=>{const{isConnected:i,ndk:l}=Ze(),{counters:u,loading:c,error:f,refetch:d}=Rr(void 0,!0);console.log("Home: Render state",{isConnected:i,ndkConnected:!!l,countersCount:u.length,loading:c,error:f});const y=Ir.useMemo(()=>[...u].sort((C,S)=>{const $=on(C.date,C.type),A=on(S.date,S.type);return Math.abs(A)-Math.abs($)}).slice(0,6),[u]);return s.jsxs("div",{className:"min-h-screen bg-gray-50",children:[s.jsx("div",{className:"bg-gradient-to-br from-blue-600 to-purple-700 text-white",children:s.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-20",children:s.jsxs("div",{className:"text-center",children:[s.jsx("h1",{className:"text-4xl md:text-6xl font-bold mb-6",children:"Track Your Life Milestones"}),s.jsx("p",{className:"text-xl md:text-2xl mb-8 text-blue-100 max-w-3xl mx-auto",children:"Count the days since your last achievement or until your next big event. Built on Nostr."}),s.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 justify-center",children:[i?s.jsxs(Re,{to:"/dashboard",className:"inline-flex items-center gap-2 px-8 py-3 bg-white text-blue-600 rounded-lg font-semibold hover:bg-blue-50 transition-colors",children:[s.jsx(qt,{className:"w-5 h-5"}),"Create Your First Counter"]}):s.jsxs("button",{onClick:()=>window.scrollTo({top:800,behavior:"smooth"}),className:"inline-flex items-center gap-2 px-8 py-3 bg-white text-blue-600 rounded-lg font-semibold hover:bg-blue-50 transition-colors",children:[s.jsx(mt,{className:"w-5 h-5"}),"Get Started"]}),s.jsxs(Re,{to:"/browse",className:"inline-flex items-center gap-2 px-8 py-3 border-2 border-white text-white rounded-lg font-semibold hover:bg-white hover:text-blue-600 transition-colors",children:[s.jsx(cn,{className:"w-5 h-5"}),"Browse Public Counters"]})]})]})})}),s.jsx("div",{className:"py-20 bg-white",children:s.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[s.jsxs("div",{className:"text-center mb-16",children:[s.jsx("h2",{className:"text-3xl md:text-4xl font-bold text-gray-900 mb-4",children:"Why NostrCount?"}),s.jsx("p",{className:"text-xl text-gray-600 max-w-2xl mx-auto",children:"Experience the future of personal tracking with decentralized technology"})]}),s.jsxs("div",{className:"grid md:grid-cols-3 gap-8",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4",children:s.jsx(Ca,{className:"w-8 h-8 text-blue-600"})}),s.jsx("h3",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Censorship Resistant"}),s.jsx("p",{className:"text-gray-600",children:"Your data is stored on the Nostr network, ensuring no single entity can control or delete your progress."})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4",children:s.jsx(Sa,{className:"w-8 h-8 text-purple-600"})}),s.jsx("h3",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Social & Shareable"}),s.jsx("p",{className:"text-gray-600",children:"Share your milestones with friends and family. Get support from the community on your journey."})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center mx-auto mb-4",children:s.jsx(Fn,{className:"w-8 h-8 text-yellow-600"})}),s.jsx("h3",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Lightning Zaps"}),s.jsx("p",{className:"text-gray-600",children:"Support others on their journey with Lightning Network tips. Every sat counts!"})]})]})]})}),s.jsx("div",{className:"py-20 bg-gray-50",children:s.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[s.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between mb-12",children:[s.jsxs("div",{className:"text-center md:text-left",children:[s.jsx("h2",{className:"text-3xl md:text-4xl font-bold text-gray-900 mb-4",children:"Featured Counters"}),s.jsx("p",{className:"text-xl text-gray-600",children:"See what others are tracking and celebrating"})]}),s.jsxs("div",{className:"mt-4 md:mt-0 flex gap-2",children:[s.jsxs("button",{onClick:d,disabled:c,className:"px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors text-sm disabled:opacity-50",children:[s.jsx(ks,{className:`w-4 h-4 inline mr-1 ${c?"animate-spin":""}`}),c?"Loading...":"Refetch"]}),s.jsxs(Re,{to:"/browse",className:"inline-flex items-center gap-2 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:["View All Counters",s.jsx(ba,{className:"w-4 h-4"})]})]})]}),c?s.jsx("div",{className:"flex justify-center items-center py-12",children:s.jsx(an,{size:"lg"})}):f?s.jsxs("div",{className:"text-center py-12",children:[s.jsx("div",{className:"w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4",children:s.jsx(ks,{className:"w-8 h-8 text-red-600"})}),s.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"Error Loading Counters"}),s.jsx("p",{className:"text-gray-600 mb-6",children:f}),s.jsx("button",{onClick:d,className:"px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"Try Again"})]}):y.length>0?s.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 gap-6",children:y.map(p=>s.jsx(Re,{to:`/counter/${p.slug}`,className:"block transform hover:scale-105 transition-transform",children:s.jsx(Wn,{counter:p})},p.id))}):s.jsxs("div",{className:"text-center py-12",children:[s.jsx("div",{className:"w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:s.jsx(mt,{className:"w-8 h-8 text-gray-400"})}),s.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"No public counters yet"}),s.jsx("p",{className:"text-gray-600 mb-6",children:"Be the first to create and share a public counter!"}),i&&s.jsxs(Re,{to:"/dashboard",className:"inline-flex items-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[s.jsx(qt,{className:"w-4 h-4"}),"Create First Counter"]})]})]})}),s.jsx("div",{className:"bg-blue-600 text-white py-20",children:s.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center",children:[s.jsx("h2",{className:"text-3xl md:text-4xl font-bold mb-4",children:"Ready to Start Tracking?"}),s.jsx("p",{className:"text-xl text-blue-100 mb-8 max-w-2xl mx-auto",children:"Join the decentralized movement. Track your progress, share your journey, and celebrate your milestones with the world."}),i?s.jsxs(Re,{to:"/dashboard",className:"inline-flex items-center gap-2 px-8 py-3 bg-white text-blue-600 rounded-lg font-semibold hover:bg-blue-50 transition-colors",children:[s.jsx(qt,{className:"w-5 h-5"}),"Create Your First Counter"]}):s.jsx("p",{className:"text-blue-100 mb-4",children:"Connect your Nostr account to get started"})]})})]})},Ra=({isOpen:i,onClose:l,onSubmit:u,initialData:c,isLoading:f=!1})=>{const[d,y]=R.useState({title:"",date:Cs(),type:"since",visibility:"private"}),[p,C]=R.useState({});R.useEffect(()=>{y(c||{title:"",date:Cs(),type:"since",visibility:"private"}),C({})},[c,i]);const S=sn(d.date),$=S==="since"?"Days Since":"Days Until",A=()=>{const T={};return d.title.trim()?d.title.length>100&&(T.title="Title must be 100 characters or less"):T.title="Title is required",d.date?Ma(d.date)||(T.date="Invalid date format"):T.date="Date is required",C(T),Object.keys(T).length===0},Y=async T=>{if(T.preventDefault(),!!A())try{const ne={...d,type:S};await u(ne),l()}catch(ne){console.error("Error submitting form:",ne)}},M=(T,ne)=>{y(pe=>({...pe,[T]:ne})),p[T]&&C(pe=>({...pe,[T]:void 0}))};return i?s.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-white rounded-lg max-w-md w-full max-h-[90vh] overflow-y-auto",children:[s.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[s.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:c?"Edit Counter":"Create Counter"}),s.jsx("button",{onClick:l,className:"p-2 hover:bg-gray-100 rounded-full transition-colors",disabled:f,children:s.jsx(Yn,{className:"w-5 h-5 text-gray-500"})})]}),s.jsxs("form",{onSubmit:Y,className:"p-6 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Title"}),s.jsx("input",{type:"text",value:d.title,onChange:T=>M("title",T.target.value),className:`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 ${p.title?"border-red-500":"border-gray-300"}`,placeholder:"e.g., Quit smoking",disabled:f}),p.title&&s.jsx("p",{className:"mt-1 text-sm text-red-600",children:p.title})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Date"}),s.jsxs("div",{className:"relative",children:[s.jsx("input",{type:"date",value:d.date,onChange:T=>M("date",T.target.value),className:`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 ${p.date?"border-red-500":"border-gray-300"}`,disabled:f}),s.jsx(mt,{className:"absolute right-3 top-2.5 w-5 h-5 text-gray-400 pointer-events-none"})]}),p.date&&s.jsx("p",{className:"mt-1 text-sm text-red-600",children:p.date})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Counter Type"}),s.jsx("div",{className:"px-3 py-2 bg-gray-50 border border-gray-300 rounded-md",children:s.jsxs("p",{className:"text-sm text-gray-700",children:[s.jsx("span",{className:"font-medium",children:$}),s.jsx("span",{className:"text-gray-500 ml-2",children:"(auto-detected from date)"})]})})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Visibility"}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsxs("button",{type:"button",onClick:()=>M("visibility","private"),className:`px-4 py-2 rounded-md border font-medium transition-colors flex items-center justify-center gap-2 ${d.visibility==="private"?"bg-blue-600 text-white border-blue-600":"bg-white text-gray-700 border-gray-300 hover:bg-gray-50"}`,disabled:f,children:[s.jsx(zs,{className:"w-4 h-4"}),"Private"]}),s.jsxs("button",{type:"button",onClick:()=>M("visibility","public"),className:`px-4 py-2 rounded-md border font-medium transition-colors flex items-center justify-center gap-2 ${d.visibility==="public"?"bg-blue-600 text-white border-blue-600":"bg-white text-gray-700 border-gray-300 hover:bg-gray-50"}`,disabled:f,children:[s.jsx(cn,{className:"w-4 h-4"}),"Public"]})]})]}),s.jsxs("div",{className:"flex gap-3 pt-4",children:[s.jsx("button",{type:"button",onClick:l,className:"flex-1 px-4 py-2 text-gray-700 bg-gray-100 rounded-md hover:bg-gray-200 transition-colors font-medium",disabled:f,children:"Cancel"}),s.jsx("button",{type:"submit",className:"flex-1 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors font-medium disabled:opacity-50",disabled:f,children:f?"Saving...":c?"Update":"Create"})]})]})]})}):null},Fa="modulepreload",qa=function(i){return"/"+i},Ss={},Xs=function(l,u,c){if(!u||u.length===0)return l();const f=document.getElementsByTagName("link");return Promise.all(u.map(d=>{if(d=qa(d),d in Ss)return;Ss[d]=!0;const y=d.endsWith(".css"),p=y?'[rel="stylesheet"]':"";if(!!c)for(let $=f.length-1;$>=0;$--){const A=f[$];if(A.href===d&&(!y||A.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${d}"]${p}`))return;const S=document.createElement("link");if(S.rel=y?"stylesheet":Fa,y||(S.as="script",S.crossOrigin=""),S.href=d,document.head.appendChild(S),y)return new Promise(($,A)=>{S.addEventListener("load",$),S.addEventListener("error",()=>A(new Error(`Unable to preload CSS for ${d}`)))})})).then(()=>l()).catch(d=>{const y=new Event("vite:preloadError",{cancelable:!0});if(y.payload=d,window.dispatchEvent(y),!y.defaultPrevented)throw d})},ei=({isOpen:i,onClose:l,counter:u,onUpdate:c})=>{const{publishEvent:f}=Ze(),[d,y]=R.useState({title:"",date:"",type:"since",visibility:"public"}),[p,C]=R.useState(!1);R.useEffect(()=>{i&&u&&y({title:u.title,date:u.date,type:u.type,visibility:u.visibility})},[i,u]);const S=async A=>{if(A.preventDefault(),!d.title.trim()){Le.error("Title is required");return}if(!d.date){Le.error("Date is required");return}try{C(!0);const Y={kind:30078,content:"",tags:[["type",d.type],["title",d.title],["date",d.date],["visibility",d.visibility]],created_at:Math.floor(Date.now()/1e3)};console.log("Updating counter with data:",Y);const M=await f(Y),{eventToCounter:T}=await Xs(()=>Promise.resolve().then(()=>ma),void 0),ne=T(M);if(ne)c(ne),Le.success("Counter updated successfully!"),l();else throw new Error("Failed to parse updated counter")}catch(Y){console.error("Error updating counter:",Y),Le.error("Failed to update counter. Please try again.")}finally{C(!1)}},$=()=>{p||l()};return i?s.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full max-h-[90vh] overflow-y-auto",children:[s.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[s.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Edit Counter"}),s.jsx("button",{onClick:$,disabled:p,className:"text-gray-400 hover:text-gray-600 transition-colors disabled:opacity-50",children:s.jsx(Yn,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:S,className:"p-6 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Title"}),s.jsx("input",{type:"text",value:d.title,onChange:A=>y({...d,title:A.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Enter counter title",disabled:p,required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Date"}),s.jsx("input",{type:"date",value:d.date,onChange:A=>y({...d,date:A.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:p,required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Type"}),s.jsxs("select",{value:d.type,onChange:A=>y({...d,type:A.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:p,children:[s.jsx("option",{value:"since",children:"Days Since"}),s.jsx("option",{value:"until",children:"Days Until"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Visibility"}),s.jsxs("select",{value:d.visibility,onChange:A=>y({...d,visibility:A.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:p,children:[s.jsx("option",{value:"public",children:"Public"}),s.jsx("option",{value:"private",children:"Private"})]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t border-gray-200",children:[s.jsx("button",{type:"button",onClick:$,disabled:p,className:"px-4 py-2 text-gray-700 bg-gray-100 rounded-lg font-medium hover:bg-gray-200 transition-colors disabled:opacity-50",children:"Cancel"}),s.jsx("button",{type:"submit",disabled:p||!d.title.trim()||!d.date,className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:p?s.jsxs(s.Fragment,{children:[s.jsx(Us,{className:"w-4 h-4 animate-spin"}),"Updating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(Na,{className:"w-4 h-4"}),"Update Counter"]})})]})]})]})}):null},Ba=()=>{const{user:i,isConnected:l}=Ze(),{counters:u,loading:c,refetch:f}=Rr(i==null?void 0:i.pubkey),{createCounter:d,loading:y}=Qs(),{deleteCounter:p}=Gs(),[C,S]=R.useState(!1),[$,A]=R.useState(!1),[Y,M]=R.useState(null),[T,ne]=R.useState(""),[pe,ue]=R.useState("all"),[ie,G]=R.useState("all");if(!l)return s.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Please log in to access your dashboard"}),s.jsx("p",{className:"text-gray-600",children:"Connect your Nostr account to create and manage your counters."})]})});const de=u.filter(X=>{const te=X.title.toLowerCase().includes(T.toLowerCase()),Ne=pe==="all"||X.type===pe,ke=ie==="all"||X.visibility===ie;return te&&Ne&&ke}),me=async X=>{try{await d(X),Le.success("Counter created successfully!"),f()}catch{Le.error("Failed to create counter. Please try again.")}},Q=async X=>{if(window.confirm("Are you sure you want to delete this counter?"))try{await p(X),Le.success("Counter deleted successfully!"),f()}catch{Le.error("Failed to delete counter. Please try again.")}},F=X=>{const te=`${window.location.origin}/counter/${X.slug}`;navigator.clipboard.writeText(te),Le.success("Counter link copied to clipboard!")},W=X=>{M(X),A(!0)},le=()=>{f()};return s.jsx("div",{className:"min-h-screen bg-gray-50",children:s.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[s.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between mb-8",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-3xl font-bold text-gray-900 mb-2",children:"My Counters"}),s.jsx("p",{className:"text-gray-600",children:"Track your progress and celebrate your milestones"})]}),s.jsxs("button",{onClick:()=>S(!0),className:"mt-4 md:mt-0 inline-flex items-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",children:[s.jsx(qt,{className:"w-5 h-5"}),"Create Counter"]})]}),s.jsx("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 mb-6",children:s.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[s.jsx("div",{className:"flex-1",children:s.jsxs("div",{className:"relative",children:[s.jsx(Kr,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4"}),s.jsx("input",{type:"text",placeholder:"Search counters...",value:T,onChange:X=>ne(X.target.value),className:"w-full pl-10 pr-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("select",{value:pe,onChange:X=>ue(X.target.value),className:"px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[s.jsx("option",{value:"all",children:"All Types"}),s.jsx("option",{value:"since",children:"Days Since"}),s.jsx("option",{value:"until",children:"Days Until"})]}),s.jsxs("select",{value:ie,onChange:X=>G(X.target.value),className:"px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[s.jsx("option",{value:"all",children:"All Visibility"}),s.jsx("option",{value:"public",children:"Public"}),s.jsx("option",{value:"private",children:"Private"})]})]})]})}),c?s.jsx("div",{className:"flex justify-center items-center py-12",children:s.jsx(an,{size:"lg"})}):de.length>0?s.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 gap-6",children:de.map(X=>s.jsx(Wn,{counter:X,onDelete:Q,onEdit:W,onShare:F,showActions:!0},X.id))}):s.jsx("div",{className:"text-center py-12",children:s.jsx("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-12",children:u.length===0?s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No counters yet"}),s.jsx("p",{className:"text-gray-500 mb-6",children:"Create your first counter to start tracking your progress"}),s.jsxs("button",{onClick:()=>S(!0),className:"inline-flex items-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",children:[s.jsx(qt,{className:"w-5 h-5"}),"Create Your First Counter"]})]}):s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No counters match your filters"}),s.jsx("p",{className:"text-gray-500",children:"Try adjusting your search or filter settings"})]})})}),s.jsx(Ra,{isOpen:C,onClose:()=>S(!1),onSubmit:me,isLoading:y}),Y&&s.jsx(ei,{isOpen:$,onClose:()=>{A(!1),M(null)},counter:Y,onUpdate:le})]})})},La=({counter:i,userProfile:l,className:u=""})=>{const[c,f]=R.useState(!1),[d,y]=R.useState(1e3),[p,C]=R.useState(""),[S,$]=R.useState(!1),A=l?Fs(l):null;if(!A)return null;const Y=async()=>{if(A)try{f(!0);const T=`lightning:${A}?amount=${d}&comment=${encodeURIComponent(p||`Zapped ${i.title}`)}`;window.open(T,"_blank"),$(!1)}catch(T){console.error("Error creating zap:",T)}finally{f(!1)}},M=[100,500,1e3,5e3,1e4];return S?s.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-white rounded-lg max-w-md w-full p-6",children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:["Zap ",i.title]}),s.jsx("button",{onClick:()=>$(!1),className:"text-gray-400 hover:text-gray-600",children:"×"})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Amount (sats)"}),s.jsx("div",{className:"grid grid-cols-3 gap-2 mb-2",children:M.map(T=>s.jsx("button",{onClick:()=>y(T),className:`px-3 py-2 rounded-md border font-medium transition-colors ${d===T?"bg-yellow-500 text-white border-yellow-500":"bg-white text-gray-700 border-gray-300 hover:bg-gray-50"}`,children:T},T))}),s.jsx("input",{type:"number",value:d,onChange:T=>y(Number(T.target.value)),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-yellow-500",placeholder:"Custom amount",min:"1"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Comment (optional)"}),s.jsx("textarea",{value:p,onChange:T=>C(T.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-yellow-500",rows:3,placeholder:"Add a comment..."})]}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx("button",{onClick:()=>$(!1),className:"flex-1 px-4 py-2 text-gray-700 bg-gray-100 rounded-md hover:bg-gray-200 transition-colors font-medium",children:"Cancel"}),s.jsxs("button",{onClick:Y,disabled:c,className:"flex-1 px-4 py-2 bg-yellow-500 text-white rounded-md hover:bg-yellow-600 transition-colors font-medium disabled:opacity-50 flex items-center justify-center gap-2",children:[s.jsx(Fn,{className:"w-4 h-4"}),c?"Creating...":"Zap"]})]})]})]})}):s.jsxs("button",{onClick:()=>$(!0),className:`inline-flex items-center gap-2 px-4 py-2 bg-yellow-500 text-white rounded-md hover:bg-yellow-600 transition-colors font-medium ${u}`,children:[s.jsx(Fn,{className:"w-4 h-4"}),"Zap"]})},za=({isOpen:i,onClose:l,counter:u})=>{const{ndk:c,user:f}=Ze(),[d,y]=R.useState(""),[p,C]=R.useState(!1),S=`Check out my ${u.type==="since"?"progress":"countdown"}: ${u.title}`;Ir.useEffect(()=>{i&&y(S)},[i,S]);const $=async()=>{if(!c||!f){Le.error("Please log in to share on Nostr");return}if(!d.trim()){Le.error("Please enter a message to share");return}try{C(!0);const{NDKEvent:Y}=await Xs(()=>import("./ndk-40656944.js").then(T=>T.j),[]),M=new Y(c);M.kind=1,M.content=d,M.tags=[["e",u.id,"","mention"],["p",u.pubkey,"","mention"]],console.log("Publishing Nostr share event:",{content:M.content,tags:M.tags,kind:M.kind}),await M.sign(),await M.publish(),Le.success("Shared on Nostr successfully!"),l()}catch(Y){console.error("Error publishing Nostr share:",Y),Le.error("Failed to share on Nostr. Please try again.")}finally{C(!1)}},A=()=>{p||l()};return i?s.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full max-h-[80vh] overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[s.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Share on Nostr"}),s.jsx("button",{onClick:A,disabled:p,className:"text-gray-400 hover:text-gray-600 transition-colors disabled:opacity-50",children:s.jsx(Yn,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"p-6",children:[s.jsxs("div",{className:"mb-4",children:[s.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Your message"}),s.jsx("textarea",{value:d,onChange:Y=>y(Y.target.value),placeholder:"Write your message...",className:"w-full h-32 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none",disabled:p})]}),s.jsx("div",{className:"text-xs text-gray-500 mb-4",children:"This will publish a NIP-1 text note that references the counter."}),s.jsxs("div",{className:"bg-gray-50 rounded-lg p-4 mb-4",children:[s.jsx("div",{className:"text-sm text-gray-600 mb-2",children:"Sharing counter:"}),s.jsx("div",{className:"font-medium text-gray-900",children:u.title}),s.jsxs("div",{className:"text-sm text-gray-600",children:[u.type==="since"?"Days since":"Days until"," ",new Date(u.date).toLocaleDateString()]})]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-3 p-6 border-t border-gray-200",children:[s.jsx("button",{onClick:A,disabled:p,className:"px-4 py-2 text-gray-700 bg-gray-100 rounded-lg font-medium hover:bg-gray-200 transition-colors disabled:opacity-50",children:"Cancel"}),s.jsx("button",{onClick:$,disabled:p||!d.trim(),className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:p?s.jsxs(s.Fragment,{children:[s.jsx(Us,{className:"w-4 h-4 animate-spin"}),"Publishing..."]}):s.jsxs(s.Fragment,{children:[s.jsx(ka,{className:"w-4 h-4"}),"Share on Nostr"]})})]})]})}):null},Ua=()=>{const{slug:i}=Mi(),{counter:l,loading:u,error:c}=Ka(i),{fetchUserProfile:f,user:d}=Ze(),{deleteCounter:y}=Gs(),[p,C]=R.useState(null),[S,$]=R.useState(!1),[A,Y]=R.useState(!1),[M,T]=R.useState(!1);R.useEffect(()=>{l&&l.pubkey&&($(!0),f(l.pubkey).then(C).catch(console.error).finally(()=>$(!1)))},[l,f]);const ne=()=>{const me=window.location.href;navigator.clipboard.writeText(me),Le.success("Counter link copied to clipboard!")},pe=()=>{l&&Y(!0)},ue=()=>{l&&T(!0)},ie=async()=>{if(l&&window.confirm("Are you sure you want to delete this counter?"))try{await y(l.slug),Le.success("Counter deleted successfully!"),window.location.href="/"}catch{Le.error("Failed to delete counter. Please try again.")}},G=()=>{window.location.reload()},de=(d==null?void 0:d.pubkey)===(l==null?void 0:l.pubkey);return u?s.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:s.jsx(an,{size:"lg"})}):c||!l?s.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Counter not found"}),s.jsx("p",{className:"text-gray-600 mb-6",children:"The counter you're looking for doesn't exist or has been deleted."}),s.jsxs(Re,{to:"/",className:"inline-flex items-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",children:[s.jsx(js,{className:"w-4 h-4"}),"Back to Home"]})]})}):s.jsxs("div",{className:"min-h-screen bg-gray-50",children:[s.jsxs("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[s.jsxs(Re,{to:"/",className:"inline-flex items-center gap-2 text-gray-600 hover:text-gray-900 mb-8 font-medium",children:[s.jsx(js,{className:"w-4 h-4"}),"Back to Home"]}),s.jsx("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden",children:s.jsx("div",{className:"p-8",children:s.jsx("div",{className:"max-w-md mx-auto",children:s.jsx(Wn,{counter:l})})})}),s.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 mt-6 p-6",children:[s.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Counter Details"}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Vs,{className:"w-5 h-5 text-gray-400"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-gray-600",children:"Created by:"}),S?s.jsx(an,{size:"sm",className:"ml-2"}):s.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[(p==null?void 0:p.picture)&&s.jsx("img",{src:p.picture,alt:p.name||"Author",className:"w-6 h-6 rounded-full"}),s.jsx("span",{className:"font-medium text-gray-900",children:(p==null?void 0:p.display_name)||(p==null?void 0:p.name)||`${l.pubkey.slice(0,8)}...${l.pubkey.slice(-8)}`})]})]})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(mt,{className:"w-5 h-5 text-gray-400"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-gray-600",children:"Target date:"}),s.jsx("div",{className:"font-medium text-gray-900 mt-1",children:new Date(l.date).toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"})})]})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Bs,{className:"w-5 h-5 text-gray-400"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-gray-600",children:"Created:"}),s.jsx("div",{className:"font-medium text-gray-900 mt-1",children:new Date(l.createdAt*1e3).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})})]})]})]})]}),s.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 mt-6 p-6",children:[s.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Actions"}),s.jsxs("div",{className:"flex flex-wrap gap-3",children:[s.jsxs("button",{onClick:ne,className:"inline-flex items-center gap-2 px-4 py-2 bg-gray-100 text-gray-700 rounded-lg font-medium hover:bg-gray-200 transition-colors",children:[s.jsx(Mr,{className:"w-4 h-4"}),"Copy Link"]}),s.jsxs("button",{onClick:pe,className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-500 text-white rounded-lg font-medium hover:bg-blue-600 transition-colors",children:[s.jsx(ja,{className:"w-4 h-4"}),"Share on Nostr"]}),de&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{onClick:ue,className:"inline-flex items-center gap-2 px-4 py-2 bg-green-600 text-white rounded-lg font-medium hover:bg-green-700 transition-colors",children:[s.jsx(Ys,{className:"w-4 h-4"}),"Edit Counter"]}),s.jsxs("button",{onClick:ie,className:"inline-flex items-center gap-2 px-4 py-2 bg-red-600 text-white rounded-lg font-medium hover:bg-red-700 transition-colors",children:[s.jsx(Ws,{className:"w-4 h-4"}),"Delete Counter"]})]}),p&&s.jsx(La,{counter:l,userProfile:p,className:"flex-shrink-0"})]})]}),s.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 mt-6 p-6",children:[s.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Nostr Details"}),s.jsxs("div",{className:"space-y-3 text-sm",children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-gray-600",children:"Event ID:"}),s.jsx("code",{className:"ml-2 px-2 py-1 bg-gray-100 rounded text-xs font-mono",children:l.id})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-gray-600",children:"Author Pubkey:"}),s.jsx("code",{className:"ml-2 px-2 py-1 bg-gray-100 rounded text-xs font-mono",children:l.pubkey})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-gray-600",children:"Kind:"}),s.jsx("code",{className:"ml-2 px-2 py-1 bg-gray-100 rounded text-xs font-mono",children:"30078"})]})]})]})]}),l&&s.jsx(za,{isOpen:A,onClose:()=>Y(!1),counter:l}),l&&s.jsx(ei,{isOpen:M,onClose:()=>T(!1),counter:l,onUpdate:G})]})},Ya=()=>{const{counters:i,loading:l,error:u}=Rr(void 0,!0),[c,f]=R.useState(""),[d,y]=R.useState("all"),p=R.useMemo(()=>{let S=i;if(d!=="all"&&(S=S.filter($=>$.type===d)),c.trim()){const $=c.toLowerCase();S=S.filter(A=>A.title.toLowerCase().includes($)||A.date.includes($))}return S.sort(($,A)=>{const Y=on($.date,$.type),M=on(A.date,A.type);return Math.abs(M)-Math.abs(Y)}),S},[i,c,d]),C=R.useMemo(()=>{const S=i.length,$=i.filter(Y=>Y.type==="since").length,A=i.filter(Y=>Y.type==="until").length;return{total:S,since:$,until:A}},[i]);return u?s.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Error Loading Counters"}),s.jsx("p",{className:"text-gray-600 mb-4",children:u}),s.jsx("button",{onClick:()=>window.location.reload(),className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:"Try Again"})]})}):s.jsxs("div",{className:"min-h-screen bg-gray-50",children:[s.jsx("div",{className:"bg-white border-b border-gray-200",children:s.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:s.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-3xl font-bold text-gray-900 mb-2",children:"Browse Public Counters"}),s.jsx("p",{className:"text-gray-600",children:"Discover and celebrate milestones from around the Nostr network"})]}),s.jsx("div",{className:"mt-4 md:mt-0",children:s.jsxs(Re,{to:"/dashboard",className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[s.jsx(mt,{className:"w-4 h-4"}),"Create Counter"]})})]})})}),s.jsx("div",{className:"bg-white border-b border-gray-200",children:s.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6",children:s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"text-2xl font-bold text-gray-900",children:C.total}),s.jsx("div",{className:"text-sm text-gray-600",children:"Total Counters"})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"text-2xl font-bold text-green-600",children:C.since}),s.jsx("div",{className:"text-sm text-gray-600",children:"Days Since"})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"text-2xl font-bold text-blue-600",children:C.until}),s.jsx("div",{className:"text-sm text-gray-600",children:"Days Until"})]})]})})}),s.jsx("div",{className:"bg-white border-b border-gray-200",children:s.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6",children:s.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[s.jsxs("div",{className:"flex-1 relative",children:[s.jsx(Kr,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-400"}),s.jsx("input",{type:"text",placeholder:"Search counters by title or date...",value:c,onChange:S=>f(S.target.value),className:"w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("button",{onClick:()=>y("all"),className:`px-4 py-2 rounded-lg font-medium transition-colors ${d==="all"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:"All"}),s.jsxs("button",{onClick:()=>y("since"),className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-1 ${d==="since"?"bg-green-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[s.jsx(cn,{className:"w-4 h-4"}),"Since"]}),s.jsxs("button",{onClick:()=>y("until"),className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-1 ${d==="until"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[s.jsx(mt,{className:"w-4 h-4"}),"Until"]})]})]})})}),s.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:l?s.jsx("div",{className:"flex justify-center items-center py-12",children:s.jsx(an,{size:"lg"})}):p.length>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mb-6",children:s.jsxs("p",{className:"text-gray-600",children:["Showing ",p.length," of ",i.length," counters"]})}),s.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:p.map(S=>s.jsx(Re,{to:`/counter/${S.slug}`,className:"block transform hover:scale-105 transition-transform",children:s.jsx(Wn,{counter:S})},S.id))})]}):s.jsxs("div",{className:"text-center py-12",children:[s.jsx("div",{className:"w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:s.jsx(Kr,{className:"w-8 h-8 text-gray-400"})}),s.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:c||d!=="all"?"No counters found":"No public counters yet"}),s.jsx("p",{className:"text-gray-600 mb-6",children:c||d!=="all"?"Try adjusting your search terms or filters":"Be the first to create and share a public counter!"}),!c&&d==="all"&&s.jsxs(Re,{to:"/dashboard",className:"inline-flex items-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[s.jsx(mt,{className:"w-4 h-4"}),"Create First Counter"]})]})})]})},Wa=()=>{const{isConnected:i,login:l,ndk:u,user:c}=Ze(),{createCounter:f,loading:d,error:y}=Qs(),[p,C]=R.useState(""),S=async()=>{try{C("Testing counter creation...");const T={title:"Test Counter",date:"2024-01-01",type:"since",visibility:"public"};console.log("Creating test counter with data:",T);const ne=await f(T);console.log("Test counter created:",ne),C(`✅ Counter created successfully! Event ID: ${ne.id}`)}catch(T){console.error("Test failed:",T),C(`❌ Test failed: ${T instanceof Error?T.message:"Unknown error"}`)}},$=async()=>{try{if(C("Testing NDK connection..."),!u){C("❌ NDK not initialized");return}const T={kinds:[1],limit:1},ne=await u.fetchEvents(T);C(`✅ NDK connection working! Found ${ne.size} events`)}catch(T){console.error("Connection test failed:",T),C(`❌ Connection test failed: ${T instanceof Error?T.message:"Unknown error"}`)}},A=async()=>{if(!u||!c){C("❌ NDK not initialized or user not logged in");return}try{C("Creating simple counter...");const T={kind:30078,content:"",tags:[["type","since"],["title","Simple Test"],["date","2024-01-01"],["visibility","public"]],created_at:Math.floor(Date.now()/1e3),pubkey:c.pubkey};console.log("Simple event data:",T);const ne=new Pt(u,T);console.log("Simple event created:",ne),console.log("Event tags:",ne.tags),console.log("Event kind:",ne.kind),console.log("Signing simple event..."),await ne.sign(),console.log("Simple event signed successfully"),console.log("Publishing simple event..."),await ne.publish(),console.log("Simple event published successfully"),C(`✅ Simple counter created! Event ID: ${ne.id}`)}catch(T){console.error("Simple test failed:",T),C(`❌ Simple test failed: ${T instanceof Error?T.message:"Unknown error"}`)}},Y=async()=>{if(!u||!c){C("❌ NDK not initialized or user not logged in");return}try{C("Creating counter manually...");const T="2024-01-01",ne=sn(T);console.log("Test date:",T),console.log("Derived type:",ne);const pe={kind:30078,content:"",tags:[["type",ne],["title","Manual Test Counter"],["date",T],["visibility","public"]],created_at:Math.floor(Date.now()/1e3),pubkey:c.pubkey};console.log("Manual event data:",pe);const ue=new Pt(u,pe);console.log("Event created with tags:",ue.tags),console.log("Signing event..."),await ue.sign(),console.log("Event signed successfully"),console.log("Publishing event..."),await ue.publish(),console.log("Event published successfully"),C(`✅ Manual counter created! Event ID: ${ue.id}`)}catch(T){console.error("Manual test failed:",T),C(`❌ Manual test failed: ${T instanceof Error?T.message:"Unknown error"}`)}},M=()=>{const T=[{date:"2023-01-01",expected:"since"},{date:"2024-01-01",expected:"since"},{date:"2025-01-01",expected:"until"},{date:new Date().toISOString().split("T")[0],expected:"since"}];let ne=`Testing type derivation:
|
||
`;T.forEach(({date:pe,expected:ue})=>{const ie=sn(pe);ne+=`${ie===ue?"✅":"❌"} ${pe} → ${ie} (expected: ${ue})
|
||
`}),C(ne)};return s.jsx("div",{className:"min-h-screen bg-gray-50 p-8",children:s.jsxs("div",{className:"max-w-2xl mx-auto",children:[s.jsx("h1",{className:"text-3xl font-bold mb-8",children:"NostrCount Test Page"}),s.jsxs("div",{className:"bg-white rounded-lg shadow p-6 mb-6",children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Connection Status"}),s.jsxs("p",{className:"mb-4",children:[s.jsx("strong",{children:"Connected:"})," ",i?"✅ Yes":"❌ No"]}),!i&&s.jsx("button",{onClick:l,className:"bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700",children:"Connect Nostr Extension"})]}),s.jsxs("div",{className:"bg-white rounded-lg shadow p-6 mb-6",children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Connection Test"}),s.jsx("button",{onClick:$,className:"bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 mr-2",children:"Test NDK Connection"}),p&&s.jsx("div",{className:"mt-4 p-4 bg-gray-100 rounded",children:s.jsx("pre",{className:"text-sm whitespace-pre-wrap",children:p})})]}),s.jsxs("div",{className:"bg-white rounded-lg shadow p-6 mb-6",children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Type Derivation Test"}),s.jsx("button",{onClick:M,className:"bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700",children:"Test Type Derivation"})]}),s.jsxs("div",{className:"bg-white rounded-lg shadow p-6 mb-6",children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Counter Creation Tests"}),i?s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("button",{onClick:S,disabled:d,className:"bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700 disabled:opacity-50 mr-2",children:d?"Creating...":"Create Test Counter (Hook)"}),s.jsx("button",{onClick:Y,className:"bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700 mr-2",children:"Create Manual Counter"}),s.jsx("button",{onClick:A,className:"bg-orange-600 text-white px-4 py-2 rounded hover:bg-orange-700",children:"Simple Test"})]}),y&&s.jsxs("p",{className:"text-red-600 mt-2",children:["Error: ",y]})]}):s.jsx("p",{className:"text-gray-600",children:"Please connect your Nostr extension first."})]}),s.jsxs("div",{className:"bg-white rounded-lg shadow p-6",children:[s.jsx("h2",{className:"text-xl font-semibold mb-4",children:"Debug Information"}),s.jsx("p",{className:"text-sm text-gray-600",children:"Check the browser console for detailed logs about the counter creation process."}),c&&s.jsx("div",{className:"mt-4 p-4 bg-gray-100 rounded",children:s.jsxs("p",{className:"text-sm",children:[s.jsx("strong",{children:"User Pubkey:"})," ",c.pubkey]})})]})]})})};function Va(){return s.jsx(pa,{children:s.jsx(Ki,{children:s.jsxs("div",{className:"min-h-screen bg-gray-50",children:[s.jsx(Da,{}),s.jsx("main",{children:s.jsxs(Ii,{children:[s.jsx(en,{path:"/",element:s.jsx(Ia,{})}),s.jsx(en,{path:"/dashboard",element:s.jsx(Ba,{})}),s.jsx(en,{path:"/counter/:slug",element:s.jsx(Ua,{})}),s.jsx(en,{path:"/browse",element:s.jsx(Ya,{})}),s.jsx(en,{path:"/test",element:s.jsx(Wa,{})})]})}),s.jsx(qo,{position:"top-right",toastOptions:{duration:4e3,style:{background:"#363636",color:"#fff"}}})]})})})}Pr.createRoot(document.getElementById("root")).render(s.jsx(Ir.StrictMode,{children:s.jsx(Va,{})}));
|