import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{t}from"./react-Augu_vA3.js";import{Dt as n,It as r,N as i,Rt as a,Tt as o,V as s,Vt as c,_t as l,ct as u,st as d,vn as f,zt as p}from"./forms-CL2ODv4X.js";import{t as m}from"./useTranslation-B_YCgyrR.js";import{t as h}from"./dayjs.min-wxmwWtJd.js";import{v as g}from"./dist-DWDqendd.js";import{t as _}from"./jsx-runtime-CTknu7_t.js";import{t as v}from"./Modal-C4GWc9Ry.js";import{t as y}from"./ArrowRight-DsSPsdeY.js";import{t as b}from"./react-string-replace-CPIx4QiK.js";import{t as x}from"./useCompanyTimeFormat-DYiW9xWz.js";import{t as S}from"./SquareActivityChart-VmmmWI4W.js";var C=e(b()),w=e(t()),T=e(h()),E=e(_()),D=u.div` background-color: ${e=>e.theme.backgroundColor}; &:hover { background-color: ${e=>e.theme.hoverBackgroundColor}; } `;function O(){let[e]=m(),t=l(),{timeFormat:n}=x(),{dateFormat:s}=a(),c=t=>{let n=r(`activity_${t.activity_type_id}`,{});t.activity_type_id===10&&t.contact&&(n=r(`activity_10_online`,{})),t.activity_type_id===54&&t.contact&&(n=n.replace(`:user`,`:contact`));let a=[`invoice`,`quote`,`recurring_invoice`,`vendor`,`credit`,`payment`,`project`,`task`,`expense`,`recurring_expense`,`bank_transaction`,`purchase_order`],o=(()=>{let e=Object.keys(t||{}).find(e=>a.includes(e));return!e&&t?.client?`client`:e||``})(),s={client:(0,E.jsx)(i,{to:g(`/clients/:id`,{id:t.client?.hashed_id}),children:t.client?.label}),contact:(0,E.jsx)(i,{to:g(`/${t?.contact?.contact_entity}/:id`,{id:t.contact?.hashed_id}),children:t.contact?.label}),quote:(0,E.jsx)(i,{to:g(`/quotes/:id/edit`,{id:t.quote?.hashed_id}),children:t.quote?.label}),user:t.user?.label??e(`system`),expense:(0,E.jsx)(i,{to:g(`/expenses/:id/edit`,{id:t.expense?.hashed_id}),children:t?.expense?.label}),recurring_invoice:(0,E.jsx)(i,{to:g(`/recurring_invoices/:id/edit`,{id:t.recurring_invoice?.hashed_id}),children:t?.recurring_invoice?.label}),recurring_expense:(0,E.jsx)(i,{to:g(`/recurring_expenses/:id/edit`,{id:t.recurring_expense?.hashed_id}),children:t?.recurring_expense?.label}),purchase_order:(0,E.jsx)(i,{to:g(`/purchase_orders/:id/edit`,{id:t.purchase_order?.hashed_id}),children:t?.purchase_order?.label}),invoice:(0,E.jsx)(i,{to:g(`/invoices/:id/edit`,{id:t.invoice?.hashed_id}),children:t?.invoice?.label}),payment_amount:t?.payment_amount?.label,payment:(0,E.jsx)(i,{to:g(`/payments/:id/edit`,{id:t.payment?.hashed_id}),children:t?.payment?.label}),credit:(0,E.jsx)(i,{to:g(`/credits/:id/edit`,{id:t.credit?.hashed_id}),children:t?.credit?.label}),task:(0,E.jsx)(i,{to:g(`/tasks/:id/edit`,{id:t.task?.hashed_id}),children:t?.task?.label}),vendor:(0,E.jsx)(i,{to:g(`/vendors/:id/edit`,{id:t.vendor?.hashed_id}),children:t?.vendor?.label}),subscription:(0,E.jsx)(i,{to:g(`/settings/subscriptions/:id/edit`,{id:t.subscription?.hashed_id}),children:t?.subscription?.label}),adjustment:t?.adjustment?.label,notes:t?.notes&&[151,152,153].includes(t.activity_type_id)?(0,E.jsx)(E.Fragment,{children:t?.notes??``}):o&&t[o]?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`br`,{}),(0,E.jsx)(i,{to:g(`/${o}s/${t[o].hashed_id}/edit`),children:t?.notes})]}):null};for(let[e,t]of Object.entries(s))n=(0,C.default)(n,`:${e}`,()=>t);return n},u=t=>{let r=(0,T.default)(),i=T.default.unix(t),a=r.diff(i,`day`);return r.diff(i,`minute`)<=1?e(`just_now`):a===1?e(`yesterday`):o(t,`${s} ${n.replace(`:ss`,``)}`)};return e=>(0,E.jsxs)(D,{className:`flex space-x-3 p-4 rounded-md flex-1 min-w-0 w-full`,theme:{backgroundColor:t.$1,hoverBackgroundColor:t.$25},children:[(0,E.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,E.jsx)(`div`,{className:`p-2 rounded-full`,style:{backgroundColor:t.$20},children:(0,E.jsx)(S,{size:`1.3rem`,color:t.$16,filledColor:t.$16})})}),(0,E.jsxs)(`div`,{className:`flex flex-col space-y-0.5 flex-1 min-w-0`,children:[(0,E.jsx)(`div`,{className:`text-sm`,style:{color:t.$3},children:c(e)}),(0,E.jsxs)(`div`,{className:`flex w-full items-center space-x-1 text-xs truncate`,style:{color:t.$17},children:[(0,E.jsx)(`span`,{className:`whitespace-nowrap`,children:u(e.created_at)}),(0,E.jsx)(`span`,{children:`-`}),(0,E.jsx)(`span`,{children:e.ip})]})]})]},e.id)}function k(e){let[t]=m(),r=l(),{entity:i,entityId:a,label:o,labelElement:u}=e,[h,g]=(0,w.useState)(!1),[_,b]=(0,w.useState)(!1),[x,S]=(0,w.useState)(``),C=()=>{b(!1),S(``)};return(0,E.jsxs)(E.Fragment,{children:[a&&(0,E.jsx)(`div`,{className:`cursor-pointer`,onClick:()=>b(!0),children:u||(0,E.jsx)(d,{behavior:`button`,type:`secondary`,onClick:()=>{},children:t(`add_comment`)})}),(0,E.jsxs)(v,{size:`regular`,title:(0,E.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,E.jsx)(`span`,{children:t(`comment`)}),(0,E.jsx)(`div`,{children:(0,E.jsx)(y,{color:r.$17})}),(0,E.jsxs)(`span`,{children:[t(i),` `,o]})]}),visible:_,onClose:C,children:[(0,E.jsx)(s,{element:`textarea`,value:x,onValueChange:e=>S(e),changeOverride:!0}),(0,E.jsx)(`div`,{className:`flex self-end`,children:(0,E.jsx)(d,{behavior:`button`,onClick:()=>{h||(g(!0),f.processing(),p(`POST`,n(`/api/v1/activities/notes`),{entity:`${i}s`,entity_id:a,notes:x}).then(()=>{f.success(`saved_comment`),c([`activities`])}).finally(()=>{g(!1),C()}))},disabled:h||!x,disableWithoutIcon:!0,children:t(`add`)})})]})]})}export{O as n,k as t};