(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[105],{235:(e,t,r)=>{"use strict";r.d(t,{J:()=>l});var a=r(5155),s=r(2115),o=r(5016);let l=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)("label",{ref:t,className:(0,o.cn)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",r),...s})});l.displayName="Label"},2327:(e,t,r)=>{"use strict";r.d(t,{u:()=>o});let a="http://localhost:8000/api";class s{getToken(){return localStorage.getItem("auth_token")}async request(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this.getToken(),s={"Content-Type":"application/json",...t.headers};r&&(s.Authorization="Bearer ".concat(r));try{let r=await fetch("".concat(a).concat(e),{...t,headers:s}),o=await r.json();if(!r.ok)throw 401===r.status&&(localStorage.removeItem("auth_token"),window.location.href="/login"),Error(o.message||"API request failed");return o}catch(e){throw console.error("API Error:",e),e}}async get(e){return this.request(e,{method:"GET"})}async post(e,t){return this.request(e,{method:"POST",body:t?JSON.stringify(t):void 0})}async put(e,t){return this.request(e,{method:"PUT",body:t?JSON.stringify(t):void 0})}async delete(e){return this.request(e,{method:"DELETE"})}async upload(e,t){let r=this.getToken(),s={};r&&(s.Authorization="Bearer ".concat(r));try{let r=await fetch("".concat(a).concat(e),{method:"POST",headers:s,body:t}),o=await r.json();if(!r.ok)throw 401===r.status&&(localStorage.removeItem("auth_token"),window.location.href="/login"),Error(o.message||"Upload failed");return o}catch(e){throw console.error("Upload Error:",e),e}}}let o=new s},3209:(e,t,r)=>{"use strict";r.d(t,{BT:()=>d,Wu:()=>c,ZB:()=>i,Zp:()=>l,aR:()=>n,wL:()=>u});var a=r(5155),s=r(2115),o=r(5016);let l=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)("div",{ref:t,className:(0,o.cn)("rounded-lg border bg-card text-card-foreground shadow-sm",r),...s})});l.displayName="Card";let n=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)("div",{ref:t,className:(0,o.cn)("flex flex-col space-y-1.5 p-6",r),...s})});n.displayName="CardHeader";let i=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)("h3",{ref:t,className:(0,o.cn)("text-2xl font-semibold leading-none tracking-tight",r),...s})});i.displayName="CardTitle";let d=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)("p",{ref:t,className:(0,o.cn)("text-sm text-muted-foreground",r),...s})});d.displayName="CardDescription";let c=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)("div",{ref:t,className:(0,o.cn)("p-6 pt-0",r),...s})});c.displayName="CardContent";let u=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)("div",{ref:t,className:(0,o.cn)("flex items-center p-6 pt-0",r),...s})});u.displayName="CardFooter"},4635:(e,t,r)=>{Promise.resolve().then(r.bind(r,5974))},4845:(e,t,r)=>{"use strict";r.d(t,{AuthProvider:()=>i,c:()=>n});var a=r(5155),s=r(2115),o=r(63),l=r(2327);let n=(0,s.createContext)(void 0);function i(e){let{children:t}=e,[r,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),[u,h]=(0,s.useState)(!0),m=(0,o.useRouter)();(0,s.useEffect)(()=>{let e=localStorage.getItem("auth_token");e?(c(e),f(e)):h(!1)},[]);let f=async e=>{try{let e=await l.u.get("/auth/user");e.success&&e.data&&i(e.data)}catch(e){console.error("Failed to fetch user:",e),localStorage.removeItem("auth_token"),c(null)}finally{h(!1)}},p=async e=>{try{let t=await l.u.post("/auth/login",e);if(t.success&&t.data){let{token:e,user:r}=t.data;localStorage.setItem("auth_token",e),c(e),i(r),m.push("/dashboard")}else throw Error(t.message||"Login failed")}catch(e){throw console.error("Login error:",e),e}},x=async e=>{try{let t=await l.u.post("/auth/register",e);if(t.success&&t.data){let{token:e,user:r}=t.data;localStorage.setItem("auth_token",e),c(e),i(r),m.push("/dashboard")}else throw Error(t.message||"Registration failed")}catch(e){throw console.error("Registration error:",e),e}};return(0,a.jsx)(n.Provider,{value:{user:r,token:d,isAuthenticated:!!d,isLoading:u,login:p,register:x,logout:()=>{localStorage.removeItem("auth_token"),c(null),i(null),m.push("/login")}},children:t})}},5016:(e,t,r)=>{"use strict";r.d(t,{cn:()=>o});var a=r(2821),s=r(5889);function o(){for(var e=arguments.length,t=Array(e),r=0;r{"use strict";r.r(t),r.d(t,{default:()=>x});var a=r(5155),s=r(2115),o=r(9178),l=r(2327),n=r(7003),i=r(6170),d=r(235),c=r(3209),u=r(1847);let h=(0,u.A)("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]),m=(0,u.A)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),f=(0,u.A)("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]),p=(0,u.A)("Rocket",[["path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z",key:"m3kijz"}],["path",{d:"m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z",key:"1fmvmk"}],["path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0",key:"1f8sc4"}],["path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5",key:"qeys4"}]]);function x(){let{user:e,logout:t}=(0,o.A)(),{portfolios:r,isLoading:u,error:x,createPortfolio:g,uploadPortfolio:y,deployPortfolio:v}=function(){let[e,t]=(0,s.useState)([]),[r,a]=(0,s.useState)(!0),[o,n]=(0,s.useState)(null),i=async()=>{try{a(!0),n(null);let e=await l.u.get("/portfolios");e.success&&e.data&&t(e.data)}catch(e){n(e instanceof Error?e.message:"Failed to fetch portfolios")}finally{a(!1)}};(0,s.useEffect)(()=>{i()},[]);let d=async(r,a)=>{try{let s=await l.u.post("/portfolios",{name:r,domain:a});if(s.success&&s.data)return t([...e,s.data]),s.data}catch(e){throw e}},c=async(r,a)=>{try{let s=new FormData;s.append("file",a);let o=await l.u.upload("/portfolios/".concat(r,"/upload"),s);if(o.success&&o.data)return t(e.map(e=>e.id===r?o.data:e)),o.data}catch(e){throw e}},u=async r=>{try{let a=await l.u.post("/portfolios/".concat(r,"/deploy"));if(a.success&&a.data)return t(e.map(e=>e.id===r?a.data:e)),a.data}catch(e){throw e}};return{portfolios:e,isLoading:r,error:o,fetchPortfolios:i,createPortfolio:d,uploadPortfolio:c,deployPortfolio:u}}(),[j,b]=(0,s.useState)(!1),[N,w]=(0,s.useState)({name:"",domain:""}),[k,C]=(0,s.useState)(null),[S,P]=(0,s.useState)(null),R=(0,s.useRef)({}),E=async e=>{e.preventDefault();try{await g(N.name,N.domain),w({name:"",domain:""}),b(!1)}catch(e){console.error("Failed to create portfolio:",e)}},_=async(e,t)=>{try{C(e),await y(e,t)}catch(e){console.error("Failed to upload portfolio:",e)}finally{C(null)}},A=async e=>{try{P(e),await v(e)}catch(e){console.error("Failed to deploy portfolio:",e)}finally{P(null)}};return(0,a.jsxs)("div",{className:"min-h-screen bg-gray-50",children:[(0,a.jsx)("header",{className:"bg-white border-b",children:(0,a.jsxs)("div",{className:"container mx-auto px-4 py-4 flex justify-between items-center",children:[(0,a.jsx)("h1",{className:"text-2xl font-bold",children:"Portfolio Dashboard"}),(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Welcome, ",null==e?void 0:e.name]}),(0,a.jsxs)(n.$,{variant:"outline",size:"sm",onClick:t,children:[(0,a.jsx)(h,{className:"mr-2",size:16}),"Logout"]})]})]})}),(0,a.jsxs)("main",{className:"container mx-auto px-4 py-8",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8",children:[(0,a.jsxs)(c.Zp,{children:[(0,a.jsx)(c.aR,{className:"pb-3",children:(0,a.jsx)(c.ZB,{className:"text-sm font-medium text-muted-foreground",children:"Total Portfolios"})}),(0,a.jsx)(c.Wu,{children:(0,a.jsx)("div",{className:"text-3xl font-bold",children:r.length})})]}),(0,a.jsxs)(c.Zp,{children:[(0,a.jsx)(c.aR,{className:"pb-3",children:(0,a.jsx)(c.ZB,{className:"text-sm font-medium text-muted-foreground",children:"Active"})}),(0,a.jsx)(c.Wu,{children:(0,a.jsx)("div",{className:"text-3xl font-bold",children:r.filter(e=>e.active).length})})]}),(0,a.jsxs)(c.Zp,{children:[(0,a.jsx)(c.aR,{className:"pb-3",children:(0,a.jsx)(c.ZB,{className:"text-sm font-medium text-muted-foreground",children:"Uploaded"})}),(0,a.jsx)(c.Wu,{children:(0,a.jsx)("div",{className:"text-3xl font-bold",children:r.filter(e=>e.path).length})})]})]}),(0,a.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,a.jsx)("h2",{className:"text-xl font-semibold",children:"Your Portfolios"}),(0,a.jsxs)(n.$,{onClick:()=>b(!j),children:[(0,a.jsx)(m,{className:"mr-2",size:16}),"New Portfolio"]})]}),j&&(0,a.jsxs)(c.Zp,{className:"mb-6",children:[(0,a.jsxs)(c.aR,{children:[(0,a.jsx)(c.ZB,{children:"Create New Portfolio"}),(0,a.jsx)(c.BT,{children:"Enter the details for your new portfolio"})]}),(0,a.jsxs)("form",{onSubmit:E,children:[(0,a.jsxs)(c.Wu,{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.J,{htmlFor:"name",children:"Portfolio Name"}),(0,a.jsx)(i.p,{id:"name",placeholder:"My Portfolio",value:N.name,onChange:e=>w({...N,name:e.target.value}),required:!0})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.J,{htmlFor:"domain",children:"Domain"}),(0,a.jsx)(i.p,{id:"domain",placeholder:"myportfolio.com",value:N.domain,onChange:e=>w({...N,domain:e.target.value}),required:!0})]})]}),(0,a.jsxs)(c.wL,{className:"flex gap-2",children:[(0,a.jsx)(n.$,{type:"submit",children:"Create"}),(0,a.jsx)(n.$,{type:"button",variant:"outline",onClick:()=>b(!1),children:"Cancel"})]})]})]}),u?(0,a.jsx)("div",{className:"text-center py-12",children:"Loading portfolios..."}):x?(0,a.jsx)("div",{className:"text-center py-12 text-destructive",children:x}):0===r.length?(0,a.jsx)("div",{className:"text-center py-12 text-muted-foreground",children:"No portfolios yet. Create your first one!"}):(0,a.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:r.map(e=>(0,a.jsxs)(c.Zp,{children:[(0,a.jsx)(c.aR,{children:(0,a.jsxs)("div",{className:"flex justify-between items-start",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(c.ZB,{className:"text-lg",children:e.name}),(0,a.jsx)(c.BT,{className:"mt-1",children:e.domain})]}),e.active?e.path?(0,a.jsx)("span",{className:"px-2 py-1 text-xs rounded-full bg-green-100 text-green-800",children:"Uploaded"}):(0,a.jsx)("span",{className:"px-2 py-1 text-xs rounded-full bg-blue-100 text-blue-800",children:"Pending Upload"}):(0,a.jsx)("span",{className:"px-2 py-1 text-xs rounded-full bg-yellow-100 text-yellow-800",children:"Pending Payment"})]})}),(0,a.jsx)(c.Wu,{children:(0,a.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Created: ",new Date(e.created_at).toLocaleDateString()]})}),(0,a.jsxs)(c.wL,{className:"flex flex-col gap-2",children:[e.active&&!e.path&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{type:"file",accept:".zip",ref:t=>{R.current[e.id]=t},className:"hidden",onChange:t=>{var r;let a=null==(r=t.target.files)?void 0:r[0];a&&_(e.id,a)}}),(0,a.jsxs)(n.$,{className:"w-full",onClick:()=>{var t;return null==(t=R.current[e.id])?void 0:t.click()},disabled:k===e.id,children:[(0,a.jsx)(f,{className:"mr-2",size:16}),k===e.id?"Uploading...":"Upload ZIP"]})]}),e.path&&(0,a.jsxs)(n.$,{className:"w-full",onClick:()=>A(e.id),disabled:S===e.id,children:[(0,a.jsx)(p,{className:"mr-2",size:16}),S===e.id?"Deploying...":"Deploy"]})]})]},e.id))})]})]})}},6170:(e,t,r)=>{"use strict";r.d(t,{p:()=>l});var a=r(5155),s=r(2115),o=r(5016);let l=s.forwardRef((e,t)=>{let{className:r,type:s,...l}=e;return(0,a.jsx)("input",{type:s,className:(0,o.cn)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",r),ref:t,...l})});l.displayName="Input"},7003:(e,t,r)=>{"use strict";r.d(t,{$:()=>i});var a=r(5155),s=r(2115),o=r(3101),l=r(5016);let n=(0,o.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),i=s.forwardRef((e,t)=>{let{className:r,variant:s,size:o,...i}=e;return(0,a.jsx)("button",{className:(0,l.cn)(n({variant:s,size:o,className:r})),ref:t,...i})});i.displayName="Button"},9178:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var a=r(2115),s=r(4845);function o(){let e=(0,a.useContext)(s.c);if(void 0===e)throw Error("useAuth must be used within an AuthProvider");return e}}},e=>{e.O(0,[676,441,255,358],()=>e(e.s=4635)),_N_E=e.O()}]);