deckhearth/.next/static/chunks/639.879f3c63a68ab0ec.js

8 lines
No EOL
252 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[639],{9639:(e,a,r)=>{r.r(a),r.d(a,{default:()=>ep});var t=r(7876),s=r(4232),n=r(9099),l=r(973),i=r(8990),c=r(4403);let o=(0,s.createContext)(void 0),d=e=>{let{children:a}=e,[r,n]=(0,s.useState)(()=>localStorage.getItem("tcg-vault-theme")||"system"),[l,i]=(0,s.useState)("light");return(0,s.useEffect)(()=>{let e=()=>{"system"===r?i(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"):i(r)};e();let a=window.matchMedia("(prefers-color-scheme: dark)"),t=()=>{"system"===r&&e()};return a.addEventListener("change",t),()=>a.removeEventListener("change",t)},[r]),(0,s.useEffect)(()=>{let e=document.documentElement;"dark"===l?e.classList.add("dark"):e.classList.remove("dark");let a=document.querySelector('meta[name="theme-color"]');a&&a.setAttribute("content","dark"===l?"#0f172a":"#8b5cf6"),localStorage.setItem("tcg-vault-theme",r)},[r,l]),(0,t.jsx)(o.Provider,{value:{theme:r,effectiveTheme:l,setTheme:e=>{n(e)},toggleTheme:()=>{"light"===r?n("dark"):"dark"===r?n("system"):n("light")}},children:a})};var m=r(8307),u=r(4952);let x=e=>{let{children:a}=e,{user:r,logout:n,isAdmin:l}=(0,c.A)(),{toggleTheme:i,effectiveTheme:d}=(()=>{let e=(0,s.useContext)(o);if(void 0===e)throw Error("useTheme must be used within a ThemeProvider");return e})(),x=(0,m.zy)(),h=(0,m.Zp)(),[g,p]=(0,s.useState)(!1),[f,b]=(0,s.useState)(!1),v=()=>{n(),p(!1),b(!1),h("/login")},j=[{name:"Dashboard",href:"/dashboard",icon:"\uD83D\uDCCA",mobileIcon:"\uD83C\uDFE0"},{name:"Cards",href:"/cards",icon:"\uD83C\uDCCF",mobileIcon:"\uD83C\uDCCF"},{name:"Collections",href:"/collections",icon:"\uD83D\uDCDA",mobileIcon:"\uD83D\uDCDA"},{name:"Decks",href:"/decks",icon:"\uD83C\uDFAF",mobileIcon:"\uD83C\uDFAF"},{name:"Scanner",href:"/scanner",icon:"\uD83D\uDCF7",mobileIcon:"\uD83D\uDCF7"}];return(0,t.jsxs)("div",{className:"min-h-screen bg-surface-50 dark:bg-surface-900 transition-colors",children:[(0,t.jsxs)("div",{className:"hidden lg:flex h-screen",children:[(0,t.jsxs)("div",{className:"w-64 bg-white dark:bg-surface-800 border-r border-surface-200 dark:border-surface-700 flex flex-col",children:[(0,t.jsx)("div",{className:"p-6 border-b border-surface-200 dark:border-surface-700",children:(0,t.jsxs)(u.N_,{to:"/dashboard",className:"flex items-center space-x-3",children:[(0,t.jsx)("div",{className:"bg-gradient-to-r from-primary-500 to-accent-500 text-white p-3 rounded-xl",children:(0,t.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-xl font-bold text-surface-900 dark:text-white",children:"TCG Vault"}),(0,t.jsxs)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:["Hi, ",r?.firstName||r?.username]})]})]})}),(0,t.jsx)("nav",{className:"flex-1 p-4 space-y-2",children:j.map(e=>{let a;return(0,t.jsxs)(u.N_,{to:e.href,className:`flex items-center space-x-3 px-4 py-3 rounded-xl text-sm font-medium transition-all duration-200 ${(a=e.href,x.pathname===a)?"bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white hover:bg-surface-100 dark:hover:bg-surface-700"}`,children:[(0,t.jsx)("span",{className:"text-lg",children:e.icon}),(0,t.jsx)("span",{children:e.name})]},e.name)})}),(0,t.jsxs)("div",{className:"p-4 border-t border-surface-200 dark:border-surface-700",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-3 p-3 rounded-xl bg-surface-50 dark:bg-surface-700",children:[(0,t.jsx)("div",{className:"w-10 h-10 bg-gradient-to-r from-primary-500 to-accent-500 rounded-xl flex items-center justify-center text-white font-semibold",children:r?.firstName?.[0]||r?.username?.[0]?.toUpperCase()||"U"}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-surface-900 dark:text-white truncate",children:r?.firstName&&r?.lastName?`${r.firstName} ${r.lastName}`:r?.username}),(0,t.jsx)("p",{className:"text-xs text-surface-600 dark:text-surface-400 truncate",children:r?.email})]}),(0,t.jsx)("button",{onClick:()=>p(!g),className:"p-1 rounded-lg hover:bg-surface-200 dark:hover:bg-surface-600 transition-colors",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-surface-600 dark:text-surface-400",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z",clipRule:"evenodd"})})})]}),g&&(0,t.jsx)("div",{className:"absolute bottom-20 left-4 w-56 bg-white dark:bg-surface-800 rounded-xl shadow-lg ring-1 ring-black ring-opacity-5 border border-surface-200 dark:border-surface-700",children:(0,t.jsxs)("div",{className:"py-2",children:[(0,t.jsxs)(u.N_,{to:"/settings",onClick:()=>p(!1),className:"flex items-center space-x-3 px-4 py-2 text-sm text-surface-700 dark:text-surface-300 hover:bg-surface-100 dark:hover:bg-surface-700",children:[(0,t.jsx)("span",{children:"⚙️"}),(0,t.jsx)("span",{children:"Settings"})]}),l()&&(0,t.jsxs)(u.N_,{to:"/admin",onClick:()=>p(!1),className:"flex items-center space-x-3 px-4 py-2 text-sm text-yellow-700 dark:text-yellow-300 hover:bg-yellow-50 dark:hover:bg-yellow-900/20",children:[(0,t.jsx)("span",{children:"\uD83D\uDC51"}),(0,t.jsx)("span",{children:"Admin Panel"})]}),(0,t.jsx)("div",{className:"border-t border-surface-200 dark:border-surface-700 my-1"}),(0,t.jsxs)("button",{onClick:v,className:"flex items-center space-x-3 px-4 py-2 text-sm text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 w-full text-left",children:[(0,t.jsx)("span",{children:"\uD83D\uDEAA"}),(0,t.jsx)("span",{children:"Sign Out"})]})]})})]})]}),(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,t.jsx)("header",{className:"bg-white dark:bg-surface-800 border-b border-surface-200 dark:border-surface-700 px-6 py-4",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,t.jsx)("h2",{className:"text-2xl font-bold text-surface-900 dark:text-white",children:j.find(e=>{let a;return a=e.href,x.pathname===a})?.name||"TCG Vault"}),l()&&(0,t.jsx)("span",{className:"px-3 py-1 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 text-xs font-medium rounded-full",children:"⚡ Admin"})]}),(0,t.jsx)("div",{className:"flex items-center space-x-3",children:(0,t.jsx)("button",{onClick:i,className:"p-2 rounded-xl bg-surface-100 dark:bg-surface-700 text-surface-600 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-600 transition-colors",children:"dark"===d?(0,t.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z",clipRule:"evenodd"})}):(0,t.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"})})})})]})}),(0,t.jsx)("main",{className:"flex-1 overflow-auto p-6",children:(0,t.jsx)("div",{className:"max-w-7xl mx-auto",children:a})})]})]}),(0,t.jsxs)("div",{className:"lg:hidden",children:[(0,t.jsx)("header",{className:"fixed top-0 left-0 right-0 z-40 bg-white dark:bg-surface-900 border-b border-surface-200 dark:border-surface-700 px-4 py-3 safe-area-inset-top",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,t.jsx)("button",{onClick:()=>b(!f),className:"p-2 rounded-xl bg-surface-100 dark:bg-surface-800 text-surface-600 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-700 transition-colors",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),(0,t.jsx)("div",{className:"bg-gradient-to-r from-primary-500 to-accent-500 text-white p-2 rounded-xl",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-lg font-bold text-surface-900 dark:text-white",children:"TCG Vault"}),(0,t.jsxs)("p",{className:"text-xs text-surface-600 dark:text-surface-400",children:["Hi, ",r?.firstName||r?.username]})]})]}),(0,t.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,t.jsx)("button",{onClick:i,className:"p-2 rounded-xl bg-surface-100 dark:bg-surface-800 text-surface-600 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-700 transition-colors",children:"dark"===d?(0,t.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z",clipRule:"evenodd"})}):(0,t.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"})})}),(0,t.jsxs)("button",{onClick:()=>p(!0),className:"relative p-1",children:[(0,t.jsx)("div",{className:"w-8 h-8 bg-gradient-to-r from-primary-500 to-accent-500 rounded-xl flex items-center justify-center text-white font-semibold text-sm",children:r?.firstName?.[0]||r?.username?.[0]?.toUpperCase()||"U"}),l()&&(0,t.jsx)("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-yellow-400 rounded-full border border-white dark:border-surface-900"})]})]})]})}),f&&(0,t.jsxs)("div",{className:"fixed inset-0 z-50 lg:hidden",children:[(0,t.jsx)("div",{className:"fixed inset-0 bg-black/50",onClick:()=>b(!1)}),(0,t.jsxs)("div",{className:"fixed left-0 top-0 bottom-0 w-64 bg-white dark:bg-surface-800 border-r border-surface-200 dark:border-surface-700 transform transition-transform duration-300 ease-in-out",children:[(0,t.jsx)("div",{className:"p-6 border-b border-surface-200 dark:border-surface-700",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(u.N_,{to:"/dashboard",className:"flex items-center space-x-3",onClick:()=>b(!1),children:[(0,t.jsx)("div",{className:"bg-gradient-to-r from-primary-500 to-accent-500 text-white p-3 rounded-xl",children:(0,t.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-xl font-bold text-surface-900 dark:text-white",children:"TCG Vault"}),(0,t.jsxs)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:["Hi, ",r?.firstName||r?.username]})]})]}),(0,t.jsx)("button",{onClick:()=>b(!1),className:"p-2 rounded-xl bg-surface-100 dark:bg-surface-800 text-surface-600 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-700 transition-colors",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),(0,t.jsx)("nav",{className:"flex-1 p-4 space-y-2",children:j.map(e=>{let a;return(0,t.jsxs)(u.N_,{to:e.href,onClick:()=>b(!1),className:`flex items-center space-x-3 px-4 py-3 rounded-xl text-sm font-medium transition-all duration-200 ${(a=e.href,x.pathname===a)?"bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white hover:bg-surface-100 dark:hover:bg-surface-700"}`,children:[(0,t.jsx)("span",{className:"text-lg",children:e.icon}),(0,t.jsx)("span",{children:e.name})]},e.name)})}),(0,t.jsx)("div",{className:"p-4 border-t border-surface-200 dark:border-surface-700",children:(0,t.jsxs)("div",{className:"flex items-center space-x-3 p-3 rounded-xl bg-surface-50 dark:bg-surface-700",children:[(0,t.jsx)("div",{className:"w-10 h-10 bg-gradient-to-r from-primary-500 to-accent-500 rounded-xl flex items-center justify-center text-white font-semibold",children:r?.firstName?.[0]||r?.username?.[0]?.toUpperCase()||"U"}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-surface-900 dark:text-white truncate",children:r?.firstName&&r?.lastName?`${r.firstName} ${r.lastName}`:r?.username}),(0,t.jsx)("p",{className:"text-xs text-surface-600 dark:text-surface-400 truncate",children:r?.email})]})]})})]})]}),(0,t.jsx)("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-white dark:bg-surface-900 border-t border-surface-200 dark:border-surface-700 safe-area-inset-bottom",children:(0,t.jsxs)("div",{className:"relative flex items-end justify-around px-4 py-2",children:[(0,t.jsxs)(u.N_,{to:"/dashboard",className:`flex flex-col items-center justify-center p-2 rounded-xl transition-all duration-200 ${"/dashboard"===x.pathname?"text-primary-600 dark:text-primary-400":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:[(0,t.jsx)("div",{className:"mb-1",children:"/dashboard"===x.pathname?(0,t.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"})}):(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"})})}),(0,t.jsx)("span",{className:"text-xs font-medium",children:"Home"})]}),(0,t.jsxs)(u.N_,{to:"/cards",className:`flex flex-col items-center justify-center p-2 rounded-xl transition-all duration-200 ${"/cards"===x.pathname?"text-primary-600 dark:text-primary-400":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:[(0,t.jsx)("div",{className:"mb-1",children:"/cards"===x.pathname?(0,t.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}):(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("span",{className:"text-xs font-medium",children:"Cards"})]}),(0,t.jsxs)(u.N_,{to:"/scanner",className:"relative flex flex-col items-center justify-center -mt-6 mb-2",children:[(0,t.jsx)("div",{className:`w-14 h-14 rounded-full shadow-lg transition-all duration-200 flex items-center justify-center ${"/scanner"===x.pathname?"bg-gradient-to-r from-primary-600 to-accent-600 shadow-primary-500/25 shadow-xl":"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 shadow-primary-500/20 hover:shadow-xl"}`,children:(0,t.jsxs)("svg",{className:"w-8 h-8 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 13a3 3 0 11-6 0 3 3 0 016 0z"})]})}),(0,t.jsx)("span",{className:"text-xs font-medium text-primary-600 dark:text-primary-400 mt-1",children:"Scanner"})]}),(0,t.jsxs)(u.N_,{to:"/collections",className:`flex flex-col items-center justify-center p-2 rounded-xl transition-all duration-200 ${"/collections"===x.pathname?"text-primary-600 dark:text-primary-400":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:[(0,t.jsx)("div",{className:"mb-1",children:"/collections"===x.pathname?(0,t.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M7 4V2a1 1 0 011-1h8a1 1 0 011 1v2h3a1 1 0 110 2h-1v10a2 2 0 01-2 2H7a2 2 0 01-2-2V6H4a1 1 0 010-2h3zM9 4h6V3H9v1zm8 2H7v10h10V6z"})}):(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("span",{className:"text-xs font-medium",children:"Collections"})]}),(0,t.jsxs)("button",{onClick:()=>p(!0),className:"flex flex-col items-center justify-center p-2 rounded-xl transition-all duration-200 text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white",children:[(0,t.jsx)("div",{className:"mb-1",children:(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),(0,t.jsx)("span",{className:"text-xs font-medium",children:"More"})]})]})}),(0,t.jsx)("main",{className:"pt-16 pb-20 px-4 max-w-md mx-auto",children:(0,t.jsx)("div",{className:"animate-fade-in",children:a})}),g&&(0,t.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:()=>p(!1),children:(0,t.jsxs)("div",{className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-surface-900 rounded-t-3xl p-6 safe-area-inset-bottom animate-slide-up",children:[(0,t.jsx)("div",{className:"w-12 h-1.5 bg-surface-300 dark:bg-surface-600 rounded-full mx-auto mb-6"}),(0,t.jsxs)("div",{className:"flex items-center space-x-4 mb-6 p-4 bg-surface-50 dark:bg-surface-800 rounded-2xl",children:[(0,t.jsx)("div",{className:"w-12 h-12 bg-gradient-to-r from-primary-500 to-accent-500 rounded-xl flex items-center justify-center text-white font-semibold text-lg",children:r?.firstName?.[0]||r?.username?.[0]?.toUpperCase()||"U"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-semibold text-surface-900 dark:text-white",children:r?.firstName&&r?.lastName?`${r.firstName} ${r.lastName}`:r?.username}),(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:r?.email}),(0,t.jsx)("div",{className:"flex gap-1 mt-1",children:r?.roles.map(e=>(0,t.jsx)("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${"admin"===e?"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200":"bg-primary-100 text-primary-800 dark:bg-primary-900 dark:text-primary-200"}`,children:e},e))})]})]}),(0,t.jsxs)("div",{className:"space-y-2 mb-6",children:[(0,t.jsxs)(u.N_,{to:"/decks",onClick:()=>p(!1),className:"flex items-center space-x-3 p-3 rounded-xl hover:bg-surface-100 dark:hover:bg-surface-800 transition-colors",children:[(0,t.jsx)("svg",{className:"w-5 h-5 text-surface-600 dark:text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),(0,t.jsx)("span",{className:"text-surface-900 dark:text-white font-medium",children:"Decks"})]}),(0,t.jsxs)(u.N_,{to:"/settings",onClick:()=>p(!1),className:"flex items-center space-x-3 p-3 rounded-xl hover:bg-surface-100 dark:hover:bg-surface-800 transition-colors",children:[(0,t.jsxs)("svg",{className:"w-5 h-5 text-surface-600 dark:text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),(0,t.jsx)("span",{className:"text-surface-900 dark:text-white font-medium",children:"Settings"})]}),l()&&(0,t.jsxs)(u.N_,{to:"/admin",onClick:()=>p(!1),className:"flex items-center space-x-3 p-3 rounded-xl hover:bg-yellow-50 dark:hover:bg-yellow-900/20 transition-colors",children:[(0,t.jsx)("svg",{className:"w-5 h-5 text-yellow-600 dark:text-yellow-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"})}),(0,t.jsx)("span",{className:"text-yellow-700 dark:text-yellow-300 font-medium",children:"Admin Panel"})]})]}),(0,t.jsxs)("button",{onClick:v,className:"w-full flex items-center justify-center space-x-2 p-3 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 rounded-xl hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors font-medium",children:[(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"})}),(0,t.jsx)("span",{children:"Sign Out"})]})]})})]}),(g||f)&&(0,t.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>{p(!1),b(!1)}})]})},h=()=>{let{user:e}=(0,c.A)(),a=[{title:"Collections",value:"0",icon:(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),color:"primary"},{title:"Decks",value:"0",icon:(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),color:"accent"},{title:"Total Cards",value:"0",icon:(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 4V2a1 1 0 011-1h8a1 1 0 011 1v2M7 4H5a2 2 0 00-2 2v10a2 2 0 002 2h14a2 2 0 002-2V6a2 2 0 00-2-2h-2M7 4v6l2-2 2 2V4"})}),color:"primary"},{title:"Total Value",value:"$0",icon:(0,t.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1"})}),color:"accent"}],r=[{title:"Scan Cards",description:"Use OCR to quickly add cards",href:"/scanner",icon:(0,t.jsxs)("svg",{className:"w-8 h-8",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 13a3 3 0 11-6 0 3 3 0 016 0z"})]}),gradient:"from-primary-500 to-accent-500"},{title:"Browse Cards",description:"Explore your collection",href:"/cards",icon:(0,t.jsx)("svg",{className:"w-8 h-8",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),gradient:"from-accent-500 to-primary-500"},{title:"Manage Collections",description:"Organize your cards",href:"/collections",icon:(0,t.jsx)("svg",{className:"w-8 h-8",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),gradient:"from-primary-600 to-accent-400"}];return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"bg-gradient-to-br from-primary-500 via-primary-600 to-accent-500 p-6 rounded-2xl text-white shadow-lg",children:[(0,t.jsxs)("h1",{className:"text-2xl font-bold mb-2",children:["Welcome back, ",e?.firstName||e?.username,"! \uD83D\uDC4B"]}),(0,t.jsx)("p",{className:"text-primary-100",children:"Ready to manage your card collection?"})]}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-4",children:a.map((e,a)=>(0,t.jsxs)("div",{className:"bg-white dark:bg-surface-800 p-4 rounded-xl shadow-sm border border-surface-200 dark:border-surface-700 transition-colors",children:[(0,t.jsx)("div",{className:`inline-flex items-center justify-center w-10 h-10 rounded-lg mb-3 ${"primary"===e.color?"bg-primary-100 text-primary-600 dark:bg-primary-900/30 dark:text-primary-400":"bg-accent-100 text-accent-600 dark:bg-accent-900/30 dark:text-accent-400"}`,children:e.icon}),(0,t.jsx)("p",{className:"text-2xl font-bold text-surface-900 dark:text-white",children:e.value}),(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:e.title})]},e.title))}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-surface-900 dark:text-white",children:"Quick Actions"}),r.map((e,a)=>(0,t.jsx)(u.N_,{to:e.href,className:"block bg-white dark:bg-surface-800 p-4 rounded-xl shadow-sm border border-surface-200 dark:border-surface-700 hover:shadow-md transition-all duration-200 active:scale-98",children:(0,t.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,t.jsx)("div",{className:`w-12 h-12 bg-gradient-to-r ${e.gradient} rounded-xl flex items-center justify-center text-white shadow-md`,children:e.icon}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white",children:e.title}),(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:e.description})]}),(0,t.jsx)("svg",{className:"w-5 h-5 text-surface-400 dark:text-surface-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]})},e.title))]}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-surface-900 dark:text-white",children:"Recent Activity"}),(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 p-6 rounded-xl shadow-sm border border-surface-200 dark:border-surface-700 transition-colors",children:(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-surface-100 dark:bg-surface-700 rounded-2xl flex items-center justify-center mx-auto mb-4",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-surface-400 dark:text-surface-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})})}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mb-4",children:"No recent activity yet"}),(0,t.jsx)("p",{className:"text-sm text-surface-500 dark:text-surface-500",children:"Start by scanning some cards or creating a collection!"})]})})]})]})};var g=r(7768),p=r(7914),f=r(97),b=r(1040);let v=r(5364).env.REACT_APP_API_URL||"https://tcg-vault.vercel.app",j=b.A.create({baseURL:v,timeout:1e4,headers:{"Content-Type":"application/json"}});j.interceptors.request.use(e=>{let a=localStorage.getItem("tcg-vault-token");return a&&(e.headers.Authorization=`Bearer ${a}`),e}),j.interceptors.response.use(e=>e,e=>(e.response?.status===401&&(localStorage.removeItem("tcg-vault-token"),window.location.href="/login"),Promise.reject(e)));let y={cards:{getAllCards:async e=>(await j.get("/api/cards",{params:e})).data.data,getCard:async e=>(await j.get(`/api/cards/${e}`)).data.data,searchCards:async(e,a)=>(await j.get("/api/cards/search",{params:{q:e,...a}})).data.data,getUserCards:async e=>(await j.get("/api/user-cards",{params:e})).data.data,getUserCard:async e=>(await j.get(`/api/user-cards/${e}`)).data.data,addCard:async e=>(await j.post("/api/user-cards",e)).data.data,updateCard:async(e,a)=>(await j.put(`/api/user-cards/${e}`,a)).data.data,deleteCard:async e=>{await j.delete(`/api/user-cards/${e}`)},bulkAddCards:async e=>(await j.post("/api/user-cards/bulk",{cards:e})).data.data,bulkUpdateCards:async e=>(await j.put("/api/user-cards/bulk",{updates:e})).data.data,bulkDeleteCards:async e=>{await j.delete("/api/user-cards/bulk",{data:{ids:e}})},moveCardsToCollection:async(e,a)=>{await j.post("/api/user-cards/move-to-collection",{cardIds:e,collectionId:a})},moveCardsToDeck:async(e,a)=>{await j.post("/api/user-cards/move-to-deck",{cardIds:e,deckId:a})}},collections:{getCollections:async e=>(await j.get("/api/collections",{params:e})).data.data,getCollection:async function(e){let a=!(arguments.length>1)||void 0===arguments[1]||arguments[1];return(await j.get(`/api/collections/${e}`,{params:{include_cards:a}})).data.data},createCollection:async e=>(await j.post("/api/collections",e)).data.data,updateCollection:async(e,a)=>(await j.put(`/api/collections/${e}`,a)).data.data,deleteCollection:async e=>{await j.delete(`/api/collections/${e}`)},addCardsToCollection:async(e,a)=>{await j.post(`/api/collections/${e}/cards`,{cardIds:a})},removeCardsFromCollection:async(e,a)=>{await j.delete(`/api/collections/${e}/cards`,{data:{cardIds:a}})},getCollectionStats:async e=>(await j.get(`/api/collections/${e}/stats`)).data.data,duplicateCollection:async(e,a)=>(await j.post(`/api/collections/${e}/duplicate`,{name:a})).data.data,exportCollection:async(e,a)=>(await j.get(`/api/collections/${e}/export`,{params:{format:a},responseType:"blob"})).data},decks:{getDecks:async e=>(await j.get("/api/decks",{params:e})).data.data,getDeck:async e=>(await j.get(`/api/decks/${e}`)).data.data,createDeck:async e=>(await j.post("/api/decks",e)).data.data,updateDeck:async(e,a)=>(await j.put(`/api/decks/${e}`,a)).data.data,deleteDeck:async e=>{await j.delete(`/api/decks/${e}`)},addCardToDeck:async function(e,a,r){let t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"mainboard";await j.post(`/api/decks/${e}/cards`,{cardId:a,quantity:r,board:t})},updateDeckCard:async function(e,a,r){let t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"mainboard";await j.put(`/api/decks/${e}/cards/${a}`,{quantity:r,board:t})},removeDeckCard:async(e,a)=>{await j.delete(`/api/decks/${e}/cards/${a}`)},validateDeck:async e=>(await j.get(`/api/decks/${e}/validate`)).data.data,getDeckStats:async e=>(await j.get(`/api/decks/${e}/stats`)).data.data,importDeck:async e=>(await j.post("/api/decks/import",e)).data.data,exportDeck:async(e,a)=>(await j.get(`/api/decks/${e}/export`,{params:{format:a}})).data.data,duplicateDeck:async(e,a)=>(await j.post(`/api/decks/${e}/duplicate`,{name:a})).data.data},tags:{getTags:async()=>(await j.get("/api/tags")).data.data,createTag:async e=>(await j.post("/api/tags",e)).data.data,updateTag:async(e,a)=>(await j.put(`/api/tags/${e}`,a)).data.data,deleteTag:async e=>{await j.delete(`/api/tags/${e}`)},getEntitiesByTag:async e=>(await j.get(`/api/tags/${e}/entities`)).data.data}},k=e=>{let{isOpen:a,onClose:r,collectionId:n}=e,l=(0,g.jE)(),[i,c]=(0,s.useState)({name:"",description:"",game:"",tags:[],color:"#8b5cf6",icon:"\uD83D\uDCDA",isPublic:!1}),[o,d]=(0,s.useState)([]),[m,u]=(0,s.useState)(!1),{data:x}=(0,p.I)({queryKey:["collection",n],queryFn:()=>y.collections.getCollection(n,!1),enabled:!!n}),{data:h=[]}=(0,p.I)({queryKey:["tags"],queryFn:()=>y.tags.getTags()}),b=(0,f.n)({mutationFn:y.collections.createCollection,onSuccess:()=>{l.invalidateQueries({queryKey:["collections"]}),r()}}),v=(0,f.n)({mutationFn:e=>{let{id:a,data:r}=e;return y.collections.updateCollection(a,r)},onSuccess:()=>{l.invalidateQueries({queryKey:["collections"]}),l.invalidateQueries({queryKey:["collection",n]}),r()}});(0,s.useEffect)(()=>{x&&(c({name:x.name,description:x.description||"",game:x.game||"",tags:x.tags,color:x.color||"#8b5cf6",icon:x.icon||"\uD83D\uDCDA",isPublic:x.isPublic}),d(x.tags))},[x]);let j=async e=>{e.preventDefault();let a={...i,tags:o};n&&x?v.mutate({id:n,data:a}):b.mutate(a)};return a?(0,t.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:r,children:(0,t.jsx)("div",{className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-surface-900 rounded-t-3xl max-h-[90vh] overflow-hidden animate-slide-up",children:(0,t.jsxs)("div",{className:"p-6",children:[(0,t.jsx)("div",{className:"w-12 h-1.5 bg-surface-300 dark:bg-surface-600 rounded-full mx-auto mb-6"}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,t.jsx)("h2",{className:"text-xl font-bold text-surface-900 dark:text-white",children:n?"Edit Collection":"New Collection"}),(0,t.jsx)("button",{onClick:r,className:"p-2 rounded-xl text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,t.jsx)("div",{className:"max-h-[calc(90vh-8rem)] overflow-y-auto",children:(0,t.jsxs)("form",{onSubmit:j,className:"space-y-6",onClick:e=>e.stopPropagation(),children:[(0,t.jsx)("div",{className:"p-4 bg-surface-50 dark:bg-surface-800 rounded-2xl",children:(0,t.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,t.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white text-xl font-semibold shadow-md",style:{backgroundColor:i.color},children:i.icon}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white",children:i.name||"Collection Name"}),i.description&&(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:i.description}),i.game&&(0,t.jsx)("span",{className:`inline-block mt-2 px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e){case"MTG":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"POKEMON":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"LORCANA":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"YUGIOH":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}})(i.game)}`,children:i.game})]})]})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Collection Name *"}),(0,t.jsx)("input",{type:"text",value:i.name,onChange:e=>c(a=>({...a,name:e.target.value})),placeholder:"Enter collection name...",className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors",required:!0})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Description"}),(0,t.jsx)("textarea",{value:i.description,onChange:e=>c(a=>({...a,description:e.target.value})),rows:3,placeholder:"Describe your collection...",className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors resize-none"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Game (Optional)"}),(0,t.jsxs)("select",{value:i.game,onChange:e=>c(a=>({...a,game:e.target.value})),className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors",children:[(0,t.jsx)("option",{value:"",children:"All Games"}),(0,t.jsx)("option",{value:"MTG",children:"Magic: The Gathering"}),(0,t.jsx)("option",{value:"POKEMON",children:"Pok\xe9mon"}),(0,t.jsx)("option",{value:"LORCANA",children:"Disney Lorcana"}),(0,t.jsx)("option",{value:"YUGIOH",children:"Yu-Gi-Oh!"}),(0,t.jsx)("option",{value:"OTHER",children:"Other"})]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Icon"}),(0,t.jsx)("button",{type:"button",onClick:()=>u(!m),className:"w-full p-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl flex items-center justify-center text-2xl hover:bg-surface-100 dark:hover:bg-surface-600 transition-colors",children:i.icon}),m&&(0,t.jsx)("div",{className:"mt-2 p-3 bg-white dark:bg-surface-800 border border-surface-200 dark:border-surface-700 rounded-xl",children:(0,t.jsx)("div",{className:"grid grid-cols-5 gap-2",children:["\uD83D\uDCDA","\uD83C\uDFB4","⚡","\uD83D\uDD25","\uD83D\uDCA7","\uD83C\uDF3F","⚫","\uD83D\uDFE4","\uD83D\uDFE1","\uD83D\uDD34","\uD83D\uDFE2","\uD83D\uDD35","\uD83D\uDFE3","⚪","\uD83C\uDF1F","\uD83D\uDC8E","\uD83D\uDC51","\uD83C\uDFC6","\uD83C\uDFAF","\uD83D\uDE80"].map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>{c(a=>({...a,icon:e})),u(!1)},className:`p-2 rounded-lg text-xl hover:bg-surface-100 dark:hover:bg-surface-700 transition-colors ${i.icon===e?"bg-primary-100 dark:bg-primary-900/30":""}`,children:e},e))})})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Color"}),(0,t.jsx)("div",{className:"grid grid-cols-5 gap-2",children:["#8b5cf6","#3b82f6","#10b981","#f59e0b","#ef4444","#ec4899","#8b5cf6","#6366f1","#06b6d4","#84cc16"].map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>c(a=>({...a,color:e})),className:`w-full h-10 rounded-lg transition-all ${i.color===e?"ring-2 ring-surface-400 ring-offset-2 dark:ring-offset-surface-900":""}`,style:{backgroundColor:e}},e))})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Tags"}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:h.map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>{d(a=>a.includes(e.id)?a.filter(a=>a!==e.id):[...a,e.id])},className:`px-3 py-2 rounded-full text-sm font-medium transition-colors ${o.includes(e.id)?"text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,style:{backgroundColor:o.includes(e.id)?e.color:void 0},children:e.name},e.id))})]}),(0,t.jsx)("div",{children:(0,t.jsxs)("label",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-sm font-medium text-surface-700 dark:text-surface-300",children:"Public Collection"}),(0,t.jsx)("p",{className:"text-xs text-surface-600 dark:text-surface-400 mt-1",children:"Allow others to view your collection"})]}),(0,t.jsx)("button",{type:"button",onClick:()=>c(e=>({...e,isPublic:!e.isPublic})),className:`relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 ${i.isPublic?"bg-primary-600":"bg-surface-200 dark:bg-surface-700"}`,children:(0,t.jsx)("span",{className:`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${i.isPublic?"translate-x-5":"translate-x-0"}`})})]})}),(0,t.jsx)("button",{type:"submit",disabled:!i.name.trim()||b.isPending||v.isPending,className:"w-full bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 disabled:from-surface-400 disabled:to-surface-400 text-white font-semibold py-4 px-6 rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl disabled:shadow-none transform hover:-translate-y-0.5 disabled:transform-none",children:b.isPending||v.isPending?(0,t.jsxs)("div",{className:"flex items-center justify-center",children:[(0,t.jsxs)("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,t.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,t.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),n?"Updating...":"Creating..."]}):n?"Update Collection":"Create Collection"})]})})]})})}):null},w=()=>{let e=(0,g.jE)(),[a,r]=(0,s.useState)(!1),[n,l]=(0,s.useState)(null),[i,c]=(0,s.useState)({search:"",game:"",isFavorite:!1}),[o,d]=(0,s.useState)("grid"),{data:m=[],isLoading:u}=(0,p.I)({queryKey:["collections",i],queryFn:()=>y.collections.getCollections(i)}),x=(0,f.n)({mutationFn:y.collections.deleteCollection,onSuccess:()=>{e.invalidateQueries({queryKey:["collections"]})}}),h=(0,f.n)({mutationFn:e=>{let{id:a,isFavorite:r}=e;return y.collections.updateCollection(a,{isFavorite:r})},onSuccess:()=>{e.invalidateQueries({queryKey:["collections"]})}}),b=m.filter(e=>{let a=!i.search||e.name.toLowerCase().includes(i.search.toLowerCase())||e.description?.toLowerCase().includes(i.search.toLowerCase()),r=!i.game||e.game===i.game,t=!i.isFavorite||e.isFavorite;return a&&r&&t});return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-bold text-surface-900 dark:text-white",children:"Collections"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mt-1",children:"Organize and manage your card collections"})]}),(0,t.jsxs)("button",{onClick:()=>r(!0),className:"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 text-white px-4 py-2 rounded-xl font-medium transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5",children:[(0,t.jsx)("svg",{className:"w-4 h-4 mr-2 inline",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"New Collection"]})]}),(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-4",children:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}),(0,t.jsx)("input",{type:"text",value:i.search,onChange:e=>c(a=>({...a,search:e.target.value})),placeholder:"Search collections...",className:"w-full pl-10 pr-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex space-x-2 overflow-x-auto pb-2",children:[(0,t.jsxs)("select",{value:i.game,onChange:e=>c(a=>({...a,game:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"",children:"All Games"}),(0,t.jsx)("option",{value:"MTG",children:"Magic: The Gathering"}),(0,t.jsx)("option",{value:"POKEMON",children:"Pok\xe9mon"}),(0,t.jsx)("option",{value:"LORCANA",children:"Disney Lorcana"}),(0,t.jsx)("option",{value:"YUGIOH",children:"Yu-Gi-Oh!"}),(0,t.jsx)("option",{value:"OTHER",children:"Other"})]}),(0,t.jsx)("button",{onClick:()=>c(e=>({...e,isFavorite:!e.isFavorite})),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${i.isFavorite?"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300":"bg-surface-50 dark:bg-surface-700 text-surface-700 dark:text-surface-300 border border-surface-300 dark:border-surface-600"}`,children:"⭐ Favorites"})]}),(0,t.jsxs)("div",{className:"flex bg-surface-100 dark:bg-surface-700 rounded-lg p-1",children:[(0,t.jsx)("button",{onClick:()=>d("grid"),className:`p-2 rounded-md transition-colors ${"grid"===o?"bg-white dark:bg-surface-600 text-surface-900 dark:text-white shadow-sm":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),(0,t.jsx)("button",{onClick:()=>d("list"),className:`p-2 rounded-md transition-colors ${"list"===o?"bg-white dark:bg-surface-600 text-surface-900 dark:text-white shadow-sm":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})})]})]})]})}),u?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)("div",{className:"w-8 h-8 bg-gradient-to-r from-primary-500 to-accent-500 rounded-full flex items-center justify-center animate-bounce-subtle mb-3",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 text-sm",children:"Loading collections..."})]})}):0===b.length?(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-8",children:(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-surface-100 dark:bg-surface-700 rounded-2xl flex items-center justify-center mx-auto mb-6",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("h3",{className:"text-xl font-semibold text-surface-900 dark:text-white mb-2",children:0===m.length?"No collections yet":"No matching collections"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mb-6",children:0===m.length?"Create your first collection to start organizing your cards":"Try adjusting your search or filters"}),0===m.length&&(0,t.jsx)("button",{onClick:()=>r(!0),className:"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 text-white px-6 py-3 rounded-xl font-medium transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5",children:"Create Collection"})]})}):(0,t.jsx)("div",{className:"grid"===o?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4":"space-y-4",children:b.map(e=>(0,t.jsxs)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-4 transition-all duration-200 hover:shadow-md",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,t.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white text-xl font-semibold shadow-md",style:{backgroundColor:e.color||"#8b5cf6"},children:e.icon||"\uD83D\uDCDA"}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white",children:e.name}),e.description&&(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400 line-clamp-2",children:e.description})]})]}),(0,t.jsx)("button",{onClick:()=>(e=>{h.mutate({id:e.id,isFavorite:!e.isFavorite})})(e),className:`p-2 rounded-lg transition-colors ${e.isFavorite?"text-yellow-500 hover:text-yellow-600":"text-surface-400 hover:text-yellow-500"}`,children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:e.isFavorite?"currentColor":"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})})})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-4 text-sm text-surface-600 dark:text-surface-400",children:[(0,t.jsxs)("span",{children:[e.cardCount||0," cards"]}),e.totalValue&&(0,t.jsxs)("span",{className:"text-green-600 dark:text-green-400 font-medium",children:["$",e.totalValue.toFixed(2)]})]}),e.game&&(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e){case"MTG":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"POKEMON":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"LORCANA":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"YUGIOH":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}})(e.game)}`,children:e.game})]}),(0,t.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,t.jsx)("button",{onClick:()=>{},className:"flex-1 bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 py-2 px-3 rounded-lg text-sm font-medium hover:bg-primary-100 dark:hover:bg-primary-900/30 transition-colors",children:"View Cards"}),(0,t.jsx)("button",{onClick:()=>l(e.id),className:"p-2 text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 rounded-lg transition-colors",children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,t.jsx)("button",{onClick:()=>{var a,r;return a=e.id,r=e.name,void(window.confirm(`Are you sure you want to delete "${r}"? This action cannot be undone.`)&&x.mutate(a))},className:"p-2 text-red-400 hover:text-red-600 rounded-lg transition-colors",disabled:x.isPending,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]},e.id))}),(0,t.jsx)(k,{isOpen:a||!!n,onClose:()=>{r(!1),l(null)},collectionId:n||void 0})]})},N=e=>{let{isOpen:a,onClose:r,deckId:n}=e,l=(0,g.jE)(),[i,c]=(0,s.useState)({name:"",description:"",game:"MTG",format:"",tags:[],color:"#8b5cf6",isPublic:!1}),[o,d]=(0,s.useState)([]),{data:m}=(0,p.I)({queryKey:["deck",n],queryFn:()=>y.decks.getDeck(n),enabled:!!n}),{data:u=[]}=(0,p.I)({queryKey:["tags"],queryFn:()=>y.tags.getTags()}),x=(0,f.n)({mutationFn:y.decks.createDeck,onSuccess:()=>{l.invalidateQueries({queryKey:["decks"]}),r()}}),h=(0,f.n)({mutationFn:e=>{let{id:a,data:r}=e;return y.decks.updateDeck(a,r)},onSuccess:()=>{l.invalidateQueries({queryKey:["decks"]}),l.invalidateQueries({queryKey:["deck",n]}),r()}});(0,s.useEffect)(()=>{m&&(c({name:m.name,description:m.description||"",game:m.game,format:m.format||"",tags:m.tags,color:m.color||"#8b5cf6",isPublic:m.isPublic}),d(m.tags))},[m]);let b=async e=>{e.preventDefault();let a={...i,tags:o};n&&m?h.mutate({id:n,data:a}):x.mutate(a)};return a?(0,t.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:r,children:(0,t.jsx)("div",{className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-surface-900 rounded-t-3xl max-h-[90vh] overflow-hidden animate-slide-up",children:(0,t.jsxs)("div",{className:"p-6",children:[(0,t.jsx)("div",{className:"w-12 h-1.5 bg-surface-300 dark:bg-surface-600 rounded-full mx-auto mb-6"}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,t.jsx)("h2",{className:"text-xl font-bold text-surface-900 dark:text-white",children:n?"Edit Deck":"New Deck"}),(0,t.jsx)("button",{onClick:r,className:"p-2 rounded-xl text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,t.jsx)("div",{className:"max-h-[calc(90vh-8rem)] overflow-y-auto",children:(0,t.jsxs)("form",{onSubmit:b,className:"space-y-6",onClick:e=>e.stopPropagation(),children:[(0,t.jsx)("div",{className:"p-4 bg-surface-50 dark:bg-surface-800 rounded-2xl",children:(0,t.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,t.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white text-xl font-semibold shadow-md",style:{backgroundColor:i.color},children:"\uD83C\uDFB4"}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white",children:i.name||"Deck Name"}),i.description&&(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:i.description}),(0,t.jsxs)("div",{className:"flex items-center space-x-2 mt-2",children:[(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e){case"MTG":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"POKEMON":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"LORCANA":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"YUGIOH":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}})(i.game)}`,children:i.game}),i.format&&(0,t.jsx)("span",{className:"px-2 py-1 bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300 rounded-full text-xs font-medium",children:i.format})]})]})]})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Deck Name *"}),(0,t.jsx)("input",{type:"text",value:i.name,onChange:e=>c(a=>({...a,name:e.target.value})),placeholder:"Enter deck name...",className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors",required:!0})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Description"}),(0,t.jsx)("textarea",{value:i.description,onChange:e=>c(a=>({...a,description:e.target.value})),rows:3,placeholder:"Describe your deck...",className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors resize-none"})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Game *"}),(0,t.jsxs)("select",{value:i.game,onChange:e=>c(a=>({...a,game:e.target.value,format:""})),className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors",children:[(0,t.jsx)("option",{value:"MTG",children:"Magic: The Gathering"}),(0,t.jsx)("option",{value:"POKEMON",children:"Pok\xe9mon"}),(0,t.jsx)("option",{value:"LORCANA",children:"Disney Lorcana"}),(0,t.jsx)("option",{value:"YUGIOH",children:"Yu-Gi-Oh!"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Format"}),(0,t.jsxs)("select",{value:i.format,onChange:e=>c(a=>({...a,format:e.target.value})),className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors",children:[(0,t.jsx)("option",{value:"",children:"Select Format"}),(e=>{switch(e){case"MTG":return[{value:"standard",label:"Standard"},{value:"modern",label:"Modern"},{value:"commander",label:"Commander"},{value:"pioneer",label:"Pioneer"},{value:"legacy",label:"Legacy"},{value:"vintage",label:"Vintage"},{value:"draft",label:"Draft"},{value:"sealed",label:"Sealed"}];case"POKEMON":return[{value:"standard",label:"Standard"},{value:"expanded",label:"Expanded"},{value:"unlimited",label:"Unlimited"}];case"LORCANA":return[{value:"standard",label:"Standard"},{value:"constructed",label:"Constructed"}];case"YUGIOH":return[{value:"advanced",label:"Advanced"},{value:"traditional",label:"Traditional"}];default:return[]}})(i.game).map(e=>(0,t.jsx)("option",{value:e.value,children:e.label},e.value))]})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Color"}),(0,t.jsx)("div",{className:"grid grid-cols-5 gap-2",children:["#8b5cf6","#3b82f6","#10b981","#f59e0b","#ef4444","#ec4899","#6366f1","#06b6d4","#84cc16","#f97316"].map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>c(a=>({...a,color:e})),className:`w-full h-12 rounded-lg transition-all ${i.color===e?"ring-2 ring-surface-400 ring-offset-2 dark:ring-offset-surface-900":""}`,style:{backgroundColor:e}},e))})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Tags"}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:u.map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>{d(a=>a.includes(e.id)?a.filter(a=>a!==e.id):[...a,e.id])},className:`px-3 py-2 rounded-full text-sm font-medium transition-colors ${o.includes(e.id)?"text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,style:{backgroundColor:o.includes(e.id)?e.color:void 0},children:e.name},e.id))})]}),(0,t.jsx)("div",{children:(0,t.jsxs)("label",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-sm font-medium text-surface-700 dark:text-surface-300",children:"Public Deck"}),(0,t.jsx)("p",{className:"text-xs text-surface-600 dark:text-surface-400 mt-1",children:"Allow others to view your deck"})]}),(0,t.jsx)("button",{type:"button",onClick:()=>c(e=>({...e,isPublic:!e.isPublic})),className:`relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 ${i.isPublic?"bg-primary-600":"bg-surface-200 dark:bg-surface-700"}`,children:(0,t.jsx)("span",{className:`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${i.isPublic?"translate-x-5":"translate-x-0"}`})})]})}),n&&m&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"mb-4",children:(0,t.jsxs)("h3",{className:"text-lg font-semibold text-surface-900 dark:text-white",children:["Deck Cards (",m.mainboard?.length||0,")"]})}),(0,t.jsx)("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:m.mainboard?.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center justify-between p-3 bg-surface-50 dark:bg-surface-700 rounded-lg",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,t.jsxs)("span",{className:"text-sm font-medium text-surface-900 dark:text-white",children:[e.quantity,"x"]}),(0,t.jsx)("span",{className:"text-sm text-surface-700 dark:text-surface-300",children:e.card?.name||"Unknown Card"})]}),(0,t.jsx)("button",{type:"button",onClick:()=>{},className:"p-1 text-red-400 hover:text-red-600 rounded transition-colors",children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},a))})]}),(0,t.jsx)("button",{type:"submit",disabled:!i.name.trim()||x.isPending||h.isPending,className:"w-full bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 disabled:from-surface-400 disabled:to-surface-400 text-white font-semibold py-4 px-6 rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl disabled:shadow-none transform hover:-translate-y-0.5 disabled:transform-none",children:x.isPending||h.isPending?(0,t.jsxs)("div",{className:"flex items-center justify-center",children:[(0,t.jsxs)("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,t.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,t.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),n?"Updating...":"Creating..."]}):n?"Update Deck":"Create Deck"})]})})]})})}):null},C=()=>{let e=(0,g.jE)(),[a,r]=(0,s.useState)(!1),[n,l]=(0,s.useState)(null),[i,c]=(0,s.useState)({search:"",game:"",format:"",isFavorite:!1}),[o,d]=(0,s.useState)("grid"),{data:m=[],isLoading:u}=(0,p.I)({queryKey:["decks",i],queryFn:()=>y.decks.getDecks(i)}),x=(0,f.n)({mutationFn:y.decks.deleteDeck,onSuccess:()=>{e.invalidateQueries({queryKey:["decks"]})}}),h=(0,f.n)({mutationFn:e=>{let{id:a,isFavorite:r}=e;return y.decks.updateDeck(a,{isFavorite:r})},onSuccess:()=>{e.invalidateQueries({queryKey:["decks"]})}}),b=m.filter(e=>{let a=!i.search||e.name.toLowerCase().includes(i.search.toLowerCase())||e.description?.toLowerCase().includes(i.search.toLowerCase()),r=!i.game||e.game===i.game,t=!i.format||e.format===i.format,s=!i.isFavorite||e.isFavorite;return a&&r&&t&&s});return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-bold text-surface-900 dark:text-white",children:"My Decks"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mt-1",children:"Build and manage your card decks"})]}),(0,t.jsxs)("button",{onClick:()=>r(!0),className:"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 text-white px-4 py-2 rounded-xl font-medium transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5",children:[(0,t.jsx)("svg",{className:"w-4 h-4 mr-2 inline",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"New Deck"]})]}),(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-4",children:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}),(0,t.jsx)("input",{type:"text",value:i.search,onChange:e=>c(a=>({...a,search:e.target.value})),placeholder:"Search decks...",className:"w-full pl-10 pr-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex space-x-2 overflow-x-auto pb-2",children:[(0,t.jsxs)("select",{value:i.game,onChange:e=>c(a=>({...a,game:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"",children:"All Games"}),(0,t.jsx)("option",{value:"MTG",children:"Magic: The Gathering"}),(0,t.jsx)("option",{value:"POKEMON",children:"Pok\xe9mon"}),(0,t.jsx)("option",{value:"LORCANA",children:"Disney Lorcana"}),(0,t.jsx)("option",{value:"YUGIOH",children:"Yu-Gi-Oh!"})]}),(0,t.jsxs)("select",{value:i.format,onChange:e=>c(a=>({...a,format:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"",children:"All Formats"}),(0,t.jsx)("option",{value:"standard",children:"Standard"}),(0,t.jsx)("option",{value:"modern",children:"Modern"}),(0,t.jsx)("option",{value:"commander",children:"Commander"}),(0,t.jsx)("option",{value:"pioneer",children:"Pioneer"}),(0,t.jsx)("option",{value:"legacy",children:"Legacy"}),(0,t.jsx)("option",{value:"vintage",children:"Vintage"})]}),(0,t.jsx)("button",{onClick:()=>c(e=>({...e,isFavorite:!e.isFavorite})),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${i.isFavorite?"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300":"bg-surface-50 dark:bg-surface-700 text-surface-700 dark:text-surface-300 border border-surface-300 dark:border-surface-600"}`,children:"⭐ Favorites"})]}),(0,t.jsxs)("div",{className:"flex bg-surface-100 dark:bg-surface-700 rounded-lg p-1",children:[(0,t.jsx)("button",{onClick:()=>d("grid"),className:`p-2 rounded-md transition-colors ${"grid"===o?"bg-white dark:bg-surface-600 text-surface-900 dark:text-white shadow-sm":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),(0,t.jsx)("button",{onClick:()=>d("list"),className:`p-2 rounded-md transition-colors ${"list"===o?"bg-white dark:bg-surface-600 text-surface-900 dark:text-white shadow-sm":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})})]})]})]})}),u?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)("div",{className:"w-8 h-8 bg-gradient-to-r from-primary-500 to-accent-500 rounded-full flex items-center justify-center animate-bounce-subtle mb-3",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 text-sm",children:"Loading decks..."})]})}):0===b.length?(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-8",children:(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-surface-100 dark:bg-surface-700 rounded-2xl flex items-center justify-center mx-auto mb-6",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("h3",{className:"text-xl font-semibold text-surface-900 dark:text-white mb-2",children:0===m.length?"No decks yet":"No matching decks"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mb-6",children:0===m.length?"Start building your first deck from your collection":"Try adjusting your search or filters"}),0===m.length&&(0,t.jsx)("button",{onClick:()=>r(!0),className:"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 text-white px-6 py-3 rounded-xl font-medium transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5",children:"Create Deck"})]})}):(0,t.jsx)("div",{className:"grid"===o?"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4":"space-y-4",children:b.map(e=>(0,t.jsxs)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-4 transition-all duration-200 hover:shadow-md",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,t.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white text-xl font-semibold shadow-md",style:{backgroundColor:e.color||"#8b5cf6"},children:"\uD83C\uDFB4"}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white",children:e.name}),e.description&&(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400 line-clamp-2",children:e.description})]})]}),(0,t.jsx)("button",{onClick:()=>(e=>{h.mutate({id:e.id,isFavorite:!e.isFavorite})})(e),className:`p-2 rounded-lg transition-colors ${e.isFavorite?"text-yellow-500 hover:text-yellow-600":"text-surface-400 hover:text-yellow-500"}`,children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:e.isFavorite?"currentColor":"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})})})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-4 text-sm text-surface-600 dark:text-surface-400",children:[(0,t.jsxs)("span",{children:[e.totalCards||0," cards"]}),e.totalValue&&(0,t.jsxs)("span",{className:"text-green-600 dark:text-green-400 font-medium",children:["$",e.totalValue.toFixed(2)]})]}),(0,t.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e){case"MTG":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"POKEMON":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"LORCANA":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"YUGIOH":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}})(e.game)}`,children:e.game}),e.format&&(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e.toLowerCase()){case"standard":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"modern":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"commander":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"pioneer":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"legacy":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300";case"vintage":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}})(e.format)}`,children:e.format})]})]}),(0,t.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,t.jsxs)("div",{className:"flex items-center space-x-2",children:[void 0!==e.isLegal&&(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${e.isLegal?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300":"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300"}`,children:e.isLegal?"✅ Legal":"❌ Illegal"}),e.averageManaValue&&(0,t.jsxs)("span",{className:"px-2 py-1 bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300 rounded-full text-xs font-medium",children:[e.averageManaValue.toFixed(1)," CMC"]})]})}),(0,t.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,t.jsx)("button",{onClick:()=>{},className:"flex-1 bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 py-2 px-3 rounded-lg text-sm font-medium hover:bg-primary-100 dark:hover:bg-primary-900/30 transition-colors",children:"View Deck"}),(0,t.jsx)("button",{onClick:()=>l(e.id),className:"p-2 text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 rounded-lg transition-colors",children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,t.jsx)("button",{onClick:()=>{var a,r;return a=e.id,r=e.name,void(window.confirm(`Are you sure you want to delete "${r}"? This action cannot be undone.`)&&x.mutate(a))},className:"p-2 text-red-400 hover:text-red-600 rounded-lg transition-colors",disabled:x.isPending,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]},e.id))}),(0,t.jsx)(N,{isOpen:a||!!n,onClose:()=>{r(!1),l(null)},deckId:n||void 0})]})},_=e=>{let{isOpen:a,onClose:r,cardId:n,initialCardData:l}=e,i=(0,g.jE)(),[c,o]=(0,s.useState)({cardId:l?.id||"",status:"owned",quantity:1,condition:"near_mint",notes:"",tags:[],collectionIds:[],deckIds:[]}),[d,m]=(0,s.useState)([]),[u,x]=(0,s.useState)([]),{data:h}=(0,p.I)({queryKey:["user-card",n],queryFn:()=>y.cards.getUserCard(n),enabled:!!n}),{data:b}=(0,p.I)({queryKey:["card-info",c.cardId],queryFn:()=>y.cards.getCard(c.cardId),enabled:!!c.cardId}),{data:v=[]}=(0,p.I)({queryKey:["tags"],queryFn:()=>y.tags.getTags()}),{data:j=[]}=(0,p.I)({queryKey:["collections"],queryFn:()=>y.collections.getCollections()}),k=(0,f.n)({mutationFn:y.cards.addCard,onSuccess:()=>{i.invalidateQueries({queryKey:["user-cards"]}),i.invalidateQueries({queryKey:["collections"]}),r()}}),w=(0,f.n)({mutationFn:e=>{let{id:a,data:r}=e;return y.cards.updateCard(a,r)},onSuccess:()=>{i.invalidateQueries({queryKey:["user-cards"]}),i.invalidateQueries({queryKey:["user-card",n]}),r()}});(0,s.useEffect)(()=>{h&&(o({cardId:h.cardId,status:h.status,quantity:h.quantity,condition:h.condition||"near_mint",notes:h.notes||"",tags:h.tags,collectionIds:h.collectionIds}),m(h.tags),x(h.collectionIds))},[h]);let N=async e=>{e.preventDefault();let a={...c,tags:d,collectionIds:u};n&&h?w.mutate({id:n,data:a}):k.mutate(a)};return a?(0,t.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:r,children:(0,t.jsx)("div",{className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-surface-900 rounded-t-3xl max-h-[90vh] overflow-hidden animate-slide-up",children:(0,t.jsxs)("div",{className:"p-6",children:[(0,t.jsx)("div",{className:"w-12 h-1.5 bg-surface-300 dark:bg-surface-600 rounded-full mx-auto mb-6"}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,t.jsx)("h2",{className:"text-xl font-bold text-surface-900 dark:text-white",children:n?"Edit Card":"Add Card"}),(0,t.jsx)("button",{onClick:r,className:"p-2 rounded-xl text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,t.jsxs)("div",{className:"max-h-[calc(90vh-8rem)] overflow-y-auto",children:[b&&(0,t.jsx)("div",{className:"mb-6 p-4 bg-surface-50 dark:bg-surface-800 rounded-2xl",children:(0,t.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,t.jsx)("div",{className:"w-16 h-20 bg-surface-200 dark:bg-surface-700 rounded-lg flex items-center justify-center",children:b.image_url?(0,t.jsx)("img",{src:b.image_url,alt:b.name,className:"w-full h-full object-cover rounded-lg"}):(0,t.jsx)("svg",{className:"w-6 h-6 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white",children:b.name}),(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:b.set_name}),(0,t.jsxs)("div",{className:"flex items-center space-x-2 mt-2",children:[(0,t.jsx)("span",{className:"px-2 py-1 bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300 rounded-full text-xs font-medium",children:b.game}),(0,t.jsx)("span",{className:"px-2 py-1 bg-accent-100 dark:bg-accent-900/30 text-accent-700 dark:text-accent-300 rounded-full text-xs font-medium",children:b.rarity})]})]})]})}),(0,t.jsxs)("form",{onSubmit:N,className:"space-y-6",onClick:e=>e.stopPropagation(),children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-3",children:"Ownership Status"}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsx)("button",{type:"button",onClick:()=>o(e=>({...e,status:"owned"})),className:`p-4 rounded-xl border-2 transition-all ${"owned"===c.status?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-surface-200 dark:border-surface-700"}`,children:(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsx)("div",{className:"text-2xl mb-2",children:"✅"}),(0,t.jsx)("div",{className:"font-medium text-surface-900 dark:text-white",children:"Owned"}),(0,t.jsx)("div",{className:"text-sm text-surface-600 dark:text-surface-400",children:"Cards you own"})]})}),(0,t.jsx)("button",{type:"button",onClick:()=>o(e=>({...e,status:"wanted"})),className:`p-4 rounded-xl border-2 transition-all ${"wanted"===c.status?"border-accent-500 bg-accent-50 dark:bg-accent-900/20":"border-surface-200 dark:border-surface-700"}`,children:(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsx)("div",{className:"text-2xl mb-2",children:"❤️"}),(0,t.jsx)("div",{className:"font-medium text-surface-900 dark:text-white",children:"Wanted"}),(0,t.jsx)("div",{className:"text-sm text-surface-600 dark:text-surface-400",children:"Wishlist cards"})]})})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Quantity"}),(0,t.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,t.jsx)("button",{type:"button",onClick:()=>o(e=>({...e,quantity:Math.max(1,e.quantity-1)})),className:"w-10 h-10 bg-surface-100 dark:bg-surface-700 rounded-lg flex items-center justify-center text-surface-600 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-600 transition-colors",children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})}),(0,t.jsx)("span",{className:"text-xl font-semibold text-surface-900 dark:text-white min-w-[3rem] text-center",children:c.quantity}),(0,t.jsx)("button",{type:"button",onClick:()=>o(e=>({...e,quantity:e.quantity+1})),className:"w-10 h-10 bg-surface-100 dark:bg-surface-700 rounded-lg flex items-center justify-center text-surface-600 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-600 transition-colors",children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})})})]})]}),"owned"===c.status&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Condition"}),(0,t.jsxs)("select",{value:c.condition,onChange:e=>o(a=>({...a,condition:e.target.value})),className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors",children:[(0,t.jsx)("option",{value:"mint",children:"Mint (M)"}),(0,t.jsx)("option",{value:"near_mint",children:"Near Mint (NM)"}),(0,t.jsx)("option",{value:"excellent",children:"Excellent (EX)"}),(0,t.jsx)("option",{value:"good",children:"Good (G)"}),(0,t.jsx)("option",{value:"light_played",children:"Light Played (LP)"}),(0,t.jsx)("option",{value:"played",children:"Played (P)"}),(0,t.jsx)("option",{value:"poor",children:"Poor (PO)"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Tags"}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:v.map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>{m(a=>a.includes(e.id)?a.filter(a=>a!==e.id):[...a,e.id])},className:`px-3 py-2 rounded-full text-sm font-medium transition-colors ${d.includes(e.id)?"text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,style:{backgroundColor:d.includes(e.id)?e.color:void 0},children:e.name},e.id))})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Collections"}),(0,t.jsx)("div",{className:"space-y-2 max-h-32 overflow-y-auto",children:j.map(e=>(0,t.jsxs)("label",{className:"flex items-center space-x-3",children:[(0,t.jsx)("input",{type:"checkbox",checked:u.includes(e.id),onChange:a=>{x(r=>a.target.checked?[...r,e.id]:r.filter(a=>a!==e.id))},className:"w-4 h-4 text-primary-600 bg-surface-50 border-surface-300 rounded focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-surface-800 dark:bg-surface-700 dark:border-surface-600"}),(0,t.jsx)("span",{className:"text-sm text-surface-700 dark:text-surface-300",children:e.name})]},e.id))})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Notes"}),(0,t.jsx)("textarea",{value:c.notes,onChange:e=>o(a=>({...a,notes:e.target.value})),rows:3,placeholder:"Add any notes about this card...",className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors resize-none"})]}),(0,t.jsx)("button",{type:"submit",disabled:!c.cardId||k.isPending||w.isPending,className:"w-full bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 disabled:from-surface-400 disabled:to-surface-400 text-white font-semibold py-4 px-6 rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl disabled:shadow-none transform hover:-translate-y-0.5 disabled:transform-none",children:k.isPending||w.isPending?(0,t.jsxs)("div",{className:"flex items-center justify-center",children:[(0,t.jsxs)("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,t.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,t.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),n?"Updating...":"Adding..."]}):n?"Update Card":"Add Card"})]})]})]})})}):null},S=e=>{let{isOpen:a,onClose:r,onCardSelect:n}=e,[l,i]=(0,s.useState)(""),[c,o]=(0,s.useState)(""),[d,m]=(0,s.useState)({game:"",rarity:"",status:"all"}),[u,x]=(0,s.useState)(null),[h,g]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=setTimeout(()=>{o(l)},300);return()=>clearTimeout(e)},[l]);let{data:f=[],isLoading:b}=(0,p.I)({queryKey:["card-search",c,d],queryFn:()=>c.trim()?y.cards.searchCards(c,d):y.cards.getAllCards(d),enabled:a});return a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:r,children:(0,t.jsxs)("div",{className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-surface-900 rounded-t-3xl h-[90vh] overflow-hidden animate-slide-up",children:[(0,t.jsxs)("div",{className:"p-4 pb-0",children:[(0,t.jsx)("div",{className:"w-12 h-1.5 bg-surface-300 dark:bg-surface-600 rounded-full mx-auto mb-4"}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsx)("h2",{className:"text-xl font-bold text-surface-900 dark:text-white",children:"Browse Cards"}),(0,t.jsx)("button",{onClick:r,className:"p-2 rounded-xl text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,t.jsxs)("div",{className:"relative mb-4",children:[(0,t.jsx)("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}),(0,t.jsx)("input",{type:"text",value:l,onChange:e=>i(e.target.value),placeholder:"Search cards...",className:"w-full pl-10 pr-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors"})]}),(0,t.jsxs)("div",{className:"flex space-x-2 mb-4 overflow-x-auto pb-2",children:[(0,t.jsxs)("select",{value:d.game,onChange:e=>m(a=>({...a,game:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"",children:"All Games"}),(0,t.jsx)("option",{value:"MTG",children:"Magic: The Gathering"}),(0,t.jsx)("option",{value:"POKEMON",children:"Pok\xe9mon"}),(0,t.jsx)("option",{value:"LORCANA",children:"Disney Lorcana"}),(0,t.jsx)("option",{value:"YUGIOH",children:"Yu-Gi-Oh!"})]}),(0,t.jsxs)("select",{value:d.rarity,onChange:e=>m(a=>({...a,rarity:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"",children:"All Rarities"}),(0,t.jsx)("option",{value:"Common",children:"Common"}),(0,t.jsx)("option",{value:"Uncommon",children:"Uncommon"}),(0,t.jsx)("option",{value:"Rare",children:"Rare"}),(0,t.jsx)("option",{value:"Super Rare",children:"Super Rare"}),(0,t.jsx)("option",{value:"Legendary",children:"Legendary"}),(0,t.jsx)("option",{value:"Mythic",children:"Mythic"})]})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto px-4 pb-4",onClick:e=>e.stopPropagation(),children:b?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)("div",{className:"w-8 h-8 bg-gradient-to-r from-primary-500 to-accent-500 rounded-full flex items-center justify-center animate-bounce-subtle mb-3",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 text-sm",children:"Searching cards..."})]})}):0===f.length?(0,t.jsxs)("div",{className:"text-center py-12",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-surface-100 dark:bg-surface-700 rounded-2xl flex items-center justify-center mx-auto mb-4",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.172 16.172a4 4 0 015.656 0M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,t.jsx)("h3",{className:"text-lg font-semibold text-surface-900 dark:text-white mb-2",children:"No cards found"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400",children:"Try adjusting your search or filters"})]}):(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("p",{className:"text-sm text-surface-600 dark:text-surface-400 mb-4",children:[f.length," cards found"]}),f.map(e=>(0,t.jsxs)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-4 transition-colors",children:[(0,t.jsxs)("div",{className:"flex items-start space-x-4",children:[(0,t.jsx)("div",{className:"w-12 h-16 bg-surface-200 dark:bg-surface-700 rounded-lg flex items-center justify-center flex-shrink-0",children:e.image_url?(0,t.jsx)("img",{src:e.image_url,alt:e.name,className:"w-full h-full object-cover rounded-lg"}):(0,t.jsx)("svg",{className:"w-4 h-4 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white truncate",children:e.name}),(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400 truncate",children:e.set_name}),(0,t.jsx)("p",{className:"text-xs text-surface-500 dark:text-surface-500 mt-1",children:e.card_type}),(0,t.jsxs)("div",{className:"flex items-center space-x-2 mt-2",children:[(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e){case"MTG":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"POKEMON":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"LORCANA":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"YUGIOH":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}})(e.game)}`,children:e.game}),(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e.toLowerCase()){case"common":default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300";case"uncommon":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"rare":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"super rare":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"legendary":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"mythic":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300"}})(e.rarity)}`,children:e.rarity})]}),e.current_price&&(0,t.jsxs)("p",{className:"text-sm font-medium text-green-600 dark:text-green-400 mt-2",children:["$",e.current_price.toFixed(2)]})]}),(0,t.jsx)("button",{onClick:()=>{x(e),g(!0)},className:"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 text-white p-2 rounded-xl transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5 flex-shrink-0",children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})})})]}),(e.mana_cost||e.power&&e.toughness)&&(0,t.jsxs)("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-surface-200 dark:border-surface-700",children:[e.mana_cost&&(0,t.jsxs)("span",{className:"text-xs text-surface-600 dark:text-surface-400",children:["Mana Cost: ",e.mana_cost]}),e.power&&e.toughness&&(0,t.jsxs)("span",{className:"text-xs text-surface-600 dark:text-surface-400",children:[e.power,"/",e.toughness]})]})]},e.id))]})})]})}),h&&u&&(0,t.jsx)(_,{isOpen:h,onClose:()=>{g(!1),x(null)},initialCardData:u})]}):null},L="https://api.scryfall.com",M="https://api.lorcast.com/v0",A="https://api.lorcana-api.com",$="https://tcg-vault.vercel.app/api/proxy/lorcana";class P{constructor(e,a){this.requests=[],this.maxRequests=e,this.timeWindow=a}async waitForSlot(){let e=Date.now();if(this.requests=this.requests.filter(a=>e-a<this.timeWindow),this.requests.length>=this.maxRequests){let a=this.requests[0],r=this.timeWindow-(e-a);await new Promise(e=>setTimeout(e,r))}this.requests.push(e)}}let O=new P(10,1e3),I=new P(5,1e3),D=new P(10,1e3),T={async searchCards(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;await O.waitForSlot();try{let r=await fetch(`${L}/cards/search?q=${encodeURIComponent(e)}&page=${a}`);if(!r.ok)throw Error(`Scryfall API error: ${r.status}`);return(await r.json()).data.map(e=>({id:e.id,name:e.name,set_name:e.set_name,set_code:e.set,card_number:e.collector_number,rarity:e.rarity,game:"MTG",mana_cost:e.mana_cost,cmc:e.cmc,card_type:e.type_line,colors:e.colors,oracle_text:e.oracle_text,power:e.power,toughness:e.toughness,image_url:e.image_uris?.normal,stock_image_url:e.image_uris?.normal,current_price:e.prices?.usd?parseFloat(e.prices.usd):void 0,market_price:e.prices?.usd_foil?parseFloat(e.prices.usd_foil):void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}catch(e){return console.error("Error fetching MTG cards:",e),[]}},async getCardByName(e){await O.waitForSlot();try{let a=await fetch(`${L}/cards/named?fuzzy=${encodeURIComponent(e)}`);if(!a.ok)return null;let r=await a.json();return{id:r.id,name:r.name,set_name:r.set_name,set_code:r.set,card_number:r.collector_number,rarity:r.rarity,game:"MTG",mana_cost:r.mana_cost,cmc:r.cmc,card_type:r.type_line,colors:r.colors,oracle_text:r.oracle_text,power:r.power,toughness:r.toughness,image_url:r.image_uris?.normal,stock_image_url:r.image_uris?.normal,current_price:r.prices?.usd?parseFloat(r.prices.usd):void 0,market_price:r.prices?.usd_foil?parseFloat(r.prices.usd_foil):void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}catch(e){return console.error("Error fetching MTG card:",e),null}},async getRandomCards(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;await O.waitForSlot();try{let a=await fetch(`${L}/cards/random?q=game:paper&page_size=${e}`);if(!a.ok)throw Error(`Scryfall API error: ${a.status}`);let r=await a.json();return(Array.isArray(r)?r:[r]).map(e=>({id:e.id,name:e.name,set_name:e.set_name,set_code:e.set,card_number:e.collector_number,rarity:e.rarity,game:"MTG",mana_cost:e.mana_cost,cmc:e.cmc,card_type:e.type_line,colors:e.colors,oracle_text:e.oracle_text,power:e.power,toughness:e.toughness,image_url:e.image_uris?.normal,stock_image_url:e.image_uris?.normal,current_price:e.prices?.usd?parseFloat(e.prices.usd):void 0,market_price:e.prices?.usd_foil?parseFloat(e.prices.usd_foil):void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}catch(e){return console.error("Error fetching random MTG cards:",e),[]}}},z={async searchCards(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;await I.waitForSlot();try{let r=await fetch(`https://api.pokemontcg.io/v2/cards?q=name:${encodeURIComponent(e)}&page=${a}&pageSize=20`);if(!r.ok)throw Error(`Pok\xe9mon API error: ${r.status}`);return(await r.json()).data.map(e=>({id:e.id,name:e.name,set_name:e.set.name,set_code:e.set.id,card_number:e.number,rarity:e.rarity,game:"POKEMON",mana_cost:e.convertedRetreatCost?.toString(),cmc:e.convertedRetreatCost,card_type:e.supertype,colors:e.types||[],oracle_text:e.attacks?.map(e=>`${e.name}: ${e.text}`).join("\n"),power:e.hp,toughness:null,image_url:e.images.small,stock_image_url:e.images.large,current_price:e.cardmarket?.prices?.averageSellPrice||void 0,market_price:e.cardmarket?.prices?.lowPrice||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}catch(e){return console.error("Error fetching Pok\xe9mon cards:",e),[]}},async getCardByName(e){let a=await this.searchCards(e,1);return a.length>0?a[0]:null}},R={async searchCards(e){try{let a=await fetch(`https://db.ygoprodeck.com/api/v7/cardinfo.php?fname=${encodeURIComponent(e)}`);if(!a.ok)throw Error(`Yu-Gi-Oh! API error: ${a.status}`);return(await a.json()).data.map(e=>({id:e.id,name:e.name,set_name:e.set_name,set_code:e.set_code,card_number:e.num,rarity:e.rarity,game:"YUGIOH",mana_cost:e.level?.toString(),cmc:e.level,card_type:e.type,colors:[e.attribute],oracle_text:e.desc,power:e.atk?.toString(),toughness:e.def?.toString(),image_url:e.card_images?.[0]?.image_url,stock_image_url:e.card_images?.[0]?.image_url_small,current_price:e.card_prices?.[0]?.amazon_price?parseFloat(e.card_prices[0].amazon_price):void 0,market_price:e.card_prices?.[0]?.cardmarket_price?parseFloat(e.card_prices[0].cardmarket_price):void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}catch(e){return console.error("Error fetching Yu-Gi-Oh! cards:",e),[]}},async getCardByName(e){let a=await this.searchCards(e);return a.length>0?a[0]:null}},V={async searchCards(e){await D.waitForSlot();try{try{let a=await fetch(`${$}?search=${encodeURIComponent(e)}&api=lorcana`);if(a.ok){let e=await a.json();if(console.log("\uD83D\uDD0D Proxy API response:",JSON.stringify(e,null,2)),e.success&&e.data){let a=e.data.cards||e.data.data||e.data||[];if(a.length>0)return console.log(`✅ Found ${a.length} Lorcana cards via proxy (${e.source})`),console.log("\uD83D\uDD0D First card structure:",JSON.stringify(a[0],null,2)),a.map(e=>({id:e.id||e.uuid||e.card_id||`lorcana-${Math.random()}`,name:e.name||e.card_name||e.title||"",set_name:e.set?.name||e.set_name||e.set_name||"",set_code:e.set?.code||e.set_code||e.set_code||"",card_number:e.number||e.card_number||e.card_num||"",rarity:e.rarity||e.rarity_name||"",game:"LORCANA",mana_cost:e.cost?.toString()||e.mana_cost||e.ink_cost?.toString()||"",cmc:e.cost||e.cmc||e.ink_cost||0,card_type:e.type||e.card_type||e.type_name||"",colors:e.colors||e.ink||[],oracle_text:e.text||e.oracle_text||e.description||e.effect||"",power:e.strength?.toString()||e.power||e.attack?.toString()||"",toughness:e.willpower?.toString()||e.toughness||e.defense?.toString()||"",image_url:e.image_url||e.images?.small||e.images?.png||e.image||"",stock_image_url:e.image_url||e.images?.small||e.images?.png||e.image||"",current_price:e.price?.market||e.current_price||void 0,market_price:e.price?.low||e.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}}}catch(e){console.log("❌ Proxy API failed, trying direct APIs")}try{let a=await fetch(`${A}/cards/fetch?search=name~${encodeURIComponent(e)}`);if(a.ok){let e=await a.json();console.log("\uD83D\uDD0D Direct API response:",JSON.stringify(e,null,2));let r=e.cards||e.data||e||[];if(r.length>0)return console.log(`✅ Found ${r.length} Lorcana cards from direct Lorcana API`),console.log("\uD83D\uDD0D First card structure:",JSON.stringify(r[0],null,2)),r.map(e=>({id:e.id||e.uuid||e.card_id||`lorcana-${Math.random()}`,name:e.name||e.card_name||e.title||"",set_name:e.set?.name||e.set_name||e.set_name||"",set_code:e.set?.code||e.set_code||e.set_code||"",card_number:e.number||e.card_number||e.card_num||"",rarity:e.rarity||e.rarity_name||"",game:"LORCANA",mana_cost:e.cost?.toString()||e.mana_cost||e.ink_cost?.toString()||"",cmc:e.cost||e.cmc||e.ink_cost||0,card_type:e.type||e.card_type||e.type_name||"",colors:e.colors||e.ink||[],oracle_text:e.text||e.oracle_text||e.description||e.effect||"",power:e.strength?.toString()||e.power||e.attack?.toString()||"",toughness:e.willpower?.toString()||e.toughness||e.defense?.toString()||"",image_url:e.image_url||e.images?.small||e.images?.png||e.image||"",stock_image_url:e.image_url||e.images?.small||e.images?.png||e.image||"",current_price:e.price?.market||e.current_price||void 0,market_price:e.price?.low||e.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}}catch(e){console.log("❌ Direct Lorcana API failed")}for(let a of[`/cards?q=${encodeURIComponent(e)}`,`/cards?search=${encodeURIComponent(e)}`,`/cards?query=${encodeURIComponent(e)}`])try{let e=await fetch(`${M}${a}`);if(e.ok){let r=await e.json();console.log(`🔍 Lorcast API response from ${a}:`,JSON.stringify(r,null,2));let t=r.cards||r.data||r||[];if(t.length>0)return console.log(`✅ Found ${t.length} Lorcana cards from Lorcast ${a}`),console.log("\uD83D\uDD0D First card structure:",JSON.stringify(t[0],null,2)),t.map(e=>({id:e.id||e.uuid||e.card_id||`lorcana-${Math.random()}`,name:e.name||e.card_name||e.title||"",set_name:e.set?.name||e.set_name||e.set_name||"",set_code:e.set?.code||e.set_code||e.set_code||"",card_number:e.number||e.card_number||e.card_num||"",rarity:e.rarity||e.rarity_name||"",game:"LORCANA",mana_cost:e.cost?.toString()||e.mana_cost||e.ink_cost?.toString()||"",cmc:e.cost||e.cmc||e.ink_cost||0,card_type:e.type||e.card_type||e.type_name||"",colors:e.colors||e.ink||[],oracle_text:e.text||e.oracle_text||e.description||e.effect||"",power:e.strength?.toString()||e.power||e.attack?.toString()||"",toughness:e.willpower?.toString()||e.toughness||e.defense?.toString()||"",image_url:e.image_url||e.images?.small||e.images?.png||e.image||"",stock_image_url:e.image_url||e.images?.small||e.images?.png||e.image||"",current_price:e.price?.market||e.current_price||void 0,market_price:e.price?.low||e.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}}catch(e){console.log(`❌ Failed to search from Lorcast ${a}:`,e);continue}return console.log("⚠️ No Lorcana cards found from any API"),[]}catch(e){return console.error("Error searching Lorcana cards:",e),[]}},async getCardByName(e){await D.waitForSlot();try{try{let a=await fetch(`${$}?search=${encodeURIComponent(e)}&api=lorcana`);if(a.ok){let r=await a.json();if(r.success&&r.data){let a=r.data.cards||r.data.data||r.data||[];if(a.length>0){let t=a[0];return console.log(`✅ Found Lorcana card "${e}" via proxy (${r.source})`),{id:t.id||t.uuid||t.card_id||`lorcana-${Math.random()}`,name:t.name||t.card_name||t.title||"",set_name:t.set?.name||t.set_name||t.set_name||"",set_code:t.set?.code||t.set_code||t.set_code||"",card_number:t.number||t.card_number||t.card_num||"",rarity:t.rarity||t.rarity_name||"",game:"LORCANA",mana_cost:t.cost?.toString()||t.mana_cost||t.ink_cost?.toString()||"",cmc:t.cost||t.cmc||t.ink_cost||0,card_type:t.type||t.card_type||t.type_name||"",colors:t.colors||t.ink||[],oracle_text:t.text||t.oracle_text||t.description||t.effect||"",power:t.strength?.toString()||t.power||t.attack?.toString()||"",toughness:t.willpower?.toString()||t.toughness||t.defense?.toString()||"",image_url:t.image_url||t.images?.small||t.images?.png||t.image||"",stock_image_url:t.image_url||t.images?.small||t.images?.png||t.image||"",current_price:t.price?.market||t.current_price||void 0,market_price:t.price?.low||t.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}}}}catch(e){console.log("❌ Proxy API failed for card lookup, trying direct APIs")}try{let a=await fetch(`${A}/cards/fetch?search=name~${encodeURIComponent(e)}`);if(a.ok){let r=await a.json(),t=r.cards||r.data||r||[];if(t.length>0){let a=t[0];return console.log(`✅ Found Lorcana card "${e}" from direct Lorcana API`),{id:a.id||a.uuid||a.card_id||`lorcana-${Math.random()}`,name:a.name||a.card_name||a.title||"",set_name:a.set?.name||a.set_name||a.set_name||"",set_code:a.set?.code||a.set_code||a.set_code||"",card_number:a.number||a.card_number||a.card_num||"",rarity:a.rarity||a.rarity_name||"",game:"LORCANA",mana_cost:a.cost?.toString()||a.mana_cost||a.ink_cost?.toString()||"",cmc:a.cost||a.cmc||a.ink_cost||0,card_type:a.type||a.card_type||a.type_name||"",colors:a.colors||a.ink||[],oracle_text:a.text||a.oracle_text||a.description||a.effect||"",power:a.strength?.toString()||a.power||a.attack?.toString()||"",toughness:a.willpower?.toString()||a.toughness||a.defense?.toString()||"",image_url:a.image_url||a.images?.small||a.images?.png||a.image||"",stock_image_url:a.image_url||a.images?.small||a.images?.png||a.image||"",current_price:a.price?.market||a.current_price||void 0,market_price:a.price?.low||a.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}}}catch(e){console.log("❌ Direct Lorcana API failed for card lookup")}for(let a of[`/cards?q=name:${encodeURIComponent(e)}`,`/cards?search=${encodeURIComponent(e)}`,`/cards?query=${encodeURIComponent(e)}`])try{let r=await fetch(`${M}${a}`);if(r.ok){let t=await r.json(),s=t.cards||t.data||t||[];if(s.length>0){let r=s[0];return console.log(`✅ Found Lorcana card "${e}" from Lorcast ${a}`),{id:r.id||r.uuid||r.card_id||`lorcana-${Math.random()}`,name:r.name||r.card_name||r.title||"",set_name:r.set?.name||r.set_name||r.set_name||"",set_code:r.set?.code||r.set_code||r.set_code||"",card_number:r.number||r.card_number||r.card_num||"",rarity:r.rarity||r.rarity_name||"",game:"LORCANA",mana_cost:r.cost?.toString()||r.mana_cost||r.ink_cost?.toString()||"",cmc:r.cost||r.cmc||r.ink_cost||0,card_type:r.type||r.card_type||r.type_name||"",colors:r.colors||r.ink||[],oracle_text:r.text||r.oracle_text||r.description||r.effect||"",power:r.strength?.toString()||r.power||r.attack?.toString()||"",toughness:r.willpower?.toString()||r.toughness||r.defense?.toString()||"",image_url:r.image_url||r.images?.small||r.images?.png||r.image||"",stock_image_url:r.image_url||r.images?.small||r.images?.png||r.image||"",current_price:r.price?.market||r.current_price||void 0,market_price:r.price?.low||r.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}}}catch(e){console.log(`❌ Failed to fetch card from Lorcast ${a}:`,e);continue}return console.log(`⚠️ Lorcana card "${e}" not found from any API`),null}catch(e){return console.error("Error fetching Lorcana card:",e),null}},async getRandomCards(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;await D.waitForSlot();try{try{let a=await fetch(`${$}?limit=${e}&api=lorcana`);if(a.ok){let r=await a.json();if(r.success&&r.data){let a=r.data.cards||r.data.data||r.data||[];if(a.length>0)return console.log(`✅ Found ${a.length} cards via proxy (${r.source})`),a.sort(()=>.5-Math.random()).slice(0,e).map(e=>({id:e.id||e.uuid||`lorcana-${Math.random()}`,name:e.name,set_name:e.set?.name||e.set_name||"",set_code:e.set?.code||e.set_code||"",card_number:e.number||e.card_number||"",rarity:e.rarity,game:"LORCANA",mana_cost:e.cost?.toString()||e.mana_cost,cmc:e.cost||e.cmc,card_type:e.type||e.card_type,colors:e.colors||[],oracle_text:e.text||e.oracle_text||"",power:e.strength?.toString()||e.power,toughness:e.willpower?.toString()||e.toughness,image_url:e.image_url||e.images?.small||e.images?.png,stock_image_url:e.image_url||e.images?.small||e.images?.png,current_price:e.price?.market||e.current_price||void 0,market_price:e.price?.low||e.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}}}catch(e){console.log("❌ Proxy API failed for random cards, trying direct APIs")}try{let a=await fetch(`${A}/cards/fetch?pagesize=${e}`);if(a.ok){let r=await a.json(),t=r.cards||r.data||r||[];if(t.length>0)return console.log(`✅ Found ${t.length} cards from direct Lorcana API`),t.sort(()=>.5-Math.random()).slice(0,e).map(e=>({id:e.id||e.uuid||`lorcana-${Math.random()}`,name:e.name,set_name:e.set?.name||e.set_name||"",set_code:e.set?.code||e.set_code||"",card_number:e.number||e.card_number||"",rarity:e.rarity,game:"LORCANA",mana_cost:e.cost?.toString()||e.mana_cost,cmc:e.cost||e.cmc,card_type:e.type||e.card_type,colors:e.colors||[],oracle_text:e.text||e.oracle_text||"",power:e.strength?.toString()||e.power,toughness:e.willpower?.toString()||e.toughness,image_url:e.image_url||e.images?.small||e.images?.png,stock_image_url:e.image_url||e.images?.small||e.images?.png,current_price:e.price?.market||e.current_price||void 0,market_price:e.price?.low||e.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}}catch(e){console.log("❌ Direct Lorcana API failed for random cards")}let a=[];for(let e of["/cards","/api/cards","/v0/cards"])try{let r=await fetch(`${M}${e}`);if(r.ok){let t=await r.json();a=t.cards||t.data||t||[],console.log(`✅ Found ${a.length} cards from Lorcast ${e}`);break}}catch(a){console.log(`❌ Failed to fetch from Lorcast ${e}:`,a);continue}if(0===a.length)return console.log("⚠️ No cards found from any endpoint, returning empty array"),[];return a.sort(()=>.5-Math.random()).slice(0,e).map(e=>({id:e.id||e.uuid||`lorcana-${Math.random()}`,name:e.name,set_name:e.set?.name||e.set_name||"",set_code:e.set?.code||e.set_code||"",card_number:e.number||e.card_number||"",rarity:e.rarity,game:"LORCANA",mana_cost:e.cost?.toString()||e.mana_cost,cmc:e.cost||e.cmc,card_type:e.type||e.card_type,colors:e.colors||[],oracle_text:e.text||e.oracle_text||"",power:e.strength?.toString()||e.power,toughness:e.willpower?.toString()||e.toughness,image_url:e.image_url||e.images?.small||e.images?.png,stock_image_url:e.image_url||e.images?.small||e.images?.png,current_price:e.price?.market||e.current_price||void 0,market_price:e.price?.low||e.market_price||void 0,verified:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}))}catch(e){return console.error("Error fetching random Lorcana cards:",e),[]}}},B={async searchCards(e,a){console.log(`🔍 Database search: "${e}" for game: "${a}"`);try{let r=new URLSearchParams({q:e,limit:"50"});a&&"ALL"!==a&&r.append("game",a);let t=await fetch(`https://tcg-vault.vercel.app/api/cards?${r}`);if(!t.ok)throw Error(`Database search failed: ${t.status}`);let s=await t.json();if(s.success&&s.data)return console.log(`✅ Found ${s.data.length} cards from database`),s.data.map(e=>({id:e.id,name:e.name,set_name:e.set_name,set_code:e.set_code,card_number:e.card_number,rarity:e.rarity,game:e.game,mana_cost:e.mana_cost,cmc:e.cmc,card_type:e.card_type,colors:e.colors||[],oracle_text:e.oracle_text,power:e.power,toughness:e.toughness,image_url:e.image_url,stock_image_url:e.stock_image_url,current_price:e.current_price,market_price:e.market_price,verified:e.verified,createdAt:e.createdAt,updatedAt:e.updatedAt}));return[]}catch(e){return console.error("Error in database card search:",e),[]}},async getCardByName(e,a){try{if("MTG"===a)return await T.getCardByName(e);if("POKEMON"===a)return await z.getCardByName(e);if("YUGIOH"===a)return await R.getCardByName(e);if("LORCANA"===a)return await V.getCardByName(e);let r=await T.getCardByName(e);if(r)return r;let t=await z.getCardByName(e);if(t)return t;let s=await R.getCardByName(e);if(s)return s;let n=await V.getCardByName(e);if(n)return n;return null}catch(e){return console.error("Error in unified card search by name:",e),null}},async getRandomCards(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20,a=arguments.length>1?arguments[1]:void 0,r=[];console.log(`🎲 Getting ${e} random cards for game: "${a}"`);try{if(!a||"MTG"===a){console.log("\uD83C\uDFB2 Getting random MTG cards...");let a=await T.getRandomCards(Math.ceil(e/4));console.log(`✅ Found ${a.length} random MTG cards`),r.push(...a)}if(!a||"LORCANA"===a){console.log("\uD83C\uDFB2 Getting random Lorcana cards...");let a=await V.getRandomCards(Math.ceil(e/4));console.log(`✅ Found ${a.length} random Lorcana cards`),r.push(...a)}let t=r.slice(0,e);return console.log(`🎯 Returning ${t.length} random cards`),t}catch(e){return console.error("Error getting random cards:",e),[]}}},F=e=>{let{isOpen:a,onClose:r,onCardSelect:n}=e,[l,i]=(0,s.useState)(""),[c,o]=(0,s.useState)(""),[d,m]=(0,s.useState)(""),[u,x]=(0,s.useState)(null),[h,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[y,k]=(0,s.useState)("cards"),w=(0,g.jE)();(0,s.useEffect)(()=>{let e=setTimeout(()=>{o(l)},500);return()=>clearTimeout(e)},[l]);let{data:N=[],isLoading:C}=(0,p.I)({queryKey:["external-cards",c,d],queryFn:async()=>{if(!c.trim())return[];j(!0);try{let e=await B.searchCards(c,d||void 0);return console.log(`Found ${e.length} cards for search "${c}" in game "${d}"`),e}catch(e){return console.error("Error searching external cards:",e),[]}finally{j(!1)}},enabled:!!c.trim()&&a,staleTime:3e5,retry:2}),{data:_=[]}=(0,p.I)({queryKey:["random-cards",d],queryFn:async()=>{try{let e=await B.getRandomCards(20,d||void 0);return console.log(`Found ${e.length} random cards for game "${d}"`),e}catch(e){return console.error("Error fetching random cards:",e),[]}},enabled:a&&!c.trim(),staleTime:6e5,retry:2}),S=(0,f.n)({mutationFn:async e=>{let a=await fetch("/api/cards/find-or-create",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("tcg-vault-token")}`},body:JSON.stringify({name:e.name,game:e.game,setName:e.set_name,setCode:e.set_code,rarity:e.rarity,cardType:e.card_type,manaCost:e.mana_cost,imageUrl:e.stock_image_url})});if(!a.ok)throw Error("Failed to add card to database");return(await a.json()).card},onSuccess:()=>{w.invalidateQueries({queryKey:["cards"]})}}),L=async e=>{n?(n(e),r()):(x(e),b(!0))},M=async e=>{try{await S.mutateAsync(e),alert(`${e.name} has been added to the database!`)}catch(e){console.error("Error adding card to database:",e),alert("Failed to add card to database. Please try again.")}},A=e=>{switch(e){case"MTG":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"POKEMON":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"LORCANA":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"YUGIOH":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}},$=e=>{switch(e?.toLowerCase()){case"common":default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300";case"uncommon":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"rare":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"super rare":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"legendary":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"mythic":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300"}};if(!a)return null;let P=c.trim()?N:_,O=C||v;return console.log("CardDatabaseBrowser state:",{isOpen:a,searchTerm:l,debouncedSearch:c,selectedGame:d,externalCards:N.length,randomCards:_.length,displayCards:P.length,isLoading:O}),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50",onClick:r,children:(0,t.jsx)("div",{className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-surface-900 rounded-t-3xl h-[90vh] overflow-hidden animate-slide-up",onClick:e=>e.stopPropagation(),children:(0,t.jsxs)("div",{className:"p-4 pb-0",children:[(0,t.jsx)("div",{className:"w-12 h-1.5 bg-surface-300 dark:bg-surface-600 rounded-full mx-auto mb-4"}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsx)("h2",{className:"text-xl font-bold text-surface-900 dark:text-white",children:"Card Database Browser"}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),r()},className:"p-2 rounded-xl text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,t.jsxs)("div",{className:"relative mb-4",children:[(0,t.jsx)("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}),(0,t.jsx)("input",{type:"text",value:l,onChange:e=>i(e.target.value),onKeyDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),placeholder:"Search cards from external databases...",className:"w-full pl-10 pr-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors"})]}),(0,t.jsxs)("div",{className:"flex space-x-2 mb-4 overflow-x-auto pb-2",children:[(0,t.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),m("")},className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${!d?"bg-primary-500 text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,children:"All Games"}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),m("MTG")},className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${"MTG"===d?"bg-orange-500 text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,children:"Magic: The Gathering"}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),m("POKEMON")},className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${"POKEMON"===d?"bg-yellow-500 text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,children:"Pok\xe9mon"}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),m("YUGIOH")},className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${"YUGIOH"===d?"bg-blue-500 text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,children:"Yu-Gi-Oh!"}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),m("LORCANA")},className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${"LORCANA"===d?"bg-purple-500 text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300"}`,children:"Disney Lorcana"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,t.jsx)("span",{className:"text-sm font-medium text-surface-700 dark:text-surface-300",children:"View:"}),(0,t.jsxs)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),k("cards")},className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${"cards"===y?"bg-primary-500 text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-600"}`,children:[(0,t.jsx)("svg",{className:"w-4 h-4 inline mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})}),"Cards"]}),(0,t.jsxs)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),k("table")},className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${"table"===y?"bg-primary-500 text-white":"bg-surface-100 dark:bg-surface-700 text-surface-700 dark:text-surface-300 hover:bg-surface-200 dark:hover:bg-surface-600"}`,children:[(0,t.jsx)("svg",{className:"w-4 h-4 inline mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H6a2 2 0 00-2 2v8a2 2 0 002 2z"})}),"Table"]})]}),P.length>0&&(0,t.jsxs)("span",{className:"text-sm text-surface-600 dark:text-surface-400",children:[P.length," card",1!==P.length?"s":""]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto pb-20",children:O?(0,t.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,t.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary-500"}),(0,t.jsx)("span",{className:"ml-3 text-surface-600 dark:text-surface-400",children:"Searching external databases..."})]}):0===P.length?(0,t.jsxs)("div",{className:"text-center py-8",children:[(0,t.jsx)("div",{className:"text-6xl mb-4",children:"\uD83D\uDD0D"}),(0,t.jsx)("h3",{className:"text-lg font-semibold text-surface-900 dark:text-white mb-2",children:c.trim()?"No cards found":"Discover Cards"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400",children:c.trim()?"Try adjusting your search terms or game filter":"Search for cards to see results from external databases"})]}):(0,t.jsxs)(t.Fragment,{children:["cards"===y&&(0,t.jsx)("div",{className:"grid grid-cols-1 gap-4",children:P.map(e=>(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-4 transition-all duration-200 hover:shadow-md",children:(0,t.jsxs)("div",{className:"flex items-start space-x-4",children:[(0,t.jsx)("div",{className:"w-16 h-20 bg-surface-200 dark:bg-surface-700 rounded-lg flex items-center justify-center flex-shrink-0",children:e.stock_image_url?(0,t.jsx)("img",{src:e.stock_image_url,alt:e.name,className:"w-full h-full object-cover rounded-lg"}):(0,t.jsx)("svg",{className:"w-6 h-6 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white truncate",children:e.name}),(0,t.jsxs)("p",{className:"text-sm text-surface-600 dark:text-surface-400",children:[e.set_name," • ",e.card_number]}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-2 mt-2",children:[(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${A(e.game)}`,children:e.game}),e.rarity&&(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${$(e.rarity)}`,children:e.rarity}),e.current_price&&(0,t.jsxs)("span",{className:"px-2 py-1 bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300 rounded-full text-xs font-medium",children:["$",e.current_price]})]})]}),(0,t.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,t.jsx)("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),L(e)},className:"px-3 py-1 bg-primary-500 hover:bg-primary-600 text-white text-xs font-medium rounded-lg transition-colors",children:"Add to Collection"}),(0,t.jsx)("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),M(e)},disabled:S.isPending,className:"px-3 py-1 bg-surface-100 dark:bg-surface-700 hover:bg-surface-200 dark:hover:bg-surface-600 text-surface-700 dark:text-surface-300 text-xs font-medium rounded-lg transition-colors disabled:opacity-50",children:S.isPending?"Adding...":"Add to DB"})]})]})},`${e.game}-${e.id}`))}),"table"===y&&(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 overflow-hidden",children:(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"w-full",children:[(0,t.jsx)("thead",{className:"bg-surface-50 dark:bg-surface-700",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-surface-600 dark:text-surface-400 uppercase tracking-wider",children:"Card"}),(0,t.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-surface-600 dark:text-surface-400 uppercase tracking-wider",children:"Set"}),(0,t.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-surface-600 dark:text-surface-400 uppercase tracking-wider",children:"Game"}),(0,t.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-surface-600 dark:text-surface-400 uppercase tracking-wider",children:"Rarity"}),(0,t.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-surface-600 dark:text-surface-400 uppercase tracking-wider",children:"Price"}),(0,t.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-surface-600 dark:text-surface-400 uppercase tracking-wider",children:"Actions"})]})}),(0,t.jsx)("tbody",{className:"divide-y divide-surface-200 dark:divide-surface-700",children:P.map(e=>(0,t.jsxs)("tr",{className:"hover:bg-surface-50 dark:hover:bg-surface-700 transition-colors",children:[(0,t.jsx)("td",{className:"px-4 py-3",children:(0,t.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,t.jsx)("div",{className:"w-10 h-12 bg-surface-200 dark:bg-surface-700 rounded flex items-center justify-center flex-shrink-0",children:e.stock_image_url?(0,t.jsx)("img",{src:e.stock_image_url,alt:e.name,className:"w-full h-full object-cover rounded"}):(0,t.jsx)("svg",{className:"w-4 h-4 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-sm font-medium text-surface-900 dark:text-white truncate",children:e.name}),(0,t.jsxs)("div",{className:"text-xs text-surface-500 dark:text-surface-400",children:["#",e.card_number]})]})]})}),(0,t.jsx)("td",{className:"px-4 py-3 text-sm text-surface-900 dark:text-white",children:e.set_name}),(0,t.jsx)("td",{className:"px-4 py-3",children:(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${A(e.game)}`,children:e.game})}),(0,t.jsx)("td",{className:"px-4 py-3",children:e.rarity&&(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${$(e.rarity)}`,children:e.rarity})}),(0,t.jsx)("td",{className:"px-4 py-3 text-sm text-surface-900 dark:text-white",children:e.current_price?`$${e.current_price}`:"-"}),(0,t.jsx)("td",{className:"px-4 py-3",children:(0,t.jsxs)("div",{className:"flex space-x-2",children:[(0,t.jsx)("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),L(e)},className:"px-2 py-1 bg-primary-500 hover:bg-primary-600 text-white text-xs font-medium rounded transition-colors",children:"Add"}),(0,t.jsx)("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),M(e)},disabled:S.isPending,className:"px-2 py-1 bg-surface-100 dark:bg-surface-700 hover:bg-surface-200 dark:hover:bg-surface-600 text-surface-700 dark:text-surface-300 text-xs font-medium rounded transition-colors disabled:opacity-50",children:"DB"})]})})]},`${e.game}-${e.id}`))})]})})})]})})]})})}),u&&h&&(0,t.jsx)("div",{className:"fixed inset-0 z-60",children:(0,t.jsx)("div",{className:"fixed inset-0 bg-black/50",onClick:()=>b(!1),children:(0,t.jsx)("div",{className:"fixed bottom-0 left-0 right-0 bg-white dark:bg-surface-900 rounded-t-3xl p-6 max-h-[80vh] overflow-y-auto",children:(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsxs)("h3",{className:"text-lg font-semibold text-surface-900 dark:text-white mb-4",children:["Add ",u.name," to your collection"]}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mb-6",children:"This card will be added to your collection with the details you specify."}),(0,t.jsxs)("div",{className:"flex space-x-4",children:[(0,t.jsx)("button",{onClick:()=>{L(u),b(!1)},className:"flex-1 bg-primary-500 hover:bg-primary-600 text-white font-medium py-3 px-6 rounded-xl transition-colors",children:"Continue"}),(0,t.jsx)("button",{onClick:()=>b(!1),className:"flex-1 bg-surface-100 dark:bg-surface-700 hover:bg-surface-200 dark:hover:bg-surface-600 text-surface-700 dark:text-surface-300 font-medium py-3 px-6 rounded-xl transition-colors",children:"Cancel"})]})]})})})})]})},E=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{maxTilt:a=15,perspective:r=1e3,scale:t=1.05,speed:n=600,reset:l=!0,easing:i="cubic-bezier(0.25, 0.46, 0.45, 0.94)"}=e,c=(0,s.useRef)(null),[o,d]=(0,s.useState)({tiltX:0,tiltY:0,scale:1,transform:""}),m=(0,s.useCallback)((e,s,n)=>{let l=n.left+n.width/2,i=(s-(n.top+n.height/2))/(n.height/2)*a,c=(l-e)/(n.width/2)*a,o=`perspective(${r}px) rotateX(${i}deg) rotateY(${c}deg) scale(${t})`;d({tiltX:i,tiltY:c,scale:t,transform:o})},[a,r,t]),u=(0,s.useCallback)(()=>{d({tiltX:0,tiltY:0,scale:1,transform:`perspective(${r}px) rotateX(0deg) rotateY(0deg) scale(1)`})},[r]),x=(0,s.useCallback)(e=>{if(!c.current)return;let a=c.current.getBoundingClientRect();m(e.clientX,e.clientY,a)},[m]),h=(0,s.useCallback)(()=>{c.current&&c.current.addEventListener("mousemove",x)},[x]),g=(0,s.useCallback)(()=>{c.current&&(c.current.removeEventListener("mousemove",x),l&&u())},[x,l,u]);(0,s.useEffect)(()=>{let e=c.current;if(e)return e.addEventListener("mouseenter",h),e.addEventListener("mouseleave",g),()=>{e.removeEventListener("mouseenter",h),e.removeEventListener("mouseleave",g),e.removeEventListener("mousemove",x)}},[h,g,x]);let p={transform:o.transform,transformStyle:"preserve-3d",transition:l?`transform ${n}ms ${i}`:"none"};return{ref:c,tiltState:o,tiltStyles:p,resetTilt:u}},H=e=>{let{card:a,userImages:r=[],size:n="medium",showUserPhotos:l=!1,className:i=""}=e,[c,o]=(0,s.useState)(!1),[d,m]=(0,s.useState)(0),[u,x]=(0,s.useState)(l),{ref:h,tiltStyles:g}=E({maxTilt:"large"===n?15:10,scale:1,speed:400,easing:"cubic-bezier(0.23, 1, 0.320, 1)"}),p=()=>["super rare","legendary","mythic"].includes(a.rarity.toLowerCase()),f=()=>{let e=a.rarity.toLowerCase().replace(/\s+/g,"");return`rarity-border-${e}`},b={small:"w-16 h-22",medium:"w-24 h-32",large:"w-48 h-64"},v=u&&r.length>0?r[d]:a.stock_image_url||a.image_url;if(!v||c)return(()=>{let e={MTG:"from-orange-400 to-red-500",POKEMON:"from-yellow-400 to-red-500",LORCANA:"from-purple-400 to-pink-500"}[a.game]||"from-gray-400 to-gray-600",r=f(),s=p()?"foil-rainbow":"";return(0,t.jsxs)("div",{ref:h,style:g,className:`${b[n]} bg-gradient-to-br ${e} rounded-lg flex flex-col items-center justify-center text-white shadow-md card-transition card-depth ${r} ${s} ${i}`,children:[(0,t.jsx)("div",{className:"text-lg font-bold mb-1",children:"\uD83C\uDCCF"}),(0,t.jsx)("div",{className:"text-xs text-center px-2 leading-tight",children:a.name.split(" ").slice(0,2).join(" ")}),(0,t.jsx)("div",{className:"text-xs opacity-75 mt-1",children:a.game})]})})();let j=f(),y=p()?"foil-card":"",k="legendary"===a.rarity.toLowerCase()||"mythic"===a.rarity.toLowerCase()?"holographic":"";return(0,t.jsxs)("div",{className:`relative ${i}`,children:[(0,t.jsx)("div",{ref:h,style:g,className:`card-transition card-depth ${j} ${y} ${k} rounded-lg`,children:(0,t.jsx)("img",{src:v,alt:a.name,className:`${b[n]} object-cover rounded-lg`,onError:()=>o(!0)})}),u&&r.length>0&&(0,t.jsxs)("div",{className:"absolute top-1 left-1 bg-blue-500 text-white text-xs px-1 py-0.5 rounded",children:["\uD83D\uDCF8 ",d+1,"/",r.length]}),r.length>0&&(0,t.jsx)("div",{className:"absolute bottom-1 right-1",children:(0,t.jsx)("button",{onClick:()=>x(!u),className:"bg-black bg-opacity-50 text-white text-xs px-1 py-0.5 rounded hover:bg-opacity-75",title:u?"Show stock image":"Show your photos",children:u?"\uD83D\uDCCB":"\uD83D\uDCF8"})}),u&&r.length>1&&(0,t.jsxs)("div",{className:"absolute bottom-1 left-1 flex gap-1",children:[(0,t.jsx)("button",{onClick:()=>m(e=>Math.max(0,e-1)),disabled:0===d,className:"bg-black bg-opacity-50 text-white text-xs px-1 py-0.5 rounded disabled:opacity-50",children:""}),(0,t.jsx)("button",{onClick:()=>m(e=>Math.min(r.length-1,e+1)),disabled:d===r.length-1,className:"bg-black bg-opacity-50 text-white text-xs px-1 py-0.5 rounded disabled:opacity-50",children:""})]}),(0,t.jsx)("div",{className:"absolute top-1 right-1",children:u?(0,t.jsx)("span",{className:"bg-blue-500 text-white text-xs px-1 py-0.5 rounded",title:"Your card photo",children:"\uD83D\uDC64"}):(0,t.jsx)("span",{className:"bg-green-500 text-white text-xs px-1 py-0.5 rounded",title:"Stock image",children:"✓"})})]})},G=e=>{let{children:a,rarity:r,className:s=""}=e;return(0,t.jsx)("div",{className:`${(()=>{let e=r.toLowerCase().replace(/\s+/g,"");return`rarity-border-${e}`})()} ${(()=>{switch(r.toLowerCase()){case"mythic":return"mythic-expansion premium-card-animation";case"legendary":case"super rare":return"premium-card-animation";default:return"card-expansion-organic"}})()} ${s}`,children:a})},W=()=>{let[e,a]=(0,s.useState)(""),[r,n]=(0,s.useState)({game:"",rarity:"",status:"all",search:""}),[l,i]=(0,s.useState)("card"),[c,o]=(0,s.useState)(!1),[d,m]=(0,s.useState)(!1),[u,x]=(0,s.useState)(null),{data:h=[],isLoading:g,error:f}=(0,p.I)({queryKey:["user-cards",{...r,search:e}],queryFn:()=>y.cards.getUserCards({...r,search:e})}),b=h.filter(e=>{let a=e.card;return!!a&&(!r.rarity||a.rarity===r.rarity)&&(!r.game||a.game===r.game)&&(!r.status||"all"===r.status||e.status===r.status)}),v=e=>{switch(e){case"MTG":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"POKEMON":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"LORCANA":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"YUGIOH":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}},j=e=>{switch(e.toLowerCase()){case"common":default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300";case"uncommon":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"rare":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"super rare":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";case"legendary":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"mythic":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300"}},k=e=>{switch(e){case"owned":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"wanted":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}};return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-bold text-surface-900 dark:text-white",children:"My Cards"}),(0,t.jsxs)("p",{className:"text-surface-600 dark:text-surface-400 mt-1",children:[b.length," cards in your collection"]})]}),(0,t.jsxs)("div",{className:"flex space-x-3",children:[(0,t.jsxs)("button",{onClick:()=>o(!0),className:"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 text-white px-4 py-2 rounded-xl font-medium transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5",children:[(0,t.jsx)("svg",{className:"w-4 h-4 mr-2 inline",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"Add Cards"]}),(0,t.jsxs)("button",{onClick:()=>m(!0),className:"bg-gradient-to-r from-accent-500 to-primary-500 hover:from-accent-600 hover:to-primary-600 text-white px-4 py-2 rounded-xl font-medium transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5",children:[(0,t.jsx)("svg",{className:"w-4 h-4 mr-2 inline",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),"Browse Database"]})]})]}),(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-4",children:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}),(0,t.jsx)("input",{type:"text",value:e,onChange:e=>a(e.target.value),placeholder:"Search your cards...",className:"w-full pl-10 pr-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex space-x-2 overflow-x-auto pb-2",children:[(0,t.jsxs)("select",{value:r.game,onChange:e=>n(a=>({...a,game:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"",children:"All Games"}),(0,t.jsx)("option",{value:"MTG",children:"Magic: The Gathering"}),(0,t.jsx)("option",{value:"POKEMON",children:"Pok\xe9mon"}),(0,t.jsx)("option",{value:"LORCANA",children:"Disney Lorcana"}),(0,t.jsx)("option",{value:"YUGIOH",children:"Yu-Gi-Oh!"})]}),(0,t.jsxs)("select",{value:r.rarity,onChange:e=>n(a=>({...a,rarity:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"",children:"All Rarities"}),(0,t.jsx)("option",{value:"Common",children:"Common"}),(0,t.jsx)("option",{value:"Uncommon",children:"Uncommon"}),(0,t.jsx)("option",{value:"Rare",children:"Rare"}),(0,t.jsx)("option",{value:"Super Rare",children:"Super Rare"}),(0,t.jsx)("option",{value:"Legendary",children:"Legendary"}),(0,t.jsx)("option",{value:"Mythic",children:"Mythic"})]}),(0,t.jsxs)("select",{value:r.status,onChange:e=>n(a=>({...a,status:e.target.value})),className:"px-3 py-2 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors whitespace-nowrap",children:[(0,t.jsx)("option",{value:"all",children:"All Cards"}),(0,t.jsx)("option",{value:"owned",children:"Owned"}),(0,t.jsx)("option",{value:"wanted",children:"Wanted"})]})]}),(0,t.jsxs)("div",{className:"flex bg-surface-100 dark:bg-surface-700 rounded-lg p-1",children:[(0,t.jsx)("button",{onClick:()=>i("card"),className:`p-2 rounded-md transition-colors ${"card"===l?"bg-white dark:bg-surface-600 text-surface-900 dark:text-white shadow-sm":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),(0,t.jsx)("button",{onClick:()=>i("list"),className:`p-2 rounded-md transition-colors ${"list"===l?"bg-white dark:bg-surface-600 text-surface-900 dark:text-white shadow-sm":"text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-white"}`,children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})})]})]})]})}),g&&(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)("div",{className:"w-8 h-8 bg-gradient-to-r from-primary-500 to-accent-500 rounded-full flex items-center justify-center animate-bounce-subtle mb-3",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 text-sm",children:"Loading your cards..."})]})}),f&&(0,t.jsx)("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl p-4 mb-6",children:(0,t.jsx)("p",{className:"text-red-800 dark:text-red-400",children:"Error loading cards. Please try again."})}),!g&&!f&&(0,t.jsx)(t.Fragment,{children:0===b.length?(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 p-8",children:(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-surface-100 dark:bg-surface-700 rounded-2xl flex items-center justify-center mx-auto mb-6",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("h3",{className:"text-xl font-semibold text-surface-900 dark:text-white mb-2",children:0===h.length?"No cards yet":"No matching cards"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mb-6",children:0===h.length?"Start building your collection by adding cards":"Try adjusting your search or filters"}),0===h.length&&(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-center justify-center",children:[(0,t.jsx)("button",{onClick:()=>o(!0),className:"bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 text-white px-6 py-3 rounded-xl font-medium transition-all duration-200 shadow-md hover:shadow-lg transform hover:-translate-y-0.5",children:"Browse Cards"}),(0,t.jsx)("button",{className:"bg-surface-100 dark:bg-surface-700 hover:bg-surface-200 dark:hover:bg-surface-600 text-surface-800 dark:text-surface-300 px-6 py-3 rounded-xl font-medium transition-colors",children:"Scan Cards"})]})]})}):"card"===l?(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:b.map(e=>{let a=e.card;return a?(0,t.jsxs)(G,{rarity:a.rarity,className:"bg-white dark:bg-surface-800 rounded-xl shadow overflow-hidden hover:shadow-lg transition-all duration-200",children:[(0,t.jsx)("div",{className:"flex justify-center p-4 bg-surface-50 dark:bg-surface-700/50",children:(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(H,{card:a,size:"large",className:"mx-auto"}),(0,t.jsx)("div",{className:"absolute -top-2 -right-2",children:(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${k(e.status)}`,children:"owned"===e.status?"✅":"❤️"})}),e.quantity>1&&(0,t.jsx)("div",{className:"absolute -bottom-2 -right-2",children:(0,t.jsxs)("span",{className:"bg-surface-800 dark:bg-surface-200 text-white dark:text-surface-900 text-xs font-bold px-2 py-1 rounded-full",children:[e.quantity,"x"]})})]})}),(0,t.jsxs)("div",{className:"p-4",children:[(0,t.jsxs)("div",{className:"flex justify-between items-start mb-3",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white truncate",title:a.name,children:a.name}),(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400 truncate",children:a.set_name})]}),(0,t.jsx)("span",{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${v(a.game)}`,children:a.game})]}),(0,t.jsxs)("div",{className:"space-y-1 mb-3",children:[a.card_type&&(0,t.jsx)("p",{className:"text-xs text-surface-600 dark:text-surface-400 truncate",title:a.card_type,children:a.card_type}),(0,t.jsxs)("div",{className:"flex justify-between items-center",children:[a.mana_cost&&(0,t.jsxs)("span",{className:"text-xs text-surface-600 dark:text-surface-400",children:["Cost: ",a.mana_cost]}),a.power&&a.toughness&&(0,t.jsxs)("span",{className:"text-xs text-surface-600 dark:text-surface-400",children:[a.power,"/",a.toughness]})]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,t.jsx)("span",{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${j(a.rarity)}`,children:a.rarity}),a.current_price&&(0,t.jsxs)("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:["$",a.current_price.toFixed(2)]})]}),e.condition&&"owned"===e.status&&(0,t.jsx)("div",{className:"mb-3",children:(0,t.jsx)("span",{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${(e=>{switch(e){case"mint":return"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300";case"near_mint":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"excellent":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"good":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"light_played":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300";case"played":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300";case"poor":return"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-300";default:return"bg-surface-100 text-surface-800 dark:bg-surface-700 dark:text-surface-300"}})(e.condition)}`,children:e.condition.replace("_"," ").toUpperCase()})}),(0,t.jsx)("button",{onClick:()=>x(e.id),className:"w-full bg-surface-100 dark:bg-surface-700 hover:bg-surface-200 dark:hover:bg-surface-600 text-surface-800 dark:text-surface-300 py-2 px-3 rounded-lg text-sm font-medium transition-colors",children:"Edit Card"})]})]},e.id):null})}):(0,t.jsx)("div",{className:"bg-white dark:bg-surface-800 rounded-xl border border-surface-200 dark:border-surface-700 overflow-hidden",children:(0,t.jsx)("div",{className:"space-y-1",children:b.map(e=>{let a=e.card;return a?(0,t.jsxs)("div",{className:"flex items-center p-4 hover:bg-surface-50 dark:hover:bg-surface-700/50 transition-colors",children:[(0,t.jsx)("div",{className:"w-12 h-16 bg-surface-200 dark:bg-surface-700 rounded-lg flex items-center justify-center flex-shrink-0 mr-4",children:a.image_url?(0,t.jsx)("img",{src:a.image_url,alt:a.name,className:"w-full h-full object-cover rounded-lg"}):(0,t.jsx)("svg",{className:"w-4 h-4 text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("h3",{className:"font-semibold text-surface-900 dark:text-white truncate",children:a.name}),(0,t.jsx)("p",{className:"text-sm text-surface-600 dark:text-surface-400 truncate",children:a.set_name}),(0,t.jsxs)("div",{className:"flex items-center space-x-2 mt-1",children:[(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${v(a.game)}`,children:a.game}),(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${j(a.rarity)}`,children:a.rarity}),(0,t.jsx)("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${k(e.status)}`,children:e.status})]})]}),(0,t.jsxs)("div",{className:"text-right mr-4",children:[(0,t.jsxs)("div",{className:"text-sm font-medium text-surface-900 dark:text-white",children:[e.quantity,"x"]}),a.current_price&&(0,t.jsxs)("div",{className:"text-sm text-green-600 dark:text-green-400",children:["$",(a.current_price*e.quantity).toFixed(2)]})]}),(0,t.jsx)("button",{onClick:()=>x(e.id),className:"p-2 text-surface-400 hover:text-surface-600 dark:hover:text-surface-300 rounded-lg transition-colors",children:(0,t.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})})]},e.id):null})})})}),(0,t.jsx)(S,{isOpen:c,onClose:()=>o(!1)}),u&&(0,t.jsx)(_,{isOpen:!!u,onClose:()=>x(null),cardId:u}),(0,t.jsx)(F,{isOpen:d,onClose:()=>m(!1),onCardSelect:e=>{console.log("Selected card from database:",e),m(!1)}})]})},U=e=>{let{onModeSelect:a}=e;return(0,t.jsx)("div",{className:"min-h-screen bg-gray-50 px-4 py-6 sm:px-6 lg:px-8",children:(0,t.jsxs)("div",{className:"max-w-md mx-auto sm:max-w-2xl",children:[(0,t.jsxs)("div",{className:"text-center mb-8",children:[(0,t.jsx)("h1",{className:"text-2xl sm:text-3xl font-bold text-gray-900 mb-3",children:"Card Scanner"}),(0,t.jsx)("p",{className:"text-gray-600 text-sm sm:text-base px-2",children:"Choose your scanning mode to get started"})]}),(0,t.jsx)("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 mb-8",children:[{id:"add-to-database",title:"Add Cards to Database",description:"Scan new cards and add them to your collections",icon:"\uD83D\uDCDA",color:"bg-blue-500 hover:bg-blue-600 active:bg-blue-700"},{id:"search-collections",title:"Search Collections",description:"Find these cards in your existing collections",icon:"\uD83D\uDD0D",color:"bg-green-500 hover:bg-green-600 active:bg-green-700"},{id:"price-check",title:"Price Check",description:"Get real-time pricing for your cards",icon:"\uD83D\uDCB0",color:"bg-yellow-500 hover:bg-yellow-600 active:bg-yellow-700"},{id:"deck-building",title:"Deck Building",description:"Scan cards directly into a deck with legality checks",icon:"\uD83C\uDFAF",color:"bg-purple-500 hover:bg-purple-600 active:bg-purple-700"}].map(e=>(0,t.jsxs)("button",{onClick:()=>a(e.id),className:`${e.color} text-white rounded-xl shadow-lg transition-all duration-200 hover:shadow-xl transform hover:scale-[1.02] active:scale-[0.98] text-left relative overflow-hidden`,style:{minHeight:"120px"},children:[(0,t.jsxs)("div",{className:"p-6 sm:p-6 h-full flex flex-col",children:[(0,t.jsxs)("div",{className:"flex items-start space-x-4 mb-3",children:[(0,t.jsx)("div",{className:"text-3xl sm:text-4xl flex-shrink-0",role:"img","aria-label":e.title,children:e.icon}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsx)("h3",{className:"text-lg sm:text-xl font-semibold leading-tight mb-2",children:e.title})})]}),(0,t.jsx)("p",{className:"text-white/90 text-sm sm:text-base leading-relaxed flex-1",children:e.description})]}),(0,t.jsx)("div",{className:"absolute inset-0 bg-gradient-to-br from-white/10 to-transparent pointer-events-none"})]},e.id))}),(0,t.jsxs)("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-5 sm:p-6",children:[(0,t.jsxs)("div",{className:"flex items-center mb-4",children:[(0,t.jsx)("span",{className:"text-2xl mr-3",role:"img","aria-label":"Tips",children:"\uD83D\uDCA1"}),(0,t.jsx)("h2",{className:"font-semibold text-gray-900 text-lg",children:"Pro Tips"})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,t.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full mt-2 flex-shrink-0"}),(0,t.jsx)("p",{className:"text-gray-700 text-sm sm:text-base",children:"Position cards clearly within the camera frame"})]}),(0,t.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,t.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full mt-2 flex-shrink-0"}),(0,t.jsx)("p",{className:"text-gray-700 text-sm sm:text-base",children:"Scanner will auto-detect cards after 2-3 seconds"})]}),(0,t.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,t.jsx)("div",{className:"w-2 h-2 bg-purple-500 rounded-full mt-2 flex-shrink-0"}),(0,t.jsx)("p",{className:"text-gray-700 text-sm sm:text-base",children:"You can scan up to 100 cards in a single session"})]}),(0,t.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,t.jsx)("div",{className:"w-2 h-2 bg-yellow-500 rounded-full mt-2 flex-shrink-0"}),(0,t.jsx)("p",{className:"text-gray-700 text-sm sm:text-base",children:"Duplicates are allowed and will be tracked separately"})]})]})]}),(0,t.jsx)("div",{className:"h-8 sm:h-4"})]})})},q=e=>{let{isVisible:a,message:r,progress:s,type:n="scanning"}=e;return a?(0,t.jsx)("div",{className:"fixed top-4 left-4 right-4 z-50 animate-slide-down sm:left-1/2 sm:right-auto sm:transform sm:-translate-x-1/2 sm:w-auto sm:min-w-80 sm:max-w-md",children:(0,t.jsx)("div",{className:`${(()=>{switch(n){case"scanning":default:return"bg-blue-600 text-white";case"processing":return"bg-purple-600 text-white";case"success":return"bg-green-600 text-white";case"error":return"bg-red-600 text-white"}})()} rounded-xl shadow-lg px-4 py-3 sm:px-5 sm:py-4`,children:(0,t.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,t.jsx)("div",{className:"text-lg sm:text-xl flex-shrink-0",role:"img","aria-label":n,children:(()=>{switch(n){case"scanning":default:return"\uD83D\uDCF7";case"processing":return"\uD83E\uDD16";case"success":return"✅";case"error":return"❌"}})()}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("div",{className:"font-medium text-sm sm:text-base leading-tight",children:r}),void 0!==s&&(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)("div",{className:"w-full bg-white/20 rounded-full h-1.5 sm:h-2",children:(0,t.jsx)("div",{className:"bg-white h-1.5 sm:h-2 rounded-full transition-all duration-300 ease-out",style:{width:`${Math.min(100,Math.max(0,s))}%`}})})})]}),("scanning"===n||"processing"===n)&&(0,t.jsx)("div",{className:"w-5 h-5 sm:w-6 sm:h-6 flex-shrink-0",children:(0,t.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 sm:h-6 sm:w-6 border-2 border-white border-t-transparent"})})]})})}):null};var K=r(5364);class Y{constructor(){this.apiKey=null,this.apiKey=K.env.REACT_APP_OPENAI_API_KEY||null}setApiKey(e){this.apiKey=e}async analyzeCard(e){if(!this.apiKey)throw Error("OpenAI API key not configured");try{let a=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({model:"gpt-4o-mini",messages:[{role:"user",content:[{type:"text",text:'Analyze this trading card image and extract information. Respond with ONLY valid JSON, no markdown formatting or code blocks:\n\n{"cardName": "exact card name", "setName": "set name if visible", "setCode": "3-4 letter set code if visible", "cardType": "creature, spell, pokemon, etc", "rarity": "common, uncommon, rare, etc", "hp": "HP value for Pokemon", "attacks": ["attack names"], "abilities": ["ability names"], "rawText": "all visible text on the card", "game": "MTG or POKEMON or LORCANA", "confidence": 95}\n\nIMPORTANT: Return ONLY the JSON object, no markdown code blocks. Focus on accuracy, leave fields empty if unclear. For the cardName, use the exact name as printed on the card.'},{type:"image_url",image_url:{url:e,detail:"high"}}]}],max_tokens:1e3,temperature:.1})});if(!a.ok)throw Error(`OpenAI API error: ${a.status} ${a.statusText}`);let r=await a.json(),t=r.choices[0]?.message?.content;if(!t)throw Error("No content received from OpenAI");try{let e=t.trim();e.startsWith("```json")?e=e.replace(/^```json\s*/,"").replace(/\s*```$/,""):e.startsWith("```")&&(e=e.replace(/^```\s*/,"").replace(/\s*```$/,""));let a=JSON.parse(e);return{cardName:a.cardName||"",setName:a.setName||void 0,setCode:a.setCode||void 0,cardType:a.cardType||void 0,rarity:a.rarity||void 0,hp:a.hp||void 0,attacks:a.attacks||[],abilities:a.abilities||[],rawText:a.rawText||t,confidence:a.confidence||85,game:a.game||"UNKNOWN"}}catch(a){console.log("JSON parsing failed, trying text extraction:",a),console.log("Raw content:",t);let e=this.extractDataFromRawResponse(t);return{cardName:e.cardName||"Unknown Card",setName:e.setName,setCode:e.setCode,cardType:e.cardType,rarity:e.rarity,hp:e.hp,attacks:e.attacks||[],abilities:e.abilities||[],rawText:t,confidence:70,game:e.game||"UNKNOWN"}}}catch(e){throw console.error("AI OCR error:",e),Error(`AI OCR failed: ${e.message}`)}}extractCardNameFromText(e){let a=e.split("\n").map(e=>e.trim()).filter(e=>e.length>0);for(let e of a)if(!e.match(/^(card name|name:|the card|this is)/i)&&e.length>3&&e.length<50)return e;return a[0]||"Unknown Card"}extractDataFromRawResponse(e){let a=e.split("\n").map(e=>e.trim()).filter(e=>e.length>0),r="",t="",s="",n="",l="",i=[],c=[];for(let e of a)!(e.startsWith("```")||e.startsWith("#"))&&(e.match(/card\s*name[:]?\s*(.+)/i)?r=e.replace(/card\s*name[:]?\s*/i,"").replace(/['"]/g,""):e.match(/name[:]?\s*(.+)/i)&&!r?r=e.replace(/name[:]?\s*/i,"").replace(/['"]/g,""):e.match(/set[:]?\s*(.+)/i)?t=e.replace(/set[:]?\s*/i,"").replace(/['"]/g,""):e.match(/hp[:]?\s*(\d+)/i)?l=e.match(/hp[:]?\s*(\d+)/i)?.[1]||"":e.match(/type[:]?\s*(.+)/i)?s=e.replace(/type[:]?\s*/i,"").replace(/['"]/g,""):e.match(/rarity[:]?\s*(.+)/i)&&(n=e.replace(/rarity[:]?\s*/i,"").replace(/['"]/g,"")));return r||(r=this.extractCardNameFromText(e)),{cardName:r||"Unknown Card",setName:t||void 0,setCode:void 0,cardType:s||void 0,rarity:n||void 0,hp:l||void 0,attacks:i.length>0?i:void 0,abilities:c.length>0?c:void 0,game:this.detectGameFromText(e)}}detectGameFromText(e){let a=e.toLowerCase();return a.includes("pokemon")||a.includes("hp")||a.includes("evolves")?"POKEMON":a.includes("mana")||a.includes("creature")||a.includes("instant")?"MTG":a.includes("lorcana")||a.includes("ink")?"LORCANA":"UNKNOWN"}}class Q{constructor(e="http://localhost:11434"){this.baseUrl=e}async analyzeCard(e){try{let a=e.split(",")[1],r=await fetch(`${this.baseUrl}/api/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:"llava:latest",prompt:`Analyze this trading card image and extract:
1. Card name (exact spelling)
2. Set name and code
3. Game type (Magic: The Gathering, Pokemon, or Lorcana)
4. All visible text
5. Card type and rarity if visible
Provide accurate information only. Format as JSON with fields: cardName, setName, setCode, game, cardType, rarity, rawText`,images:[a],stream:!1})});if(!r.ok)throw Error(`Ollama API error: ${r.status}`);let t=(await r.json()).response;try{let e=JSON.parse(t);return{cardName:e.cardName||"",setName:e.setName,setCode:e.setCode,cardType:e.cardType,rarity:e.rarity,rawText:e.rawText||t,confidence:85,game:e.game?.toUpperCase()||"UNKNOWN"}}catch{return{cardName:this.extractCardNameFromText(t),rawText:t,confidence:75,game:this.detectGameFromText(t)}}}catch(e){throw console.error("Ollama OCR error:",e),Error(`Ollama OCR failed: ${e.message}`)}}extractCardNameFromText(e){return e.split("\n").map(e=>e.trim()).filter(e=>e.length>0).find(e=>e.length>3&&e.length<50)||"Unknown Card"}detectGameFromText(e){let a=e.toLowerCase();return a.includes("pokemon")||a.includes("hp")?"POKEMON":a.includes("mana")||a.includes("creature")?"MTG":a.includes("lorcana")?"LORCANA":"UNKNOWN"}}let J=new Y,X=new Q,Z=e=>{let{onCardScanned:a,onError:r,isActive:n,maxQueueSize:l=100}=e,i=(0,s.useRef)(null),c=(0,s.useRef)(null),o=(0,s.useRef)(null),d=(0,s.useRef)(null),m=(0,s.useRef)(0),[u,x]=(0,s.useState)(!1),[h,g]=(0,s.useState)({isScanning:!1,isProcessing:!1,message:"",countdown:0}),[p,f]=(0,s.useState)(0),[b,v]=(0,s.useState)(new Set),[j,y]=(0,s.useState)(!1);(0,s.useEffect)(()=>{(async()=>{try{let e=localStorage.getItem("openai_api_key"),a=localStorage.getItem("tcg_vault_token");if(a)try{let e=await fetch("/api/user/preferences",{headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json"}});if(e.ok){let a=await e.json(),r=a.preferences?.ocrSettings?.openai_api_key;if(r){J.setApiKey(r),y(!0),console.log("✅ OCR configured with user preferences API key");return}}}catch(e){console.log("Could not load user preferences, checking localStorage...")}e?(J.setApiKey(e),y(!0),console.log("✅ OCR configured with localStorage API key")):(console.log("❌ No OpenAI API key found. OCR scanning will not work."),y(!1))}catch(e){console.error("Error initializing OCR:",e),y(!1)}})()},[]),(0,s.useEffect)(()=>(n?k():w(),()=>{w()}),[n]),(0,s.useEffect)(()=>{if(!u||!n||!j)return;let e=setInterval(()=>{Date.now()-m.current>5e3&&(()=>{if(h.isProcessing||p>=l)return;d.current&&clearTimeout(d.current),g(e=>({...e,isScanning:!0,message:"Card detected, stabilizing...",countdown:3}));let e=3,a=setInterval(()=>{e--,g(a=>({...a,countdown:e,message:e>0?`Scanning in ${e}...`:"Scanning card..."})),e<=0&&(clearInterval(a),C())},1e3);d.current=setTimeout(()=>{clearInterval(a),C()},3e3)})()},2e3);return()=>{clearInterval(e),d.current&&clearTimeout(d.current)}},[u,n,h.isProcessing,p,l,j]);let k=async()=>{try{let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment",width:{ideal:1920},height:{ideal:1080}}});i.current&&(i.current.srcObject=e,o.current=e,i.current.onloadedmetadata=()=>{i.current?.play().then(()=>{x(!0)})})}catch(e){console.error("Camera error:",e),r(`Camera access failed: ${e.message}`)}},w=()=>{o.current&&(o.current.getTracks().forEach(e=>e.stop()),o.current=null),x(!1),g({isScanning:!1,isProcessing:!1,message:"",countdown:0})},N=(0,s.useCallback)(()=>{if(!i.current||!c.current)return null;let e=i.current,a=c.current,r=a.getContext("2d");return r?(a.width=e.videoWidth,a.height=e.videoHeight,r.drawImage(e,0,0,a.width,a.height),a.toDataURL("image/jpeg",.8)):null},[]),C=(0,s.useCallback)(async()=>{if(!h.isProcessing&&!(p>=l)){if(!j){g(e=>({...e,isScanning:!1,isProcessing:!1,message:"OCR not configured - please set up your API key in Settings"})),setTimeout(()=>{g(e=>({...e,message:""}))},4e3);return}g(e=>({...e,isScanning:!1,isProcessing:!0,message:"Processing card with AI...",countdown:0}));try{let e,r=N();if(!r)throw Error("Failed to capture image");try{console.log("\uD83E\uDD16 Trying OpenAI Vision API..."),e=await J.analyzeCard(r),console.log("✅ OpenAI Vision result:",e)}catch(a){console.log("❌ OpenAI failed, trying Ollama:",a);try{e=await X.analyzeCard(r),console.log("✅ Ollama Vision result:",e)}catch(e){throw console.error("❌ All AI OCR methods failed"),Error("AI OCR services unavailable. Please configure OpenAI API key or run Ollama locally.")}}let t=`scan_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,s=(e.cardName||"unknown").toLowerCase().replace(/\s+/g,"");if(b.has(s))g(a=>({...a,isProcessing:!1,message:`Duplicate detected: ${e.cardName||"Unknown Card"}`}));else{v(e=>{let a=new Set(e);if(a.add(s),a.size>10){let e=a.values().next().value;a.delete(e)}return a});let n={id:t,cardData:e,imageDataUrl:r,timestamp:Date.now(),queuePosition:p+1};a(n),f(e=>e+1),m.current=Date.now(),g(a=>({...a,isProcessing:!1,message:`Added: ${e.cardName||"Unknown Card"}`}))}setTimeout(()=>{g(e=>({...e,message:""}))},2e3)}catch(a){console.error("Scan processing error:",a);let e="Scan failed, try again";a.message.includes("OpenAI API key not configured")?e="OpenAI API key not configured - check Settings":a.message.includes("OpenAI API error: 401")?e="Invalid OpenAI API key - check Settings":a.message.includes("OpenAI API error: 429")?e="API rate limit exceeded - wait a moment":a.message.includes("AI OCR services unavailable")&&(e="OCR service unavailable - configure API key"),g(a=>({...a,isProcessing:!1,message:e})),setTimeout(()=>{g(e=>({...e,message:""}))},4e3)}}},[N,a,p,l,b,h.isProcessing,j]);return(0,t.jsxs)("div",{className:"relative px-4 sm:px-0",children:[(0,t.jsx)(q,{isVisible:h.isScanning||h.isProcessing||!!h.message,message:h.message,progress:h.isScanning?(3-h.countdown)/3*100:void 0,type:h.isProcessing?"processing":h.message.includes("Added:")?"success":h.message.includes("not configured")||h.message.includes("unavailable")?"error":"scanning"}),!j&&u&&(0,t.jsx)("div",{className:"mb-4 bg-yellow-50 border border-yellow-200 rounded-xl p-4",children:(0,t.jsxs)("div",{className:"flex items-start",children:[(0,t.jsx)("span",{className:"text-yellow-600 text-xl mr-3 flex-shrink-0 mt-0.5",children:"⚠️"}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"font-medium text-yellow-900 text-sm sm:text-base",children:"OCR Not Configured"}),(0,t.jsx)("p",{className:"text-yellow-700 text-sm mt-1",children:"Please configure your OpenAI API key in Settings to enable card scanning."})]})]})}),(0,t.jsxs)("div",{className:"relative bg-black rounded-xl overflow-hidden shadow-lg",children:[(0,t.jsx)("video",{ref:i,autoPlay:!0,playsInline:!0,muted:!0,className:"w-full h-auto object-cover",style:{minHeight:"280px",maxHeight:"calc(100vh - 300px)",aspectRatio:"4/3"}}),u&&(0,t.jsxs)("div",{className:"absolute inset-0 pointer-events-none",children:[(0,t.jsx)("div",{className:"absolute inset-4 sm:inset-6 border-2 border-white border-dashed rounded-lg flex items-center justify-center",children:(0,t.jsxs)("div",{className:"bg-black bg-opacity-60 text-white px-4 py-3 rounded-xl text-center max-w-xs",children:[(0,t.jsx)("div",{className:"font-medium text-sm sm:text-base mb-1",children:"Position card within this area"}),(0,t.jsx)("div",{className:"text-xs sm:text-sm opacity-90",children:j?"Auto-scan in 2-3 seconds":"Configure OCR in Settings first"})]})}),(0,t.jsxs)("div",{className:"absolute top-3 right-3 sm:top-4 sm:right-4 bg-blue-600 text-white px-3 py-1.5 rounded-full text-xs sm:text-sm font-medium shadow-lg",children:["Queue: ",p,"/",l]}),h.isScanning&&(0,t.jsx)("div",{className:"absolute inset-0 bg-blue-500 bg-opacity-20 border-2 border-blue-500 rounded-xl animate-pulse"}),(0,t.jsx)("div",{className:"absolute bottom-4 left-4 right-4 flex justify-center",children:(0,t.jsx)("div",{className:"bg-black bg-opacity-50 backdrop-blur-sm rounded-full px-4 py-2",children:(0,t.jsxs)("div",{className:"flex items-center space-x-3 text-white text-xs",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,t.jsx)("div",{className:"w-2 h-2 bg-green-400 rounded-full animate-pulse"}),(0,t.jsx)("span",{children:"Live"})]}),h.isScanning&&(0,t.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,t.jsx)("div",{className:"w-2 h-2 bg-blue-400 rounded-full animate-pulse"}),(0,t.jsx)("span",{children:"Scanning..."})]})]})})})]}),!u&&(0,t.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,t.jsxs)("div",{className:"text-white text-center",children:[(0,t.jsx)("div",{className:"text-4xl sm:text-5xl mb-3",children:"\uD83D\uDCF9"}),(0,t.jsx)("div",{className:"font-medium text-base sm:text-lg",children:"Starting Camera..."}),(0,t.jsx)("div",{className:"text-sm sm:text-base opacity-75 mt-1",children:"Please allow camera access"})]})})]}),(0,t.jsx)("canvas",{ref:c,className:"hidden"}),u&&(0,t.jsxs)("div",{className:"mt-6 text-center",children:[(0,t.jsx)("button",{onClick:()=>{!h.isProcessing&&p<l&&C()},disabled:h.isProcessing||p>=l||!j,className:"w-full sm:w-auto bg-blue-600 hover:bg-blue-700 disabled:bg-gray-400 text-white px-8 py-4 sm:px-6 sm:py-3 rounded-xl font-medium transition-all duration-200 shadow-lg hover:shadow-xl disabled:shadow-none text-base sm:text-sm",children:h.isProcessing?(0,t.jsxs)("div",{className:"flex items-center justify-center space-x-2",children:[(0,t.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 border-2 border-white border-t-transparent"}),(0,t.jsx)("span",{children:"Processing..."})]}):j?(0,t.jsxs)("div",{className:"flex items-center justify-center space-x-2",children:[(0,t.jsx)("span",{children:"\uD83D\uDCF7"}),(0,t.jsx)("span",{children:"Manual Scan"})]}):"Configure OCR First"}),!j&&(0,t.jsx)("p",{className:"text-sm text-gray-600 mt-3 px-4",children:"Go to Settings → OCR to configure your OpenAI API key"})]})]})},ee=e=>{let{cards:a,onRemoveCard:r,onClearQueue:n,onCardSelect:l,selectedCards:i,onViewCard:c}=e,[o,d]=(0,s.useState)(!1),m=(0,s.useCallback)(()=>{let e=!o;d(e),a.forEach(a=>{l(a.id,e)})},[o,a,l]);return 0===a.length?(0,t.jsxs)("div",{className:"text-center py-16 px-4",children:[(0,t.jsx)("div",{className:"text-6xl sm:text-7xl mb-4",children:"\uD83D\uDCF7"}),(0,t.jsx)("h3",{className:"text-xl sm:text-2xl font-semibold text-gray-700 mb-2",children:"Queue is Empty"}),(0,t.jsx)("p",{className:"text-gray-500 text-sm sm:text-base",children:"Scanned cards will appear here"})]}):(0,t.jsxs)("div",{className:"space-y-4 px-4 sm:px-0",children:[(0,t.jsx)("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-4 sm:p-6",children:(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-4",children:[(0,t.jsxs)("h3",{className:"text-lg sm:text-xl font-semibold text-gray-900",children:["Scanned Cards (",a.length,"/100)"]}),(0,t.jsxs)("label",{className:"flex items-center space-x-2 cursor-pointer select-none",children:[(0,t.jsx)("input",{type:"checkbox",checked:o,onChange:m,className:"w-5 h-5 sm:w-4 sm:h-4 text-blue-600 rounded focus:ring-blue-500 focus:ring-2"}),(0,t.jsx)("span",{className:"text-sm sm:text-sm text-gray-700 font-medium",children:"Select All"})]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between sm:justify-end gap-2",children:[i.size>0&&(0,t.jsxs)("span",{className:"text-xs sm:text-sm text-gray-600 bg-blue-50 px-3 py-1.5 rounded-full font-medium",children:[i.size," selected"]}),(0,t.jsx)("button",{onClick:n,className:"px-4 py-2 text-sm bg-red-50 text-red-700 rounded-lg hover:bg-red-100 active:bg-red-200 transition-colors font-medium",children:"Clear All"})]})]})}),(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:a.map(e=>(0,t.jsxs)("div",{className:`relative bg-white rounded-xl shadow-sm border-2 transition-all duration-200 hover:shadow-md ${i.has(e.id)?"border-blue-500 bg-blue-50/30":"border-gray-100 hover:border-gray-200"}`,children:[(0,t.jsx)("div",{className:"absolute top-3 left-3 z-10",children:(0,t.jsx)("label",{className:"cursor-pointer",children:(0,t.jsx)("input",{type:"checkbox",checked:i.has(e.id),onChange:a=>l(e.id,a.target.checked),className:"w-5 h-5 text-blue-600 rounded focus:ring-blue-500 focus:ring-2 bg-white shadow-sm"})})}),(0,t.jsx)("button",{onClick:()=>r(e.id),className:"absolute top-3 right-3 z-10 w-8 h-8 bg-red-500 text-white rounded-full text-sm hover:bg-red-600 active:bg-red-700 transition-colors flex items-center justify-center shadow-sm","aria-label":"Remove card",children:"\xd7"}),(0,t.jsx)("div",{className:"aspect-[2.5/3.5] bg-gray-100 cursor-pointer overflow-hidden rounded-t-xl",onClick:()=>c(e),children:(0,t.jsx)("img",{src:e.imageDataUrl,alt:e.cardData.cardName||"Scanned card",className:"w-full h-full object-cover transition-transform duration-200 hover:scale-105"})}),(0,t.jsxs)("div",{className:"p-4 space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("h4",{className:"font-medium text-gray-900 text-sm leading-tight line-clamp-2",children:e.cardData.cardName||"Unknown Card"}),e.cardData.setName&&(0,t.jsx)("p",{className:"text-xs text-gray-500 mt-1 line-clamp-1",children:e.cardData.setName})]}),(0,t.jsx)("div",{className:`px-2 py-1 rounded-full text-xs font-medium text-white flex-shrink-0 ${(e=>e?e>=.9?"bg-green-500":e>=.7?"bg-yellow-500":"bg-red-500":"bg-gray-400")(e.cardData.confidence)}`,children:(e=>e?`${Math.round(100*e)}%`:"Unknown")(e.cardData.confidence)})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between text-xs text-gray-500",children:[(0,t.jsx)("span",{className:"truncate",children:e.cardData.game||"Unknown Game"}),e.cardData.rarity&&(0,t.jsx)("span",{className:"capitalize flex-shrink-0 ml-2",children:e.cardData.rarity})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"text-xs text-gray-400",children:["#",e.queuePosition]}),(0,t.jsx)("div",{className:"text-xs text-gray-400",children:new Date(e.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})]})]},e.id))}),(0,t.jsx)("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-4 sm:p-6",children:(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3 sm:gap-4",children:[(0,t.jsxs)("span",{className:"text-sm font-medium text-gray-900",children:["Total: ",a.length," cards"]}),(0,t.jsxs)("span",{className:"text-sm text-gray-600",children:["Selected: ",i.size]})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3 sm:gap-4",children:[(0,t.jsxs)("span",{className:"flex items-center space-x-1.5 text-xs sm:text-sm",children:[(0,t.jsx)("div",{className:"w-2.5 h-2.5 bg-green-500 rounded-full"}),(0,t.jsx)("span",{className:"text-gray-600",children:"High confidence"})]}),(0,t.jsxs)("span",{className:"flex items-center space-x-1.5 text-xs sm:text-sm",children:[(0,t.jsx)("div",{className:"w-2.5 h-2.5 bg-yellow-500 rounded-full"}),(0,t.jsx)("span",{className:"text-gray-600",children:"Medium"})]}),(0,t.jsxs)("span",{className:"flex items-center space-x-1.5 text-xs sm:text-sm",children:[(0,t.jsx)("div",{className:"w-2.5 h-2.5 bg-red-500 rounded-full"}),(0,t.jsx)("span",{className:"text-gray-600",children:"Low"})]})]})]})})]})},ea=e=>{let{selectedCount:a,onAddToCollection:r,onAddToDeck:n,onAddTags:l,onRemoveSelected:i,collections:c,decks:o,isProcessing:d}=e,[m,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[g,p]=(0,s.useState)(!1),[f,b]=(0,s.useState)(""),[v,j]=(0,s.useState)(!1),[y,k]=(0,s.useState)("");if(0===a)return null;let w=()=>{x.trim()&&(l(x.split(",").map(e=>e.trim()).filter(Boolean)),h(""),u(!1))};return(0,t.jsxs)("div",{className:"bg-white border-t border-gray-200 px-4 py-6 sm:px-6",children:[(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[(0,t.jsxs)("h3",{className:"text-lg sm:text-xl font-semibold text-gray-900",children:["Bulk Operations (",a," selected)"]}),(0,t.jsx)("button",{onClick:i,className:"self-start sm:self-auto px-4 py-2 text-sm bg-red-50 text-red-700 rounded-lg hover:bg-red-100 active:bg-red-200 transition-colors font-medium",disabled:d,children:"Remove Selected"})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("h4",{className:"font-medium text-gray-900 text-base",children:"Add to Collection"}),c.length>0&&(0,t.jsxs)("select",{className:"w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-white",onChange:e=>e.target.value&&r(e.target.value),defaultValue:"",disabled:d,children:[(0,t.jsx)("option",{value:"",children:"Select existing collection..."}),c.map(e=>(0,t.jsx)("option",{value:e.id,children:e.name},e.id))]}),g?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("input",{type:"text",value:f,onChange:e=>b(e.target.value),placeholder:"Collection name...",className:"w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500",disabled:d}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("button",{onClick:()=>{f.trim()&&(r("",f.trim()),b(""),p(!1))},className:"flex-1 px-4 py-3 bg-blue-600 text-white rounded-xl text-sm font-medium hover:bg-blue-700 active:bg-blue-800 disabled:bg-gray-400 transition-colors",disabled:!f.trim()||d,children:"Create"}),(0,t.jsx)("button",{onClick:()=>p(!1),className:"px-4 py-3 bg-gray-100 text-gray-700 rounded-xl text-sm font-medium hover:bg-gray-200 active:bg-gray-300 transition-colors",disabled:d,children:"Cancel"})]})]}):(0,t.jsx)("button",{onClick:()=>p(!0),className:"w-full px-4 py-3 border-2 border-dashed border-gray-300 rounded-xl text-sm text-gray-600 hover:border-blue-400 hover:text-blue-600 active:border-blue-500 transition-colors font-medium",disabled:d,children:"+ Create New Collection"})]}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("h4",{className:"font-medium text-gray-900 text-base",children:"Add to Deck"}),o.length>0&&(0,t.jsxs)("select",{className:"w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-white",onChange:e=>e.target.value&&n(e.target.value),defaultValue:"",disabled:d,children:[(0,t.jsx)("option",{value:"",children:"Select existing deck..."}),o.map(e=>(0,t.jsx)("option",{value:e.id,children:e.name},e.id))]}),v?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("input",{type:"text",value:y,onChange:e=>k(e.target.value),placeholder:"Deck name...",className:"w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500",disabled:d}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("button",{onClick:()=>{y.trim()&&(n("",y.trim()),k(""),j(!1))},className:"flex-1 px-4 py-3 bg-purple-600 text-white rounded-xl text-sm font-medium hover:bg-purple-700 active:bg-purple-800 disabled:bg-gray-400 transition-colors",disabled:!y.trim()||d,children:"Create"}),(0,t.jsx)("button",{onClick:()=>j(!1),className:"px-4 py-3 bg-gray-100 text-gray-700 rounded-xl text-sm font-medium hover:bg-gray-200 active:bg-gray-300 transition-colors",disabled:d,children:"Cancel"})]})]}):(0,t.jsx)("button",{onClick:()=>j(!0),className:"w-full px-4 py-3 border-2 border-dashed border-gray-300 rounded-xl text-sm text-gray-600 hover:border-purple-400 hover:text-purple-600 active:border-purple-500 transition-colors font-medium",disabled:d,children:"+ Create New Deck"})]}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("h4",{className:"font-medium text-gray-900 text-base",children:"Add Tags"}),m?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),placeholder:"Enter tags (comma-separated)...",className:"w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500",disabled:d,onKeyPress:e=>"Enter"===e.key&&w()}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("button",{onClick:w,className:"flex-1 px-4 py-3 bg-green-600 text-white rounded-xl text-sm font-medium hover:bg-green-700 active:bg-green-800 disabled:bg-gray-400 transition-colors",disabled:!x.trim()||d,children:"Add Tags"}),(0,t.jsx)("button",{onClick:()=>u(!1),className:"px-4 py-3 bg-gray-100 text-gray-700 rounded-xl text-sm font-medium hover:bg-gray-200 active:bg-gray-300 transition-colors",disabled:d,children:"Cancel"})]})]}):(0,t.jsx)("button",{onClick:()=>u(!0),className:"w-full px-4 py-3 border-2 border-dashed border-gray-300 rounded-xl text-sm text-gray-600 hover:border-green-400 hover:text-green-600 active:border-green-500 transition-colors font-medium",disabled:d,children:"+ Add Tags"}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("p",{className:"text-xs text-gray-500 font-medium",children:"Quick Tags:"}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:["Foil","Mint","Near Mint","Played","Favorite"].map(e=>(0,t.jsx)("button",{onClick:()=>l([e]),className:"px-3 py-2 bg-gray-100 text-gray-700 rounded-lg text-xs font-medium hover:bg-gray-200 active:bg-gray-300 transition-colors",disabled:d,children:e},e))})]})]})]}),d&&(0,t.jsx)("div",{className:"flex items-center justify-center py-8 mt-6 border-t border-gray-100",children:(0,t.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,t.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-blue-600 border-t-transparent"}),(0,t.jsx)("span",{className:"text-sm text-gray-600 font-medium",children:"Processing..."})]})})]})};class er{static generateTags(e){let a=[],r=[];if(e.game){let t=this.normalizeGame(e.game);a.push(t),r.push(`Game: ${t}`)}if(e.rarity){let t=this.normalizeRarity(e.rarity);a.push(t),r.push(`Rarity: ${t}`),this.isHighValueRarity(e.rarity)&&(a.push("High Value"),r.push("High-value rarity detected"))}if(e.setName){let t=this.generateSetTag(e.setName);t&&(a.push(t),r.push(`Set: ${t}`));let s=this.detectSpecialSets(e.setName);a.push(...s),s.length>0&&r.push(`Special sets: ${s.join(", ")}`)}if(e.cardType){let t=this.normalizeCardType(e.cardType);if(t&&(a.push(t),r.push(`Type: ${t}`)),e.power&&e.toughness){a.push("Creature");let t=this.categorizeCreaturePower(e.power,e.toughness);t&&(a.push(t),r.push(`Power level: ${t}`))}}if(e.manaCost){let t=this.analyzeManaColor(e.manaCost);a.push(...t),t.length>0&&r.push(`Mana colors: ${t.join(", ")}`)}if(e.element){let t=this.normalizeElement(e.element);t&&(a.push(t),r.push(`Element: ${t}`))}if(e.cardName){let t=this.analyzeCardName(e.cardName);a.push(...t),t.length>0&&r.push(`Name analysis: ${t.join(", ")}`)}return{tags:Array.from(new Set(a)).filter(e=>e.length>0),confidence:.8,reasoning:r.join("; ")}}static normalizeGame(e){return({"magic the gathering":"MTG",magic:"MTG",mtg:"MTG",pokemon:"Pokemon",pokémon:"Pokemon",lorcana:"Lorcana","disney lorcana":"Lorcana"})[e.toLowerCase()]||e}static normalizeRarity(e){return({c:"Common",common:"Common",u:"Uncommon",uncommon:"Uncommon",r:"Rare",rare:"Rare",m:"Mythic",mythic:"Mythic","mythic rare":"Mythic",sr:"Super Rare","super rare":"Super Rare","ultra rare":"Ultra Rare","secret rare":"Secret Rare",legendary:"Legendary",enchanted:"Enchanted"})[e.toLowerCase()]||e}static isHighValueRarity(e){return["mythic","super rare","ultra rare","secret rare","legendary","enchanted"].some(a=>e.toLowerCase().includes(a))}static generateSetTag(e){return({"dominaria united":"DMU","brothers war":"BRO","phyrexia all will be one":"ONE","march of the machine":"MOM","battle for zendikar":"BFZ","sword shield":"SWSH","sun moon":"SM","the first chapter":"TFC"})[e.toLowerCase()]||null}static detectSpecialSets(e){let a=[],r=e.toLowerCase();return r.includes("promo")&&a.push("Promo"),r.includes("prerelease")&&a.push("Prerelease"),r.includes("foil")&&a.push("Foil"),r.includes("alternate art")&&a.push("Alt Art"),r.includes("full art")&&a.push("Full Art"),r.includes("borderless")&&a.push("Borderless"),r.includes("showcase")&&a.push("Showcase"),r.includes("collector")&&a.push("Collector"),a}static normalizeCardType(e){let a=e.toLowerCase();for(let[e,r]of Object.entries({creature:"Creature",instant:"Instant",sorcery:"Sorcery",artifact:"Artifact",enchantment:"Enchantment",planeswalker:"Planeswalker",land:"Land","basic land":"Basic Land",legendary:"Legendary"}))if(a.includes(e))return r;return null}static categorizeCreaturePower(e,a){let r=parseInt(e),t=parseInt(a);if(isNaN(r)||isNaN(t))return null;let s=r+t;return s>=10?"High Power":s>=6?"Mid Power":s>=3?"Low Power":"Utility"}static analyzeManaColor(e){let a=[];return(e.includes("W")||e.includes("white"))&&a.push("White"),(e.includes("U")||e.includes("blue"))&&a.push("Blue"),(e.includes("B")||e.includes("black"))&&a.push("Black"),(e.includes("R")||e.includes("red"))&&a.push("Red"),(e.includes("G")||e.includes("green"))&&a.push("Green"),a.length>1?a.push("Multicolor"):0===a.length&&e.match(/\d+/)&&a.push("Colorless"),a}static normalizeElement(e){return({fire:"Fire",water:"Water",grass:"Grass",electric:"Electric",psychic:"Psychic",fighting:"Fighting",darkness:"Dark",metal:"Steel",fairy:"Fairy",dragon:"Dragon",colorless:"Colorless"})[e.toLowerCase()]||e}static analyzeCardName(e){let a=[],r=e.toLowerCase();return(r.includes("legendary")||this.isLegendaryName(r))&&a.push("Legendary"),(r.includes("foil")||r.includes("holo"))&&a.push("Foil"),(r.includes("ex")||r.includes("gx")||r.includes("vmax"))&&a.push("Special"),a}static isLegendaryName(e){return[/\b(jace|chandra|garruk|liliana|ajani|elspeth|vraska|nissa|gideon|teferi)\b/,/\b(pikachu|charizard|mewtwo|mew|rayquaza|arceus)\b/,/\b(mickey|minnie|donald|goofy|elsa|anna|simba)\b/].some(a=>a.test(e))}}let et=()=>{let e=(0,m.Zp)(),[a,r]=(0,s.useState)("mode-selection"),[n,l]=(0,s.useState)(null),[i,c]=(0,s.useState)([]),[o,d]=(0,s.useState)(new Set),[u,x]=(0,s.useState)(!1),[h]=(0,s.useState)([{id:"1",name:"My Collection"},{id:"2",name:"Trade Binder"},{id:"3",name:"Deck Ideas"}]),[g]=(0,s.useState)([{id:"1",name:"Standard Deck"},{id:"2",name:"Commander"},{id:"3",name:"Draft Picks"}]),[p]=(0,s.useState)(new Map);(0,s.useEffect)(()=>()=>{p.forEach(e=>{e.startsWith("blob:")&&URL.revokeObjectURL(e)}),p.clear()},[p]);let f=(0,s.useCallback)(e=>{l(e),r("scanning")},[]),b=(0,s.useCallback)(e=>{let a=er.generateTags(e.cardData),r={...e,autoTags:a.tags};p.set(e.id,e.imageDataUrl),c(e=>[...e,r]),c(e=>e.length>100?(e.slice(0,e.length-100).forEach(e=>{let a=p.get(e.id);a&&a.startsWith("blob:")&&URL.revokeObjectURL(a),p.delete(e.id)}),e.slice(e.length-100)):e)},[p]),v=(0,s.useCallback)(e=>{c(a=>a.filter(a=>a.id!==e)),d(a=>{let r=new Set(a);return r.delete(e),r});let a=p.get(e);a&&a.startsWith("blob:")&&URL.revokeObjectURL(a),p.delete(e)},[p]),j=(0,s.useCallback)(()=>{i.forEach(e=>{let a=p.get(e.id);a&&a.startsWith("blob:")&&URL.revokeObjectURL(a)}),p.clear(),c([]),d(new Set)},[i,p]),y=(0,s.useCallback)((e,a)=>{d(r=>{let t=new Set(r);return a?t.add(e):t.delete(e),t})},[]),k=(0,s.useCallback)(e=>{console.log("Viewing card:",e)},[]),w=(0,s.useCallback)(async(e,a)=>{if(0!==o.size){x(!0);try{console.log("Adding to collection:",{collectionId:e,newCollectionName:a,cards:Array.from(o)}),await new Promise(e=>setTimeout(e,1e3)),alert(`Added ${o.size} cards to ${a||"collection"}`)}catch(e){console.error("Failed to add to collection:",e),alert("Failed to add cards to collection")}finally{x(!1)}}},[o]),N=(0,s.useCallback)(async(e,a)=>{if(0!==o.size){x(!0);try{console.log("Adding to deck:",{deckId:e,newDeckName:a,cards:Array.from(o)}),await new Promise(e=>setTimeout(e,1e3)),alert(`Added ${o.size} cards to ${a||"deck"}`)}catch(e){console.error("Failed to add to deck:",e),alert("Failed to add cards to deck")}finally{x(!1)}}},[o]),C=(0,s.useCallback)(async e=>{if(0!==o.size){x(!0);try{console.log("Adding tags:",{tags:e,cards:Array.from(o)}),await new Promise(e=>setTimeout(e,1e3)),alert(`Added tags "${e.join(", ")}" to ${o.size} cards`)}catch(e){console.error("Failed to add tags:",e),alert("Failed to add tags")}finally{x(!1)}}},[o]),_=(0,s.useCallback)(()=>{o.forEach(e=>v(e))},[o,v]),S=(0,s.useCallback)(async()=>{if(0===i.length)return void e("/scanner");r("processing"),x(!0);try{switch(n){case"add-to-database":console.log("Adding all cards to database:",i);break;case"search-collections":console.log("Searching collections for:",i);break;case"price-check":console.log("Getting prices for:",i);break;case"deck-building":console.log("Adding to deck:",i)}await new Promise(e=>setTimeout(e,2e3)),r("complete"),setTimeout(()=>{e("/scanner")},3e3)}catch(e){console.error("Failed to process cards:",e),alert("Failed to process cards"),r("review")}finally{x(!1)}},[i,n,e]),L=(0,s.useCallback)(()=>{r("scanning")},[]),M=(0,s.useCallback)(()=>{r("review")},[]),A=(0,s.useCallback)(e=>{console.error("Scanner error:",e),alert(e)},[]);return(0,t.jsx)("div",{className:"min-h-screen bg-gray-50",children:(0,t.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4 sm:py-6",children:(()=>{switch(a){case"mode-selection":return(0,t.jsx)(U,{onModeSelect:f});case"scanning":return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsx)("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-4 sm:p-6",children:(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsxs)("h2",{className:"text-xl sm:text-2xl font-bold text-gray-900 mb-2",children:["add-to-database"===n&&"\uD83D\uDCDA Adding Cards to Database","search-collections"===n&&"\uD83D\uDD0D Searching Collections","price-check"===n&&"\uD83D\uDCB0 Price Checking Cards","deck-building"===n&&"\uD83C\uDFAF Building Deck"]}),(0,t.jsx)("p",{className:"text-gray-600 text-sm sm:text-base",children:"Position cards clearly within the camera frame"})]}),(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2",children:[i.length>0&&(0,t.jsx)("button",{onClick:M,className:"w-full sm:w-auto bg-green-600 text-white px-4 py-3 sm:px-6 sm:py-2 rounded-xl font-medium hover:bg-green-700 active:bg-green-800 transition-colors text-sm sm:text-base shadow-lg",children:(0,t.jsxs)("div",{className:"flex items-center justify-center space-x-2",children:[(0,t.jsx)("span",{children:"Review Queue"}),(0,t.jsx)("span",{className:"bg-green-700 px-2 py-0.5 rounded-full text-xs",children:i.length})]})}),(0,t.jsx)("button",{onClick:()=>r("mode-selection"),className:"w-full sm:w-auto bg-gray-100 text-gray-700 px-4 py-3 sm:px-6 sm:py-2 rounded-xl font-medium hover:bg-gray-200 active:bg-gray-300 transition-colors text-sm sm:text-base",children:"Change Mode"})]})]})}),(0,t.jsx)(Z,{onCardScanned:b,onError:A,isActive:"scanning"===a,maxQueueSize:100})]});case"review":return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsx)("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-4 sm:p-6",children:(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-gray-900 mb-2",children:"Review Scanned Cards"}),(0,t.jsx)("p",{className:"text-gray-600 text-sm sm:text-base",children:"Select cards and choose where to add them"})]}),(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2",children:[(0,t.jsx)("button",{onClick:L,className:"w-full sm:w-auto bg-blue-600 text-white px-4 py-3 sm:px-6 sm:py-2 rounded-xl font-medium hover:bg-blue-700 active:bg-blue-800 transition-colors text-sm sm:text-base",children:"Continue Scanning"}),(0,t.jsx)("button",{onClick:S,disabled:0===i.length||u,className:"w-full sm:w-auto bg-green-600 text-white px-4 py-3 sm:px-6 sm:py-2 rounded-xl font-medium hover:bg-green-700 active:bg-green-800 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors text-sm sm:text-base shadow-lg",children:u?(0,t.jsxs)("div",{className:"flex items-center justify-center space-x-2",children:[(0,t.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white border-t-transparent"}),(0,t.jsx)("span",{children:"Processing..."})]}):"Finish & Process"})]})]})}),(0,t.jsx)(ee,{cards:i,onRemoveCard:v,onClearQueue:j,onCardSelect:y,selectedCards:o,onViewCard:k}),(0,t.jsx)(ea,{selectedCount:o.size,onAddToCollection:w,onAddToDeck:N,onAddTags:C,onRemoveSelected:_,collections:h,decks:g,isProcessing:u})]});case"processing":return(0,t.jsx)("div",{className:"flex items-center justify-center min-h-[60vh] px-4",children:(0,t.jsxs)("div",{className:"text-center max-w-md mx-auto",children:[(0,t.jsx)("div",{className:"animate-spin rounded-full h-16 w-16 sm:h-20 sm:w-20 border-4 border-blue-600 border-t-transparent mx-auto mb-6"}),(0,t.jsx)("h3",{className:"text-xl sm:text-2xl font-semibold text-gray-900 mb-3",children:"Processing Cards..."}),(0,t.jsxs)("p",{className:"text-gray-600 text-sm sm:text-base mb-4",children:["Adding ",i.length," cards to your collection"]}),(0,t.jsx)("div",{className:"bg-gray-100 rounded-full h-2 w-full max-w-xs mx-auto",children:(0,t.jsx)("div",{className:"bg-blue-600 h-2 rounded-full animate-pulse",style:{width:"60%"}})})]})});case"complete":return(0,t.jsx)("div",{className:"flex items-center justify-center min-h-[60vh] px-4",children:(0,t.jsxs)("div",{className:"text-center max-w-md mx-auto",children:[(0,t.jsx)("div",{className:"text-6xl sm:text-7xl mb-6",children:"✅"}),(0,t.jsx)("h3",{className:"text-xl sm:text-2xl font-semibold text-green-600 mb-3",children:"Success!"}),(0,t.jsxs)("p",{className:"text-gray-600 text-sm sm:text-base mb-6",children:["Successfully processed ",i.length," cards"]}),(0,t.jsx)("div",{className:"bg-green-50 border border-green-200 rounded-xl p-4 mb-6",children:(0,t.jsx)("p",{className:"text-green-800 text-sm font-medium",children:"\uD83C\uDF89 All cards have been added to your collection!"})}),(0,t.jsx)("p",{className:"text-sm text-gray-500",children:"Redirecting to scanner..."})]})});default:return null}})()})})},es=()=>(0,t.jsx)(et,{}),en=()=>{let{user:e}=(0,c.A)(),[a,r]=(0,s.useState)(null),[n,l]=(0,s.useState)(!0),[i,o]=(0,s.useState)(!1),[d,m]=(0,s.useState)(null),[u,x]=(0,s.useState)("general"),[h,g]=(0,s.useState)(!1),[p,f]=(0,s.useState)(!1),[b,v]=(0,s.useState)({});(0,s.useEffect)(()=>{j()},[e]);let j=async()=>{if(e)try{let e=localStorage.getItem("tcg_vault_token"),a=await fetch("/api/user/preferences",{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(a.ok){let e=await a.json();r(e.preferences)}else m({type:"error",text:"Failed to load preferences"})}catch(e){console.error("Error loading preferences:",e),m({type:"error",text:"Error loading preferences"})}finally{l(!1)}},y=async()=>{if(a){o(!0);try{let e=localStorage.getItem("tcg_vault_token"),t=await fetch("/api/user/preferences",{method:"PUT",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(a)}),s=await t.json();t.ok?(m({type:"success",text:"Settings saved successfully!"}),r(s.preferences)):m({type:"error",text:s.error||"Failed to save settings"})}catch(e){console.error("Error saving preferences:",e),m({type:"error",text:"Error saving settings"})}finally{o(!1)}}},k=async()=>{if(!a?.ocrSettings.openai_api_key)return void v(e=>({...e,openai:"❌ API key required"}));g(!0);try{let e=await fetch("https://api.openai.com/v1/models",{headers:{Authorization:`Bearer ${a.ocrSettings.openai_api_key}`}});e.ok?v(e=>({...e,openai:"✅ API key valid"})):v(a=>({...a,openai:`❌ API error: ${e.status}`}))}catch(e){v(a=>({...a,openai:`❌ Connection failed: ${e.message}`}))}finally{g(!1)}},w=async()=>{if(a?.ocrSettings.ollama_url){f(!0);try{let e=await fetch(`${a.ocrSettings.ollama_url}/api/tags`);if(e.ok){let a=await e.json();a.models?.some(e=>e.name.includes("llava")||e.name.includes("vision"))?v(e=>({...e,ollama:"✅ Ollama with vision models available"})):v(e=>({...e,ollama:"⚠️ Ollama running but no vision models found"}))}else v(a=>({...a,ollama:`❌ Ollama error: ${e.status}`}))}catch(e){v(a=>({...a,ollama:`❌ Cannot reach Ollama: ${e.message}`}))}finally{f(!1)}}},N=(e,t)=>{a&&r({...a,[e]:t})},C=(e,t)=>{a&&r({...a,ocrSettings:{...a.ocrSettings,[e]:t}})};return n?(0,t.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,t.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-indigo-600"})}):a?(0,t.jsxs)("div",{className:"max-w-4xl mx-auto p-6",children:[(0,t.jsxs)("div",{className:"mb-8",children:[(0,t.jsx)("h1",{className:"text-3xl font-bold text-gray-900 mb-2",children:"Settings"}),(0,t.jsx)("p",{className:"text-gray-600",children:"Manage your account preferences and OCR configuration"})]}),d&&(0,t.jsx)("div",{className:`mb-6 p-4 rounded-lg ${"success"===d.type?"bg-green-50 text-green-800 border border-green-200":"bg-red-50 text-red-800 border border-red-200"}`,children:d.text}),(0,t.jsx)("div",{className:"border-b border-gray-200 mb-6",children:(0,t.jsx)("nav",{className:"-mb-px flex space-x-8",children:[{id:"general",label:"General",icon:"⚙️"},{id:"ocr",label:"AI OCR",icon:"\uD83E\uDD16"},{id:"privacy",label:"Privacy",icon:"\uD83D\uDD12"}].map(e=>(0,t.jsxs)("button",{onClick:()=>x(e.id),className:`py-2 px-1 border-b-2 font-medium text-sm ${u===e.id?"border-indigo-500 text-indigo-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:[(0,t.jsx)("span",{className:"mr-2",children:e.icon}),e.label]},e.id))})}),(0,t.jsxs)("div",{className:"space-y-6",children:["general"===u&&(0,t.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-6",children:[(0,t.jsx)("h3",{className:"text-lg font-medium mb-4",children:"General Preferences"}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Default View"}),(0,t.jsxs)("select",{value:a.defaultView,onChange:e=>N("defaultView",e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500",children:[(0,t.jsx)("option",{value:"card",children:"Card View"}),(0,t.jsx)("option",{value:"table",children:"Table View"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Items per Page"}),(0,t.jsxs)("select",{value:a.itemsPerPage,onChange:e=>N("itemsPerPage",parseInt(e.target.value)),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500",children:[(0,t.jsx)("option",{value:10,children:"10"}),(0,t.jsx)("option",{value:20,children:"20"}),(0,t.jsx)("option",{value:50,children:"50"}),(0,t.jsx)("option",{value:100,children:"100"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Theme"}),(0,t.jsxs)("select",{value:a.theme,onChange:e=>N("theme",e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500",children:[(0,t.jsx)("option",{value:"light",children:"Light"}),(0,t.jsx)("option",{value:"dark",children:"Dark"}),(0,t.jsx)("option",{value:"system",children:"System"})]})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"checkbox",checked:a.enableAnimations,onChange:e=>N("enableAnimations",e.target.checked),className:"rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Enable animations"})]}),(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"checkbox",checked:a.enableOcr,onChange:e=>N("enableOcr",e.target.checked),className:"rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Enable OCR scanning"})]})]})]})]}),"ocr"===u&&(0,t.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-6",children:[(0,t.jsx)("h3",{className:"text-lg font-medium mb-4",children:"AI OCR Configuration"}),(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-3",children:"Preferred OCR Service"}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"radio",value:"openai",checked:"openai"===a.ocrSettings.preferred_service,onChange:e=>C("preferred_service",e.target.value),className:"text-indigo-600 focus:ring-indigo-500"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"OpenAI Vision API (Recommended)"})]}),(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"radio",value:"ollama",checked:"ollama"===a.ocrSettings.preferred_service,onChange:e=>C("preferred_service",e.target.value),className:"text-indigo-600 focus:ring-indigo-500"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Ollama (Local/Private)"})]})]})]}),(0,t.jsxs)("div",{className:"border rounded-lg p-4 mb-6",children:[(0,t.jsx)("h4",{className:"font-medium text-gray-900 mb-3",children:"OpenAI Configuration"}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"API Key"}),(0,t.jsx)("input",{type:"password",value:a.ocrSettings.openai_api_key,onChange:e=>C("openai_api_key",e.target.value),placeholder:"sk-...",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500"}),(0,t.jsxs)("p",{className:"text-xs text-gray-500 mt-1",children:["Get your API key from"," ",(0,t.jsx)("a",{href:"https://platform.openai.com/api-keys",target:"_blank",rel:"noopener noreferrer",className:"text-indigo-600 hover:underline",children:"OpenAI Platform"})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("button",{onClick:k,disabled:h||!a.ocrSettings.openai_api_key,className:"bg-blue-600 text-white px-3 py-1 rounded text-sm disabled:bg-gray-400 hover:bg-blue-700",children:h?"Testing...":"Test API Key"}),b.openai&&(0,t.jsx)("span",{className:"text-sm",children:b.openai})]})]})]}),(0,t.jsxs)("div",{className:"border rounded-lg p-4 mb-6",children:[(0,t.jsx)("h4",{className:"font-medium text-gray-900 mb-3",children:"Ollama Configuration"}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Ollama URL"}),(0,t.jsx)("input",{type:"text",value:a.ocrSettings.ollama_url,onChange:e=>C("ollama_url",e.target.value),placeholder:"http://localhost:11434",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500"}),(0,t.jsxs)("p",{className:"text-xs text-gray-500 mt-1",children:["Requires LLaVA or similar vision model:"," ",(0,t.jsx)("code",{className:"bg-gray-100 px-1 rounded",children:"ollama pull llava"})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("button",{onClick:w,disabled:p,className:"bg-green-600 text-white px-3 py-1 rounded text-sm disabled:bg-gray-400 hover:bg-green-700",children:p?"Testing...":"Test Ollama"}),b.ollama&&(0,t.jsx)("span",{className:"text-sm",children:b.ollama})]})]})]}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Confidence Threshold (",a.ocrSettings.confidence_threshold,"%)"]}),(0,t.jsx)("input",{type:"range",min:"0",max:"100",value:a.ocrSettings.confidence_threshold,onChange:e=>C("confidence_threshold",parseInt(e.target.value)),className:"w-full"}),(0,t.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Minimum confidence required to accept OCR results"})]}),(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"checkbox",checked:a.ocrSettings.auto_add_to_collection,onChange:e=>C("auto_add_to_collection",e.target.checked),className:"rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Automatically add scanned cards to selected collection"})]})]})]}),"privacy"===u&&(0,t.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-6",children:[(0,t.jsx)("h3",{className:"text-lg font-medium mb-4",children:"Privacy Settings"}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"checkbox",checked:a.privacySettings.collections_public,onChange:e=>N("privacySettings",{...a.privacySettings,collections_public:e.target.checked}),className:"rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Make collections public by default"})]}),(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"checkbox",checked:a.privacySettings.decks_public,onChange:e=>N("privacySettings",{...a.privacySettings,decks_public:e.target.checked}),className:"rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Make decks public by default"})]})]})]})]}),(0,t.jsx)("div",{className:"mt-8 flex justify-end",children:(0,t.jsxs)("button",{onClick:y,disabled:i,className:"bg-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700 disabled:bg-gray-400 flex items-center gap-2",children:[i&&(0,t.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}),i?"Saving...":"Save Settings"]})})]}):(0,t.jsxs)("div",{className:"text-center py-8",children:[(0,t.jsx)("p",{className:"text-red-600",children:"Failed to load preferences"}),(0,t.jsx)("button",{onClick:j,className:"mt-4 text-indigo-600 hover:underline",children:"Try Again"})]})},el=()=>{let{login:e}=(0,c.A)(),[a,r]=(0,s.useState)({email:"",password:""}),[n,l]=(0,s.useState)(!1),[i,o]=(0,s.useState)(null),[d,m]=(0,s.useState)(!1),x=async r=>{r.preventDefault(),l(!0),o(null);try{await e(a.email,a.password)}catch(e){o(e instanceof Error?e.message:"Login failed")}finally{l(!1)}},h=e=>{r(a=>({...a,[e.target.name]:e.target.value}))};return(0,t.jsxs)("div",{className:"bg-white dark:bg-surface-800 p-8 rounded-2xl shadow-xl border border-surface-200 dark:border-surface-700 transition-colors",children:[(0,t.jsxs)("div",{className:"text-center mb-8",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-gradient-to-r from-primary-500 to-accent-500 rounded-2xl flex items-center justify-center mx-auto mb-4 shadow-lg",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("h1",{className:"text-2xl font-bold text-surface-900 dark:text-white mb-2",children:"Welcome Back"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400",children:"Sign in to your TCG Vault"})]}),i&&(0,t.jsx)("div",{className:"mb-6 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl",children:(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)("svg",{className:"w-5 h-5 text-red-500 mr-2",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})}),(0,t.jsx)("span",{className:"text-red-700 dark:text-red-400 text-sm",children:i})]})}),(0,t.jsxs)("form",{onSubmit:x,className:"space-y-6",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"email",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Email Address"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{type:"email",id:"email",name:"email",value:a.email,onChange:h,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors",placeholder:"Enter your email",required:!0}),(0,t.jsx)("svg",{className:"absolute right-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-surface-400 dark:text-surface-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207"})})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"password",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Password"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{type:d?"text":"password",id:"password",name:"password",value:a.password,onChange:h,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors pr-12",placeholder:"Enter your password",required:!0}),(0,t.jsx)("button",{type:"button",onClick:()=>m(!d),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:d?(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L3 3m6.878 6.878L21 21"})}):(0,t.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]}),(0,t.jsx)("button",{type:"submit",disabled:n,className:"w-full bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 disabled:from-surface-400 disabled:to-surface-400 text-white font-semibold py-3 px-4 rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl disabled:shadow-none transform hover:-translate-y-0.5 disabled:transform-none",children:n?(0,t.jsxs)("div",{className:"flex items-center justify-center",children:[(0,t.jsxs)("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,t.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,t.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Signing In..."]}):"Sign In"}),(0,t.jsx)("div",{className:"text-center",children:(0,t.jsxs)("p",{className:"text-surface-600 dark:text-surface-400",children:["Don't have an account?"," ",(0,t.jsx)(u.N_,{to:"/register",className:"text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 font-medium transition-colors",children:"Sign up"})]})})]})]})},ei=()=>{let{register:e}=(0,c.A)(),[a,r]=(0,s.useState)({firstName:"",lastName:"",username:"",email:"",password:"",confirmPassword:""}),[n,l]=(0,s.useState)(!1),[i,o]=(0,s.useState)(null),[d,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),g=async r=>{if(r.preventDefault(),l(!0),o(null),a.password!==a.confirmPassword){o("Passwords do not match"),l(!1);return}try{await e(a)}catch(e){o(e instanceof Error?e.message:"Registration failed")}finally{l(!1)}},p=e=>{r(a=>({...a,[e.target.name]:e.target.value}))};return(0,t.jsxs)("div",{className:"bg-white dark:bg-surface-800 p-8 rounded-2xl shadow-xl border border-surface-200 dark:border-surface-700 transition-colors",children:[(0,t.jsxs)("div",{className:"text-center mb-8",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-gradient-to-r from-primary-500 to-accent-500 rounded-2xl flex items-center justify-center mx-auto mb-4 shadow-lg",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("h1",{className:"text-2xl font-bold text-surface-900 dark:text-white mb-2",children:"Join TCG Vault"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400",children:"Create your account to get started"})]}),i&&(0,t.jsx)("div",{className:"mb-6 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl",children:(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)("svg",{className:"w-5 h-5 text-red-500 mr-2",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})}),(0,t.jsx)("span",{className:"text-red-700 dark:text-red-400 text-sm",children:i})]})}),(0,t.jsxs)("form",{onSubmit:g,className:"space-y-4",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"firstName",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"First Name"}),(0,t.jsx)("input",{type:"text",id:"firstName",name:"firstName",value:a.firstName,onChange:p,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors",placeholder:"John",required:!0})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"lastName",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Last Name"}),(0,t.jsx)("input",{type:"text",id:"lastName",name:"lastName",value:a.lastName,onChange:p,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors",placeholder:"Doe",required:!0})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"username",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Username"}),(0,t.jsx)("input",{type:"text",id:"username",name:"username",value:a.username,onChange:p,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors",placeholder:"johndoe",required:!0})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"email",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Email Address"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{type:"email",id:"email",name:"email",value:a.email,onChange:p,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors",placeholder:"john@example.com",required:!0}),(0,t.jsx)("svg",{className:"absolute right-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-surface-400 dark:text-surface-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207"})})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"password",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Password"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{type:d?"text":"password",id:"password",name:"password",value:a.password,onChange:p,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors pr-12",placeholder:"Create a strong password",required:!0}),(0,t.jsx)("button",{type:"button",onClick:()=>m(!d),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:d?(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L3 3m6.878 6.878L21 21"})}):(0,t.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"confirmPassword",className:"block text-sm font-medium text-surface-700 dark:text-surface-300 mb-2",children:"Confirm Password"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{type:x?"text":"password",id:"confirmPassword",name:"confirmPassword",value:a.confirmPassword,onChange:p,className:"w-full px-4 py-3 bg-surface-50 dark:bg-surface-700 border border-surface-300 dark:border-surface-600 rounded-xl text-surface-900 dark:text-white placeholder-surface-500 dark:placeholder-surface-400 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-colors pr-12",placeholder:"Confirm your password",required:!0}),(0,t.jsx)("button",{type:"button",onClick:()=>h(!x),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",children:x?(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L3 3m6.878 6.878L21 21"})}):(0,t.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]}),(0,t.jsx)("button",{type:"submit",disabled:n,className:"w-full bg-gradient-to-r from-primary-500 to-accent-500 hover:from-primary-600 hover:to-accent-600 disabled:from-surface-400 disabled:to-surface-400 text-white font-semibold py-3 px-4 rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl disabled:shadow-none transform hover:-translate-y-0.5 disabled:transform-none",children:n?(0,t.jsxs)("div",{className:"flex items-center justify-center",children:[(0,t.jsxs)("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,t.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,t.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Creating Account..."]}):"Create Account"}),(0,t.jsx)("div",{className:"text-center",children:(0,t.jsxs)("p",{className:"text-surface-600 dark:text-surface-400",children:["Already have an account?"," ",(0,t.jsx)(u.N_,{to:"/login",className:"text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 font-medium transition-colors",children:"Sign in"})]})})]})]})},ec=()=>{let{token:e}=(0,c.A)(),[a,r]=(0,s.useState)([]),[n,l]=(0,s.useState)(!0),[i,o]=(0,s.useState)(""),[d,m]=(0,s.useState)(""),[u,x]=(0,s.useState)(1),[h,g]=(0,s.useState)(1),[p,f]=(0,s.useState)(null),b=async function(){let a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";try{l(!0);let s=await fetch(`/api/admin/users?page=${a}&limit=20&search=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!s.ok)throw Error("Failed to fetch users");let n=await s.json();r(n.users),x(n.pagination.page),g(n.pagination.totalPages),o("")}catch(e){o(e.message)}finally{l(!1)}};(0,s.useEffect)(()=>{b(u,d)},[u,e]);let v=async(a,r)=>{try{if(!(await fetch(`/api/admin/users?id=${a}`,{method:"PUT",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(r)})).ok)throw Error("Failed to update user");b(u,d),f(null)}catch(e){o(e.message)}},j=e=>new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});return n&&0===a.length?(0,t.jsx)("div",{className:"p-6 flex justify-center items-center",children:(0,t.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-indigo-600"})}):(0,t.jsxs)("div",{className:"p-6",children:[(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsx)("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"User Management"}),(0,t.jsx)("p",{className:"text-sm text-gray-600",children:"Manage user accounts, roles, and permissions."})]}),(0,t.jsx)("form",{onSubmit:e=>{e.preventDefault(),x(1),b(1,d)},className:"mb-6",children:(0,t.jsxs)("div",{className:"flex gap-4",children:[(0,t.jsx)("div",{className:"flex-1",children:(0,t.jsx)("input",{type:"text",placeholder:"Search users by username, email, or name...",value:d,onChange:e=>m(e.target.value),className:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"})}),(0,t.jsx)("button",{type:"submit",className:"px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500",children:"Search"})]})}),i&&(0,t.jsx)("div",{className:"mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg",children:i}),(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"min-w-full divide-y divide-gray-200",children:[(0,t.jsx)("thead",{className:"bg-gray-50",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"User"}),(0,t.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Roles"}),(0,t.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Status"}),(0,t.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Created"}),(0,t.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Last Login"}),(0,t.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),(0,t.jsx)("tbody",{className:"bg-white divide-y divide-gray-200",children:a.map(e=>(0,t.jsxs)("tr",{className:"hover:bg-gray-50",children:[(0,t.jsx)("td",{className:"px-6 py-4 whitespace-nowrap",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-gray-900",children:e.first_name||e.last_name?`${e.first_name||""} ${e.last_name||""}`.trim():e.username}),(0,t.jsx)("div",{className:"text-sm text-gray-500",children:e.email}),(e.first_name||e.last_name)&&(0,t.jsxs)("div",{className:"text-xs text-gray-400",children:["@",e.username]})]})}),(0,t.jsx)("td",{className:"px-6 py-4 whitespace-nowrap",children:(0,t.jsx)("div",{className:"flex flex-wrap gap-1",children:e.roles.map(e=>(0,t.jsx)("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${(e=>{switch(e){case"admin":return"bg-purple-100 text-purple-800";case"user":return"bg-blue-100 text-blue-800";default:return"bg-gray-100 text-gray-800"}})(e)}`,children:e},e))})}),(0,t.jsx)("td",{className:"px-6 py-4 whitespace-nowrap",children:(0,t.jsx)("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${e.is_active?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:e.is_active?"Active":"Inactive"})}),(0,t.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:j(e.created_at)}),(0,t.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:e.last_login?j(e.last_login):"Never"}),(0,t.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium",children:(0,t.jsxs)("div",{className:"flex space-x-2",children:[(0,t.jsx)("button",{onClick:()=>f(e),className:"text-indigo-600 hover:text-indigo-900",children:"Edit"}),(0,t.jsx)("button",{onClick:()=>v(e.id,{isActive:!e.is_active}),className:e.is_active?"text-red-600 hover:text-red-900":"text-green-600 hover:text-green-900",children:e.is_active?"Deactivate":"Activate"})]})})]},e.id))})]})}),h>1&&(0,t.jsx)("div",{className:"mt-6 flex justify-center",children:(0,t.jsxs)("nav",{className:"flex space-x-2",children:[(0,t.jsx)("button",{onClick:()=>x(Math.max(1,u-1)),disabled:1===u,className:"px-3 py-2 text-sm border border-gray-300 rounded-md disabled:opacity-50",children:"Previous"}),(0,t.jsxs)("span",{className:"px-3 py-2 text-sm",children:["Page ",u," of ",h]}),(0,t.jsx)("button",{onClick:()=>x(Math.min(h,u+1)),disabled:u===h,className:"px-3 py-2 text-sm border border-gray-300 rounded-md disabled:opacity-50",children:"Next"})]})}),p&&(0,t.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,t.jsxs)("div",{className:"bg-white rounded-lg p-6 w-full max-w-md",children:[(0,t.jsx)("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:"Edit User"}),(0,t.jsx)("div",{className:"space-y-4",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-sm font-medium text-gray-700",children:"Roles"}),(0,t.jsx)("div",{className:"mt-2 space-y-2",children:["user","admin"].map(e=>(0,t.jsxs)("label",{className:"flex items-center",children:[(0,t.jsx)("input",{type:"checkbox",checked:p.roles.includes(e),onChange:a=>{let r=a.target.checked?[...p.roles,e]:p.roles.filter(a=>a!==e);f({...p,roles:r})},className:"mr-2"}),(0,t.jsx)("span",{className:"capitalize",children:e})]},e))})]})}),(0,t.jsxs)("div",{className:"mt-6 flex justify-end space-x-3",children:[(0,t.jsx)("button",{onClick:()=>f(null),className:"px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-md hover:bg-gray-200",children:"Cancel"}),(0,t.jsx)("button",{onClick:()=>v(p.id,{roles:p.roles}),className:"px-4 py-2 text-sm font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700",children:"Save Changes"})]})]})})]})},eo=()=>(0,t.jsxs)("div",{className:"p-6",children:[(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsx)("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"System Dashboard"}),(0,t.jsx)("p",{className:"text-sm text-gray-600",children:"Overview of system statistics and health."})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8",children:[(0,t.jsx)("div",{className:"bg-gradient-to-r from-blue-500 to-blue-600 rounded-lg p-6 text-white",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-blue-100 text-sm",children:"Total Users"}),(0,t.jsx)("p",{className:"text-3xl font-bold",children:"-"})]}),(0,t.jsx)("div",{className:"bg-blue-400 bg-opacity-30 rounded-full p-3",children:(0,t.jsx)("svg",{className:"w-8 h-8",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M9 6a3 3 0 11-6 0 3 3 0 016 0zM17 6a3 3 0 11-6 0 3 3 0 016 0zM12.93 17c.046-.327.07-.66.07-1a6.97 6.97 0 00-1.5-4.33A5 5 0 0119 16v1h-6.07zM6 11a5 5 0 015 5v1H1v-1a5 5 0 015-5z"})})})]})}),(0,t.jsx)("div",{className:"bg-gradient-to-r from-green-500 to-green-600 rounded-lg p-6 text-white",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-green-100 text-sm",children:"Total Cards"}),(0,t.jsx)("p",{className:"text-3xl font-bold",children:"-"})]}),(0,t.jsx)("div",{className:"bg-green-400 bg-opacity-30 rounded-full p-3",children:(0,t.jsx)("svg",{className:"w-8 h-8",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})})]})}),(0,t.jsx)("div",{className:"bg-gradient-to-r from-purple-500 to-purple-600 rounded-lg p-6 text-white",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-purple-100 text-sm",children:"Active Sessions"}),(0,t.jsx)("p",{className:"text-3xl font-bold",children:"-"})]}),(0,t.jsx)("div",{className:"bg-purple-400 bg-opacity-30 rounded-full p-3",children:(0,t.jsx)("svg",{className:"w-8 h-8",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})})]})}),(0,t.jsx)("div",{className:"bg-gradient-to-r from-orange-500 to-orange-600 rounded-lg p-6 text-white",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-orange-100 text-sm",children:"Collections"}),(0,t.jsx)("p",{className:"text-3xl font-bold",children:"-"})]}),(0,t.jsx)("div",{className:"bg-orange-400 bg-opacity-30 rounded-full p-3",children:(0,t.jsx)("svg",{className:"w-8 h-8",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})})]})})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8",children:[(0,t.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-6",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"System Health"}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-sm text-gray-600",children:"Database Status"}),(0,t.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800",children:"● Online"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-sm text-gray-600",children:"API Status"}),(0,t.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800",children:"● Operational"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-sm text-gray-600",children:"Storage"}),(0,t.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800",children:"● 75% Used"})]})]})]}),(0,t.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-6",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Recent Activity"}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-start",children:[(0,t.jsx)("div",{className:"bg-blue-100 rounded-full p-1 mr-3 mt-0.5",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-blue-600",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M9 6a3 3 0 11-6 0 3 3 0 016 0zM17 6a3 3 0 11-6 0 3 3 0 016 0z"})})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm text-gray-900",children:"New user registration"}),(0,t.jsx)("p",{className:"text-xs text-gray-500",children:"2 minutes ago"})]})]}),(0,t.jsxs)("div",{className:"flex items-start",children:[(0,t.jsx)("div",{className:"bg-green-100 rounded-full p-1 mr-3 mt-0.5",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-green-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm text-gray-900",children:"Card database updated"}),(0,t.jsx)("p",{className:"text-xs text-gray-500",children:"15 minutes ago"})]})]}),(0,t.jsxs)("div",{className:"flex items-start",children:[(0,t.jsx)("div",{className:"bg-purple-100 rounded-full p-1 mr-3 mt-0.5",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-purple-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm text-gray-900",children:"System backup completed"}),(0,t.jsx)("p",{className:"text-xs text-gray-500",children:"1 hour ago"})]})]})]})]})]}),(0,t.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-6",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Quick Actions"}),(0,t.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[(0,t.jsxs)("button",{className:"p-4 text-center border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors",children:[(0,t.jsx)("div",{className:"text-indigo-600 mb-2",children:(0,t.jsx)("svg",{className:"w-8 h-8 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),(0,t.jsx)("p",{className:"text-sm font-medium text-gray-900",children:"Add User"})]}),(0,t.jsxs)("button",{className:"p-4 text-center border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors",children:[(0,t.jsx)("div",{className:"text-green-600 mb-2",children:(0,t.jsx)("svg",{className:"w-8 h-8 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"})})}),(0,t.jsx)("p",{className:"text-sm font-medium text-gray-900",children:"Import Cards"})]}),(0,t.jsxs)("button",{className:"p-4 text-center border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors",children:[(0,t.jsx)("div",{className:"text-orange-600 mb-2",children:(0,t.jsx)("svg",{className:"w-8 h-8 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,t.jsx)("p",{className:"text-sm font-medium text-gray-900",children:"View Reports"})]}),(0,t.jsxs)("button",{className:"p-4 text-center border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors",children:[(0,t.jsx)("div",{className:"text-red-600 mb-2",children:(0,t.jsxs)("svg",{className:"w-8 h-8 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),(0,t.jsx)("p",{className:"text-sm font-medium text-gray-900",children:"Settings"})]})]})]})]}),ed=()=>{let{user:e,token:a}=(0,c.A)(),[r,n]=(0,s.useState)({}),[l,i]=(0,s.useState)(!1),[o,d]=(0,s.useState)({}),[m,u]=(0,s.useState)("ALL"),[x,h]=(0,s.useState)(""),g=async()=>{try{let e=await fetch("https://tcg-vault.vercel.app/api/admin?action=card-counts",{headers:{Authorization:`Bearer ${a}`}});if(e.ok){let a=await e.json();n(a.counts||{})}}catch(e){console.error("Error fetching card counts:",e)}};(0,s.useEffect)(()=>{g()},[]);let p=async e=>{i(!0),h(`Loading ${e} cards...`),d({});try{let r=await fetch("https://tcg-vault.vercel.app/api/admin?action=load-cards",{method:"POST",headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json"},body:JSON.stringify({game:e})});if(r.ok){let e=await r.json();d(e.results||{}),h(`Successfully loaded cards! ${e.message}`),setTimeout(()=>{g()},1e3)}else{let e=await r.json();h(`Error loading cards: ${e.error}`)}}catch(e){console.error("Error loading cards:",e),h("Error loading cards. Please try again.")}finally{i(!1)}};return(0,t.jsxs)("div",{className:"bg-white rounded-lg shadow-md p-6",children:[(0,t.jsx)("h2",{className:"text-2xl font-bold text-gray-800 mb-6",children:"Card Database Loader"}),(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold text-gray-700 mb-3",children:"Current Database Status"}),(0,t.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[(0,t.jsxs)("div",{className:"bg-blue-50 p-4 rounded-lg",children:[(0,t.jsx)("div",{className:"text-2xl font-bold text-blue-600",children:r.MTG||0}),(0,t.jsx)("div",{className:"text-sm text-blue-500",children:"MTG Cards"})]}),(0,t.jsxs)("div",{className:"bg-yellow-50 p-4 rounded-lg",children:[(0,t.jsx)("div",{className:"text-2xl font-bold text-yellow-600",children:r.POKEMON||0}),(0,t.jsx)("div",{className:"text-sm text-yellow-500",children:"Pok\xe9mon Cards"})]}),(0,t.jsxs)("div",{className:"bg-purple-50 p-4 rounded-lg",children:[(0,t.jsx)("div",{className:"text-2xl font-bold text-purple-600",children:r.LORCANA||0}),(0,t.jsx)("div",{className:"text-sm text-purple-500",children:"Lorcana Cards"})]}),(0,t.jsxs)("div",{className:"bg-green-50 p-4 rounded-lg",children:[(0,t.jsx)("div",{className:"text-2xl font-bold text-green-600",children:r.total||0}),(0,t.jsx)("div",{className:"text-sm text-green-500",children:"Total Cards"})]})]})]}),(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold text-gray-700 mb-3",children:"Load Cards from External APIs"}),(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 mb-4",children:[(0,t.jsxs)("select",{value:m,onChange:e=>u(e.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[(0,t.jsx)("option",{value:"ALL",children:"All Games (MTG, Pok\xe9mon, Lorcana)"}),(0,t.jsx)("option",{value:"MTG",children:"Magic: The Gathering"}),(0,t.jsx)("option",{value:"POKEMON",children:"Pok\xe9mon"}),(0,t.jsx)("option",{value:"LORCANA",children:"Disney Lorcana"})]}),(0,t.jsx)("button",{onClick:()=>{p(m)},disabled:l,className:"px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors",children:l?"Loading...":"Load Cards"})]}),Object.keys(o).length>0&&(0,t.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,t.jsx)("h4",{className:"font-semibold text-gray-700 mb-2",children:"Loading Results:"}),(0,t.jsxs)("div",{className:"space-y-2",children:[void 0!==o.mtg&&(0,t.jsxs)("div",{className:"text-blue-600",children:["MTG: ",o.mtg," cards loaded"]}),void 0!==o.pokemon&&(0,t.jsxs)("div",{className:"text-yellow-600",children:["Pok\xe9mon: ",o.pokemon," cards loaded"]}),void 0!==o.lorcana&&(0,t.jsxs)("div",{className:"text-purple-600",children:["Lorcana: ",o.lorcana," cards loaded"]})]})]}),x&&(0,t.jsx)("div",{className:`mt-4 p-3 rounded-lg ${x.includes("Error")?"bg-red-50 text-red-700 border border-red-200":"bg-green-50 text-green-700 border border-green-200"}`,children:x})]}),(0,t.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold text-gray-700 mb-2",children:"Instructions"}),(0,t.jsxs)("ul",{className:"text-sm text-gray-600 space-y-1",children:[(0,t.jsx)("li",{children:"• This will load cards from external APIs into your database"}),(0,t.jsx)("li",{children:"• MTG cards come from Scryfall API"}),(0,t.jsx)("li",{children:"• Pok\xe9mon cards come from Pok\xe9mon TCG API"}),(0,t.jsx)("li",{children:"• Lorcana cards come from Lorcana API and Lorcast API"}),(0,t.jsx)("li",{children:"• Loading may take several minutes for large datasets"}),(0,t.jsx)("li",{children:"• Cards are deduplicated automatically"})]})]})]})},em=()=>{let{user:e,isAdmin:a}=(0,c.A)(),[r,n]=(0,s.useState)("dashboard");return a()?(0,t.jsxs)("div",{className:"min-h-screen bg-gray-50",children:[(0,t.jsx)("div",{className:"bg-white shadow-sm border-b border-gray-200",children:(0,t.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:(0,t.jsxs)("div",{className:"flex justify-between items-center py-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-bold text-gray-900",children:"Admin Panel"}),(0,t.jsxs)("p",{className:"text-sm text-gray-600",children:["Welcome back, ",e?.firstName||e?.username]})]}),(0,t.jsx)("div",{className:"flex items-center space-x-4",children:(0,t.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-800",children:"Admin"})})]})})}),(0,t.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:(0,t.jsxs)("div",{className:"flex flex-col lg:flex-row gap-8",children:[(0,t.jsxs)("div",{className:"lg:w-64 flex-shrink-0",children:[(0,t.jsxs)("nav",{className:"bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden",children:[(0,t.jsx)("div",{className:"p-4 bg-gray-50 border-b border-gray-200",children:(0,t.jsx)("h2",{className:"text-sm font-semibold text-gray-900 uppercase tracking-wide",children:"Administration"})}),(0,t.jsx)("div",{className:"p-2",children:[{id:"dashboard",name:"Dashboard",icon:"\uD83D\uDCCA"},{id:"users",name:"Users",icon:"\uD83D\uDC65"},{id:"cards",name:"Cards",icon:"\uD83C\uDCCF"},{id:"decks",name:"Decks",icon:"\uD83D\uDCDA"},{id:"settings",name:"Settings",icon:"⚙️"}].map(e=>(0,t.jsxs)("button",{onClick:()=>n(e.id),className:`w-full flex items-center px-3 py-2 text-sm font-medium rounded-md mb-1 transition-colors duration-200 ${r===e.id?"bg-indigo-100 text-indigo-700 border-r-2 border-indigo-500":"text-gray-600 hover:bg-gray-50 hover:text-gray-900"}`,children:[(0,t.jsx)("span",{className:"mr-3 text-lg",children:e.icon}),e.name]},e.id))})]}),(0,t.jsxs)("div",{className:"mt-6 bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-gray-900 mb-3",children:"Quick Stats"}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,t.jsx)("span",{className:"text-gray-600",children:"Total Users"}),(0,t.jsx)("span",{className:"font-medium text-gray-900",children:"-"})]}),(0,t.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,t.jsx)("span",{className:"text-gray-600",children:"Total Cards"}),(0,t.jsx)("span",{className:"font-medium text-gray-900",children:"-"})]}),(0,t.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,t.jsx)("span",{className:"text-gray-600",children:"Active Sessions"}),(0,t.jsx)("span",{className:"font-medium text-gray-900",children:"-"})]})]})]})]}),(0,t.jsx)("div",{className:"flex-1",children:(0,t.jsx)("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 min-h-[600px]",children:(()=>{switch(r){case"dashboard":default:return(0,t.jsx)(eo,{});case"users":return(0,t.jsx)(ec,{});case"cards":return(0,t.jsx)(ed,{});case"decks":return(0,t.jsx)("div",{className:"p-6",children:"Deck Management - Coming Soon"});case"settings":return(0,t.jsx)("div",{className:"p-6",children:"System Settings - Coming Soon"})}})()})})]})})]}):(0,t.jsx)(m.C5,{to:"/dashboard",replace:!0})},eu=e=>{let{children:a}=e,{user:r,isLoading:s}=(0,c.A)(),l=(0,n.useRouter)();return s?(0,t.jsx)("div",{className:"min-h-screen-safe flex items-center justify-center bg-white dark:bg-surface-900",children:(0,t.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[(0,t.jsx)("div",{className:"w-12 h-12 bg-gradient-to-r from-primary-500 to-accent-500 rounded-xl flex items-center justify-center animate-bounce-subtle",children:(0,t.jsx)("svg",{className:"w-6 h-6 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 text-sm",children:"Loading TCG Vault..."})]})}):r?(0,t.jsx)(t.Fragment,{children:a}):(l.push("/login"),null)},ex=e=>{let{children:a}=e,{user:r,isLoading:s}=(0,c.A)(),l=(0,n.useRouter)();return s?(0,t.jsx)("div",{className:"min-h-screen-safe flex items-center justify-center bg-white dark:bg-surface-900",children:(0,t.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[(0,t.jsx)("div",{className:"w-12 h-12 bg-gradient-to-r from-primary-500 to-accent-500 rounded-xl flex items-center justify-center animate-bounce-subtle",children:(0,t.jsx)("svg",{className:"w-6 h-6 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 text-sm",children:"Loading TCG Vault..."})]})}):r?(l.push("/dashboard"),null):(0,t.jsx)(t.Fragment,{children:a})},eh=e=>{let{children:a}=e;return(0,t.jsx)(x,{children:a})},eg=e=>{let{children:a}=e;return(0,t.jsx)("div",{className:"min-h-screen-safe bg-gradient-to-br from-primary-50 via-white to-accent-50 dark:from-surface-900 dark:via-surface-800 dark:to-surface-900 flex items-center justify-center px-4 transition-colors",children:(0,t.jsx)("div",{className:"w-full max-w-sm animate-slide-up",children:a})})},ep=function(){let e=(0,n.useRouter)(),{pathname:a}=e;return(0,t.jsxs)(d,{children:["/login"===a&&(0,t.jsx)(ex,{children:(0,t.jsx)(eg,{children:(0,t.jsx)(el,{})})}),"/register"===a&&(0,t.jsx)(ex,{children:(0,t.jsx)(eg,{children:(0,t.jsx)(ei,{})})}),"/dashboard"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(h,{})})}),"/collections"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(w,{})})}),"/decks"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(C,{})})}),"/cards"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(W,{})})}),"/scanner"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(es,{})})}),"/settings"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(en,{})})}),"/admin"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(em,{})})}),"/"===a&&(0,t.jsx)(eu,{children:(0,t.jsx)(eh,{children:(0,t.jsx)(h,{})})}),!["/login","/register","/dashboard","/collections","/decks","/cards","/scanner","/settings","/admin","/"].includes(a)&&(0,t.jsx)(eh,{children:(0,t.jsxs)("div",{className:"text-center py-12",children:[(0,t.jsx)("div",{className:"w-16 h-16 bg-surface-200 dark:bg-surface-700 rounded-2xl flex items-center justify-center mx-auto mb-6",children:(0,t.jsx)("svg",{className:"w-8 h-8 text-surface-500 dark:text-surface-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.172 16.172a4 4 0 015.656 0M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,t.jsx)("h1",{className:"text-2xl font-bold text-surface-900 dark:text-white mb-2",children:"Page Not Found"}),(0,t.jsx)("p",{className:"text-surface-600 dark:text-surface-400 mb-6",children:"The page you're looking for doesn't exist."}),(0,t.jsx)("button",{onClick:()=>e.back(),className:"bg-primary-600 hover:bg-primary-700 text-white px-6 py-3 rounded-xl font-medium transition-colors",children:"Go Back"})]})}),(0,t.jsx)(l.j,{}),(0,t.jsx)(i.b,{})]})}}}]);