(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8796],{23726:(e,t,i)=>{"use strict";i.d(t,{default:()=>o});var r=i(95155),a=i(12115);function o(e){let{token:t,artifact:i}=e,[o,n]=(0,a.useState)("email"),[l,d]=(0,a.useState)(""),[s,c]=(0,a.useState)(""),[m,u]=(0,a.useState)(null),[f,p]=(0,a.useState)(""),[h,y]=(0,a.useState)(!1),[g,b]=(0,a.useState)(null),x=(null==i?void 0:i.title)||"Shared artifact",w=((null==i?void 0:i.kind)||"").toLowerCase();async function S(e){if(e.preventDefault(),!l.trim()||!l.includes("@"))return void p("Please enter a valid email address.");y(!0),p("");try{let e=await fetch("/api/share/".concat(t,"/otp"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:l.trim().toLowerCase()})}),i=await e.json();if(!e.ok)return void p(i.error||"Failed to send verification code.");b(i.expires_in),i.warning&&p(i.warning),n("code")}catch(e){p("Network error. Please try again.")}finally{y(!1)}}async function v(e){if(e.preventDefault(),!s.trim()||6!==s.trim().length)return void p("Please enter the 6-digit code from your email.");y(!0),p("");try{let e=await fetch("/api/share/".concat(t,"/verify"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:l.trim().toLowerCase(),code:s.trim()})});if(429===e.status){p("Too many failed attempts. Please wait and request a new code."),n("email");return}if(401===e.status)return void p("Incorrect code. Please try again.");if(!e.ok){let t=await e.json().catch(()=>({}));p(t.error||"Verification failed.");return}let i=await fetch("/api/share/".concat(t),{method:"GET"});if(!i.ok){let e=await i.json().catch(()=>({}));p(e.error||"Failed to load artifact.");return}let r=await i.text();u(r),n("verified")}catch(e){p("Network error. Please try again.")}finally{y(!1)}}let j={width:"100%",padding:"0.625rem 0.875rem",border:"1px solid #d1d5db",borderRadius:"6px",fontSize:"0.9375rem",outline:"none",fontFamily:"inherit"},k={width:"100%",padding:"0.625rem 1rem",background:"#1a1a1a",color:"#fff",border:"none",borderRadius:"6px",fontSize:"0.9375rem",cursor:"pointer",fontFamily:"inherit",marginTop:"0.75rem"},_={color:"#dc2626",fontSize:"0.8125rem",marginTop:"0.5rem"};return"verified"===o&&null!==m?"html"===w||"ui"===w||"mines_investor_presentation"===w||"mines_project_package"===w?(0,r.jsx)("iframe",{title:x,srcDoc:m,sandbox:"allow-scripts allow-same-origin",style:{width:"100%",minHeight:"60vh",border:"1px solid #e5e7eb",borderRadius:"8px",background:"#fff"}}):(0,r.jsx)("pre",{style:{background:"#f6f8fa",padding:"1.25rem",borderRadius:"8px",overflow:"auto",fontSize:"0.875rem",lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word",border:"1px solid #e5e7eb"},children:m}):(0,r.jsxs)("div",{style:{maxWidth:"360px",margin:"0 auto",padding:"2rem 0"},children:[(0,r.jsx)("h2",{style:{fontSize:"1.125rem",fontWeight:600,marginBottom:"0.5rem"},children:"Verify your email"}),(0,r.jsx)("p",{style:{fontSize:"0.875rem",color:"#555",marginBottom:"1.5rem",lineHeight:1.5},children:"email"===o?"This shared artifact requires email verification. Enter your email to receive a code.":"A 6-digit code was sent to ".concat(l,". Enter it below.").concat(g?" Valid for ".concat(Math.ceil(g/60)," minutes."):"")}),"email"===o&&(0,r.jsxs)("form",{onSubmit:S,children:[(0,r.jsx)("label",{style:{fontSize:"0.8125rem",fontWeight:500,display:"block",marginBottom:"0.375rem"},children:"Email address"}),(0,r.jsx)("input",{type:"email",required:!0,value:l,onChange:e=>d(e.target.value),placeholder:"you@example.com",style:j,disabled:h}),f&&(0,r.jsx)("p",{style:_,children:f}),(0,r.jsx)("button",{type:"submit",style:k,disabled:h,children:h?"Sending...":"Send verification code"})]}),"code"===o&&(0,r.jsxs)("form",{onSubmit:v,children:[(0,r.jsx)("label",{style:{fontSize:"0.8125rem",fontWeight:500,display:"block",marginBottom:"0.375rem"},children:"Verification code"}),(0,r.jsx)("input",{type:"text",required:!0,inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:s,onChange:e=>c(e.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"123456",style:{...j,letterSpacing:"0.25em",textAlign:"center",fontSize:"1.25rem"},disabled:h,autoFocus:!0}),f&&(0,r.jsx)("p",{style:_,children:f}),(0,r.jsx)("button",{type:"submit",style:k,disabled:h,children:h?"Verifying...":"Verify code"}),(0,r.jsx)("button",{type:"button",onClick:()=>{n("email"),c(""),p("")},style:{...k,background:"transparent",color:"#555",border:"1px solid #d1d5db",marginTop:"0.5rem"},disabled:h,children:"Use a different email"})]})]})}},91489:(e,t,i)=>{Promise.resolve().then(i.bind(i,23726))}},e=>{e.O(0,[8441,1255,7358],()=>e(e.s=91489)),_N_E=e.O()}]);