import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{$ as t}from"./vendor-charts-iXlq6Rne.js";import{y as n}from"./vendor-react-Dzc9WstK.js";import{t as r}from"./circle-alert-BWguVnCJ.js";import{t as i}from"./circle-check-BqIK9ymt.js";import{t as a}from"./circle-x-CwRaDtL5.js";import{t as o}from"./info-CKXMLsCK.js";import{_ as s}from"./vendor-flow-IzlrcDx6.js";import{Rn as c}from"./index-HkVQGc9M.js";var l=e(t(),1),u=s(),d=`https://api.salesapp.tenalidoublehorse.com/api/v1`;function f(){let[e]=n(),t=e.get(`token`),[s,f]=(0,l.useState)(()=>t?{status:`loading`}:{status:`error`,message:`No token provided in the link.`,errorCode:`INVALID`}),p=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{p.current||!t||(p.current=!0,fetch(`${d}/workflow/email-action/`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:t})}).then(async e=>{let t=await e.json().catch(()=>({}));t.success?f({status:`success`,action:t.action,message:t.message||`Action processed successfully.`,workflowName:t.workflow_name,documentName:t.document_name}):f({status:`error`,action:t.action,message:t.message||`Unable to process this action.`,errorCode:t.error_code||`ERROR`,approvalStatus:t.approval_status})}).catch(()=>{f({status:`error`,message:`Something went wrong. Please log in to take action.`,errorCode:`ERROR`})}))},[t]),(0,u.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-[var(--color-background)] p-4`,children:(0,u.jsxs)(`div`,{className:`w-full max-w-md space-y-4 rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)] p-10 text-center shadow-[var(--shadow-lg)]`,children:[s.status===`loading`&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(c,{className:`mx-auto h-12 w-12 animate-spin text-[var(--color-text-muted)]`}),(0,u.jsx)(`p`,{className:`text-lg text-[var(--color-text-secondary)]`,children:`Processing your action…`})]}),s.status===`success`&&(0,u.jsxs)(u.Fragment,{children:[s.action===`approve`?(0,u.jsx)(i,{className:`mx-auto h-14 w-14 text-emerald-500`}):(0,u.jsx)(a,{className:`mx-auto h-14 w-14 text-red-500`}),(0,u.jsx)(`h1`,{className:`text-2xl font-bold text-[var(--color-text-primary)]`,children:s.action===`approve`?`Approved`:`Rejected`}),(0,u.jsx)(`p`,{className:`text-[var(--color-text-secondary)]`,children:s.message}),s.documentName&&(0,u.jsxs)(`p`,{className:`text-sm text-[var(--color-text-muted)]`,children:[`Document: `,(0,u.jsx)(`span`,{className:`font-medium`,children:s.documentName})]}),s.workflowName&&(0,u.jsxs)(`p`,{className:`text-sm text-[var(--color-text-muted)]`,children:[`Workflow: `,(0,u.jsx)(`span`,{className:`font-medium`,children:s.workflowName})]}),(0,u.jsx)(`a`,{href:`/admin/workflow/approvals`,className:`mt-4 inline-block text-sm text-[var(--color-primary)] hover:underline`,children:`Go to Approvals`})]}),s.status===`error`&&(()=>{let e=s.errorCode===`NOT_PENDING`&&s.approvalStatus===`approved`,t=s.errorCode===`NOT_PENDING`&&s.approvalStatus===`rejected`,n=s.errorCode===`NOT_PENDING`;return(0,u.jsxs)(u.Fragment,{children:[e?(0,u.jsx)(i,{className:`mx-auto h-14 w-14 text-emerald-400`}):t?(0,u.jsx)(a,{className:`mx-auto h-14 w-14 text-red-400`}):n?(0,u.jsx)(o,{className:`mx-auto h-14 w-14 text-blue-400`}):(0,u.jsx)(r,{className:`mx-auto h-14 w-14 text-amber-500`}),(0,u.jsx)(`h1`,{className:`text-2xl font-bold text-[var(--color-text-primary)]`,children:s.errorCode===`USED`?`Already Actioned`:s.errorCode===`EXPIRED`?`Link Expired`:e?`Already Approved`:t?`Already Rejected`:n?`Already Processed`:`Unable to Process`}),(0,u.jsx)(`p`,{className:`text-[var(--color-text-secondary)]`,children:s.message}),(0,u.jsx)(`a`,{href:`/admin/workflow/approvals`,className:`mt-4 inline-block text-sm text-[var(--color-primary)] hover:underline`,children:`Log in to view approvals`})]})})()]})})}export{f as default};