1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7308],{7308:(e,t,a)=>{a.d(t,{x:()=>eU,s:()=>e9});var r=a(95155),n=a(46539),s=a(12115),l=a(53449),i=a(72492),d=a(96648),o=a(88744);function c(e,t){return(null!=e?e:"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||t}function u(e){let t=/\.([a-z0-9]{1,8})$/i.exec(e);return t?".".concat(t[1].toLowerCase()):""}async function m(e,t,r){var n,s;let m=(0,d.createClient)(),p=e.delivery_assets.map(e=>e.asset_id),{data:x,error:h}=p.length?await m.from("assets").select("id, name, media_path").in("id",p):{data:[],error:null};if(h)throw Error("Couldn't load the delivery's assets.");let f=(null!=x?x:[]).filter(e=>e.media_path),{data:v}=await m.from("projects").select("name, organization_id").eq("id",t).maybeSingle(),g="";if(null==v?void 0:v.organization_id){let{data:e}=await m.from("organizations").select("name").eq("id",v.organization_id).maybeSingle();g=null!=(n=null==e?void 0:e.name)?n:""}let b=[],y=f.length+e.delivery_documents.length,j=0,_=e=>null==r?void 0:r({done:j,total:y,label:e}),w=e.delivery_signoffs.find(e=>"client_acceptance"===e.kind&&e.snapshot),N=null;if(w)try{let e=await Promise.all([a.e(54792),a.e(88247),a.e(41278),a.e(99788),a.e(35363),a.e(26642),a.e(33449)]).then(a.bind(a,12712)),t=e.buildAcceptanceProtocolModel({orgName:g||"â",projectName:null!=(s=null==v?void 0:v.name)?s:"â",signoff:w});N=await e.renderAcceptanceProtocolPdf(t)}catch(e){b.push({path:"acceptance-protocol.pdf",reason:e instanceof Error?e.message:"protocol render failed"})}let k=c(e.title,"delivery");async function*C(){var t,a,r,n;if(yield{name:"".concat(k,"/manifest.json"),input:JSON.stringify({package:"BTW delivery package",exportedAt:new Date().toISOString(),organization:g||null,project:null!=(t=null==v?void 0:v.name)?t:null,delivery:{id:e.id,title:e.title,kind:e.kind,status:e.status,client:e.client_name,delivery_date:e.delivery_date,ai_use_level:e.ai_use_level},assets:f.map(e=>({id:e.id,name:e.name})),documents:e.delivery_documents.map(e=>({kind:e.kind,name:e.display_name,sha256:e.content_sha256})),signoffs:e.delivery_signoffs.map(e=>({kind:e.kind,signed_name:e.signed_name,signed_email:e.signed_email,signed_at:e.signed_at,statement:e.statement}))},null,2)},N&&(yield{name:"".concat(k,"/acceptance-protocol.pdf"),input:N}),f.length){_("Signing asset URLsâ¦");let e=await (0,l.dB)(f.map(e=>e.media_path),3600,m);for(let[t,s]of f.entries()){let l=e[s.media_path],i="".concat(k,"/assets/").concat(String(t+1).padStart(2,"0"),"-").concat(c(s.name,s.id.slice(0,8))).concat(u(s.media_path));if(!l){b.push({path:i,reason:"could not sign URL"}),j+=1,_(null!=(a=s.name)?a:"asset");continue}try{let e=await fetch(l);if(!e.ok)throw Error("HTTP ".concat(e.status));j+=1,_(null!=(r=s.name)?r:"asset"),yield{name:i,input:e}}catch(e){b.push({path:i,reason:e instanceof Error?e.message:"fetch failed"}),j+=1,_(null!=(n=s.name)?n:"asset")}}}if(e.delivery_documents.length){let t=await (0,l.dB)(e.delivery_documents.map(e=>e.storage_path),3600,m);for(let a of e.delivery_documents){let e="".concat(k,"/documents/").concat(c(a.display_name,a.id.slice(0,8))).concat(u(a.storage_path)||u(a.display_name)),r=t[a.storage_path];if(!r){b.push({path:e,reason:"could not sign URL"}),j+=1,_(a.display_name);continue}try{let t=await fetch(r);if(!t.ok)throw Error("HTTP ".concat(t.status));j+=1,_(a.display_name),yield{name:e,input:t}}catch(t){b.push({path:e,reason:t instanceof Error?t.message:"fetch failed"}),j+=1,_(a.display_name)}}}b.length&&(yield{name:"".concat(k,"/_errors.json"),input:JSON.stringify({note:"These files could not be included. Re-run the download for a complete package.",failures:b},null,2)})}let A=await (0,i.downloadZip)(C()).blob();return(0,o.IV)(A,"".concat(k,"-package.zip")),{filesTotal:y,filesFailed:b.length}}var p=a(6259),x=a(54112),h=a(73472),f=a(17198),v=a(52619),g=a.n(v),b=a(20063),y=a(99776),j=a(65820),_=a(18085),w=a(48314),N=a(85468),k=a(61362),C=a(18514),A=a(84472),S=a(10383),I=a(27937),R=a(39867),z=a(24033),D=a(23664),T=a(5937),E=a(51963),P=a(35299),q=a(59847),F=a(57828),L=a(90799),O=a(71360),M=a(52056),U=a(86651),B=a(3998),$=a(46767),K=a(65142),H=a(44846),V=a(31120),G=a(51834),W=a(74719),Y=a(20243),J=a(97850),Q=a(40847),Z=a(85366),X=a(35836),ee=a(64269),et=a(56889),ea=a(39190),er=a(96583),en=a(76444),es=a(70213),el=a(34773),ei=a(36199);
1let ed=(0,el.h)("features/deliveries/send-for-review-dialog");function eo(e){let{open:t,onOpenChange:a,projectId:n,organizationId:l,deliveryId:i,deliveryTitle:o,deliveryKind:c,initialPolicy:u,sending:m,onConfirmSend:p}=e,[x,h]=(0,s.useState)(!1),[f,v]=(0,s.useState)([]),[b,y]=(0,s.useState)(!1),[w,N]=(0,s.useState)(""),[k,C]=(0,s.useState)(!1),[A,S]=(0,s.useState)(!1),[I,R]=(0,s.useState)(u),[z,D]=(0,s.useState)({}),[T,E]=(0,s.useState)([]),q=(0,ei.zP)(n,t),F="final"===c;(0,s.useEffect)(()=>{if(!t)return;N(""),C(!1),S(!1),R(u);let e=!1;return h(!0),(async()=>{var t,a,r,s;let l=(0,d.createClient)(),[o,c,u]=await Promise.all([l.rpc("get_project_client_members",{p_project:n}),F?l.rpc("get_delivery_reviewers",{p_delivery:i}):Promise.resolve({data:[],error:null}),l.from("delivery_assets").select("asset_id").eq("delivery_id",i)]);if(e)return;let m=o.error?[]:null!=(t=o.data)?t:[],p=new Map((c.error?[]:null!=(a=c.data)?a:[]).filter(e=>e.user_id).map(e=>[e.user_id,e.can_decide])),x={};for(let e of m)x[e.user_id]=null==(r=p.get(e.user_id))||r;v(m),D(x),E(u.error?[]:(null!=(s=u.data)?s:[]).map(e=>e.asset_id)),y(0===m.length),h(!1)})(),()=>{e=!0}},[t,n,i,F,u]);let L=k||A||m;async function O(){if(!F)return!0;S(!0);try{let e=(0,d.createClient)(),{error:t}=await e.from("delivery_reviewers").delete().eq("delivery_id",i).eq("reviewer_kind","account");if(t)throw t;if(f.length>0){let t=f.map(e=>{var t;return{delivery_id:i,reviewer_kind:"account",user_id:e.user_id,email:e.email,display_name:e.display_name||null,can_decide:null==(t=z[e.user_id])||t}}),{error:a}=await e.from("delivery_reviewers").insert(t);if(a)throw a}let{error:a}=await e.from("deliveries").update({decision_policy:I}).eq("id",i);if(a)throw a;return!0}catch(e){return ed.warn("send-for-review: roster write failed",{deliveryId:i,error:(0,el.P5)(e)}),j.oR.error("Couldn't save who can decide.",{description:e instanceof Error?e.message:void 0}),!1}finally{S(!1)}}async function U(){let e=w.trim().toLowerCase();if(e){if(!e.includes("@"))return void j.oR.error("Enter a valid email address.");if(!l)return void j.oR.error("Project is still loading â try again in a moment.");C(!0);let t=(0,el.r_)();try{let a=(0,d.createClient)(),{data:r,error:s}=await a.rpc("create_organization_invite",{p_organization_id:l,p_email:e,p_role:"client",p_workspace_ids:null,p_project_ids:[n]});if(s){ed.warn("send-for-review: invite create failed",{requestId:t,error:(0,el.P5)(s)}),j.oR.error("Couldn't invite the client.",{description:s.message}),C(!1);return}let i=(0,es.IM)(r);try{await fetch("/api/organization/team-actions",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({action:"notify_invitee",organizationId:l,email:e,inviteId:i.inviteId,...i.token?{token:i.token}:{}})})}catch(e){ed.warn("send-for-review: invite notify failed",{requestId:t,error:(0,el.P5)(e)})}}catch(e){ed.warn("send-for-review: invite threw",{requestId:t,error:(0,el.P5)(e)}),j.oR.error("Couldn't invite the client."),C(!1);return}C(!1)}await O()&&(await p(),a(!1))}let $=f.length>0,V=f.map(e=>e.display_name||e.email||"Unnamed client").join(", "),W=T.filter(e=>{var t;let a=null==(t=q.data)?void 0:t.assets[e];return null==a||!a.scan||!a.isCurrent||"clearance_required"===a.scan.status&&!a.resolution}).length;return(0,r.jsx)(G.lG,{open:t,onOpenChange:e=>{L||a(e)},children:(0,r.jsxs)(G.Cf,{zones:!0,className:"max-w-2xl p-0",hideClose:L,children:[(0,r.jsxs)("div",{className:"p-8",children:[(0,r.jsx)(G.c7,{className:"mb-6",children:(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("div",{className:"bg-primary/10 rounded-xl p-2.5",children:(0,r.jsx)(_.A,{className:"text-primary h-5 w-5"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(G.L3,{className:"text-2xl tracking-tight",children:"Send Delivery for Review"}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-base",children:(0,r.jsx)("span",{className:"text-foreground font-medium",children:o})})]})]})}),(0,r.jsxs)("div",{className:"space-y-8",children:[T.length>0&&W>0?(0,r.jsxs)("div",{className:"flex gap-3 rounded-xl border border-amber-300/70 bg-amber-50 p-4 text-amber-950 dar
1k:bg-amber-950/25 dark:text-amber-100",children:[(0,r.jsx)(M.A,{className:"mt-0.5 h-4 w-4 shrink-0","aria-hidden":!0}),(0,r.jsxs)("div",{className:"min-w-0 text-xs leading-relaxed",children:[(0,r.jsxs)("p",{className:"font-semibold",children:[W," delivery asset",1===W?"":"s"," need prompt-risk attention"]}),(0,r.jsx)("p",{className:"mt-1",children:"A scan is missing/outdated or an evidence-needed result has no human review. Sending remains possible, but the responsible review should be documented first."}),(0,r.jsx)(g(),{href:"/dashboard/".concat(n,"/prompts"),className:"mt-2 inline-block font-semibold underline underline-offset-2",children:"Open Prompt Risk Scan"})]})]}):null,(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"mb-3 flex items-baseline justify-between",children:[(0,r.jsx)("div",{className:"text-sm font-semibold",children:"Reviewers"}),$&&!b&&(0,r.jsxs)("button",{onClick:()=>y(!0),className:"text-primary flex items-center gap-1 text-xs hover:underline",children:[(0,r.jsx)(er.A,{className:"h-3.5 w-3.5"})," Invite additional client"]})]}),x&&(0,r.jsx)("div",{className:"text-muted-foreground py-4 text-sm",children:"Loading rosterâ¦"}),!x&&!$&&(0,r.jsx)("div",{className:"text-muted-foreground rounded-xl border border-dashed p-6 text-center text-sm",children:"No clients currently have access to this project."}),b&&!x&&(0,r.jsxs)("div",{className:"mb-4 space-y-2 rounded-xl border p-4",children:[(0,r.jsx)(en.J,{className:"text-xs",children:"Invite new client by email"}),(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(K.p,{type:"email",value:w,onChange:e=>N(e.target.value),placeholder:"[email protected]",disabled:L})})]}),$&&!x&&(0,r.jsx)("div",{className:"space-y-2",children:f.map(e=>{var t;let a=null==(t=z[e.user_id])||t;return(0,r.jsxs)("div",{className:"bg-background flex items-center justify-between rounded-xl border px-4 py-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-[14px] font-medium",children:e.display_name||e.email}),e.email&&(0,r.jsx)("div",{className:"text-muted-foreground text-xs",children:e.email})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,r.jsx)("span",{className:(0,ee.cn)("font-medium",a?"text-emerald-600":""),children:a?"Can decide & sign-off":"Can comment only"}),(0,r.jsx)(H.d,{checked:a,onCheckedChange:t=>D(a=>({...a,[e.user_id]:t})),disabled:L,"aria-label":"".concat(e.display_name||e.email||"Client"," can decide")})]})]},e.user_id)})}),$&&!x&&(0,r.jsxs)("p",{className:"text-muted-foreground mt-3 text-xs",children:["Visible to"," ",(0,r.jsx)("span",{className:"text-foreground font-medium",children:V})]})]}),F&&$&&!x&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"mb-3 text-sm font-semibold",children:"Decision policy for this round"}),(0,r.jsx)("div",{className:"grid grid-cols-2 gap-3",children:[{p:"any",label:"Any approver",sub:"One designated reviewer can accept. Fast and practical."},{p:"all",label:"All must approve",sub:"Every designated reviewer must sign. Highest level of formality."}].map(e=>{let{p:t,label:a,sub:n}=e;return(0,r.jsxs)("button",{onClick:()=>R(t),disabled:L,className:(0,ee.cn)("rounded-2xl border p-4 text-left transition hover:shadow-sm",I===t?"border-primary bg-primary/5 ring-primary/20 ring-1":"border-border"),children:[(0,r.jsx)("div",{className:"font-semibold",children:a}),(0,r.jsx)("div",{className:"text-muted-foreground mt-1 text-xs leading-snug",children:n})]},t)})}),(0,r.jsx)("p",{className:"text-muted-foreground mt-2 text-[11px]",children:"This policy is locked the moment the delivery enters review."})]})]})]}),(0,r.jsxs)("div",{className:"bg-muted/30 flex items-center justify-between border-t px-8 py-4",children:[(0,r.jsx)("div",{className:"text-muted-foreground max-w-[320px] text-xs",children:"Sending locks the asset selection and freezes the review roster. You can always reopen later if changes are needed."}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(B.$,{variant:"ghost",onClick:()=>a(!1),disabled:L,children:"Cancel"}),(0,r.jsxs)(B.$,{onClick:()=>void U(),disabled:x||L,className:"min-w-[150px] gap-2",children:[L?(0,r.jsx)(P.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(_.A,{className:"h-4 w-4"}),w.trim()?"Invite & send for review":F?"Send & lock roster":"Send for review"]})]})]})]})})}var ec=a(73364),eu=a(4399),em=a(76907),ep=a(89715),ex=a(21786),eh=a(76311),ef=a(97591);let ev={contract:ec.A,release:eu.A,license:em.A,other:ep.A};function eg(e){let{delivery:t,documents:a,organizationId:n,canEdit:l,onCh
1anged:i}=e,{data:o}=(0,J.i)(),[c,u]=(0,s.useState)("contract"),[m,p]=(0,s.useState)(!1),[x,h]=(0,s.useState)(null),[f,v]=(0,s.useState)(!1),g=(0,s.useRef)(null),b=et.DP.includes(t.status)&&ef.G.test(t.project_id)&&!!n;async function y(e){if(e&&!m&&b&&n){p(!0);try{var a;let r=(0,d.createClient)(),{path:s,contentSha256:l}=await (0,eh.cX)(r,{file:e,orgId:n,projectId:t.project_id,prefix:"document"}),{error:u}=await r.from("delivery_documents").insert({delivery_id:t.id,organization_id:n,project_id:t.project_id,kind:c,storage_path:s,display_name:e.name||"Document",content_sha256:l,uploaded_by:null!=(a=null==o?void 0:o.id)?a:null});if(u)throw await r.storage.from("media").remove([s]).catch(()=>{}),u;j.oR.success("Document added"),i()}catch(e){j.oR.error(e instanceof Error?e.message:"Could not upload the document.")}finally{p(!1)}}}async function _(){if(x){v(!0);try{let e=(0,d.createClient)(),{error:t}=await e.from("delivery_documents").delete().eq("id",x.id);if(t)throw t;await e.storage.from("media").remove([x.storage_path]).catch(()=>{}),j.oR.success("Document removed"),h(null),i()}catch(e){j.oR.error(e instanceof Error?e.message:"Could not remove the document.")}finally{v(!1)}}}return(0,r.jsxs)("div",{className:"mb-3 rounded-lg border border-border bg-muted/10 px-3 py-2.5",children:[(0,r.jsxs)("div",{className:"mb-1.5 flex flex-wrap items-center justify-between gap-2",children:[(0,r.jsxs)("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:["Documents",a.length>0?" \xb7 ".concat(a.length):""]}),l&&b?(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("select",{value:c,onChange:e=>u(e.target.value),disabled:m,className:"h-7 rounded-md border border-border bg-background px-1.5 text-[11px] text-foreground","aria-label":"Document kind",children:et.T.map(e=>(0,r.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,r.jsx)("input",{ref:g,type:"file",accept:"application/pdf,image/*,.doc,.docx,.pages",className:"hidden",onChange:e=>{var t,a;let r=null!=(a=null==(t=e.target.files)?void 0:t[0])?a:null;e.target.value="",y(r)}}),(0,r.jsxs)(B.$,{type:"button",size:"sm",variant:"outline",className:"h-7 gap-1.5 text-xs",disabled:m,onClick:()=>{var e;return null==(e=g.current)?void 0:e.click()},children:[m?(0,r.jsx)(P.A,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):(0,r.jsx)(ex.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Upload document"]})]}):null]}),(0,r.jsx)("p",{className:"mb-2 text-[11px] leading-relaxed text-muted-foreground",children:"Contracts, releases and licenses travel with the handoff and are listed in the acceptance protocol."}),0===a.length?(0,r.jsx)("p",{className:"text-[12px] leading-relaxed text-muted-foreground",children:"No documents attached yet."}):(0,r.jsx)("ul",{className:"space-y-1.5",children:a.map(e=>{var t,a;let n=null!=(t=ev[e.kind])?t:ep.A;return(0,r.jsxs)("li",{className:"flex items-center gap-2.5 rounded-md border border-border bg-background/60 px-2.5 py-1.5",children:[(0,r.jsx)(n,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":!0}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[(0,r.jsx)("span",{className:"truncate text-[12px] font-medium text-foreground",children:e.display_name}),(0,r.jsx)("span",{className:"shrink-0 rounded-full border border-border bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:(0,et._y)(e.kind)})]}),(0,r.jsx)("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:(a=e.content_sha256)?a.slice(0,10):"not recorded"})]}),l&&b?(0,r.jsxs)(B.$,{type:"button",size:"sm",variant:"ghost",className:(0,ee.cn)("h-6 shrink-0 gap-1 px-1.5 text-[11px] text-muted-foreground","hover:bg-destructive/10 hover:text-destructive"),onClick:()=>h(e),children:[(0,r.jsx)(O.A,{className:"h-3 w-3","aria-hidden":!0}),"Remove"]}):null]},e.id)})}),(0,r.jsx)(W.T,{open:!!x,onOpenChange:e=>{e||h(null)},title:x?'Remove "'.concat(x.display_name,'"?'):"Remove document?",description:"This permanently removes the document from the delivery.",confirmLabel:"Remove document",variant:"destructive",busy:f,onConfirm:()=>void _()})]})}var eb=a(53455),ey=a(69735),ej=a(50970),e_=a(77676);let ew={sent_for_review:"sent this delivery for review",changes_requested:"requested changes",approved:"approved the review round",reopened:"reopened the delivery",delivered:"marked the delivery as delivered",client_review_acknowledged:"confirmed the review is complete"};function eN(e,t){var a;return e?null!=(a=t[e])?a:"".concat(e.slice(0,8),"â¦"):"Unknown user"}let ek={lifecycle:ey.A,signoff:ec.A,view:F.A,comment:ej.A,download:R.A};function eC(e,t){let a=URL.createObjectURL(e),r=document.createElement("a");r.href=a,r.download=t,r.click(),URL.revokeObjectURL(a)}function eA(e){return e.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"delivery"}function eS(e){var t,n;let{projectId:l,deliveryId:i,deliveryTitle:o,clientName:c,tourId:u}=e,{data:m,isLoading:p,isError:x}=(0,eb.I)({queryKey:["delivery-activity",i],staleTime:3e4,queryFn:async()=>{var e,t,a,r,n,s,o,c,u,m,p;let x=(0,d.createClient)(),[h,f,v,g,b]=await Promise.all([x.from("delivery_events").select("kind, actor_name, note, created_at").eq("delivery_id",i),x.from("delivery_signoffs").select("kind, signed_name, signed_role, statement, signed_at").eq("delivery_id",i),x.from("delivery_assets").select("asset_id").eq("delivery_id",i),x.from("delivery_download_receipts").select("downloaded_by, downloaded_name, created_at").eq("delivery_id",i),x.rpc("get_project_client_members",{p_project:l})]);if(h.error)throw h.error;if(f.error)throw f.error;if(v.error)throw v.error;let y=(null!=(e=v.data)?e:[]).map(e=>e.asset_id),[j,_,w]=await Promise.all([y.length?x.from("assets").select("id, name").in("id",y):Promise.resolve({data:[],error:null}),y.length?x.from("asset_comments").select("asset_id, author_id, body, visibility, created_at").in("asset_id",y):Promise.resolve({data:[],error:null}),x.from("client_space_views").select("user_id, subject_type, subject_id, first_seen_at").eq("project_id",l)]),N={};for(let e of null!=(t=j.data)?t:[])N[e.id]=e.name;let k=new Set([i,...y]),C=(null!=(a=w.data)?a:[]).filter(e=>k.has(e.subject_id)),A={},S=new Set;for(let e of null!=(r=b.data)?r:[])S.add(e.user_id),A[e.user_id]=(null==(n=e.display_name)?void 0:n.trim())||e.email||"A client";let I=null!=(s=_.data)?s:[],R=null!=(o=g.data)?o:[],z=new Set;for(let e of I)e.author_id&&!A[e.author_id]&&z.add(e.author_id);for(let e of R)A[e.downloaded_by]||z.add(e.downloaded_by);for(let e of C)A[e.user_id]||z.add(e.user_id);if(z.size)try{let e=await fetch("/api/projects/owners?ids=".concat(Array.from(z).join(",")));
1if(e.ok)for(let t of null!=(c=(await e.json()).owners)?c:[])A[t.id]=(null==(u=t.displayName)?void 0:u.trim())||t.email||t.id.slice(0,8)}catch(e){}return function(e){var t,a,r,n;let s=[],l=t=>{var a;return null!=(a=e.assetNameById[t])?a:"an asset"},i=t=>null==t?"unknown":e.clientUserIds.has(t)?"client":"team";for(let r of e.deliveryEvents)s.push({at:r.created_at,actor:r.actor_name,actorKind:"client_review_acknowledged"===r.kind?"client":"team",kind:"lifecycle",label:null!=(a=ew[r.kind])?a:r.kind.replace(/_/g," "),detail:(null==(t=r.note)?void 0:t.trim())||null});for(let t of e.signoffs)s.push({at:t.signed_at,actor:t.signed_name,actorKind:"client_acceptance"===t.kind?"client":"team",kind:"signoff",label:"client_acceptance"===t.kind?"accepted the delivery":"signed the team attestation",detail:(null==(r=t.statement)?void 0:r.trim())||null});for(let t of e.views)s.push({at:t.first_seen_at,actor:eN(t.user_id,e.labelByUserId),actorKind:"client",kind:"view",label:"delivery"===t.subject_type&&t.subject_id===e.deliveryId?"opened the client review":"viewed â".concat(l(t.subject_id),"â"),detail:null});for(let t of e.comments){let a=(null!=(n=t.visibility)?n:"team")!=="client";s.push({at:t.created_at,actor:eN(t.author_id,e.labelByUserId),actorKind:i(t.author_id),kind:"comment",label:"commented on â".concat(l(t.asset_id),"â").concat(a?" (internal)":""),detail:function(e){let t=e.replace(/\s+/g," ").trim();return t.length>160?"".concat(t.slice(0,159),"â¦"):t}(t.body)||null,...a?{internal:!0}:{}})}for(let t of e.receipts)s.push({at:t.created_at,actor:eN(t.downloaded_by,e.labelByUserId),actorKind:i(t.downloaded_by),kind:"download",label:"downloaded â".concat(t.downloaded_name,"â"),detail:null});return s.sort((e,t)=>t.at.localeCompare(e.at))}({deliveryEvents:null!=(m=h.data)?m:[],signoffs:null!=(p=f.data)?p:[],views:C,comments:I,receipts:R,deliveryId:i,assetNameById:N,labelByUserId:A,clientUserIds:S})}}),[h,f]=(0,s.useState)(!1),[v,g]=(0,s.useState)(!1),b=async()=>{if((null==m?void 0:m.length)&&!v){g(!0);try{var e;let{renderActivityLogPdf:t,formatUtc:r}=await Promise.all([a.e(54792),a.e(88247),a.e(41278),a.e(99788),a.e(35363),a.e(26642),a.e(12049)]).then(a.bind(a,9438)),{data:n}=await (0,d.createClient)().from("projects").select("name").eq("id",l).maybeSingle(),s=await t({projectName:null!=(e=null==n?void 0:n.name)?e:"Project",deliveryTitle:o,clientName:c,generatedAt:r(new Date().toISOString()),entries:m});eC(s,"activity-log_".concat(eA(o),".pdf"))}catch(e){j.oR.error("Could not render the activity PDF")}finally{g(!1)}}};if(!p&&!x&&(null!=(t=null==m?void 0:m.length)?t:0)===0)return null;let y=h?null!=m?m:[]:(null!=m?m:[]).slice(0,8);return(0,r.jsxs)("section",{"data-showcase-tour":u,"aria-label":"Delivery activity history",className:"border-border bg-card mt-5 overflow-hidden rounded-[var(--rad-4)] border",children:[(0,r.jsxs)("div",{className:"border-border flex flex-col gap-3 border-b px-4 py-3.5 sm:flex-row sm:items-center sm:justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"text-foreground text-xs font-semibold",children:["Activity history",(null==m?void 0:m.length)?(0,r.jsxs)("span",{className:"text-muted-foreground ml-1.5 font-normal",children:["\xb7 ",m.length," events"]}):null]}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-[10.5px] leading-relaxed",children:"The complete, exportable record of review actions, comments, and decisions."})]}),(null==m?void 0:m.length)?(0,r.jsxs)("div",{className:"flex shrink-0 gap-1",children:[(0,r.jsxs)(B.$,{size:"sm",variant:"ghost",className:"h-7 px-2.5 text-xs",onClick:()=>{(null==m?void 0:m.length)&&eC(new Blob([function(e){let t=e=>'"'.concat(e.replace(/"/g,'""'),'"');return["timestamp,actor,actor_type,event_type,event,detail",...[...e].sort((e,t)=>e.at.localeCompare(t.at)).map(e=>{var a;return[e.at,e.actor,e.actorKind,e.kind,e.label,null!=(a=e.detail)?a:""].map(t).join(",")})].join("\r\n")}(m)],{type:"text/csv;charset=utf-8"}),"activity-log_".concat(eA(o),".csv"))},children:[(0,r.jsx)(e_.A,{className:"mr-1 size-3.5","aria-hidden":!0}),"CSV"]}),(0,r.jsxs)(B.$,{size:"sm",variant:"ghost",className:"h-7 px-2.5 text-xs",disabled:v,onClick:()=>void b(),children:[v?(0,r.jsx)(P.A,{className:"mr-1 size-3.5 animate-spin","aria-hidden":!0}):(0,r.jsx)(e_.A,{className:"mr-1 size-3.5","aria-hidden":!0}),"PDF"]})]}):null]}),(0,r.jsx)("div",{className:"px-4 py-2",children:p?(0,r.jsx)("p",{className:"text-muted-foreground py-3 text-xs",children:"Loading activityâ¦"}):x?(0,r.jsx)("p",{className:"text-muted-foreground py-3 text-xs",children:"Could not load the activity feed."}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("ul",{className:"divide-border divide-y",children:y.map((e,t)=>{let a=ek[e.kind];return(0,r.jsxs)("li",{className:"grid gap-x-3 gap-y-1 py-3 text-xs sm:grid-cols-[18px_minmax(0,1fr)_auto]",children:[(0,r.jsx)(a,{className:(0,ee.cn)("mt-0.5 size-3.5 shrink-0","client"===e.actorKind?"text-amber-600":"text-muted-foreground"),"aria-hidden":!0}),(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsxs)("p",{className:"leading-relaxed",children:[(0,r.jsx)("span",{className:"text-foreground font-medium",children:e.actor})," ",(0,r.jsx)("span",{className:"text-muted-foreground",children:e.label})]}
1),e.detail?(0,r.jsx)("p",{className:"text-muted-foreground/80 mt-0.5 leading-relaxed break-words",children:e.detail}):null]}),(0,r.jsx)($.Y6,{label:function(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{weekday:"long",day:"numeric",month:"long",year:"numeric",hour:"2-digit",minute:"2-digit"})}(e.at),children:(0,r.jsx)("time",{dateTime:e.at,className:"text-muted-foreground/70 col-start-2 tabular-nums sm:col-start-3 sm:row-start-1",children:function(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})}(e.at)})})]},"".concat(e.at,"-").concat(t))})}),(null!=(n=null==m?void 0:m.length)?n:0)>8?(0,r.jsx)("button",{type:"button",className:"text-muted-foreground my-2 text-xs font-medium underline-offset-2 hover:underline",onClick:()=>f(e=>!e),children:h?"Show fewer":"Show all ".concat(null==m?void 0:m.length," events")}):null]})})]})}let eI=et.DP,eR="Locked while awaiting client review â reopen to edit.",ez=["approved","delivered"],eD={send_for_review:_.A,reopen:w.A,mark_delivered:N.A},eT={send_for_review:"Delivery sent for client approval",reopen:"Delivery reopened",mark_delivered:"Delivery marked as delivered"},eE={sent_for_review:"Sent for review",changes_requested:"Changes requested",approved:"Approved",reopened:"Reopened",delivered:"Delivered",client_review_acknowledged:"Client said it looks good"},eP="I confirm that the AI-assisted elements in this delivery were reviewed by a human and that I hold editorial responsibility for its content.",eq=[{value:"final",label:"Final delivery",description:"The binding hand-off: the client formally accepts with a named sign-off, and the delivery can be marked delivered."},{value:"review",label:"Review round",description:"A light, non-binding round â the client can say it looks good or request changes. No ceremony, no download gate."}],eF=[{stage:"draft",label:"Draft"},{stage:"assets_ready",label:"Assets ready"},{stage:"client_review",label:"Client review"},{stage:"delivered",label:"Delivered"}];function eL(e){return"delivered"===e.status?"delivered":"in_review"===e.status||"changes_requested"===e.status||"approved"===e.status?"client_review":e.delivery_assets.length>0?"assets_ready":"draft"}function eO(e){if(!e)return null;let t=new Date("".concat(e,"T12:00:00"));return Number.isNaN(t.getTime())?e:t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function eM(e){if(!e)return null;let t=new Date("".concat(e,"T12:00:00"));if(Number.isNaN(t.getTime()))return null;let a=new Date,r=new Date(a.getFullYear(),a.getMonth(),a.getDate(),12),n=Math.round((t.getTime()-r.getTime())/864e5);return 0===n?"Due today":n<0?"".concat(Math.abs(n)," day").concat(-1===n?"":"s"," overdue"):"".concat(n," day").concat(1===n?"":"s"," left")}function eU(e){let{projectId:t,organizationId:a,canEdit:n,canManage:i,createRequestKey:o,readyForFirstDelivery:c=!0,readOnly:u=!1,onOpenProductionPlan:m,onOpenCompliance:p}=e,h=(0,y.jE)(),f=(0,b.useSearchParams)().get("delivery"),v=(0,s.useRef)(null),g=(0,s.useRef)(0),[_,w]=(0,s.useState)([]),[k,C]=(0,s.useState)(!0),[A,S]=(0,s.useState)(!1),[I,R]=(0,s.useState)(new Set),[z,D]=(0,s.use
1State)(null),[T,E]=(0,s.useState)(null),[P,q]=(0,s.useState)(!1),[F,L]=(0,s.useState)(null),[O,M]=(0,s.useState)(null),[U,B]=(0,s.useState)(null),[$,K]=(0,s.useState)(!1),{data:H}=(0,eb.I)({queryKey:["client-space-views",t],enabled:!!t,staleTime:3e4,queryFn:async()=>{var e,a;let r=(0,d.createClient)(),[n,s]=await Promise.all([r.from("client_space_views").select("user_id, subject_type, subject_id, last_seen_at").eq("project_id",t),r.rpc("get_project_client_members",{p_project:t})]);if(n.error)throw n.error;let l=new Map((null!=(e=s.data)?e:[]).map(e=>{var t;return[e.user_id,(null==(t=e.display_name)?void 0:t.trim())||e.email||"A client"]}));return(null!=(a=n.data)?a:[]).map(e=>{var t;return{userId:e.user_id,label:null!=(t=l.get(e.user_id))?t:"A client",subjectType:e.subject_type,subjectId:e.subject_id,lastSeenAt:e.last_seen_at}})}}),V=(0,s.useMemo)(()=>{let e=new Map;for(let a of null!=H?H:[]){var t;if("delivery"!==a.subjectType)continue;let r=null!=(t=e.get(a.subjectId))?t:[];r.push(a),e.set(a.subjectId,r)}return e},[H]),G=(0,s.useMemo)(()=>new Set((null!=H?H:[]).filter(e=>"asset"===e.subjectType).map(e=>e.subjectId)),[H]),[J,Z]=(0,s.useState)({loading:!0,error:!1,byDelivery:new Map}),[ee,er]=(0,s.useState)({}),en=(0,s.useCallback)(async e=>{var a,r;let n=Array.from(new Set(e.flatMap(e=>e.delivery_assets.map(e=>e.asset_id))));if(0===n.length)return void Z({loading:!1,error:!1,byDelivery:new Map});Z(e=>({...e,loading:!0,error:!1}));let s=(0,d.createClient)(),[i,o]=await Promise.all([s.from("assets").select("id, name, media_kind, source_kind, tool, content_sha256, disclosure_status, legal_reference, legal_prompt, media_path, thumb_path").in("id",n),s.from("rights_records").select("id, asset_id, status").eq("project_id",t)]);if(i.error||o.error)return void Z({loading:!1,error:!0,byDelivery:new Map});let c=null!=(a=i.data)?a:[],u=new Map(c.map(e=>[e.id,e]));(async()=>{try{let r=e=>(0,x.db)(e),n=c.filter(e=>e.thumb_path),i=c.filter(e=>!e.thumb_path&&e.media_path&&("video"===r(e)||"audio"===r(e))),d=c.filter(e=>
1!e.thumb_path&&e.media_path&&"video"!==r(e)&&"audio"!==r(e)),[o,u,m]=await Promise.all([n.length?(0,l.dB)(n.map(e=>e.thumb_path),3600,s):{},i.length?(0,l.dB)(i.map(e=>e.media_path),3600,s):{},d.length?(0,l.dB)(d.map(e=>e.media_path),3600,s,l.Lj):{}]),p={};for(let n of c){var e,t,a;let s=r(n),l="video"===s||"audio"===s,i=n.thumb_path?null!=(e=o[n.thumb_path])?e:null:n.media_path&&null!=(t=(l?u:m)[n.media_path])?t:null;p[n.id]={name:null!=(a=n.name)?a:"Untitled",url:i,kind:s,mediaPath:n.media_path}}er(p)}catch(e){}})();let m=(0,et.Y8)(n,null!=(r=o.data)?r:[]),p=new Map;for(let t of e){let e=t.delivery_assets.map(e=>u.get(e.asset_id)).filter(e=>!!e);p.set(t.id,(0,X.D)(e,m))}Z({loading:!1,error:!1,byDelivery:p})},[t]),es=(0,s.useCallback)(async()=>{let e=++g.current;h.invalidateQueries({queryKey:(0,ea.w)(t)});let a=(0,d.createClient)(),{data:r,error:n}=await a.from("deliveries").select("id, title, client_name, delivery_date, ai_use_level, created_at, status, kind, sent_at, approved_at, decision_policy, watermark_enabled, watermark_text, delivery_assets(asset_id), delivery_signoffs(id, kind, signed_name, signed_role, signed_email, statement, signed_at, snapshot), delivery_events(kind, actor_name, note, created_at), delivery_download_receipts(asset_id, downloaded_name, created_at), delivery_reviewers(id, reviewer_kind, user_id, email, display_name, can_decide), delivery_decisions(id, decider_id, decider_kind, decider_name, decider_email, decision_type, decided_at), delivery_documents(id, kind, storage_path, display_name, content_sha256, uploaded_by, created_at)").eq("project_id",t).order("created_at",{ascending:!1}),s=n?[]:null!=r?r:[];if(e===g.current){for(let e of(S(!!n),s)){var l,i,o,c,u,m,p;e.delivery_assets=null!=(l=e.delivery_assets)?l:[],e.delivery_signoffs=[...null!=(i=e.delivery_signoffs)?i:[]].sort((e,t)=>e.signed_at.localeCompare(t.signed_at)),e.delivery_events=[...null!=(o=e.delivery_events)?o:[]].sort((e,t)=>e.created_at.localeCompare(t.created_at)),e.delivery_download_receipts=[...null!=(c=e.delivery_download_receipts)?c:[]].sort((e,t)=>e.created_at.localeCompare(t.created_at)),e.delivery_reviewers=null!=(u=e.delivery_reviewers)?u:[],e.delivery_decisions=null!=(m=e.delivery_decisions)?m:[],e.delivery_documents=[...null!=(p=e.delivery_documents)?p:[]].sort((e,t)=>e.created_at.localeCompare(t.created_at))}w(s),C(!1),en(s)}},[t,en,h]);(0,s.useEffect)(()=>{es()},[es]),(0,s.useEffect)(()=>{f&&!k&&v.current!==f&&_.some(e=>e.id===f)&&(v.current=f,D(null),E(f),R(e=>{let t=new Set(e);return t.add(f),t}),window.setTimeout(()=>{var e;null==(e=document.getElementById("delivery-".concat(f)))||e.scrollIntoView({behavior:"smooth",block:"start"})},100))},[_,k,f]),(0,s.useEffect)(()=>{if(k||0===_.length){k||E(null);return}E(e=>{var t,a;return e&&_.some(t=>t.id===e)?e:f&&_.some(e=>e.id===f)?f:null!=(a=null==(t=[..._].filter(e=>"delivered"!==e.status&&!!e.delivery_date).sort((e,t)=>{var a,r;return(null!=(a=e.delivery_date)?a:"9999-12-31").localeCompare(null!=(r=t.delivery_date)?r:"9999-12-31")})[0])?void 0:t.id)?a:_[0].id})},[_,k,f]);let el=(0,s.useMemo)(()=>{var e;return null!=(e=_.find(e=>e.id===T))?e:null},[_,T]),ei=(0,s.useMemo)(()=>z?_.filter(e=>eL(e)===z):_,[_,z]),ed=(0,s.useMemo)(()=>[..._].filter(e=>"delivered"!==e.status&&!!e.delivery_date).sort((e,t)=>{var a,r;return(null!=(a=e.delivery_date)?a:"9999-12-31").localeCompare(null!=(r=t.delivery_date)?r:"9999-12-31")}).slice(0,3),[_]);async function eo(){if(!U)return;let e=U.delivery_signoffs.length;K(!0);try{let a=(0,d.createClient)(),{error:r}=await a.from("deliveries").delete().eq("id",U.id);if(r)throw r;try{await (0,Q.Y)(a,t,{action:"delivery.deleted",resourceType:"delivery",resourceId:U.id,metadata:{deliveryId:U.id,title:U.title,signoffCount:e}})}catch(e){}j.oR.success("Delivery deleted"),B(null),es()}catch(e){j.oR.error(e instanceof Error?e.message:"Could not delete the delivery.")}finally{K(!1)}}return(0,s.useEffect)(()=>{o>0&&(L(null),q(!0))},[o]),(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("section",{className:"border-border bg-card overflow-hidden rounded-[var(--rad-5)] border shadow-[var(--elev-1)]",children:[_.length>0?(0,r.jsxs)("div",{className:"grid min-w-0 items-start xl:grid-cols-[minmax(0,1fr)_300px]",children:[(0,r.jsx)(e$,{delivery:el,canEdit:n,onEdit:()=>{el&&(L(el),q(!0))}}),(0,r.jsx)(eK,{deliveries:ed,selectedDeliveryId:T,canManage:i,onSelectDelivery:E,onOpenProductionPlan:m,onOpenCompliance:p})]}):null,(0,r.jsxs)("div",{className:_.length>0?"border-border border-t":void 0,children:[_.length>1?(0,r.jsxs)("div",{className:"border-border flex flex-wrap items-center justify-between gap-3 border-b px-4 py-3",children:[(0,r.jsx)(eB,{deliveries:_,active:z,onSelect:D}),(0,r.jsxs)("div",{className:"text-muted-foreground text-[11px]",children:[ei.length," shown"]})]}):null,_.length>0?(0,r.jsxs)("div",{className:"text-muted-foreground border-border hidden grid-cols-[minmax(240px,1.45fr)_120px_minmax(140px,0.8fr)_140px_60px_minmax(170px,1fr)_124px] items-center gap-3 border-b px-5 py-2.5 text-[11px] font-medium xl:grid",children:[(0,r.jsx)("span",{children:"Delivery"}),(0,r.jsx)("span",{children:"Status"}),(0,r.jsx)("span",{children:"Client"}),(0,r.jsx)("span",{children:"Delivery deadline"}),(0,r.jsx)("span",{children:"Assets"}),(0,r.jsx)("span",{children:"Next step"}),(0,r.jsx)("span",{children:"Details"})]}):null,k?(0,r.jsx)("ul",{className:"divide-border divide-y","aria-hidden":!0,
1children:Array.from({length:3}).map((e,t)=>(0,r.jsxs)("li",{className:"grid min-h-24 grid-cols-2 items-center gap-3 px-5 py-4 xl:grid-cols-[minmax(240px,1.45fr)_120px_minmax(140px,0.8fr)_140px_60px_minmax(170px,1fr)_124px]",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)(Y.EA,{className:"size-10 rounded-[var(--rad-3)]"}),(0,r.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,r.jsx)(Y.EA,{className:"h-3.5 w-40"}),(0,r.jsx)(Y.EA,{className:"h-2.5 w-28"})]})]}),Array.from({length:6}).map((e,t)=>(0,r.jsx)(Y.EA,{className:"h-3 w-full max-w-24"},t))]},t))}):A?(0,r.jsxs)("div",{className:"px-5 py-10 text-center",children:[(0,r.jsx)("p",{className:"text-destructive text-sm font-medium",children:"Couldn't load the deliveries."}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:"Reload the page to try again."})]}):0===_.length?(0,r.jsxs)("div",{className:"px-5 py-12 text-center",children:[(0,r.jsx)("div",{className:"bg-muted text-muted-foreground mx-auto flex size-11 items-center justify-center rounded-full",children:(0,r.jsx)(N.A,{className:"size-5","aria-hidden":!0})}),(0,r.jsx)("h3",{className:"text-foreground mt-4 text-sm font-semibold",children:"No deliveries yet"}),(0,r.jsx)("p",{className:"text-muted-foreground mx-auto mt-1 max-w-md text-xs leading-relaxed",children:u?"No deliveries have been prepared for this project. Open its workflow to explore the record.":c?"Create a handoff from your saved assets to prepare review and delivery.":"First add an asset in Workflow and save how it was made. Then prepare it for review here."})]}):0===ei.length?(0,r.jsxs)("div",{className:"px-5 py-10 text-center",children:[(0,r.jsx)("p",{className:"text-foreground text-sm font-medium",children:"No deliveries in this stage"}),(0,r.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground mt-2 text-xs underline underline-offset-4",onClick:()=>D(null),children:"Show all deliveries"})]}):(0,r.jsx)("ul",{className:"divide-border divide-y",children:ei.map(e=>{var s;return(0,r.jsx)(eW,{delivery:e,projectId:t,organizationId:a,expanded:I.has(e.id),highlighted:f===e.id,selected:T===e.id,canEdit:n,completeness:J.byDelivery.get(e.id),completenessLoading:J.loading,completenessError:J.error,seenBy:null!=(s=V.get(e.id))?s:[],seenAssetIds:G,mediaByAsset:ee,onToggle:()=>{var t;E(t=e.id),R(e=>{let a=new Set(e);return a.has(t)?a.delete(t):a.add(t),a})},onEdit:()=>{L(e),q(!0)},onSignoff:()=>M(e),onDelete:()=>B(e),onChanged:()=>void es()},e.id)})})]})]}),(0,r.jsx)(e9,{open:P,onOpenChange:q,projectId:t,organizationId:a,editing:F,onSaved:()=>void es()}),(0,r.jsx)(tt,{delivery:O,completeness:O?J.byDelivery.get(O.id):void 0,onOpenChange:e=>{e||M(null)},onSigned:()=>void es()}),(0,r.jsx)(W.T,{open:!!U,onOpenChange:e=>{e||B(null)},title:U?'Delete "'.concat(U.title,'"?'):"Delete delivery?",description:function(e){if(!e)return null;let t=e.delivery_signoffs.length;return(0,r.jsxs)("span",{children:["This permanently removes the delivery and its asset list.",t>0?(0,r.jsxs)(r.Fragment,{children:[" ","It also deletes"," ",(0,r.jsxs)("strong",{className:"text-foreground",children:[t," permanent sign-off record",1===t?"":"s"]}),", which cannot be recovered."]}):null]})}(U),confirmLabel:"Delete delivery",variant:"destructive",busy:$,onConfirm:()=>void eo()})]})}function eB(e){let{deliveries:t,active:a,onSelect:n}=e,s=new Map;for(let e of t){var l;let t=eL(e);s.set(t,(null!=(l=s.get(t))?l:0)+1)}return(0,r.jsxs)("div",{className:"border-border bg-muted/25 flex flex-wrap items-center gap-0.5 rounded-[var(--rad-3)] border p-0.5",role:"tablist","aria-label":"Delivery stages",children:[(0,r.jsx)("button",{type:"button",role:"tab","aria-selected":null===a,onClick:()=>n(null),className:(0,ee.cn)("rounded-[var(--rad-2)] px-3 py-1.5 text-[11px] font-medium transition-colors",null===a?"bg-card text-[var(--app-accent)] shadow-[var(--elev-1)]":"text-muted-foreground hover:text-foreground"),children:"All deliveries"}),eF.map(e=>{var t;let{stage:l,label:i}=e,d=null!=(t=s.get(l))?t:0,o=a===l;return(0,r.jsx)("button",{type:"button",role:"tab","aria-selected":o,onClick:()=>n(l),className:(0,ee.cn)("rounded-[var(--rad-2)] px-3 py-1.5 text-[11px] font-medium transition-colors",o?"bg-card text-foreground shadow-[var(--elev-1)]":d>0?"text-muted-foreground hover:text-foreground":"text-muted-foreground
1/50 hover:text-muted-foreground"),children:i},l)})]})}function e$(e){var t,a,n,s;let{delivery:l,canEdit:i,onEdit:d}=e,o=l?eL(l):"draft",c=eF.findIndex(e=>{let{stage:t}=e;return t===o}),u=null==l||null==(t=l.delivery_events.find(e=>"delivered"===e.kind))?void 0:t.created_at,m=l?[l.created_at,l.delivery_assets.length>0?l.created_at:null,l.sent_at,null!=u?u:null]:[null,null,null,null],p=eO(null!=(a=null==l?void 0:l.delivery_date)?a:null),x=eM(null!=(n=null==l?void 0:l.delivery_date)?n:null),h=!!(l&&!eI.includes(l.status));return(0,r.jsxs)("div",{className:"grid min-h-56 lg:grid-cols-[minmax(0,1fr)_210px]",children:[(0,r.jsxs)("div",{className:"min-w-0 px-5 py-5",children:[(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("h2",{className:"text-foreground text-base font-semibold tracking-tight",children:null!=(s=null==l?void 0:l.title)?s:"No delivery selected"}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:l?[l.client_name,"review"===l.kind?"Review round":"Final delivery"].filter(Boolean).join(" \xb7 "):"Create a delivery to begin the first client handoff."})]}),(0,r.jsx)("ol",{className:"grid grid-cols-2 gap-x-3 gap-y-5 sm:grid-cols-4",children:eF.map((e,t)=>{let{stage:a,label:n}=e,s=!!l&&(t<c||"delivered"===o),i=!!l&&t===c&&!s,d=m[t]?eO(m[t].slice(0,10)):null;return(0,r.jsxs)("li",{className:"relative min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:(0,ee.cn)("relative z-10 flex size-9 shrink-0 items-center justify-center rounded-full border text-xs font-semibold",s?"border-emerald-600 bg-emerald-600 text-white":i?"bg-card border-[var(--app-accent)] text-[var(--app-accent)]":"border-border bg-card text-muted-foreground"),"aria-label":s?"".concat(n,", completed"):i?"".concat(n,", in progress"):"".concat(n,", upcoming"),children:s?(0,r.jsx)(k.A,{className:"size-4","aria-hidden":!0}):t+1}),t<eF.length-1?(0,r.jsx)("span",{className:(0,ee.cn)("border-border hidden h-px flex-1 border-t sm:block",t<c&&"border-[var(--app-accent)]"),"aria-hidden":!0}):null]}),(0,r.jsx)("p",{className:"text-foreground mt-2 text-xs font-semibold",children:n}),(0,r.jsx)("p",{className:(0,ee.cn)("mt-0.5 text-[11px]",i?"text-[var(--app-accent)]":"text-muted-foreground"),children:l?s?"Completed":i?"In progress":"Upcoming":"Not started"}),d?(0,r.jsx)("p",{className:"text-muted-foreground mt-0.5 text-[10px]",children:d}):null]},a)})})]}),(0,r.jsxs)("div",{className:"border-border bg-muted/15 flex flex-col justify-center border-t px-5 py-5 lg:border-t-0 lg:border-l",children:[(0,r.jsx)("p",{className:"text-muted-foreground text-[10px] font-semibold tracking-[0.14em] uppercase",children:"Delivery deadline"}),(0,r.jsx)("p",{className:"text-foreground mt-2 text-base font-semibold tracking-tight",children:null!=p?p:"Not set yet"}),x?(0,r.jsx)("span",{className:(0,ee.cn)("mt-2 w-fit rounded-full px-2 py-0.5 text-[10px] font-medium",x.includes("overdue")?"bg-destructive/10 text-destructive":"bg-[var(--app-accent-soft)] text-[var(--app-accent)]"),children:x}):null,i&&l&&!h?(0,r.jsxs)("button",{type:"button",className:"text-muted-foreground hover:text-foreground mt-3 inline-flex w-fit items-center gap-1.5 text-xs font-medium transition-colors",onClick:d,children:[(0,r.jsx)(C.A,{className:"size-3.5","aria-hidden":!0}),p?"Edit deadline":"Add deadline"]}):i&&l?(0,r.jsxs)("p",{className:"text-muted-foreground mt-3 inline-flex items-center gap-1.5 text-[11px] font-medium",children:[(0,r.jsx)(A.A,{className:"size-3.5","aria-hidden":!0}),"Locked during review"]}):null]})]})}function eK(e){let{deliveries:t,selectedDeliveryId:a,canManage:n,onSelectDelivery:s,onOpenProductionPlan:l,onOpenCompliance:i}=e;return(0,r.jsx)("aside",{className:"border-border bg-muted/10 self-start border-t p-4 xl:border-t-0 xl:border-l",children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("section",{className:"border-border bg-card overflow-hidden rounded-[var(--rad-4)] border",children:[(0,r.jsx)("div",{className:"px-4 pt-4 pb-2",children:(0,r.jsx)("h3",{className:"text-muted-foreground text-[10px] font-semibold tracking-[0.16em] uppercase",children:"Upcoming handoffs"})}),t.length>0?(0,r.jsx)("ul",{className:"divide-border divide-y px-4",children:t.map(e=>(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",className:(0,ee.cn)("group flex w-full items-center gap-3 py-3 text-left",e.id===a&&"text-[var(--app-accent)]"),onClick:()=>s(e.id),children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("p",{className:"text-foreground truncate text-xs font-semibold transition-colors group-hover:text-[var(--app-accent)]",children:e.title}),(0,r.jsxs)("p",{className:"text-muted-foreground mt-0.5 text-[10px]",children:["Delivery due"," ",eO(e.delivery_date)]})]}),(0,r.jsx)(S.A,{className:"text-muted-foreground size-3.5 shrink-0","aria-hidden":!0})]})},e.id))}):(0,r.jsx)("p",{className:"text-muted-foreground px-4 pt-2 pb-4 text-xs leading-relaxed",children:"Deadlines will appear here as soon as the first delivery is created."})]}),(0,r.jsxs)("section",{className:"border-border bg-card overflow-hidden rounded-[var(--rad-4)] border",children:[(0,r.jsx)("div",{className:"px-4 pt-4 pb-2",children:(0,r.jsx)("h3",{className:"text-muted-foreground text-[10px] font-semibold tracking-[0.16em] uppercase",children:"Schedule & exports"})}),(0,r.jsxs)("div",{className:"divide-border divide-y px-4",children:[(0,r.jsxs)("button",{type:"button",className:"group flex w-full items-center gap-3 py-3 text-left",onClick:l,children:[(0,r.jsx)(S.A,{className:"text-muted-foreground size-4 shrink-0","aria-hidden":!0}),(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,r.jsx)("span",{className:"text-foreground block text-xs font-semibold",children:"Production schedule"}),(0,r.jsx)("span",{className:"text-muted-foreground mt-0.5 block text-[10px]",children:"View your full production plan"})]}),(0,r.jsx)(I.A,{className:"text-muted-foreground size-4 transition-transform group-hover:translate-x-0.5","aria-hidden":!0})]}),n?(0,r.jsxs)("button",{type:"button",className:"group flex w-full items-center gap-3 py-3 text-left",onClick:i,children:[(0,r.jsx)(R.A,{className:"text-muted-foreground size-4 shrink-0","aria-hidden":!0}),(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,r.jsx)("span",{className:"text-foreground block text-xs font-semibold",children:"Compliance exports"}),(0,r.jsx)("span",{className:"text-muted-foreground mt-0.5 block text-[10px]",children:"Export delivery reports"})]}),(0,r.jsx)(I.A,{className:"text-muted-foreground size-4 transition-transform group-hover:translate-x-0.5","aria-hidden":!0})]}):null]})]})]})})}function eH(e){let{delivery:t,projectId:a,canEdit:n,onSendReview:l}=e,i=function(e){let t=window.location.origin;return"".concat(t,"/client/p/").concat(e,"/approval")}(a),d=Array.from(new Set(t.delivery_reviewers.map(e=>{var t;return(null!=(t=e.email)?t:"").trim()}
1).filter(Boolean))),o="â".concat(t.title,"â is ready for your review: ").concat(i),c="mailto:".concat(encodeURIComponent(d.join(",")),"?subject=").concat(encodeURIComponent("".concat(t.title," â ready for your review")),"&body=").concat(encodeURIComponent("Hello".concat(t.client_name?" ".concat(t.client_name):"",",\n\n").concat(o,"\n"))),u="https://wa.me/?text=".concat(encodeURIComponent(o)),[x,h]=(0,s.useState)(!1),f="final"===t.kind&&("approved"===t.status||"delivered"===t.status);async function v(){if(x)return;h(!0);let e=j.oR.loading("Packing the deliveryâ¦");try{let r=await m(t,a,t=>{j.oR.loading("Packing the delivery⦠".concat(t.done,"/").concat(t.total),{id:e})});r.filesFailed>0?j.oR.warning("Package downloaded â ".concat(r.filesFailed," of ").concat(r.filesTotal," files couldn't be included (see _errors.json inside)."),{id:e}):j.oR.success("Delivery package downloaded.",{id:e})}catch(t){j.oR.error(t instanceof Error?t.message:"Couldn't build the package.",{id:e})}finally{h(!1)}}let g="draft"===t.status||"changes_requested"===t.status,b=g?"Send to client":"in_review"===t.status?"Awaiting client":"approved"===t.status?"Hand off":"Delivered",y=n&&g&&t.delivery_assets.length>0;return(0,r.jsxs)(p.rI,{children:[(0,r.jsx)(p.ty,{asChild:!0,children:(0,r.jsxs)(B.$,{type:"button",size:"sm",variant:g?"default":"outline",className:"h-7 gap-1.5 text-xs",onClick:e=>e.stopPropagation(),children:["delivered"===t.status?(0,r.jsx)(k.A,{className:"h-3.5 w-3.5","aria-hidden":!0}):(0,r.jsx)(_.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),b,(0,r.jsx)(z.A,{className:"h-3 w-3 opacity-60","aria-hidden":!0})]})}),(0,r.jsxs)(p.SQ,{align:"end",className:"min-w-[250px]",onClick:e=>e.stopPropagation(),children:[y?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(p._2,{onSelect:l,children:[(0,r.jsx)(_.A,{className:"mr-2 h-3.5 w-3.5","aria-hidden":!0}),(0,r.jsxs)("span",{className:"flex flex-col",children:[(0,r.jsx)("span",{className:"text-[12px] font-medium",children:"Send in review space"}),(0,r.jsx)("span",{className:"text-muted-foreground text-[10px]",children:"Locks the bundle and notifies the client in BTW"})]})]}),(0,r.jsx)(p.mB,{})]}):null,(0,r.jsx)(p._2,{asChild:!0,children:(0,r.jsxs)("a",{href:c,children:[(0,r.jsx)(D.A,{className:"mr-2 h-3.5 w-3.5","aria-hidden":!0}),(0,r.jsxs)("span",{className:"flex flex-col",children:[(0,r.jsx)("span",{className:"text-[12px] font-medium",children:"Email the client"}),(0,r.jsx)("span",{className:"text-muted-foreground text-[10px]",children:d.length>0?"To ".concat(d.join(", ")):"Opens your mail app with the review link"})]})]})}),(0,r.jsx)(p._2,{asChild:!0,children:(0,r.jsxs)("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:[(0,r.jsx)(T.A,{className:"mr-2 h-3.5 w-3.5","aria-hidden":!0}),(0,r.jsxs)("span",{className:"flex flex-col",children:[(0,r.jsx)("span",{className:"text-[12px] font-medium",children:"Share via WhatsApp"}),(0,r.jsx)("span",{className:"text-muted-foreground text-[10px]",children:"Review link as a message"})]})]})}),(0,r.jsxs)(p._2,{onSelect:()=>{navigator.clipboard.writeText(i).then(()=>j.oR.success("Review link copied."),()=>window.prompt("Copy this link:",i))},children:[(0,r.jsx)(E.A,{className:"mr-2 h-3.5 w-3.5","aria-hidden":!0}),"Copy review link"]}),(0,r.jsx)(p.mB,{}),(0,r.jsxs)(p._2,{disabled:!f||x,onSelect:e=>{e.preventDefault(),v()},children:[x?(0,r.jsx)(P.A,{className:"mr-2 h-3.5 w-3.5 animate-spin","aria-hidden":!0}):(0,r.jsx)(R.A,{className:"mr-2 h-3.5 w-3.5","aria-hidden":!0}),(0,r.jsxs)("span",{className:"flex flex-col",children:[(0,r.jsx)("span",{className:"text-[12px] font-medium",children:"Download package (.zip)"}),(0,r.jsx)("span",{className:"text-muted-foreground text-[10px]",children:"Originals, documents, acceptance protocol & manifest"}),f?null:(0,r.jsx)("span",{className:"text-muted-foreground text-[10px]",children:"review"===t.kind?"Review rounds carry no files. Downloads unlock on a final delivery.":"This unlocks once the client has approved the delivery."})]})]})]})]})}function eV(e){let{count:t}=e;return(0,r.jsx)("span",{className:"border-border bg-muted/35 text-muted-foreground flex size-11 shrink-0 items-center justify-center rounded-[var(--rad-3)] border","aria-hidden":!0,
1children:t>0?(0,r.jsx)(q.A,{className:"size-5 fill-current opacity-70"}):(0,r.jsx)(N.A,{className:"size-4 opacity-60"})})}function eG(e){let{assetIds:t,mediaByAsset:a,seenAssetIds:n}=e;return 0===t.length?(0,r.jsx)("p",{className:"border-border text-muted-foreground rounded-lg border border-dashed px-3 py-4 text-[12px]",children:"No assets in this delivery yet â Edit to pick the finals it should carry."}):(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-muted-foreground mb-1.5 text-[11px] font-semibold tracking-wide uppercase",children:"Contents"}),(0,r.jsx)("ul",{className:"grid grid-cols-3 gap-2 sm:grid-cols-4",children:t.map(e=>{var t,s;let l=a[e],i=n.has(e);return(0,r.jsxs)("li",{className:"min-w-0",children:[(0,r.jsxs)("div",{className:"border-border bg-muted/40 relative aspect-square overflow-hidden rounded-lg border",children:[(null==l?void 0:l.kind)==="audio"?(0,r.jsx)(f.l6,{src:l.url,fileName:null!=(t=l.mediaPath)?t:l.name,alt:"Waveform of ".concat(l.name),className:"h-full w-full",showLabel:!1}):(null==l?void 0:l.url)?"video"===l.kind?(0,r.jsx)(h.O,{url:l.url,badgeClassName:"bottom-1 right-1",className:"h-full w-full object-cover"}):(0,r.jsx)(f.qq,{src:l.url,alt:l.name,className:"h-full w-full"}):(0,r.jsx)("span",{className:"flex h-full items-center justify-center",children:(0,r.jsx)(N.A,{className:"text-muted-foreground/50 h-4 w-4","aria-hidden":!0})}),i?(0,r.jsx)($.Y6,{label:"The client has opened this asset.",children:(0,r.jsx)("span",{role:"img","aria-label":"Opened by the client",className:"absolute top-1 left-1 flex h-4 w-4 items-center justify-center rounded-full bg-emerald-500/90 text-white shadow",children:(0,r.jsx)(F.A,{className:"h-2.5 w-2.5","aria-hidden":!0})})}):null]}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 truncate text-[10.5px]",title:null==l?void 0:l.name,children:null!=(s=null==l?void 0:l.name)?s:"Untitled"})]},e)})})]})}function eW(e){var t,a,n;let{delivery:l,projectId:i,organizationId:d,expanded:o,highlighted:c,selected:u,canEdit:m,completeness:p,completenessLoading:x,completenessError:h,seenBy:f,seenAssetIds:v,mediaByAsset:g,onToggle:b,onEdit:y,onSignoff:_,onDelete:w,onChanged:N}=e,k=l.title.toLowerCase().includes("round 01")?"review-round-one":l.title.toLowerCase().includes("round 02")?"review-round-two":null,A=l.delivery_assets.length,S=(0,s.useMemo)(()=>l.delivery_signoffs.filter(e=>"client_acceptance"!==e.kind),[l.delivery_signoffs]),R=(0,s.useMemo)(()=>l.delivery_signoffs.filter(e=>"client_acceptance"===e.kind),[l.delivery_signoffs]),D=S.length,T=(0,s.useMemo)(()=>(0,et.XK)(l.delivery_reviewers,l.delivery_decisions,l.sent_at),[l.delivery_reviewers,l.delivery_decisions,l.sent_at]),E=T.total>0,q=eL(l),F=(0,et.F1)(l.status,A>0,l.kind),M=ez.includes(l.status),[U,$]=(0,s.useState)(null),[K,H]=(0,s.use
1State)(null),[V,G]=(0,s.useState)(!1);async function Y(e){$(e);try{let a=await fetch("/api/projects/".concat(i,"/deliveries/").concat(l.id,"/lifecycle"),{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e})}),r=await a.json().catch(()=>({}));if(!a.ok||!r.ok){var t;j.oR.error(null!=(t=r.error)?t:"Could not update the delivery.");return}j.oR.success(eT[e]),N()}catch(e){j.oR.error("Could not update the delivery.")}finally{$(null),H(null)}}return(0,r.jsxs)("li",{id:"delivery-".concat(l.id),"data-showcase-tour":null!=k?k:void 0,className:(0,ee.cn)("relative scroll-mt-24 overflow-hidden transition-colors",u&&"bg-[var(--app-accent-soft)]/45",c&&"ring-2 ring-[var(--app-accent)]/55 ring-inset"),children:[u?(0,r.jsx)("span",{className:"absolute inset-y-0 left-0 w-0.5 bg-[var(--app-accent)]","aria-hidden":!0}):null,(0,r.jsxs)("div",{"data-showcase-tour":k?"".concat(k,"-summary"):void 0,className:"grid min-h-24 grid-cols-1 items-center gap-x-4 gap-y-3 px-5 py-4 sm:grid-cols-2 xl:grid-cols-[minmax(240px,1.45fr)_120px_minmax(140px,0.8fr)_140px_60px_minmax(170px,1fr)_124px]",children:[(0,r.jsxs)("button",{type:"button",onClick:b,"aria-current":u?"true":void 0,"aria-expanded":o,"aria-controls":"delivery-details-".concat(l.id),className:"group flex min-w-0 items-center gap-3 text-left sm:col-span-2 xl:col-span-1",children:[(0,r.jsx)(eV,{count:A}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("p",{className:"text-foreground line-clamp-2 text-[13px] leading-snug font-semibold tracking-tight transition-colors group-hover:text-[var(--app-accent)]",children:l.title}),(0,r.jsxs)("p",{className:"text-muted-foreground mt-1 text-[10px] leading-relaxed",children:["review"===l.kind?"Review round":"Final delivery",l.ai_use_level?" \xb7 ".concat((0,et.yD)(l.ai_use_level)):""]})]}),(0,r.jsx)(I.A,{className:(0,ee.cn)("text-muted-foreground size-4 shrink-0 transition-transform group-hover:text-[var(--app-accent)] xl:hidden",o&&"rotate-90"),"aria-hidden":!0})]}),(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("p",{className:"text-muted-foreground mb-1.5 text-[9px] font-semibold tracking-[0.14em] uppercase xl:hidden",children:"Status"}),(0,r.jsx)(eQ,{stage:q}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-[10px]",children:"client_review"===q&&"changes_requested"===l.status?"Changes requested":"client_review"===q&&"approved"===l.status?"Approved":"assets_ready"===q?"Ready for review":"draft"===q?"Setup in progress":"Handoff complete"})]}),(0,r.jsxs)("div",{className:"min-w-0 text-[11px]",children:[(0,r.jsx)("p",{className:"text-muted-foreground mb-1.5 text-[9px] font-semibold tracking-[0.14em] uppercase xl:hidden",children:"Client"}),(0,r.jsx)("p",{className:"text-foreground line-clamp-2 font-medium",children:null!=(t=l.client_name)?t:"No client yet"}),E?(0,r.jsxs)("p",{className:"text-muted-foreground mt-1 text-[10px]",children:[T.decided,"/",T.total," decided"]}):null]}),(0,r.jsxs)("div",{className:"min-w-0 text-[11px]",children:[(0,r.jsx)("p",{className:"text-muted-foreground mb-1.5 text-[9px] font-semibold tracking-[0.14em] uppercase xl:hidden",children:"Delivery deadline"}),(0,r.jsx)("p",{className:"font-semibold text-[var(--app-accent)]",children:null!=(a=eO(l.delivery_date))?a:"Set deadline"}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-[10px]",children:null!=(n=eM(l.delivery_date))?n:"Not scheduled"})]}),(0,r.jsxs)("div",{className:"min-w-0 text-[11px]",children:[(0,r.jsx)("p",{className:"text-muted-foreground mb-1.5 text-[9px] font-semibold tracking-[0.14em] uppercase xl:hidden",children:"Assets"}),(0,r.jsx)("p",{className:"text-foreground font-medium tabular-nums",children:A})]}),(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("p",{className:"text-muted-foreground mb-1.5 text-[9px] font-semibold tracking-[0.14em] uppercase xl:hidden",children:"Next step"}),(0,r.jsx)("p",{className:"text-muted-foreground line-clamp-2 text-[10.5px] leading-relaxed",children:"delivered"===l.status?"Delivery complete.":"approved"===l.status?"Prepare the final handoff.":"changes_requested"===l.status?"Address client feedback and finalize.":"in_review"===l.status?"Await the client decision.":l.delivery_assets.length>0?"Finalize assets for client review.":"Add assets and set delivery details."})]}),(0,r.jsxs)(B.$,{type:"button",size:"sm",variant:o?"default":"outline",className:"h-9 w-full justify-between gap-2 px-3 text-[11px]",onClick:b,"aria-expanded":o,"aria-controls":"delivery-details-".concat(l.id),children:[o?"Hide details":"View details",o?(0,r.jsx)(z.A,{className:"size-3.5","aria-hidden":!0}):(0,r.jsx)(I.A,{className:"size-3.5","aria-hidden":!0})]})]}),o?(0,r.jsxs)("div",{id:"delivery-details-".concat(l.id),className:"border-border bg-background/70 border-t px-5 pt-5 pb-6",children:[(0,r.jsxs)("div",{className:"mb-5 flex flex-col gap-4 2xl:flex-row 2xl:items-start 2xl:justify-between",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("h3",{className:"text-foreground text-sm font-semibold tracking-tight",children:"Delivery details"}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 max-w-2xl text-[11px] leading-relaxed",children:"Review what will be handed off, its approval status, and the complete record of what happened."})]}),m?(0,r.jsxs)("div",{className:"flex flex-wrap gap-2 2xl:max-w-[70%] 2xl:justify-end",children:[F.filter(e=>"send_for_review"!==e.action).map(e=>{let t=eD[e.action],a=U===e.action;return(0,r.jsxs)(B.$,{type:"button",size:"sm",variant:"outline",className:"h-7 gap-1.5 text-xs",onClick:()=>(function(e){if(!e.disabled&&!U){if("send_for_review"===e.action)return void G(!0);e.confirm?H(e.action):Y(e.action)}})(e),disabled:e.disabled||null!==U,children:[a?(0,r.jsx)(P.A,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):(0,r.jsx)(t,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.label]},e.action)}),(0,r.jsx)(eH,{delivery:l,projectId:i,canEdit:m,onSendReview:()=>G(!0)}),(0,r.jsxs)(B.$,{type:"button",size:"sm",variant:"outline",className:"h-7 gap-1.5 text-xs",onClick:y,children:[(0,r.jsx)(C.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Edit"]}),(0,r.jsxs)(B.$,{type:"button",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:_,disabled:0===A,children:[(0,r.jsx)(L.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Sign off this delivery"]}),(0,r.jsxs)(B.$,{type:"button",size:"sm",variant:"outline",className:"border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive h-7 gap-1.5 text-xs disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent",onClick:w,disabled:M,children:[(0,r.jsx)(O.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Delete"]})]}):null,m&&(0===A||M)?(0,r.jsxs)("div",{className:"text-muted-foreground flex flex-col gap-1 text-[11px] leading-relaxed 2xl:items-end 2xl:text-right",children:[0===A?(0,r.jsx)("p",{children:"Sending for review and signing off stay
1switched off until this delivery holds at least one asset."}):null,M?(0,r.jsx)("p",{children:"This delivery holds a binding client acceptance, so it cannot be deleted. Reopen it first, which visibly voids that acceptance for everyone."}):null]}):null]}),(0,r.jsxs)("div",{className:"grid items-start gap-5 xl:grid-cols-[minmax(0,1.2fr)_minmax(360px,0.8fr)]",children:[(0,r.jsxs)("section",{"aria-label":"Delivery package",className:"border-border bg-card min-w-0 space-y-4 rounded-[var(--rad-4)] border p-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-foreground text-xs font-semibold",children:"Package"}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-[10.5px] leading-relaxed",children:"The assets and documents that will travel with this handoff."})]}),(0,r.jsx)(eG,{assetIds:l.delivery_assets.map(e=>e.asset_id),mediaByAsset:g,seenAssetIds:v}),(0,r.jsx)(eg,{delivery:{id:l.id,status:l.status,project_id:i},documents:l.delivery_documents,organizationId:d,canEdit:m,onChanged:N})]}),(0,r.jsxs)("section",{"aria-label":"Delivery review status",className:"border-border bg-card min-w-0 space-y-4 rounded-[var(--rad-4)] border p-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-foreground text-xs font-semibold",children:"Review status"}),(0,r.jsx)("p",{className:"text-muted-foreground mt-1 text-[10.5px] leading-relaxed",children:"Readiness, client decisions, views, and sign-offs at a glance."})]}),(0,r.jsx)(e5,{completeness:p,loading:x,error:h}),E?(0,r.jsx)(e1,{reviewers:l.delivery_reviewers,decisions:l.delivery_decisions,sentAt:l.sent_at,decided:T.decided,total:T.total}):null,(0,r.jsx)(e0,{seenBy:f,assetCount:A,seenAssetCount:l.delivery_assets.filter(e=>v.has(e.asset_id)).length}),"final"===l.kind&&R.length>0?(0,r.jsx)(e4,{projectId:i,acceptances:R,events:l.delivery_events,receipts:l.delivery_download_receipts}):null,"review"===l.kind&&l.delivery_events.length>0?(0,r.jsx)(e6,{events:l.delivery_events,tourId:k?"".concat(k,"-decision"):void 0}):null,D>0?(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-muted-foreground mb-1.5 text-[11px] font-semibold tracking-wide uppercase",children:"Sign-offs"}),(0,r.jsx)("ul",{className:"space-y-1.5",children:S.map(e=>(0,r.jsx)(e2,{signoff:e},e.id))})]}):(0,r.jsxs)("p",{className:"text-muted-foreground text-[12px] leading-relaxed",children:["No sign-offs yet.",0===A?" Add at least one asset before this delivery can be signed off.":""]})]})]}),(0,r.jsx)(eS,{projectId:i,deliveryId:l.id,deliveryTitle:l.title,clientName:l.client_name,tourId:k?"".concat(k,"-history"):void 0})]}):null,(0,r.jsx)(W.T,{open:null!==K,onOpenChange:e=>{e||H(null)},title:"Reopen this delivery?",description:"review"===l.kind?"The client's \"looks good\" no longer applies to the reworked version â they'll need to look again.":"The client's acceptance no longer applies to the reworked version â they will need to approve again.",confirmLabel:"Reopen",variant:"destructive",busy:null!==U,onConfirm:()=>{K&&Y(K)}}),(0,r.jsx)(eo,{open:V,onOpenChange:G,projectId:i,organizationId:d,deliveryId:l.id,deliveryTitle:l.title,deliveryKind:l.kind,initialPolicy:l.decision_policy,sending:"send_for_review"===U,onConfirmSend:()=>Y("send_for_review")})]})}let eY={neutral:"border-border bg-muted text-muted-foreground",amber:"border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300",green:"border-emerald-600/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",quiet:"border-transparent bg-transparent text-muted-foreground/70",info:"border-sky-500/40 bg-sky-500/10 text-sky-700 dark:text-sky-300"},eJ={draft:"border-border bg-muted text-muted-foreground",assets_ready:"border-emerald-600/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",client_review:"border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-300",delivered:"border-sky-500/35 bg-sky-500/10 text-sky-700 dark:text-sky-300"};function eQ(e){var t,a;let{stage:n}=e,s=null!=(a=null==(t=eF.find(e=>e.stage===n))?void 0:t.label)?a:n;return(0,r.jsxs)("span",{className:(0,ee.cn)("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-[10px] font-medium",eJ[n]),children:[(0,r.jsx)("span",{className:"size-1.5 rounded-full bg-current opacity-70","aria-hidden":!0}),s]})}function eZ(e){let{meta:t}=e;return(0,r.jsx)("span",{className:(0,ee.cn)("inline-flex shrink-0 items-center rounded-full border px-2 py-0.5 text-[10px] font-medium",eY[t.tone]),children:t.label})}function eX(e){let{meta:t}=e;return(0,r.jsx)(eZ,{meta:t})}function e0(e){let{seenBy:t,assetCount:a,seenAssetCount:n}=e;return 0===t.length&&0===n?null:(0,r.jsxs)("div",{className:"text-muted-foreground mb-3 space-y-1 text-[11px]",children:[t.map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(F.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),"Seen by ",(0,r.jsx)("span",{className:"text-foreground font-medium",children:e.label})," \xb7 ",(0,et.ic)(e.lastSeenAt)]}
1,e.userId)),n>0?(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(F.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),n," of ",a," asset",1===a?"":"s"," ","opened by a client"]}):null]})}function e1(e){let{reviewers:t,decisions:a,sentAt:n,decided:s,total:l}=e,i=(0,et.Hy)(t,a,n);return(0,r.jsxs)("div",{className:"mb-3",children:[(0,r.jsxs)("div",{className:"text-muted-foreground mb-1.5 flex flex-wrap items-center gap-2 text-[11px] font-semibold tracking-wide uppercase",children:["Client decisions",(0,r.jsxs)("span",{className:"border-border bg-muted text-muted-foreground rounded-full border px-1.5 py-0.5 text-[10px] font-medium tracking-normal normal-case",children:[s," of ",l," decided"]})]}),(0,r.jsx)("ul",{className:"space-y-1.5",children:i.map(e=>{let{reviewer:t,decisionType:a}=e;return(0,r.jsxs)("li",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-foreground truncate text-[12px]",children:t.display_name||t.email||"Reviewer"}),(0,r.jsx)(eZ,{meta:(0,et.Gd)(a)})]},t.id)})})]})}function e5(e){let{completeness:t,loading:a,error:n}=e,[l,i]=(0,s.useState)(!1);if(a)return(0,r.jsxs)("div",{className:"text-muted-foreground mb-3 flex items-center gap-2 text-[11px]",children:[(0,r.jsx)(P.A,{className:"h-3 w-3 animate-spin","aria-hidden":!0}),"Checking documentation completenessâ¦"]});if(n)return(0,r.jsx)("p",{className:"text-muted-foreground mb-3 text-[11px] leading-relaxed",children:"Couldn't check documentation completeness for this delivery."});if(!t||0===t.totalCount)return null;let{readyCount:d,totalCount:o,gapsByAsset:c}=t,u=d===o,m=Math.round(d/o*100);return(0,r.jsxs)("div",{className:"mb-3",children:[(0,r.jsxs)("div",{className:"mb-1 flex items-center justify-between gap-2 text-[11px]",children:[(0,r.jsxs)("span",{className:"text-foreground font-medium",children:[d," of ",o," asset",1===o?"":"s"," ","compliance-ready"]}),c.length>0?(0,r.jsx)("button",{type:"button",onClick:()=>i(e=>!e),className:"text-foreground/70 hover:text-foreground shrink-0 font-medium transition-colors",children:l?"Hide gaps":"Show gaps"}):null]}),(0,r.jsx)("div",{role:"progressbar","aria-valuemin":0,"aria-valuemax":o,"aria-valuenow":d,"aria-label":"Documentation completeness",className:"bg-muted h-1.5 w-full overflow-hidden rounded-full",children:(0,r.jsx)("div",{className:(0,ee.cn)("h-full rounded-full transition-[width] duration-300",u?"bg-emerald-500":"bg-amber-400"),style:{width:"".concat(m,"%")}})}),l&&c.length>0?(0,r.jsx)("ul",{className:"mt-2 space-y-1",children:c.map(e=>(0,r.jsxs)("li",{className:"text-muted-foreground text-[11px] leading-relaxed",children:[(0,r.jsx)("span",{className:"text-foreground font-medium",children:e.assetName}),": ",e.missing.map(e=>e.label).join(", ")]},e.assetId))}):null]})}function e2(e){var t;let{signoff:a}=e,[n,l]=(0,s.useState)(!1),i=a.statement.length>140;return(0,r.jsxs)("li",{className:"border-border bg-background/60 rounded-md border px-3 py-2",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-[12px]",children:[(0,r.jsx)("span",{className:"text-foreground font-medium",children:a.signed_name}),a.signed_role?(0,r.jsxs)("span",{className:"text-muted-foreground",children:["\xb7 ",a.signed_role]}):null,(0,r.jsxs)("span",{className:"text-muted-foreground",children:["\xb7 ",null!=(t=(0,Z.x)(a.signed_at))?t:a.signed_at]})]}),(0,r.jsx)("p",{className:(0,ee.cn)("text-muted-foreground mt-1 text-[12px] leading-relaxed",i&&!n&&"line-clamp-2"),children:a.statement}),i?(0,r.jsx)("button",{type:"button",onClick:()=>l(e=>!e),className:"text-foreground/70 hover:text-foreground mt-1 text-[11px] font-medium transition-colors",children:n?"Show less":"Show more"}):null]})}function e3(e){let{projectId:t,signoff:n}=e,[l,i]=(0,s.useState)(!1);async function c(){if(!l){i(!0);try{var e,r;let s=(0,d.createClient)(),[{data:l},i]=await Promise.all([s.from("projects").select("name, organization_id").eq("id",t).maybeSingle(),Promise.all([a.e(54792),a.e(88247),a.e(41278),a.e(99788),a.e(35363),a.e(26642),a.e(33449)]).then(a.bind(a,12712))]),c="";if(null==l?void 0:l.organization_id){let{data:t}=await s.from("organizations").select("name").eq("id",l.organization_id).maybeSingle();c=null!=(e=null==t?void 0:t.name)?e:""}let u=i.buildAcceptanceProtocolModel({orgName:c||"â",projectName:null!=(r=null==l?void 0:l.name)?r:"â",signoff:{signed_name:n.signed_name,signed_email:n.signed_email,signed_at:n.signed_at,statement:n.statement,snapshot:n.snapshot}}),m=await i.renderAcceptanceProtocolPdf(u),p=u.deliveryTitle.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||"delivery";(0,o.IV)(m,"acceptance-protocol-".concat(p,".pdf"))}catch(e){j.oR.error("Couldn't generate the acceptance protocol",{description:e instanceof Error?e.message:"Please try again in a moment."})}finally{i(!1)}}}return(0,r.jsx)("button",{type:"button",onClick:()=>void c(),disabled:l,className:"mt-1.5 text-[12px] font-medium text-emerald-800 underline underline-offset-2 transition hover:text-emerald-950 disabled:cursor-not-allowed disabled:opacity-50 dark:text-emerald-300 dark:hover:text-emerald-200",children:l?"Generating protocolâ¦":"Download acceptance protocol (PDF)"})}function e4(e){let{projectId:t,acceptances:a,events:n,receipts:l}=e,i=(0,s.useMemo)(()=>{let e=new Map;for(let n of a){var t,r;for(let a of null!=(r=null==(t=n.snapshot)?void 0:t.assets)?r:[])e.set(a.asset_id,a.name)}return e},[a]);return(0,r.jsxs)("div",{className:"mb-3 rounded-lg border border-emerald-600/30 bg-emerald-500/[0.06] px-3 py-2.5",children:[(0,r.jsxs)("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold tracking-wide text-emerald-700 uppercase dark:text-emerald-300",children:[(0,r.jsx)(k.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Client acceptance"]}),(0,r.jsx)("ul",{className:"space-y-2.5",children:a.map(e=>{var a;return(0,r.jsxs)("li",{children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-[12px]",children:[(0,r.jsx)("span",{className:"text-foreground font-medium",children:e.signed_name}),e.signed_email?(0,r.jsxs)("span",{className:"text-muted-foreground",children:["\xb7 ",e.signed_email]}):null,(0,r.jsxs)("span",{className:"text-muted-foreground",children:["\xb7 ",null!=(a=(0,Z.x)(e.signed_at))?a:e.signed_at]})]}),(0,r.jsx)("blockquote",{className:"text-muted-foreground mt-1 border-l-2 border-emerald-600/30 pl-2.5 text-[12px] leading-relaxed italic",children:e.statement}),(0,r.jsx)(e3,{projectId:t,signoff:e})]},e.id)})}),n.length>0?(0,r.jsxs)("div",{className:"mt-2.5 border-t border-emerald-600/20 pt-2",children:[(0,r.jsx)("div",{className:"text-muted-foreground mb-1 text-[10px] font-semibold tracking-wide uppercase",children:"History"}),(0,r.jsx)("ul",{className:"space-y-1",children:n.map((e,t)=>{var a,n;return(0,r.jsxs)("li",{className:"text-muted-foreground text-[11px] leading-relaxed",children:[(0,r.jsx)("span",{className:"text-foreground font-medium",children:e.actor_name})," \xb7 ",null!=(a=eE[e.kind])?a:e.kind," \xb7 ",null!=(n=(0,Z.x)(e.created_at))?n:e.created_at,"changes_requested"===e.kind&&e.note?(0,r.jsxs)("span",{className:"text-muted-foreground
1/90 block italic",children:["â",e.note,"â"]}):null]},t)})})]}):null,l.length>0?(0,r.jsxs)("div",{className:"mt-2.5 border-t border-emerald-600/20 pt-2",children:[(0,r.jsx)("div",{className:"text-muted-foreground mb-1 text-[10px] font-semibold tracking-wide uppercase",children:"Downloads"}),(0,r.jsx)("ul",{className:"space-y-1",children:l.map((e,t)=>{var a,n;let s=null!=(a=i.get(e.asset_id))?a:e.asset_id;return(0,r.jsxs)("li",{className:"text-muted-foreground text-[11px] leading-relaxed",children:[(0,r.jsx)("span",{className:"text-foreground font-medium",children:e.downloaded_name})," ","downloaded ",s," \xb7 ",null!=(n=(0,Z.x)(e.created_at))?n:e.created_at]},t)})})]}):null]})}function e6(e){let{events:t,tourId:a}=e;return(0,r.jsxs)("div",{"data-showcase-tour":a,className:"mb-3 rounded-lg border border-sky-500/25 bg-sky-500/[0.05] px-3 py-2.5",children:[(0,r.jsx)("div",{className:"mb-2 text-[11px] font-semibold tracking-wide text-sky-700 uppercase dark:text-sky-300",children:"Review history"}),(0,r.jsx)("ul",{className:"space-y-1",children:t.map((e,t)=>{var a,n;return(0,r.jsxs)("li",{className:"text-muted-foreground text-[11px] leading-relaxed",children:[(0,r.jsx)("span",{className:"text-foreground font-medium",children:e.actor_name})," \xb7 ",null!=(a=eE[e.kind])?a:e.kind," \xb7 ",null!=(n=(0,Z.x)(e.created_at))?n:e.created_at,"changes_requested"===e.kind&&e.note?(0,r.jsxs)("span",{className:"text-muted-foreground/90 block italic",children:["â",e.note,"â"]}):null]},t)})})]})}function e9(e){let{open:t,onOpenChange:a,projectId:l,organizationId:i,editing:o,onSaved:c,initialKind:u="final",preselectedAssetIds:m}=e,{data:p}
1=(0,J.i)(),[x,h]=(0,s.useState)(""),[f,v]=(0,s.useState)(""),[b,y]=(0,s.useState)(""),_=(0,s.useRef)(null),[w,N]=(0,s.useState)(null),[k,C]=(0,s.useState)("final"),[A,S]=(0,s.useState)(!1),[I,R]=(0,s.useState)(""),[z,D]=(0,s.useState)(new Set),[T,E]=(0,s.useState)([]),[q,F]=(0,s.useState)(!1),[L,O]=(0,s.useState)(!1),[$,V]=(0,s.useState)(""),[W,Y]=(0,s.useState)(!1),Q=(0,s.useRef)([]),Z=!!(o&&!eI.includes(o.status)),X=(0,s.useRef)(0),ea=(0,s.useCallback)(async()=>{let e=++X.current;F(!0),O(!1);let t=(0,d.createClient)(),{data:a,error:r}=await t.from("assets").select("id, name, version, verdict, approved_for_share").eq("project_id",l).is("archived_at",null);X.current===e&&(O(!!r),E(r?[]:null!=a?a:[]),F(!1))},[l]);(0,s.useEffect)(()=>{var e,a,r,n,s,l,i,d,c;if(!t)return;h(null!=(e=null==o?void 0:o.title)?e:""),v(null!=(a=null==o?void 0:o.client_name)?a:""),y(null!=(r=null==o?void 0:o.delivery_date)?r:""),N(null!=(n=null==o?void 0:o.ai_use_level)?n:null),C(null!=(s=null==o?void 0:o.kind)?s:u),S(null!=(l=null==o?void 0:o.watermark_enabled)&&l),R(null!=(i=null==o?void 0:o.watermark_text)?i:"");let p=null!=(c=null!=(d=null==o?void 0:o.delivery_assets.map(e=>e.asset_id))?d:m)?c:[];Q.current=p,D(new Set(p)),V(""),ea()},[t,o,l,ea]);let er=(0,s.useMemo)(()=>{let e=$.trim().toLowerCase();return e?T.filter(t=>t.name.toLowerCase().includes(e)):T},[T,$]),{finals:en,other:es}=(0,s.useMemo)(()=>(0,et.Px)(er),[er]),el=0===en.length&&""===$.trim();function ei(e){D(t=>{let a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})}async function ed(){if(Z)return void j.oR.error(eR);let e=x.trim();if(!e)return void j.oR.error("A title is required.");if(!o&&!i)return void j.oR.error("Project is still loading â try again in a moment.");Y(!0);try{var t,r;let s=(0,d.createClient)(),u=Array.from(z),m={title:e,client_name:f.trim()||null,delivery_date:(0,et._p)(b,null==(t=_.current)?void 0:t.value),ai_use_level:w,kind:k,watermark_enabled:A,watermark_text:A&&I.trim().slice(0,80)||null};if(o){let{error:e}=await s.from("deliveries").update(m).eq("id",o.id);if(e)throw e;let{toAdd:t,toRemove:r}=(0,et.aK)(Q.current,u),n=!1;if(r.length){let{error:e}=await s.from("delivery_assets").delete().eq("delivery_id",o.id).in("asset_id",r);e&&(n=!0)}if(!n&&t.length){let{error:e}=await s.from("delivery_assets").insert(t.map(e=>({delivery_id:o.id,asset_id:e})));e&&(n=!0)}if(n){c(),a(!1),j.oR.error("Delivery details were saved, but the asset list could not be fully updated â reopen it to check the selection.");return}j.oR.success("Delivery updated")}else{let{data:e,error:t}=await s.from("deliveries").insert({...m,organization_id:i,project_id:l,created_by:null!=(r=null==p?void 0:p.id)?r:null}).select("id").single();if(t)throw t;let d=e.id;if(u.length){let{error:e}=await s.from("delivery_assets").insert(u.map(e=>({delivery_id:d,asset_id:e})));if(e){let{error:t}=await s.from("deliveries").delete().eq("id",d);if(t){c(),a(!1),j.oR.error("Delivery was created but assets could not be attached â edit it to fix the selection.");return}throw e}}(0,n.Fg)("delivery_created",{project_id:l,delivery_id:d,source:"deliveries"}),j.oR.success("review"===k?"Review round created":"Delivery created")}c(),a(!1)}catch(e){j.oR.error(e instanceof Error?e.message:"Could not save the delivery.")}finally{Y(!1)}}return(0,r.jsx)(G.lG,{open:t,onOpenChange:e=>{W||a(e)},children:(0,r.jsxs)(G.Cf,{zones:!0,className:"sm:max-w-lg",hideClose:W,children:[(0,r.jsxs)(G.c7,{children:[(0,r.jsxs)(G.L3,{className:"flex items-center gap-2",children:[o?"Edit delivery":"review"===k?"New review round":"New delivery",(0,r.jsx)(eX,{meta:(0,et.S1)(k)})]}),(0,r.jsx)(G.rr,{children:"review"===k?"A light, non-binding round â the client can say it looks good or request changes. No ceremony, no download gate.":"Name the bundle, declare how much AI shaped it, and pick the finals it contains."})]}),(0,r.jsxs)(G.R4,{className:"space-y-4",children:[Z?(0,r.jsxs)("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2.5 text-[12px] leading-relaxed text-amber-900 dark:text-amber-200",children:[(0,r.jsx)(M.A,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}),(0,r.jsx)("span",{children:eR})]}):null,(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsxs)("label",{htmlFor:"delivery-title",className:"text-foreground block text-[12px] font-medium",children:["Title ",(0,r.jsx)("span",{className:"text-destructive",children:"*"})]}),(0,r.jsx)(K.p,{id:"delivery-title",value:x,onChange:e=>h(e.target.value),placeholder:"e.g. Season 2 key art â final delivery",disabled:W||Z,autoFocus:!0})]}),(0,r.jsxs)("fieldset",{className:"space-y-2",disabled:W||Z,children:[(0,r.jsx)("legend",{className:"text-foreground mb-0.5 block text-[12px] font-medium",children:"Kind"}),eq.map(e=>{let t=k===e.value;return(0,r.jsxs)("label",{className:(0,ee.cn)("has-[:focus-visible]:ring-ring block cursor-pointer rounded-lg border p-2.5 transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-offset-1",t?"border-foreground
1/60 bg-muted/40":"border-border hover:bg-muted/20",(W||Z)&&"opacity-60"),children:[(0,r.jsx)("input",{type:"radio",name:"delivery-kind",value:e.value,checked:t,onChange:()=>C(e.value),className:"sr-only"}),(0,r.jsxs)("span",{className:"text-foreground flex items-center gap-2 text-[13px] font-medium",children:[e.label,(0,r.jsx)(eX,{meta:(0,et.S1)(e.value)})]}),(0,r.jsx)("span",{className:"text-muted-foreground mt-0.5 block text-[12px] leading-relaxed",children:e.description})]},e.value)}),o?(0,r.jsx)("p",{className:"text-muted-foreground text-[11px] leading-relaxed",children:"Changing the kind changes what the client is asked to do â it's locked once the delivery is out for review."}):null]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{htmlFor:"delivery-client",className:"text-foreground block text-[12px] font-medium",children:"Client"}),(0,r.jsx)(K.p,{id:"delivery-client",value:f,onChange:e=>v(e.target.value),placeholder:"e.g. ZDF",disabled:W||Z})]}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{htmlFor:"delivery-date",className:"text-foreground block text-[12px] font-medium",children:"Delivery deadline"}),(0,r.jsx)(K.p,{id:"delivery-date",ref:_,type:"date",value:b,onChange:e=>y(e.target.value),disabled:W||Z}),(0,r.jsx)("p",{className:"text-muted-foreground text-[11px] leading-relaxed",children:"The client handoff date. It appears in Calendar and anchors linked Production plan tasks."})]})]}),(0,r.jsxs)("fieldset",{className:"space-y-2",disabled:W||Z,children:[(0,r.jsx)("legend",{className:"text-foreground mb-0.5 block text-[12px] font-medium",children:"AI-use level"}),et.VZ.map(e=>{let t=w===e.value;return(0,r.jsxs)("label",{className:(0,ee.cn)("has-[:focus-visible]:ring-ring block cursor-pointer rounded-lg border p-2.5 transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-offset-1",t?"border-foreground
1/60 bg-muted/40":"border-border hover:bg-muted/20",(W||Z)&&"opacity-60"),children:[(0,r.jsx)("input",{type:"radio",name:"delivery-ai-use-level",value:e.value,checked:t,onChange:()=>N(e.value),className:"sr-only"}),(0,r.jsx)("span",{className:"text-foreground block text-[13px] font-medium",children:e.label}),(0,r.jsx)("span",{className:"text-muted-foreground mt-0.5 block text-[12px] leading-relaxed",children:e.description})]},e.value)})]}),(0,r.jsxs)("div",{className:(0,ee.cn)("border-border space-y-2 border-t pt-4",Z&&"opacity-60"),children:[(0,r.jsxs)("div",{className:"flex items-baseline justify-between gap-2",children:[(0,r.jsx)("p",{className:"text-foreground text-[12px] font-medium",children:"Visible watermark"}),(0,r.jsx)("p",{className:"text-muted-foreground text-[11px]",children:"Client review only"})]}),(0,r.jsxs)("label",{htmlFor:"delivery-watermark-enabled",className:"border-border bg-background flex cursor-pointer items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[(0,r.jsxs)("span",{className:"flex flex-col",children:[(0,r.jsx)("span",{className:"text-foreground text-[13px] font-medium",children:"Show a watermark on previews"}),(0,r.jsx)("span",{className:"text-muted-foreground text-[11px] leading-relaxed",children:"Tiles a faint diagonal label across every preview in the client's review space. The original files are never changed."})]}),(0,r.jsx)(H.d,{id:"delivery-watermark-enabled",checked:A,onCheckedChange:S,disabled:W||Z,"aria-label":"Show a watermark on client previews"})]}),A?(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsxs)("label",{htmlFor:"delivery-watermark-text",className:"text-foreground block text-[12px] font-medium",children:["Watermark text"," ",(0,r.jsx)("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),(0,r.jsx)(K.p,{id:"delivery-watermark-text",value:I,onChange:e=>R(e.target.value),placeholder:"Leave blank to use the project name",maxLength:80,disabled:W||Z}),(0,r.jsx)("p",{className:"text-muted-foreground text-[11px]",children:"Up to 80 characters. Blank falls back to the project name."})]}):null]}),(0,r.jsxs)("fieldset",{className:(0,ee.cn)("space-y-1.5",Z&&"opacity-60"),disabled:W||Z,children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-foreground text-[12px] font-medium",children:"Select finals to deliver"}),(0,r.jsxs)("span",{className:"text-muted-foreground text-[11px]",children:[z.size," selected"]})]}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(U.A,{className:"text-muted-foreground pointer-events-none absolute top-1/2 left-2.5 h-3.5 w-3.5 -translate-y-1/2","aria-hidden":!0}),(0,r.jsx)(K.p,{value:$,onChange:e=>V(e.target.value),placeholder:"Search assetsâ¦",disabled:W||Z,className:"h-8 pl-8 text-xs"})]}),(0,r.jsx)("div",{className:"border-border max-h-56 overflow-y-auto rounded-lg border",children:q?(0,r.jsxs)("div",{className:"text-muted-foreground flex items-center gap-2 px-3 py-6 text-xs",children:[(0,r.jsx)(P.A,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}),"Loading assetsâ¦"]}):L?(0,r.jsxs)("div",{className:"flex flex-col items-center gap-2 px-3 py-6 text-center",children:[(0,r.jsx)("p",{className:"text-destructive text-[12px] leading-relaxed",children:"Couldn't load this project's assets."}),(0,r.jsx)(B.$,{type:"button",size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>void ea(),children:"Retry"})]}):0===er.length?(0,r.jsx)("div",{className:"text-muted-foreground px-3 py-6 text-center text-xs",children:0===T.length?"This project has no assets yet.":"No assets match your search."}):(0,r.jsxs)(r.Fragment,{children:[en.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e7,{label:"Finals"}),(0,r.jsx)(e8,{items:en,selected:z,onToggle:ei,disabled:W||Z})]}):el?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e7,{label:"Finals"}),(0,r.jsxs)("p",{className:"text-muted-foreground px-3 py-2.5 text-[11px] leading-relaxed",children:["No finals yet â"," ",(0,r.jsx)(g(),{href:"/dashboard/".concat(l,"/finals"),className:"hover:text-foreground underline underline-offset-2",children:"mark an asset Final"})," ","to see it here."]})]}):null,es.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e7,{label:"Other assets"}),(0,r.jsx)(e8,{items:es,selected:z,onToggle:ei,disabled:W||Z})]}):null]})})]})]}),(0,r.jsxs)(G.Es,{children:[(0,r.jsx)(B.$,{type:"button",variant:"outline",onClick:()=>a(!1),disabled:W,children:"Cancel"}),(0,r.jsxs)(B.$,{type:"button",onClick:()=>void ed(),disabled:W||Z||!x.trim(),className:"gap-2",children:[W?(0,r.jsx)(P.A,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):null,o?"Save changes":"Save draft"]})]})]})})}function e7(e){let{label:t}=e;return(0,r.jsx)("div",{className:"bg-muted/30 text-muted-foreground px-3 py-1 text-[10px] font-semibold tracking-[0.1em] uppercase",children:t})}function e8(e){let{items:t,selected:a,onToggle:n,disabled:s}=e;return(0,r.jsx)("ul",{className:"divide-border divide-y",children:t.map(e=>{let t=a.has(e.id);return(0,r.jsx)("li",{children:(0,r.jsxs)("label",{className:"hover:bg-muted/30 flex cursor-pointer items-center gap-2.5 px-3 py-2 transition-colors",children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:()=>n(e.id),disabled:s,className:"h-3.5 w-3.5 shrink-0 accent-[var(--app-accent)]"}),(0,r.jsx)("span",{className:"text-foreground min-w-0 flex-1 truncate text-[12px]",children:e.name}),(0,r.jsx)("span",{className:"text-muted-foreground shrink-0 text-[11px]",children:e.version}),e.verdict?(0,r.jsx)("span",{className:(0,ee.cn)("shrink-0 rounded-full border px-1.5 py-0.5 text-[10px] font-medium capitalize",(0,et.lb)(e.verdict)?"border-emerald-600/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":"border-border bg-muted text-muted-foreground"),children:e.verdict}):null]})},e.id)})})}
1function te(e){let{completeness:t}=e;if(!t)return null;let a=t.totalCount-t.readyCount;return a<=0?null:(0,r.jsxs)("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2.5 text-[12px] leading-relaxed text-amber-900 dark:text-amber-200",children:[(0,r.jsx)(M.A,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}),(0,r.jsxs)("span",{children:[a," of ",t.totalCount," asset",1===t.totalCount?"":"s"," in this delivery"," ",1===a?"has":"have"," documentation gaps (e.g. missing tool, disclosure status, or rights evidence). You can still sign off â this is advisory, not a requirement."]})]})}function tt(e){let{delivery:t,completeness:a,onOpenChange:n,onSigned:l}=e,i=!!t,[o,c]=(0,s.useState)(eP),[u,m]=(0,s.useState)(""),[p,x]=(0,s.useState)(!1);async function h(){if(!t)return;let e=o.trim();if(!e)return void j.oR.error("The attestation statement can't be empty.");x(!0);try{let a=(0,d.createClient)(),{error:r}=await a.rpc("create_delivery_signoff",{p_delivery_id:t.id,p_role:u.trim()||null,p_statement:e});if(r)throw r;j.oR.success("Delivery signed off"),l(),n(!1)}catch(e){j.oR.error(e instanceof Error?e.message:"Could not record the sign-off.")}finally{x(!1)}}return(0,s.useEffect)(()=>{i&&(c(eP),m(""))},[i]),(0,r.jsx)(G.lG,{open:i,onOpenChange:e=>{p||n(e)},children:(0,r.jsxs)(G.Cf,{zones:!0,className:"sm:max-w-lg",hideClose:p,children:[(0,r.jsxs)(G.c7,{children:[(0,r.jsx)(G.L3,{children:"Sign off this delivery"}),(0,r.jsx)(G.rr,{children:t?(0,r.jsxs)(r.Fragment,{children:["A named attestation against"," ",(0,r.jsx)("strong",{className:"text-foreground",children:t.title}),"."]}):null})]}),(0,r.jsxs)(G.R4,{className:"space-y-4",children:[(0,r.jsx)(te,{completeness:a}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{htmlFor:"signoff-statement",className:"text-foreground block text-[12px] font-medium",children:"Attestation"}),(0,r.jsx)(V.T,{id:"signoff-statement",value:o,onChange:e=>c(e.target.value),disabled:p,rows:4})]}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsxs)("label",{htmlFor:"signoff-role",className:"text-foreground block text-[12px] font-medium",children:["Your role"," ",(0,r.jsx)("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),(0,r.jsx)(K.p,{id:"signoff-role",value:u,onChange:e=>m(e.target.value),placeholder:"e.g. Editorial lead",disabled:p})]}),(0,r.jsx)("p",{className:"border-border bg-muted/30 text-muted-foreground rounded-lg border px-3 py-2.5 text-[12px] leading-relaxed",children:"Your name and the current time are recorded permanently. Sign-offs can't be edited or removed â several people may sign the same delivery."})]}),(0,r.jsxs)(G.Es,{children:[(0,r.jsx)(B.$,{type:"button",variant:"outline",onClick:()=>n(!1),disabled:p,children:"Cancel"}),(0,r.jsxs)(B.$,{type:"button",onClick:()=>void h(),disabled:p||!o.trim(),className:"gap-2",children:[p?(0,r.jsx)(P.A,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):(0,r.jsx)(L.A,{className:"h-4 w-4","aria-hidden":!0}),"Sign off"]})]})]})})}},35836:(e,t,a)=>{a.d(t,{D:()=>d,l:()=>i});let r={media_kind:"Media kind",source_kind:"Source kind (AI/human origin)",tool:"Tool",content_sha256:"Content hash",disclosure_status:"Disclosure status",rights_evidence:"Rights evidence",recorded_inputs:"Recorded inputs"};function n(e){return{key:e,label:r[e]}}function s(e){let t=String(null!=e?e:"").trim().toLowerCase();return"unclear"===t||"risky"===t}function l(e){var t;return"revoked"!==String(null!=(t=e.status)?t:"").trim().toLowerCase()}function i(e,t){var a;let r=[];return e.media_kind||r.push(n("media_kind")),e.source_kind||r.push(n("source_kind")),e.tool&&e.tool.trim()||r.push(n("tool")),e.content_sha256||r.push(n("content_sha256")),e.disclosure_status||r.push(n("disclosure_status")),!t.some(l)&&(s(e.legal_reference)||s(e.legal_prompt))&&r.push(n("rights_evidence")),void 0===e.input_count||null===e.input_count||e.input_count>0||"ai_edited"!==String(null!=(a=e.source_kind)?a:"").trim().toLowerCase()||r.push(n("recorded_inputs")),{ok:0===r.length,missing:r}}function d(e,t){let a=0,r=[];for(let s of e){var n;let e=null!=(n=t.get(s.id))?n:[],{ok:l,missing:d}=i(s,e);l?a+=1:r.push({assetId:s.id,assetName:s.name,missing:d})}return{readyCount:a,totalCount:e.length,gapsByAsset:r}}},36199:(e,t,a)=>{a.d(t,{Ek:()=>u,mo:()=>c,r3:()=>o,zP:()=>d});var r=a(53455),n=a(99776),s=a(80549),l=a(96648);async function i(e){let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||"Prompt risk scan failed.");return t}function d(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];return(0,r.I)({queryKey:["prompt-risk-scans",e],queryFn:async()=>i(await fetch("/api/projects/".concat(e,"/prompt-risk-scans"),{credentials:"same-origin",cache:"no-store"})),enabled:!!e&&t})}function o(e){let t=(0,n.jE)();return(0,s.n)({mutationFn:async t=>{let a=null,r=!1===t.allBatches||t.force?1:20;for(let s=0;s<r;s+=1){var n;if(!(a=await i(await fetch("/api/projects/".concat(e,"/prompt-risk-scans"),{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({useContext:t.useContext,territories:t.territories,enabled:null==(n=t.enabled)||n,...void 0===t.confirmExter
1nalProcessing?{}:{confirmExternalProcessing:t.confirmExternalProcessing},assetIds:t.assetIds,force:!0===t.force})}))).remainingCount)break}return a},onSuccess:a=>{a&&t.setQueryData(["prompt-risk-scans",e],a),t.invalidateQueries({queryKey:["prompt-risk-scans",e]})}})}function c(e){let t=(0,n.jE)();return(0,s.n)({mutationFn:async t=>{var a;return i(await fetch("/api/projects/".concat(e,"/prompt-risk-scans/").concat(t.scanId,"/resolve"),{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({resolution:t.resolution,note:t.note,rightsRecordId:null!=(a=t.rightsRecordId)?a:null})}))},onSuccess:()=>{t.invalidateQueries({queryKey:["prompt-risk-scans",e]})}})}function u(e){let t=(0,n.jE)();return(0,s.n)({mutationFn:async e=>{let t=(0,l.createClient)(),{error:a}=await t.from("assets").update({prompt_keep_local:e.keepLocal}).eq("id",e.assetId);if(a)throw a;return e},onSuccess:()=>{t.invalidateQueries({queryKey:["prompt-risk-scans",e]})}})}},39190:(e,t,a)=>{a.d(t,{w:()=>o,x:()=>c});var r=a(53455),n=a(19036),s=a(96648),l=a(34773),i=a(56889);let d=(0,l.h)("features/deliveries/use-project-delivery-summary");function o(e){return["delivery-summary",e]}function c(e){let t=(0,n.D)(),a=(0,s.createClient)();return(0,r.I)({queryKey:o(e),queryFn:async()=>{let{data:t,error:r}=await a.from("deliveries").select("id, delivery_date, status").eq("project_id",e).not("delivery_date","is",null);if(r)throw(0,l.RF)(r)||d.error("delivery summary query failed",{event:"deliveries.query.summary",phase:"error",error:(0,l.P5)(r)}),r;return(0,i.IE)(null!=t?t:[])},enabled:!!e&&t})}},44846:(e,t,a)=>{a.d(t,{d:()=>i});var r=a(95155),n=a(12115),s=a(27599),l=a(64269);let i=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,r.jsx)(s.bL,{className:(0,l.cn)("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors duration-[var(--dur-base)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background","disabled:cursor-not-allowed disabled:opacity-50","data-[state=checked]:bg-primary data-[state=unchecked]:bg-muted data-[state=unchecked]:shadow-[inset_0_0_0_1px_var(--palette-border)]",a),...n,ref:t,children:(0,r.jsx)(s.zi,{className:(0,l.cn)("pointer-events-none block h-4 w-4 rounded-full bg-white shadow-[var(--elev-1)] ring-0 transition-transform duration-[var(--dur-base)] ease-[var(--ease-snap)]","data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})})});i.displayName=s.bL.displayName},70213:(e,t,a)=>{a.d(t,{Gs:()=>x,IM:()=>h,IN:()=>b,Vb:()=>f,XV:()=>g,eG:()=>_,eu:()=>j,mG:()=>N,uq:()=>y,wd:()=>w,yC:()=>v});var r=a(95155),n=a(12115),s=a(99776),l=a(68854),i=a(17910),d=a(18514),o=a(57828),c=a(20508),u=a(64269),m=a(46767);let p={owner:{label:"Can do everything",help:"Full control, including billing & ownership.",Icon:l.A,tone:"border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-300"},admin:{label:"Can manage the team",help:"Add/remove people & areas. No billing.",Icon:i.A,tone:"border-violet-500/40 bg-violet-500/10 text-violet-600 dark:text-violet-300"},editor:{label:"Can edit",help:"Create & change work. Can't manage people.",Icon:d.A,tone:"border-sky-500/40 bg-sky-500/10 text-sky-600 dark:text-sky-300"},viewer:{label:"Can only view",help:"Can look, but can't change anything.",Icon:o.A,tone:"border-border bg-muted/50 text-muted-foreground"},guest:{label:"Guest (limited)",help:"Access to specific shared things only.",Icon:c.A,tone:"border-border bg-muted/50 text-muted-foreground"},client:{label:"Client (review only)",help:"External reviewer. Sees only References, Prompts, Sheets & Finals; can rate and leave notes. Can't edit, delete, or see the canvas.",Icon:o.A,tone:"border-slate-400/40 bg-slate-500/10 text-slate-600 dark:text-slate-300"}};function x(e){var t;return null!=(t=p[e])?t:p.viewer}function h(e){if(null==e)return{};if("string"==typeof e)try{let t=JSON.parse(e);return{inviteId:"string"==typeof t.invite_id?t.invite_id:void 0,token:"string"==typeof t.token?t.token:void 0}}catch(e){return{}}return"object"!=typeof e||Array.isArray(e)?{}:{inviteId:"string"==typeof e.invite_id?e.invite_id:"string"==typeof e.inviteId?e.inviteId:void 0,token:"string"==typeof e.token?e.token:void 0}}function f(e){return e.displayName||e.email||"".concat(e.userId.slice(0,6),"â¦")}function v(e){let t=(e.displayName||e.email||e.userId).trim(),a=t.split(/[\s@._-]+/).filter(
1Boolean);return a.length>=2?(a[0][0]+a[1][0]).toUpperCase():t.slice(0,2).toUpperCase()||"â"}function g(e){if(!e)return"â";try{return new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch(e){return"â"}}function b(e){if(!e)return null;let t=Date.now()-new Date(e).getTime();return Number.isFinite(t)?t<3e5?{cls:"bg-emerald-500 shadow-[0_0_0_2px_rgba(16,185,129,0.25)]",label:"Online now"}:t<36e5?{cls:"bg-amber-400",label:"Active in the last hour"}:{cls:"bg-muted-foreground/40",label:"Offline"}:null}function y(e){let t=0;for(let a=0;a<e.length;a++)t=(31*t+e.charCodeAt(a))%360;return t}function j(e){let{m:t,size:a=10}=e,n=b(t.lastActiveAt),s=y(t.userId);return(0,r.jsxs)("div",{className:"relative shrink-0",children:[(0,r.jsx)("div",{className:(0,u.cn)("flex items-center justify-center rounded-full font-semibold",8===a?"size-8 text-[10px]":14===a?"size-14 text-[16px]":"size-10 text-[12px]"),style:{background:"oklch(0.72 0.11 ".concat(s," / 0.18)"),border:"1px solid oklch(0.72 0.13 ".concat(s," / 0.45)"),color:"oklch(0.55 0.13 ".concat(s,")")},children:v(t)}),n?(0,r.jsx)(m.Y6,{label:n.label,children:(0,r.jsx)("span",{role:"img","aria-label":n.label,className:(0,u.cn)("absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full ring-2 ring-background",n.cls)})}):null]})}function _(e){let{role:t}=e,a=x(t),{Icon:n}=a;return(0,r.jsx)(m.Y6,{label:a.help,children:(0,r.jsxs)("span",{className:(0,u.cn)("inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs font-medium",a.tone),children:[(0,r.jsx)(n,{className:"h-3.5 w-3.5","aria-hidden":!0}),a.label]})})}function w(e){var t;let{visibility:a}=e,n=(null!=a?a:"team").toLowerCase(),s={team:{label:"Whole area",cls:"border-sky-400/40 bg-sky-500/10 text-sky-600 dark:text-sky-300"},private:{label:"Owner only",cls:"border-border bg-muted/50 text-muted-foreground"},restricted:{label:"Chosen people",cls:"border-amber-400/40 bg-amber-500/10 text-amber-600 dark:text-amber-300"}},l=null!=(t=s[n])?t:s.team;return(0,r.jsx)("span",{className:(0,u.cn)("inline-flex shrink-0 items-center rounded-full border px-2 py-0.5 text-[10px] font-medium",l.cls),children:l.label})}function N(e){let t=(0,s.jE)();return{postAction:(0,n.useCallback)(async t=>{let a=await fetch("/api/organization/team-actions",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({organizationId:e,...t})}),r=await a.json().catch(()=>({}));if(!a.ok&&207!==a.status)throw Error("string"==typeof r.error?r.error:"Request failed");return r},[e]),invalidate:(0,n.useCallback)(()=>{t.invalidateQueries({queryKey:["team-directory",e]}),t.invalidateQueries({queryKey:["project-members"]})},[t,e])}}},73472:(e,t,a)=>{a.d(t,{O:()=>o});var r=a(95155),n=a(12115),s=a(85921),l=a(64269),i=a(54112);function d(e){let{className:t}=e;return(0,r.jsx)("span",{"aria-hidden":!0,className:(0,l.cn)("pointer-events-none absolute bottom-1.5 right-1.5 z-[2] flex h-5 w-5 items-center justify-center rounded-full bg-black/60 text-white shadow-sm backdrop-blur-sm",t),children:(0,r.jsx)(s.A,{className:"h-2.5 w-2.5 translate-x-[0.5px] fill-current"})})}function o(e){let{url:t,poster:a,className:s,badge:l=!0,badgeClassName:o,draggable:c,ariaLabel:u,autoPreview:m=!1}=e,p=function(){let[e,t]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if("function"!=typeof window.matchMedia)return;let e=window.matchMedia("(prefers-reduced-motion: reduce)");t(e.matches);let a=e=>t(e.matches);return e.addEventListener("change",a),()=>e.removeEventListener("change",a)},[]),e}(),x=(0,n.useRef)(null),h=m&&!p;return((0,n.useEffect)(()=>{if(!h)return;let e=x.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(t=>{for(let a of t)if(a.isIntersecting)e.play().catch(()=>{});else{e.pause();try{e.currentTime=0}catch(e){}}},{threshold:.25});return t.observe(e),()=>t.disconnect()},[h,t]),t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("video",{ref:h?x:void 0,src:(0,i.eQ)(t),poster:null!=a?a:void 0,className:s,muted:!0,playsInline:!0,preload:"metadata",loop:h,tabIndex:-1,"aria-label":u||void 0,draggable:c}),l?(0,r.jsx)(d,{className:o}):null]}):null}},74719:(e,t,a)=>{a.d(t,{T:()=>i});var r=a(95155);a(12115);var n=a(52498),s=a(52056),l=a(3998);function i(e){let{open:t,onOpenChange:a,title:i,description:d,confirmLabel:o="Confirm",cancelLabel:c="Cancel",variant:u="default",onConfirm:m,busy:p}=e;return(0,r.jsx)(n.bL,{open:t,onOpenChange:a,children:(0,r.jsxs)(n.ZL,{children:[(0,r.jsx)(n.hJ,{className:"fixed inset-0 z-50 bg-black/70 backdrop-blur-[2px] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 motion-reduce:animate-none"}),(0,r.jsxs)(n.UC,{className:"fixed left-[50%] top-[50%] z-50 flex w-full max-w-md translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-[var(--rad-7)] border border-border bg-card text-sm text-card-foreground shadow-[var(--elev-4)] duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 motion-reduce:animate-none",children:[(0,r.jsxs)("div",{className:"flex items-start gap-3 px-6 pb-5 pt-5",children:["destructive"===u?(0,r.jsx)("div",{"aria-hidden":!0,
1className:"flex size-8 shrink-0 items-center justify-center rounded-[var(--rad-2)] bg-[color-mix(in_srgb,var(--palette-destructive)_10%,transparent)] text-destructive",children:(0,r.jsx)(s.A,{className:"h-4 w-4"})}):null,(0,r.jsxs)("div",{className:"flex min-w-0 flex-col gap-1.5",children:[(0,r.jsx)(n.hE,{className:"type-title text-foreground",children:i}),d?(0,r.jsx)(n.VY,{className:"type-caption",children:d}):null]})]}),(0,r.jsxs)("div",{className:"tint-muted flex items-center justify-end gap-2 border-t border-border px-6 py-3.5",children:[(0,r.jsx)(n.ZD,{asChild:!0,children:(0,r.jsx)(l.$,{variant:"outline",disabled:p,children:c})}),(0,r.jsx)(n.rc,{asChild:!0,children:(0,r.jsx)(l.$,{variant:"destructive"===u?"destructive":"default",disabled:p,onClick:e=>{e.preventDefault(),m()},children:o})})]})]})]})})}},85366:(e,t,a)=>{a.d(t,{d:()=>v,x:()=>x});var r=a(97451),n=a(35836);let s={declared:{en:"Creator-declared",de:"Vom Ersteller angegeben",note:"The creator recorded this link while working â contemporaneous and timestamped, but self-attested, not independently observed."},captured_at_creation:{en:"Captured at creation",de:"Bei Entstehung erfasst",note:"Captured by a user action at the moment of creation, before it could be altered â temporally strong, but the content is still creator-explained."},witnessed:{en:"Witnessed",de:"Bezeugt",note:"Behind The Workflow saw the reference-to-output link at generation and bound it â the derivation is witnessed, not merely claimed."},signed_at_source:{en:"Signed at source",de:"An der Quelle signiert",note:"A signed Content Credential from the generating tool was preserved with this asset and verified â third-party proof of origin."},hardware_rooted:{en:"Hardware-rooted",de:"Hardware-verwurzelt",note:"A camera/enclave signature made at the sensor was preserved â the closest thing to proof of a real capture."}},l={ai_generated:"AI-generated",ai_edited:"AI-edited",human:"Human",unknown:"Unknown"},i={image:"Image",video:"Video",audio:"Audio"},d={none_required:"Not required",credits:"In credits",on_product:"On-product label",pending:"Pending"},o={face_consent:"Face consent",voice_consent:"Voice consent",music_license:"Music license",stock_license:"Stock license",tool_terms:"Tool terms",other:"Other"},c={active:"Active",expired:"Expired",revoked:"Revoked"},u={none:"No AI",assisted:"AI-assisted",substantial:"Substantial AI",fully_generated:"Fully AI-generated"};function m(e,t){var a;return t?null!=(a=e[t])?a:t:null}function p(e){return null==e||""===e?null:String(e)}function x(e){if(!e)return null;let t=e.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/);return t?"".concat(t[1]," ").concat(t[2]," UTC"):e}function h(e,t,a){null!==a&&e.push({label:t,value:a})}function f(e){var t,a;let r=[null!=(a=null!=(t=p(e.name))?t:p(e.id))?a:"Reference"],n=p(e.legal_status);n&&r.push("license: ".concat(n));let s=p(e.owner_label);s&&r.push("owner: ".concat(s));let l=p(e.source_url);return l&&r.push("source: ".concat(l)),r.join(" â ")}function v(e){var t,a,v,g,b;let y=r.F0[e.scope],j=e.chain.filter(e=>"asset"===e.type),_=e.chain.filter(e=>"audit_event"===e.type),w=new Map;for(let e of j){let t=p(e.data.name);t&&w.set(e.id,t)}let N=j.map(e=>(function(e,t){var a,r,n,o;let c=String(e.id),u=[];h(u,"Asset ID",c),h(u,"SHA-256",null!=(a=p(e.content_sha256))?a:"not yet hashed"),h(u,"Created",x(p(e.created_at))),h(u,"Version",p(e.version));let v=p(e.parent_id);if(v){let e=t.get(v);h(u,"Derived from version",e?"".concat(e," (").concat(v,")"):v)}h(u,"Tool",p(e.tool)),h(u,"Model",p(e.generation_model)),h(u,"Source",m(l,p(e.source_kind))),h(u,"Seed",p(e.generation_seed)),h(u,"Format",p(e.media_format)),h(u,"Media kind",m(i,p(e.media_kind))),h(u,"Dimensions",function(e){let t=p(e.width_px),a=p(e.height_px),r=[];t&&a&&r.push("".concat(t,"\xd7").concat(a,"px"));let n=p(e.aspect_ratio);n&&r.push(n);let s=p(e.resolution_dpi);return s&&r.push("".concat(s,"dpi")),r.length?r.join(" \xb7 "):null}(e)),h(u,"AI disclosure",m(d,p(e.disclosure_status))),h(u,"Provenance strength",s[function(e){let t=e.provenance_strength;return"declared"===t||"captured_at_creation"===t||"witnessed"===t||"signed_at_source"===t||"hardware_rooted"===t?t:"declared"}(e)].en),h(u,"Rights / reference note",p(e.legal_reference)),h(u,"Prompt rights status (team)",p(e.legal_prompt)),h(u,"Prompt rights status (client)",p(e.client_legal_prompt));let g=e.prompt_risk&&"object"==typeof e.prompt_risk?e.prompt_risk:null;if(g){h(u,"Automated prompt risk indication","".concat(null!=(r=p(g.status))?r:"unknown").concat(!1===g.current?" (outdated)":"")),h(u,"Prompt risk policy",p(g.policy_version)),h(u,"Prompt risk scanned",x(p(g.scanned_at)));let e=g.resolution&&"object"==typeof g.resolution?g.resolution:null;e&&h(u,"Human prompt review",p(e.resolution))}!0===e.approved_for_share&&h(u,"Released to client",null!=(n=x(p(e.approved_for_share_at)))?n:"yes"),h(u,"Review verdict",p(e.verdict)),h(u,"Verdict reason",p(e.verdict_reason)),h(u,"Created by (user id)",p(e.created_by)),h(u,"Archived",x(p(e.archived_at)));let b=Array.isArray(e.derived_from)?e.derived_from:[];b.length&&h(u,"Inspired by finals",b.map(e=>{var a;let r=null!=(a=p(e.asset_id))?a:"?",n=t.get(r);return n?"".concat(n," (").concat(r,")"):r}).join(", "));let y=Array.isArray(e.references)?e.references:[];return{id:c,title:null!=(o=p(e.name))?o:c,fields:u,prompt:p(e.prompt),references:y.map(f)}})(e.data,w)),k=e.delivery?{title:e.delivery.title,clientName:null!=(t=e.delivery.clientName)?t:null,deliveryDate:null!=(a=e.delivery.deliveryDate)?a:null,aiUseLevel:m(u,null!=(v=e.delivery.aiUseLevel)?v:null)}:null,C=e.signoffs.map(e=>{var t;let a=e.signedRole?", ".concat(e.signedRole):"",r=null!=(t=x(e.signedAt))?t
1:e.signedAt;return{line:"Signed: ".concat(e.signedName).concat(a," â ").concat(r),statement:e.statement}}),A=e.rightsRecords.map(e=>{var t,a,r,n,s,l;return{kind:null!=(t=m(o,e.kind))?t:e.kind,party:e.partyName,validity:(s=null!=(a=e.validFrom)?a:null,l=null!=(r=e.validUntil)?r:null,s&&l?"".concat(s," â ").concat(l):s?"From ".concat(s):l?"Until ".concat(l):"â"),status:null!=(n=m(c,e.status))?n:e.status,evidence:e.evidenceSha256?"".concat(e.evidenceSha256.slice(0,12),"â¦"):"no document"}}),S=function(e,t){let a=e.rightsRecords.filter(e=>null===e.assetId).map(e=>({id:e.id,status:e.status})),r=[],s=new Map;for(let n of t){var l;let t=n.data,i=String(t.id),d={media_kind:p(t.media_kind),source_kind:p(t.source_kind),tool:p(t.tool),content_sha256:p(t.content_sha256),disclosure_status:p(t.disclosure_status),legal_reference:p(t.legal_reference),legal_prompt:p(t.legal_prompt),input_count:Array.isArray(t.inputs)?t.inputs.length:void 0};r.push({...d,id:i,name:null!=(l=p(t.name))?l:i});let o=e.rightsRecords.filter(e=>e.assetId===i).map(e=>({id:e.id,status:e.status}));s.set(i,[...o,...a])}let{readyCount:i,totalCount:d,gapsByAsset:o}=(0,n.D)(r,s);return{summary:"".concat(i," of ").concat(d," asset").concat(1===d?"":"s"," compliance-ready"),note:"Gaps are listed for transparency; they do not invalidate this record.",gaps:o.map(e=>({assetTitle:e.assetName,missing:e.missing.map(e=>e.label)}))}}(e,j),I=e.deliveryActivity&&e.deliveryActivity.length?[...e.deliveryActivity].sort((e,t)=>e.at.localeCompare(t.at)).map(e=>{var t,a;return{line:"".concat(null!=(t=x(e.at))?t:e.at," â ").concat(e.actor," ").concat(e.label),detail:null!=(a=e.detail)?a:null}}):null,R=null;if(_.length){let e=x(p(_[0].data.created_at)),t=x(p(_[_.length-1].data.created_at));R="".concat(_.length," logged change").concat(1===_.length?"":"s")+(e&&t?" between ".concat(e," and ").concat(t):"")+". The full entries are in manifest.json, bound by the same hash chain."}return{cover:{title:"AI-Act dossier",projectName:e.project.name,organizationName:null!=(g=e.project.organizationName)?g:null,scopeLabel:y.label,scopeExcludes:y.excludes,generatedAt:null!=(b=x(e.generatedAt))?b:e.generatedAt,assetCount:e.counts.assets,auditEventCount:e.counts.auditEvents,topLevelHash:e.rootHash,attestation:['This dossier documents how the AI-generated content in the project "'.concat(e.project.name,'" came to be: per asset its identity and file hash, the generation recipe as far as recorded, the references used, the rights status as assessed by the team, and when a human released it.'),"The machine-readable record (manifest.json in this package) carries the same content bound into a sha256 hash chain. The top-level hash below fingerprints the entire record â any alteration after export is detectable by re-running the verification script.",'How to read the provenance strength on each asset â a 5-rung ladder from weakest to strongest: "Creator-declared" (the creator recorded the link while working â contemporaneous and timestamped, but self-attested); "Captured at creation" (captured by a user action at the moment of creation, before it could be altered); "Witnessed" (Behind The Workflow saw the reference-to-output link at generation and bound it); "Signed at source" (the generating tool\'s own signed credential was preserved and verified); "Hardware-rooted" (a camera/enclave signature made at the sensor). We label these honestly and never present a declared link as observed.'],disclaimer:"Honest limits: this record attests that complete, timestamped documentation exists. It is not a certification of legal compliance, it does not by itself clear rights, and scoped exports deliberately omit the fields listed above. Any automated prompt-risk entry is a context-dependent indication, not legal advice, and does not inspect the generated asset. It proves the inclusion of what was recorded, not the exclusion of what was not, and it does not reverse-engineer from an output which input produced it. File hashes are computed at export time on the exporting team's machine. The change log covers the project and the assets that existed at export time; history of previously deleted assets is not included.",delivery:k,signoffs:C},assets:N,rights:A,completeness:S,auditSummary:R,activity:I}}},97451:(e,t,a)=>{a.d(t,{F0:()=>n,zd:()=>r});let r=["full","client","compliance"],n={full:{scope:"full",label:"Full record",description:"Everything â the complete internal record
1including seeds, review verdicts, author ids and the full audit log.",excludes:"Nothing. This is the unredacted archive copy."},client:{scope:"client",label:"Client-facing",description:"The provenance story for the client: prompts, models, references and approvals â without internal backstage data.",excludes:"Generation seeds, review verdicts, author ids and the internal audit log."},compliance:{scope:"compliance",label:"Compliance only",description:"The minimal verifiable record: identity, hashes, models, timestamps, rights status and an anonymized change log â no creative IP.",excludes:"Prompts, AI metadata cards, reference source links, seeds, verdicts and all author ids."}}}}]);
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.