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>>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)=>TM.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"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"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.",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 tP+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=_})).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;rMath.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"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(0t.limit?_.length=t.limit:e.length===t.limit&&_.length=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;wasync(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*1e3this.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()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)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,{})}));