1import{reactExports as e,jsxRuntimeExports as s,useParams as t,useNavigate as a}from"./react-vendor-Cl5BoUFb.js";import{Badge as l,Dialog as i,DialogTrigger as n,Button as r,DialogContent as d,DialogHeader as c,DialogTitle as o,DialogDescription as u,Label as m,Textarea as x,Select as h,SelectTrigger as j,SelectValue as p,SelectContent as f,SelectItem as v,toast as g,Card as N,CardContent as y,CardHeader as b,CardTitle as w,Progress as _,Separator as k,Checkbox as S,Input as q,PageSkeleton as C,Tabs as A,TabsList as D,TabsTrigger as R,TabsContent as T}from"./ui-vendor-CVwrz00e.js";import{extendedDeadlineForJurisdiction as E,deadlineForJurisdiction as L}from"./sla-D9PZE96Q.js";import{supabase as P}from"./main-OLIzgs0k.js";import{Clock as F,Pause as I,TriangleAlert as U,CalendarPlus as $,Play as O,CircleCheck as M,CircleCheckBig as z,CircleAlert as B,FileText as V,User as G,Calendar as W,MessageSquare as H,PenLine as Q,Package as Y,Upload as J,FileSpreadsheet as K,Download as Z,FileImage as X,Archive as ee,ArrowLeft as se,FilePen as te}from"./icons-vendor-BUK3cUnC.js";import{ComplianceLayout as ae}from"./ComplianceLayout-BUvuPhC6.js";import"./sla-config-BgXZRBkb.js";import"./index-YHYuFPvV.js";import"./query-vendor-Ct1xBef-.js";import"./analytics-lib-CvkHC-Ld.js";import"./nav-lib-tIVQ3Mlj.js";import"./video-modal-C9YG8PUQ.js";import"./feature-flags-lib-C1N11fmc.js";import"./Header-BZn6RWTw.js";const le=[{value:"identity_verification",label:"Awaiting Identity Verification"},{value:"additional_information",label:"Awaiting Additional Information from Requester"},{value:"technical_issues",label:"Technical Issues/System Maintenance"},{value:"complex_request",label:"Complex Request Requiring Additional Analysis"},{value:"legal_review",label:"Legal Review Required"},{value:"third_party_delay",label:"Third Party Processing Delay"},{value:"other",label:"Other (specify in notes)"}],ie=[{value:"complex_request",label:"Complex Request Requiring Additional Processing Time"},{value:"large_volume",label:"Large Volume of Personal Data to Process"},{value:"multiple_systems",label:"Data Located Across Multiple Systems"},{value:"third_party_coordination",label:"Coordination with Third Parties Required"},{value:"redaction_required",label:"Extensive Redaction of Third-Party Information Required"},{value:"legal_analysis",label:"Legal Analysis of Request Scope Required"},{value:"other",label:"Other Legitimate Reason (specify in notes)"}];function ne({request:t,onUpdate:a}){const[N,y]=e.useState(!1),[b,w]=e.useState(!1),[_,k]=e.useState(!1),[S,q]=e.useState(""),[C,A]=e.useState(""),[D,R]=e.useState(""),[T,z]=e.useState(""),[B,V]=e.useState(""),[G,W]=e.useState(""),{pauseSla:H,resumeSla:Q,extendSla:Y,isLoading:J}=function(){const[s,t]=e.useState(!1);return{pauseSla:async(e,s)=>{t(!0);try{const{data:t,error:a}=await P.functions.invoke("manage-dsar-sla",{body:{requestId:e,action:"pause",reason:s}});if(a)throw a;if(!t.success)throw new Error(t.error||"Failed to pause SLA");return t}finally{t(!1)}},resumeSla:async(e,s)=>{t(!0);try{const{data:t,error:a}=await P.functions.invoke("manage-dsar-sla",{body:{requestId:e,action:"resume",reason:s}});if(a)throw a;if(!t.success)throw new Error(t.error||"Failed to resume SLA");return t}finally{t(!1)}},extendSla:async(e,s)=>{t(!0);try{const{data:t,error:a}=await P.functions.invoke("manage-dsar-sla",{body:{requestId:e,action:"extend",reason:s}});if(a)throw a;if(!t.success)throw new Error(t.error||"Failed to extend SLA");return t}finally{t(!1)}},isLoading:s}}(),K=(()=>{if(t.extended_until)return new Date(t.extended_until);if(t.deadline_at)return new Date(t.deadline_at);if(t.deadline_date)return new Date(t.deadline_date);const e=new Date(t.submitted_at||t.created_at);return L(e,t.jurisdiction||"",t.request_type)})(),Z=new Date,X=(e=>{const s="number"==typeof e?e:0;return s>0&&s<1e7?1e3*s:s})(t.paused_total),ee=!!t.paused_from,se=!!t.extended_until,te=t.jurisdiction||"",ae=t.request_type.replace("-","_"),ne=!te.includes("GDPR")&&["opt_out","limit_spi"].includes(ae),re=te.includes("GDPR")?"two calendar months":"45 calendar days";let de;de=ee?K.getTime()-new Date(t.paused_from).getTime()+X:K.getTime()-Z.getTime()+X;const ce=Math.ceil(de/864e5);return s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{className:"h-4 w-4 text-muted-foreground"}),s.jsx(l,{variant:ce<=1?"destructive":ce<=5?"default":"secondary",className:"flex items-center gap-1",children:ee?s.jsxs(s.Fragment,{children:[s.jsx(I,{className:"h-3 w-3"}),"Paused"]}):s.jsxs(s.Fragment,{children:[Number.isFinite(ce)&&ce>0?`${ce}d left`:"Overdue",ce<=1&&s.jsx(U,{className:"h-3 w-3"})]})}),se&&s.jsxs(l,{variant:"outline",className:"text-xs",children:[s.jsx($,{className:"h-3 w-3 mr-1"}),"Extended"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[ee?s.jsxs(i,{open:b,onOpenChange:w,children:[s.jsx(n,{asChild:!0,children:s.jsxs(r,{variant:"outline",size:"sm",children:[s.jsx(O,{className:"h-4 w-4 mr-1"}),"Resume"]})}),s.jsxs(d,{children:[s.jsxs(c,{children:[s.jsx(o,{children:"Resume SLA Clock"}),s.jsx(u,{children:"The SLA clock will resume counting down from where it was paused. Please provide a reason for resuming."})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx(m,{htmlFor:"resume-reason",children:"Reason for Resuming"}),s.jsx(x,{id:"resume-reason",value:D,onChange:e=>R(e.target.value),placeholder:"Describe why the SLA is being resumed...",className:"mt-1"})]}),s.jsxs("div",{children:[s.jsx(m,{htmlFor:"resume-notes",children:"Additional Notes (Optional)"}),s.jsx(x,{id:"resume-notes",value:T,onChange:e=>z(e.target.value),placeholder:"Any additional context...",className:"mt-1"})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 pt-4",children:[s.jsx(r,{variant:"outline",onClick:()=>w(!1),children:"Cancel"}),s.jsxs(r,{onClick:async()=>
1{if(D)try{const e=T?`${D}: ${T}`:D;await Q(t.id,e),w(!1),R(""),z(""),a(),g({title:"SLA Resumed",description:"The SLA clock has been resumed for this request."})}catch(e){g({title:"Error",description:e instanceof Error?e.message:"Failed to resume SLA.",variant:"destructive"})}else g({title:"Reason Required",description:"Please provide a reason for resuming the SLA.",variant:"destructive"})},disabled:J||!D.trim(),children:[J?s.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}):s.jsx(O,{className:"h-4 w-4 mr-2"}),"Resume SLA"]})]})]})]})]}):s.jsxs(i,{open:N,onOpenChange:y,children:[s.jsx(n,{asChild:!0,children:s.jsxs(r,{variant:"outline",size:"sm",children:[s.jsx(I,{className:"h-4 w-4 mr-1"}),"Pause"]})}),s.jsxs(d,{children:[s.jsxs(c,{children:[s.jsx(o,{children:"Pause SLA Clock"}),s.jsx(u,{children:"Pausing the SLA stops the deadline countdown. This should only be done when waiting for legitimate external factors beyond your control."})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx(m,{children:"Reason for Pausing"}),s.jsxs(h,{value:S,onValueChange:q,children:[s.jsx(j,{className:"mt-1",children:s.jsx(p,{placeholder:"Select a reason..."})}),s.jsx(f,{children:le.map(e=>s.jsx(v,{value:e.value,children:e.label},e.value))})]})]}),s.jsxs("div",{children:[s.jsx(m,{htmlFor:"pause-notes",children:"Additional Notes (Optional)"}),s.jsx(x,{id:"pause-notes",value:C,onChange:e=>A(e.target.value),placeholder:"Provide additional context if needed...",className:"mt-1"})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 pt-4",children:[s.jsx(r,{variant:"outline",onClick:()=>y(!1),children:"Cancel"}),s.jsxs(r,{onClick:async()=>{var e;if(S)try{const s=(null==(e=le.find(e=>e.value===S))?void 0:e.label)||S,l=C?`${s}: ${C}`:s;await H(t.id,l),y(!1),q(""),A(""),a(),g({title:"SLA Paused",description:"The SLA clock has been paused for this request."})}catch(s){g({title:"Error",description:s instanceof Error?s.message:"Failed to pause SLA.",variant:"destructive"})}else g({title:"Reason Required",description:"Please select a reason for pausing the SLA.",variant:"destructive"})},disabled:J||!S,children:[J?s.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}):s.jsx(I,{className:"h-4 w-4 mr-2"}),"Pause SLA"]})]})]})]})]}),s.jsxs(i,{open:_,onOpenChange:k,children:[s.jsx(n,{asChild:!0,children:s.jsxs(r,{variant:"outline",size:"sm",disabled:se||ne,title:ne?"This request type does not use the general extension workflow":se?"Request has already been extended once":`Extend deadline by ${re}`,children:[s.jsx($,{className:"h-4 w-4 mr-1"}),se?"Extended":"Extend",se&&s.jsx(M,{className:"h-3 w-3 ml-1"})]})}),s.jsxs(d,{children:[s.jsxs(c,{children:[s.jsx(o,{children:"Extend SLA Deadline"}),s.jsxs(u,{children:["This will extend the response deadline by ",re," (one-time only per request). The requester will be automatically notified of this extension."]})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx(m,{children:"Reason for Extension"}),s.jsxs(h,{value:B,onValueChange:V,children:[s.jsx(j,{className:"mt-1",children:s.jsx(p,{placeholder:"Select a reason..."})}),s.jsx(f,{children:ie.map(e=>s.jsx(v,{value:e.value,children:e.label},e.value))})]})]}),s.jsxs("div",{children:[s.jsx(m,{htmlFor:"extension-notes",children:"Additional Notes (Optional)"}),s.jsx(x,{id:"extension-notes",value:G,onChange:e=>W(e.target.value),placeholder:"Provide specific details about why the extension is needed...",className:"mt-1"})]}),s.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-3",children:s.jsxs("p",{className:"text-sm text-amber-800",children:[s.jsx("strong",{children:"Note:"})," Extensions can only be applied once per request. The new deadline will be ",E(K,te,t.request_type).toLocaleDateString(),"."]})}),s.jsxs("div",{className:"flex items-center justify-end gap-2 pt-4",children:[s.jsx(r,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),s.jsxs(r,{onClick:async()=>{var e;if(B)try{const s=(null==(e=ie.find(e=>e.value===B))?void 0:e.label)||B,l=G?`${s}: ${G}`:s;await Y(t.id,l),k(!1),V(""),W(""),a(),g({title:"SLA Extended",description:`The deadline has been extended by ${re} and the requester has been notified.`})}catch(s){g({title:"Error",description:s instanceof Error?s.message:"Failed to extend SLA.",variant:"destructive"})}else g({title:"Reason Required",description:"Please select a reason for extending the SLA.",variant:"destructive"})},disabled:J||!B,children:[J?s.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}):s.jsx($,{className:"h-4 w-4 mr-2"}),"Extend by ",re]})]})]})]})]})]})]})}function re(){const[s,t]=e.useState(!1),a=async e=>{try{const{data:s,error:t}=await P.from("dsar_task_notes").select("*").eq("task_id",e).order("created_at",{ascending:!1});return t?[]:s||[]}catch(s){return[]}},l=e=>{if(!e.due_date)return!1;const s=new Date(e.due_date),t=new Date;return t.setHours(0,0,0,0),s<t&&"done"!==e.status};return{updateTask:async(e,s)=>{try{t(!0);const{error:a}=await P.functions.invoke("update-dsar-task",{body:{taskId:e,status:s.status,assignedTo:s.assignedTo,notes:s.notes}});return a?(g({title:"Error",description:"Failed to update task. Please try again.",variant:"destructive"}),!1):(g({title:"Task Updated",description:"Task has been successfully updated."}),!0)}catch(a){return g({title:"Error",description:"An unexpected error occurred.",variant:"destructive"}),!1}finally{t(!1)}},addTaskNote:async(e,s)=>{var t;try{const{error:a}=await P.from("dsar_task_notes").insert({task_id:e,author_id:null==(t=(await P.auth.getUser()).data.user)?void 0:t.id,content:s.trim()});return!a||(g({title:"Error",description:"Failed to add note. Please try again.",variant:"destructive"}),!1)}catch(a){return g({title:"Error",description:"An unexpected error occurred.",variant:"destructive"}),!1}},fetchTaskNotes:a,calculateTaskProgress:e=>{const s=e.length,t=e.filter(e=>"done"===e.status).length;return{total:s,completed:t,percentage:s>0?Math.round(t/s*100):0}},isTaskOverdue:l,enhanceTasksWithMetadata:async e=>Promise.all(e.map(async e=>{const s=await a(e.id);return{...e,notes_list:s,is_overdue:l(e)}})),updating:s}}const de={verify_identity:{label:"Verify Identity",icon:G,color:"bg-blue-100 text-blue-800"},collect_data:{label:"Collect Data",icon:V,color:"bg-green-100 text-green-800"},redact:{label:"Redact Data",icon:U,color:"bg-orange-100 text-orange-800"},legal_review:{label:"Legal Review",icon:z,color:"bg-purple-100 text-purple-800"},generate_response:{label:"Generate Response",icon:V,color:"bg-indigo-100 text-indigo-800"},deliver_response:{label:"Deliver Response",icon:z,color:"bg-green-100 text-green-800"}};function ce({task:t,onUpdate:a}){var l,u,m;const[g,y]=e.useState(!1),[b,w]=e.useState(""),[_,S]=e.useState(t.status);e.useEffect(()=>{S(t.status)},[t.status]);const{updateTask:q,addTaskNote:C,updating:A}=re(),D=de[t.kind]||de.verify_identity,R=D.icon;return s.jsx(s.Fragment,{children:s.jsxs("tr",{className:"border-b hover:bg-muted/50 "+(t.is_overdue?"bg-red-50":""),children:[s.jsx("td",{className:"px-4 py-3",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-full ${D.color}`,children:s.jsx(R,{className:"h-4 w-4"})}),s.jsxs("div",{children:[s.jsx("div",{className:"font-medium",children:D.label}),t.is_overdue&&s.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-600",children:[s.jsx(B,{className:"h-3 w-3"}),"Overdue"]})]})]})}),s.jsx("td",{className:"px-4 py-3",children:s.jsxs(h,{value:_,onValueChange:async e=>{if(e===t.status)return;await q(t.id,{status:e})&&(S(e),a())},disabled:A,children:[s.jsx(j,{className:"w-32",children:s.jsx(p,{})}),s.jsxs(f,{children:[s.jsx(v,{value:"todo",children:"To Do"}),s.jsx(v,{value:"doing",children:"In Progress"}),s.jsx(v,{value:"blocked",children:"Blocked"}),s.jsx(v,{value:"done",children:"Completed"})]})]})}),s.jsx("td",{className:"px-4 py-3",children:s.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[s.jsx(W,{className:"h-3 w-3"}),s.jsx("span",{className:t.is_overdue?"text-red-600 font-medium":"",children:(e=>{if(!e)return"No due date";const s=new Date(e),t=new Date,a=Math.ceil((s.getTime()-t.getTime())/864e5);return a<0?`${Math.abs(a)} days overdue`:0===a?"Due today":`Due in ${a} days`})(t.due_date)})]})}),s.jsx("td",{className:"px-4 py-3",children:t.assignee_email?s.jsx("div",{className:"text-sm",children:t.assignee_email}):s.jsx("span",{className:"text-sm text-muted-foreground",children:"Unassigned"})}),s.jsx("td",{className:"px-4 py-3",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs(i,{open:g,onOpenChange:y,children:[s.jsx(n,{asChild:!0,children:s.jsxs(r,{variant:"ghost",size:"sm",children:[s.jsx(H,{className:"h-4 w-4"}),(null==(l=t.notes_list)?void 0:l.length)||0]})}),s.jsxs(d,{className:"max-w-2xl",children:[s.jsx(c,{children:s.jsxs(o,{children:[D.label," - Notes"]})}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3 max-h-60 overflow-y-auto",children:[null==(u=t.notes_list)?void 0:u.map(e=>s.jsxs(N,{className:"p-3",children:[s.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:new Date(e.created_at).toLocaleStr
1ing()}),s.jsx("div",{children:e.content})]},e.id)),!(null==(m=t.notes_list)?void 0:m.length)&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"No notes yet."})]}),s.jsx(k,{}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"text-sm font-medium",children:"Add Note"}),s.jsx(x,{placeholder:"Enter your note here...",value:b,onChange:e=>w(e.target.value),rows:3}),s.jsxs(r,{onClick:async()=>{if(!b.trim())return;await C(t.id,b)&&(w(""),a())},disabled:!b.trim()||A,size:"sm",children:[s.jsx(Q,{className:"h-4 w-4 mr-2"}),"Add Note"]})]})]})]})]})})})]})})}function oe({tasks:t,onTaskUpdate:a}){const[i,n]=e.useState([]),[r,d]=e.useState({total:0,completed:0,percentage:0}),[c,o]=e.useState(!0),{calculateTaskProgress:u,enhanceTasksWithMetadata:m}=re();if(e.useEffect(()=>{(async()=>{o(!0);try{const e=await m(t);n(e),d(u(t))}catch(e){n(t.map(e=>({...e,notes_list:[],is_overdue:!1}))),d(u(t))}finally{o(!1)}})()},[t]),c)return s.jsx(N,{children:s.jsx(y,{className:"p-6",children:s.jsxs("div",{className:"animate-pulse space-y-4",children:[s.jsx("div",{className:"h-4 bg-muted rounded w-1/3"}),s.jsx("div",{className:"space-y-2",children:[1,2,3].map(e=>s.jsx("div",{className:"h-12 bg-muted rounded"},e))})]})})});if(0===i.length)return s.jsx(N,{children:s.jsxs(y,{className:"p-6 text-center",children:[s.jsx(F,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),s.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Tasks Yet"}),s.jsx("p",{className:"text-muted-foreground",children:"Tasks will be automatically generated when this request moves to verification."})]})});const x=i.filter(e=>e.is_overdue);return s.jsxs("div",{className:"space-y-6",children:[s.jsxs(N,{children:[s.jsx(b,{className:"pb-4",children:s.jsxs(w,{className:"flex items-center gap-2",children:[s.jsx(z,{className:"h-5 w-5"}),"Task Progress"]})}),s.jsxs(y,{children:[s.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[s.jsx("div",{className:"flex-1",children:s.jsx(_,{value:r.percentage,className:"h-3"})}),s.jsxs("div",{className:"text-sm font-medium",children:[r.completed," / ",r.total," (",r.percentage,"%)"]})]}),s.jsxs("div",{className:"flex gap-4 text-sm",children:[s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs(l,{variant:"secondary",children:[i.filter(e=>"todo"===e.status).length," To Do"]})}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs(l,{variant:"default",children:[i.filter(e=>"doing"===e.status).length," In Progress"]})}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs(l,{variant:"destructive",children:[i.filter(e=>"blocked"===e.status).length," Blocked"]})}),x.length>0&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs(l,{className:"bg-red-100 text-red-800",children:[s.jsx(B,{className:"h-3 w-3 mr-1"}),x.length," Overdue"]})})]})]})]}),s.jsxs(N,{children:[s.jsx(b,{children:s.jsx(w,{children:"Tasks"})}),s.jsx(y,{className:"p-0",children:s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"border-b bg-muted/50",children:[s.jsx("th",{className:"px-4 py-3 text-left font-medium",children:"Task"}),s.jsx("th",{className:"px-4 py-3 text-left font-medium",children:"Status"}),s.jsx("th",{className:"px-4 py-3 text-left font-medium",children:"Due Date"}),s.jsx("th",{className:"px-4 py-3 text-left font-medium",children:"Assignee"}),s.jsx("th",{className:"px-4 py-3 text-left font-medium",children:"Notes"})]})}),s.jsx("tbody",{children:i.map(e=>s.jsx(ce,{task:e,onUpdate:a},e.id))})]})})})]})]})}const ue=[{value:"pms_export",label:"PMS Data Export",icon:K},{value:"redacted_package",label:"Redacted Package",icon:V},{value:"legal_memo",label:"Legal Memo",icon:V},{value:"delivery_package",label:"Delivery Package",icon:Y},{value:"other",label:"Other Document",icon:V}];function me(e){if(0===e)return"0 Bytes";const s=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,s)).toFixed(2))+" "+["Bytes","KB","MB","GB"][s]}function xe({requestId:t,artifacts:a,onRefresh:x}){const[b,w]=e.useState(!1),[_,k]=e.useState(!1),[C,A]=e.useState(new Set),[D,R]=e.useState(null),[T,E]=e.useState(""),[L,I]=e.useState("other"),{uploadArtifact:U,downloadArtifact:$,exportBun
1dle:O,isUploading:M,isDownloading:z,isExporting:B}=function(){const[s,t]=e.useState(!1),[a,l]=e.useState(null),[i,n]=e.useState(!1);return{uploadArtifact:async(e,s,a,l)=>{t(!0);try{const t=new FormData;t.append("file",s),t.append("label",a),t.append("classification",l);const{data:i,error:n}=await P.functions.invoke(`upload-dsar-artifact/${e}`,{body:t,headers:{}});if(n)throw n;if(!i.success)throw new Error(i.error||"Upload failed");return i.artifact}finally{t(!1)}},downloadArtifact:async e=>{l(e);try{const{data:s,error:t}=await P.functions.invoke(`download-dsar-artifact/${e}`,{method:"GET"});if(t)throw t;if(!s.success)throw new Error(s.error||"Download failed");return window.open(s.download_url,"_blank"),s}finally{l(null)}},exportBundle:async(e,s=[])=>{n(!0);try{const{data:t,error:a}=await P.functions.invoke("export-dsar-bundle",{body:{requestId:e,artifactIds:s}});if(a)throw a;if(!t.success)throw new Error(t.error||"Export failed");return window.open(t.download_url,"_blank"),t}finally{n(!1)}},isUploading:s,isDownloading:a,isExporting:i}}();return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"text-lg font-semibold",children:"Evidence Locker"}),s.jsxs(l,{variant:"secondary",children:[a.length," items"]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(i,{open:_,onOpenChange:k,children:[s.jsx(n,{asChild:!0,children:s.jsxs(r,{variant:"outline",disabled:0===a.length,children:[s.jsx(Y,{className:"h-4 w-4 mr-2"}),"Export Bundle"]})}),s.jsxs(d,{children:[s.jsxs(c,{children:[s.jsx(o,{children:"Export Regulator Package"}),s.jsx(u,{children:"Generate a comprehensive package with case summary and selected artifacts."})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx(m,{className:"text-sm font-medium",children:"Select Artifacts to Include:"}),s.jsx("div",{className:"mt-2 space-y-2 max-h-48 overflow-y-auto",children:a.map(e=>s.jsxs("div",{className:"flex items-center space-x-2",children:[s.jsx(S,{checked:C.has(e.id),onCheckedChange:()=>(e=>{const s=new Set(C);s.has(e)?s.delete(e):s.add(e),A(s)})(e.id)}),s.jsx("span",{className:"text-sm truncate",children:e.label}),s.jsx(l,{variant:"outline",className:"text-xs capitalize",children:e.kind})]},e.id))})]}),s.jsxs("div",{className:"flex items-center justify-between pt-4",children:[s.jsxs("p",{className:"text-sm text-muted-foreground",children:[C.size," of ",a.length," selected"]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(r,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),s.jsx(r,{onClick:async()=>{try{await O(t,Array.from(C)),k(!1),A(new Set),g({title:"Export Created",description:"Regulator package has been generated and will download shortly."})}catch(e){g({title:"Export Failed",description:e instanceof Error?e.message:"Failed to create export bundle.",variant:"destructive"})}},disabled:B,children:B?s.jsxs(s.Fragment,{children:[s.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(Y,{className:"h-4 w-4 mr-2"}),"Create Package"]})})]})]})]})]})]}),s.jsxs(i,{open:b,onOpenChange:w,children:[s.jsx(n,{asChild:!0,children:s.jsxs(r,{children:[s.jsx(J,{className:"h-4 w-4 mr-2"}),"Upload Artifact"]})}),s.jsxs(d,{children:[s.jsxs(c,{children:[s.jsx(o,{children:"Upload Evidence Artifact"}),s.jsx(u,{children:"Add a new document or file to the evidence locker."})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx(m,{htmlFor:"file-upload",children:"Select File"}),s.jsx(q,{id:"file-upload",type:"file",onChange:e=>{var s;const t=null==(s=e.target.files)?void 0:s[0];t&&(R(t),E(t.name.split(".")[0]))},accept:".pdf,.doc,.docx,.xls,.xlsx,.csv,.txt,.jpg,.jpeg,.png,.zip",className:"mt-1"}),D&&s.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Selected: ",D.name," (",me(D.size),")"]})]}),s.jsxs("div",{children:[s.jsx(m,{htmlFor:"label",children:"Label"}),s.jsx(q,{id:"label",value:T,onChange:e=>E(e.target.value),placeholder:"Descriptive name for this artifact",className:"mt-1"})]}),s.jsxs("div",{children:[s.jsx(m,{children:"Classification"}),s.jsxs(h,{value:L,onValueChange:I,children:[s.jsx(j,{className:"mt-1",children:s.jsx(p,{})}),s.jsx(f,{children:ue.map(e=>{const t=e.icon;return s.jsx(v,{value:e.value,children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(t,{className:"h-4 w-4"}),e.label]})},e.value)})})]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 pt-4",children:[s.jsx(r,{variant:"outline",onClick:()=>w(!1),children:"Cancel"}),s.jsx(r,{onClick:async()=>
1{if(D&&T.trim())try{await U(t,D,T.trim(),L),w(!1),R(null),E(""),I("other"),x(),g({title:"Upload Successful",description:"Artifact has been uploaded and catalogued."})}catch(e){g({title:"Upload Failed",description:e instanceof Error?e.message:"Failed to upload artifact.",variant:"destructive"})}else g({title:"Missing Information",description:"Please select a file and provide a label.",variant:"destructive"})},disabled:!D||!T.trim()||M,children:M?s.jsxs(s.Fragment,{children:[s.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}),"Uploading..."]}):s.jsxs(s.Fragment,{children:[s.jsx(J,{className:"h-4 w-4 mr-2"}),"Upload"]})})]})]})]})]})]})]}),0===a.length?s.jsx(N,{children:s.jsxs(y,{className:"p-8 text-center",children:[s.jsx(V,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-medium mb-2",children:"No Artifacts Yet"}),s.jsx("p",{className:"text-muted-foreground mb-4",children:"Evidence and response documents will appear here once uploaded."}),s.jsxs(r,{onClick:()=>w(!0),children:[s.jsx(J,{className:"h-4 w-4 mr-2"}),"Upload First Artifact"]})]})}):s.jsx("div",{className:"grid gap-4",children:a.map(e=>{var t;const a=(null==(i=(null==(t=e.meta)?void 0:t.mime_type)||"")?void 0:i.includes("image"))?X:(null==i?void 0:i.includes("spreadsheet"))||(null==i?void 0:i.includes("excel"))?K:(null==i?void 0:i.includes("zip"))||(null==i?void 0:i.includes("archive"))?ee:V;var i;const n=ue.find(s=>s.value===e.kind);return s.jsx(N,{children:s.jsx(y,{className:"p-4",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(a,{className:"h-8 w-8 text-muted-foreground"}),s.jsxs("div",{children:[s.jsx("h4",{className:"font-medium",children:e.label}),s.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[s.jsx("span",{children:e.file_name}),e.size_bytes&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"â¢"}),s.jsx("span",{children:me(e.size_bytes)})]}),s.jsx("span",{children:"â¢"}),s.jsxs("span",{children:["Uploaded ",new Date(e.created_at).toLocaleDateString()]})]})]})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(l,{variant:"outline",className:"capitalize",children:(null==n?void 0:n.label)||e.kind}),s.jsx(r,{variant:"outline",size:"sm",onClick:()=>(async e=>{try{await $(e.id)}catch(s){g({title:"Download Failed",description:s instanceof Error?s.message:"Failed to download artifact.",variant:"destructive"})}})(e),disabled:z===e.id,children:z===e.id?s.jsx(F,{className:"h-4 w-4 animate-spin"}):s.jsx(Z,{className:"h-4 w-4"})})]})]})})},e.id)})})]})}const he=[{value:"received",label:"New",color:"bg-blue-100 text-blue-800"},{value:"verifying",label:"Verifying",color:"bg-orange-100 text-orange-800"},{value:"needs_info",label:"Needs Info",color:"bg-purple-100 text-purple-800"},{value:"in_progress",label:"In Progress",color:"bg-yellow-100 text-yellow-800"},{value:"fulfilled",label:"Fulfilled",color:"bg-green-100 text-green-800"},{value:"declined",label:"Denied",color:"bg-red-100 text-red-800"},{value:"closed",label:"Closed",color:"bg-gray-100 text-gray-800"}],je=[{value:"access",label:"Access Request"},{value:"delete",label:"Deletion Request"},{value:"correct",label:"Correction Request"},{value:"opt_out",label:"Opt-Out Request"},{value:"limit_spi",label:"Limit SPI Request"}];function pe({icon:e,title:t,description:a,timestamp:l}){return s.jsxs("div",{className:"flex gap-3 pb-4",children:[s.jsx("div",{className:"flex-shrink-0 w-8 h-8 bg-primary/10 rounded-full flex items-center justify-center",children:e}),s.jsxs("div",{className:"flex-1",children:[s.jsx("h4",{className:"text-sm font-medium",children:t}),s.jsx("p",{className:"text-xs text-muted-foreground",children:a}),s.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(l).toLocaleString()})]})]})}function fe(){var i;const{id:n}=t(),d=a(),[c,o]=e.useState(!1),{request:u,tasks:m,artifacts:x,auditEvents:_,loading:k,error:S,refetch:q,updateStatus:E}=function(s){const[t,a]=e.useState(null),[l,i]=e.useState([]),[n,r]=e.useState([]),[d,c]=e.useState([]),[o,u]=e.useState(!0),[m,x]=e.useState(null),h=async()=>{try{u(!0),x(null);const{data:e,error:t}=await P.from("dsar_requests").select("\n *,\n hotel_settings(\n hotel_name,\n user_id\n )\n ").eq("id",s).maybeSingle();if(t)return void x(t.message);if(!e)return void x("Request not found or access denied");a(e);const{data:l,error:n}=await P.from("dsar_tasks").select("*").eq("request_id",s).order("created_at",{ascending:!0});n||i(l||[]);const{data:d,error:o}=await P.from("dsar_artifacts").select("*").eq("request_id",s).order("created_at",{ascending:!1});o||r(d||[]);const{data:m,error:h}=await P.from("dsar_audit_events").select("*").eq("request_id",s).order("created_at",{ascending:!1});h||c(m||[])}catch(e){x("Failed to load request details")}finally{u(!1)}};return e.useEffect(()=>{s&&h()},[s]),{request:t,tasks:l,artifacts:n,auditEvents:d,loading:o,error:m,refetch:h,updateStatus:async e=>{if(!t)return;const a=t.status;try{const{error:t}=await P.from("dsar_requests").update({status:e,updated_at:(new Date).toISOString()}).eq("id",s);if(t)throw t;await P.from("dsar_audit_events").insert({request_id:s,actor:"user",action:"status_change",details:{from:a,to:e}});try{await P.functions.invoke("send-dsar-notification",{body:{requestId:s,templateType:"status_update",data:{oldStatus:a,newStatus:e}}})}catch(l){}await h()}catch(i){throw i}}}}(n||"");if(k)return s.jsx(ae,{maxWidth:"7xl",children:s.jsx(C,{title:"Loading request details..."})});if(S||!u)return s.jsx(ae,{maxWidth:"7xl",children:s.jsxs("div",{className:"px-0 py-8",children:[s.jsx("div",{className:"flex items-center gap-4 mb-6",children:s.jsxs(r,{variant:"outline",onClick:()=>d("/dashboard/dsar"),children:[s.jsx(se,{className:"h-4 w-4 mr-2"}),"Back to Queue"]})}),s.jsx(N,{className:"max-w-md mx-auto",children:s.jsxs(y,{className:"p-6 text-center",children:[s.jsx("p",{className:"text-red-600 mb-4",children:S||"Request not found"}),s.jsx(r,{onClick:q,className:"bg-brand-cyan text-white hover:bg-brand-cyan/90",children:"Try Again"})]})})]})});he.find(e=>e.value===u.status);const I=je.find(e=>e.value===u.request_type);return s.jsx(ae,{maxWidth:"7xl",children:s.jsxs("div",{className:"px-0 py-8",children:[s.jsxs("div",{className:"flex items-center justify-between mb-6",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsxs(r,{variant:"outline",onClick:()=>d("/dashboard/dsar"),children:[s.jsx(se,{className:"h-4 w-4 mr-2"}),"Back to Queue"]}),s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl font-bold",children:["DSAR Request #",null==n?void 0:n.slice(-8)]}),s.jsxs("p",{className:"text-muted-foreground",children:[null==(i=u.hotel_settings)?void 0:i.hotel_name," ⢠",null==I?void 0:I.label]})]})]}),s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsxs(r,{variant:"outline",onClick:()=>{const e={access:"access-response",delete:"deletion-complete",correct:"
1correction-complete",opt_out:"opt-out-complete",limit_spi:"limit-spi"}[u.request_type]||"acknowledgment";d(`/dashboard/resources?template=${e}&request=${encodeURIComponent(n||"")}`)},children:[s.jsx(te,{className:"mr-2 h-4 w-4"}),"Draft response"]}),s.jsx(ne,{request:u,onUpdate:q}),s.jsxs(h,{value:u.status,onValueChange:async e=>{var s;if(u&&!c)try{o(!0),await E(e),g({title:"Status Updated",description:`Request status changed to ${null==(s=he.find(s=>s.value===e))?void 0:s.label}`})}catch(t){g({title:"Error",description:"Failed to update status. Please try again.",variant:"destructive"})}finally{o(!1)}},disabled:c,children:[s.jsx(j,{className:"w-40",children:s.jsx(p,{})}),s.jsx(f,{children:he.map(e=>s.jsx(v,{value:e.value,children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:`w-2 h-2 rounded-full ${e.color.split(" ")[0]}`}),e.label]})},e.value))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[s.jsx("div",{className:"lg:col-span-2",children:s.jsxs(A,{defaultValue:"summary",className:"w-full",children:[s.jsxs(D,{className:"grid w-full grid-cols-4",children:[s.jsx(R,{value:"summary",children:"Summary"}),s.jsxs(R,{value:"tasks",children:["Tasks",m.length>0&&s.jsxs(l,{variant:"secondary",className:"ml-2 text-xs",children:[m.filter(e=>"done"===e.status).length,"/",m.length]})]}),s.jsxs(R,{value:"audit",children:["Audit",_.length>0&&s.jsx(l,{variant:"secondary",className:"ml-2 text-xs",children:_.length})]}),s.jsxs(R,{value:"artifacts",children:["Artifacts",x.length>0&&s.jsx(l,{variant:"secondary",className:"ml-2 text-xs",children:x.length})]})]}),s.jsx(T,{value:"summary",className:"space-y-6",children:s.jsxs(N,{children:[s.jsx(b,{children:s.jsx(w,{children:"Request Details"})}),s.jsxs(y,{className:"space-y-4",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Requester"}),s.jsx("p",{className:"font-medium",children:u.subject_name||u.guest_name}),s.jsx("p",{className:"text-sm text-muted-foreground",children:u.subject_email||u.guest_email})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Request Type"}),s.jsx("p",{children:null==I?void 0:I.label})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Jurisdiction"}),s.jsx("p",{children:u.jurisdiction||"Not specified"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Created"}),s.jsx("p",{children:new Date(u.submitted_at||u.created_at).toLocaleDateString()})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Deadline"}),s.jsx("p",{children:(()=>{if(u.deadline_at)return new Date(u.deadline_at);if(u.deadline_date)return new Date(u.deadline_date);const e=new Date(u.submitted_at||u.created_at);return L(e,u.jurisdiction||"",u.request_type)})().toLocaleDateString()})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Identity Tier"}),s.jsx(l,{variant:"outline",className:"capitalize",children:u.identity_tier||u.verification_status||"unknown"})]})]}),(u.request_details||u.internal_notes)&&s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Details"}),s.jsx("p",{className:"text-sm bg-muted p-3 rounded-md mt-1",children:u.request_details||u.internal_notes})]})]})]})}),s.jsx(T,{value:"tasks",className:"space-y-4",children:s.jsx(oe,{tasks:m,onTaskUpdate:q})}),s.jsx(T,{value:"audit",className:"space-y-4",children:0===_.length?s.jsx(N,{children:s.jsx(y,{className:"p-6 text-center",children:s.jsx("p",{className:"text-muted-foreground",children:"No audit events yet."})})}):s.jsxs(N,{children:[s.jsx(b,{children:s.jsx(w,{children:"Activity Timeline"})}),s.jsx(y,{children:s.jsx("div",{className:"space-y-4",children:_.map(e=>s.jsx(pe,{icon:s.jsx(F,{className:"h-4 w-4"}),title:e.action.replace("_"," ").replace(/\b\w/g,e=>e.toUpperCase()),description:`by ${e.actor}`,timestamp:e.created_at},e.id))})})]})}),s.jsx(T,{value:"artifacts",className:"space-y-4",children:s.jsx(xe,{requestId:u.id,artifacts:x,onRefresh:q})})]})}),s.jsx("div",{className:"lg:col-span-1",children:s.jsxs(N,{children:[s.jsx(b,{children:s.jsx(w,{children:"Timeline"})}),s.jsx(y,{children:s.jsxs("div",{className:"space-y-4",children:[s.jsx(pe,{icon:s.jsx(G,{className:"h-4 w-4"}),title:"Request Submitted",description:`by ${u.subject_name||u.guest_name}`,timestamp:u.submitted_at||u.created_at}),_.slice(0,5).map(e=>s.jsx(pe,{icon:s.jsx(F,{className:"h-4 w-4"}),title:e.action.replace("_"," ").replace(/\b\w/g,e=>e.toUpperCase()),description:`by ${e.actor}`,timestamp:e.created_at},e.id)),_.length>5&&s.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"View all events in the Audit tab"})]})})]})})]})]})})}export{fe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.