import{j as e}from"./vendor-react-DrAK5R0M.js";import{h as b,cu as g}from"./index-7eqLqzhB.js";import{D as m}from"./DrawerSection-2MUD_aar.js";import{b as j}from"./CrmWidgets-CPIn4fPO.js";import{J as y,ab as h,j as N,ah as v}from"./vendor-icons-Cu2Ube6F.js";import"./vendor-visuals-BHLltLY6.js";import"./vendor-radix-CwTvaGVy.js";import"./stageConfig-ZD7XuSnW.js";const w={contact:"Contact",account:"Account",opportunity:"Opportunity",use_case:"Use Case"},_={contact:"contact",account:"account",opportunity:"opportunity",use_case:"use-case"};function k(r){if(typeof r!="string"||!r)return"Not set";const s=new Date(r);return Number.isNaN(s.getTime())?r:s.toLocaleString()}function u(r){return typeof r=="string"&&r?r.replace(/_/g," "):"None"}function a({label:r,value:s}){return s==null||s===""?null:e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border/60 py-2 last:border-b-0",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:r}),e.jsx("span",{className:"max-w-[65%] text-right text-sm text-foreground break-words",children:typeof s=="object"?JSON.stringify(s):String(s)})]})}function U(){const{drawerEntityId:r,openDrawer:s}=b(),{data:i,isLoading:p,error:c}=g(r),t=(i==null?void 0:i.data)??null;if(!r)return e.jsx("div",{className:"p-5 text-sm text-muted-foreground",children:"No activity selected."});if(p)return e.jsx("div",{className:"space-y-3 p-5",children:[1,2,3].map(n=>e.jsx("div",{className:"h-16 rounded-xl bg-muted/50 animate-pulse"},n))});if(c||!t)return e.jsx("div",{className:"p-5",children:e.jsxs("div",{className:"rounded-xl border border-destructive/20 bg-destructive/8 p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-destructive",children:"Could not load activity"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:c instanceof Error?c.message:"The activity may have been removed or you may not have access."})]})});const d=typeof t.subject_type=="string"?t.subject_type:"",o=typeof t.subject_id=="string"?t.subject_id:"",l=_[d],x=t.detail&&typeof t.detail=="object"&&!Array.isArray(t.detail)?t.detail:{};return e.jsxs("div",{className:"pb-6",children:[e.jsxs("div",{className:"border-b border-border p-5",children:[e.jsxs("div",{className:"mb-4 flex items-start gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-muted text-muted-foreground",children:j(String(t.type??"note"))}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:u(t.type)}),e.jsx("h2",{className:"mt-1 text-lg font-display font-bold text-foreground",children:String(t.subject??"Untitled activity")})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-muted px-2.5 py-1 text-muted-foreground",children:[e.jsx(y,{className:"h-3 w-3"}),k(t.occurred_at??t.created_at)]}),typeof t.outcome=="string"&&t.outcome&&e.jsx("span",{className:"rounded-full bg-warning/10 px-2.5 py-1 text-warning",children:u(t.outcome)})]})]}),typeof t.body=="string"&&t.body&&e.jsx(m,{title:"Notes",defaultOpen:!0,children:e.jsx("p",{className:"whitespace-pre-wrap rounded-xl border border-border bg-background/50 p-3 text-sm leading-relaxed text-foreground",children:String(t.body)})}),e.jsx(m,{title:"Linked Record",defaultOpen:!!(l&&o),children:l&&o?e.jsxs("button",{onClick:()=>s(l,o),className:"flex w-full items-center justify-between rounded-xl border border-border bg-background/50 px-3 py-2 text-left hover:border-primary/30 hover:bg-muted/40 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(h,{className:"h-4 w-4 text-primary"}),w[d]??d]}),e.jsx("span",{className:"max-w-[55%] truncate font-mono text-xs text-muted-foreground",children:o})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This activity is not linked to a customer record."})}),e.jsxs(m,{title:"Details",defaultOpen:Object.keys(x).length>0,children:[e.jsxs("div",{className:"rounded-xl border border-border bg-background/50 px-3",children:[e.jsx(a,{label:"Direction",value:u(t.direction)}),e.jsx(a,{label:"Performed by",value:t.performer_name??t.performed_by}),e.jsx(a,{label:"Source",value:t.source_agent?`Agent ${t.source_agent}`:t.created_by?"User":void 0}),Object.entries(x).map(([n,f])=>e.jsx(a,{label:n.replace(/_/g," "),value:f},n))]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-xs text-muted-foreground",children:[t.source_agent?e.jsx(N,{className:"h-3.5 w-3.5"}):e.jsx(v,{className:"h-3.5 w-3.5"}),"Activity ID ",e.jsx("span",{className:"font-mono",children:r})]})]})]})}export{U as ActivityDrawer};
