1import{aT as ye,u as H,b as fe,r as i,j as e,M as be,L as se,aR as we,C as je,P as Ne}from"./index-D1aKNduO.js";import{I as ve,A as Ce,C as ae,G as ke,D as Se,B as Y,T as Ie,E as re,F as Ee,h as Ae,f as _e,x as Le,y as Oe,J as Te,O as Me}from"./contact-presentation-DHJeU79g.js";import{P as oe}from"./papaparse.min-DH3ClDLU.js";import{C as ne,a as ie,M as Re}from"./Contact-BdtXGkG8.js";import{B as E}from"./Button-cszLhf2L.js";import{S as Fe}from"./close-DomYtwOS.js";import{C as Ue}from"./ContactActivityPanel-CwxbiihH.js";import{g as Be}from"./buttonStyles-B3V8uqct.js";import{S as Pe}from"./plus-Dij65dNZ.js";import{S as $e}from"./download-BRmjMDsW.js";import{a as ze}from"./ArchiveService-u6WPu0tO.js";import{u as De}from"./useResolvedCrmOwners-B2O3EKAz.js";import"./firebase-DGovvYsO.js";import"./box-D5auXeeV.js";import"./group-CcmPs4cn.js";import"./user-line-BXqsn8Lx.js";import"./archive-CDFxr6Yx.js";import"./Badge-BZRezhTy.js";const W="__missing__",U=t=>t?.trim().toLocaleLowerCase()??"",Ve=t=>({total:t.length,professionals:t.filter(o=>o.type==="professional_genealogist").length,repositoryAccess:t.filter(o=>(o.repositoryIds?.length??0)>0).length,withoutGrantedConsent:t.filter(o=>o.marketingConsent?.status!=="granted").length});function Ge(t,o,m=new Map,g=new Map){const l=o.query.trim().toLocaleLowerCase();return t.filter(u=>{if(o.type&&u.type!==o.type||o.stage&&u.lifecycleStage!==o.stage)return!1;const r=u.countryISOA3?.trim().toUpperCase()??"";if(o.country===W&&r||o.country&&o.country!==W&&r!==o.country.trim().toUpperCase())return!1;const d=(u.repositoryIds?.length??0)>0;if(o.repository==="with"&&!d||o.repository==="without"&&d)return!1;if(!l)return!0;const k=(u.repositoryIds??[]).map(x=>g.get(x)??"").join(" ");return[u.firstName,u.lastName,u.email,m.get(u.companyId??""),...u.specialisms??[],k].filter(Boolean).some(x=>x.toLocaleLowerCase().includes(l))})}const le=["firstName","lastName","salutation","jobTitle","email","phone","company","type","countryISOA3","preferredLanguage","specialisms","source","ownerEmail","stage","tags","repositoryCodes","consentStatus","consentEvidence","internalNote"],te=t=>t?.split(";").map(o=>o.trim()).filter(Boolean)??[],B=t=>t?.trim().toLocaleLowerCase()??"";function q(t,o){const m=new Map;return t.forEach(g=>o(g).filter(Boolean).forEach(l=>{const u=B(l);m.set(u,m.has(u)?null:g)})),m}function qe(t,o){const m=oe.parse(t,{header:!0,skipEmptyLines:"greedy"}),g=m.errors.map(a=>({row:(a.row??0)+2,message:a.message})),l=[],u=q(o.companies,a=>[a.name]),r=q(o.repositories,a=>[a.id,a.repositoryCode,a.name]),d=q(o.owners.filter(ye),a=>[a.email]),k=new Map;o.existing.forEach(a=>{const h=U(a.email);h&&k.set(h,[...k.get(h)??[],a])});const x=new Map;return m.data.forEach(a=>{const h=U(a.email);h&&x.set(h,(x.get(h)??0)+1)}),m.data.forEach((a,h)=>{const p=h+2,c=[],w=U(a.email),N=w?k.get(w)??[]:[],v=N.length===1?"update":"create";N.length>1&&c.push("Email matches more than one existing contact."),!a.firstName?.trim()&&!a.lastName?.trim()&&v==="create"&&c.push("First name or last name is required.");const f={};if([["firstName",a.firstName],["lastName",a.lastName],["salutation",a.salutation],["jobTitle",a.jobTitle],["email",a.email],["phone",a.phone],["countryISOA3",a.countryISOA3?.toUpperCase()],["preferredLanguage",a.preferredLanguage],["contactSource",a.source],["internalNote",a.internalNote]].forEach(([b,n])=>{n?.trim()&&(f[b]=n.trim())}),[["specialisms",a.specialisms],["tags",a.tags]].forEach(([b,n])=>{const j=te(n);j.length&&(f[b]=j)}),a.company?.trim()){const b=u.get(B(a.company));b?f.companyId=b.id:c.push(`Company â${a.company.trim()}â was not found.`)}if(a.ownerEmail?.trim()){const b=d.get(B(a.ownerEmail));b?f.ownerId=b.id:c.push(`Owner â${a.ownerEmail.trim()}â was not found.`)}else v==="create"&&o.currentOwnerId&&(f.ownerId=o.currentOwnerId);a.type?.trim()&&(ne.includes(a.type.trim())?f.type=a.type.trim():c.push(`Unknown contact type â${a.type.trim()}â.`)),a.stage?.trim()&&(ie.includes(a.stage.trim())?f.lifecycleStage=a.stage.trim():c.push(`Unknown lifecycle stage â${a.stage.trim()}â.`)),a.consentStatus?.trim()&&(Re.includes(a.consentStatus.trim())?f.marketingConsent={status:a.consentStatus.trim(),...a.consentEvidence?.trim()&&{evidence:a.consentEvidence.trim()}}:c.push(`Unknown consent status â${a.consentStatus.trim()}â.`));const S=[];
1te(a.repositoryCodes).forEach(b=>{const n=r.get(B(b));n?S.includes(n.id)||S.push(n.id):c.push(`Repository â${b}â was not found.`)}),S.length&&(f.repositoryIds=S),c.forEach(b=>g.push({row:p,message:b})),c.length||l.push({row:p,action:v,contactId:N[0]?.id,values:f})}),m.data.forEach((a,h)=>{const p=U(a.email);if(p&&(x.get(p)??0)>1){g.push({row:h+2,message:"Email appears more than once in this file."});const c=l.findIndex(w=>w.row===h+2);c>=0&&l.splice(c,1)}}),{rows:l,errors:g}}function Ke(){return`${le.join(",")} 2Ada,Martin,,Professional genealogist,[email protected],,,,FRA,fr,Parish registers,Referral,,prospect,Vetted,,not_recorded,,`}function Ye({open:t,onClose:o,contacts:m,companies:g,repositories:l,owners:u,onImported:r}){const{t:d}=H(),{user:k}=fe(),[x,a]=i.useState(null),[h,p]=i.useState(""),[c,w]=i.useState(!1),[N,v]=i.useState(null),[f,I]=i.useState(""),O=n=>{if(!n)return;p(n.name),v(null),I("");const j=new FileReader;j.onload=()=>a(qe(String(j.result??""),{existing:m,companies:g,repositories:l,owners:u,currentOwnerId:k?.uid})),j.readAsText(n)},S=()=>{const n=URL.createObjectURL(new Blob([Ke()],{type:"text/csv;charset=utf-8"})),j=document.createElement("a");j.href=n,j.download="crm-contacts-template.csv",j.click(),URL.revokeObjectURL(n)},b=async()=>{if(x?.rows.length){w(!0),I("");try{const n=await ve(x.rows);v(n),r()}catch(n){console.error("Failed to import CRM contacts",n),I(d("crm.import.save_error","The valid rows could not be imported. Try again."))}finally{w(!1)}}};return e.jsxs(be,{isOpen:t,onClose:o,className:"max-w-3xl p-6",ariaLabelledBy:"contact-import-title",children:[e.jsx("h2",{id:"contact-import-title",className:"text-lg font-semibold text-gray-900 dark:text-white",children:d("crm.import.title","Import contacts")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:d("crm.import.help","Upload a CSV. Use semicolons between multi-value fields. Existing contacts are matched by email; blank cells preserve their current values.")}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs("label",{className:"inline-flex h-10 cursor-pointer items-center rounded-lg bg-brand-500 px-4 text-sm font-medium text-white hover:bg-brand-600",children:[e.jsx("input",{className:"sr-only",type:"file",accept:".csv,text/csv","aria-label":d("crm.import.choose","Choose CSV file"),onChange:n=>O(n.target.files?.[0])}),d("crm.import.choose","Choose CSV file")]}),e.jsx(E,{variant:"outline",onClick:S,children:d("crm.import.template","Download template")})]}),h&&e.jsx("p",{className:"mt-3 text-sm text-gray-600 dark:text-gray-300",children:h}),x&&e.jsxs("div",{className:"mt-4 rounded-xl border border-gray-200 p-4 dark:border-gray-700",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[e.jsxs("div",{children:[e.jsx("strong",{className:"block text-xl text-gray-900 dark:text-white",children:x.rows.filter(n=>n.action==="create").length}),e.jsx("span",{className:"text-xs text-gray-500",children:d("crm.import.creates","Creates")})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"block text-xl text-gray-900 dark:text-white",children:x.rows.filter(n=>n.action==="update").length}),e.jsx("span",{className:"text-xs text-gray-500",children:d("crm.import.updates","Updates")})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"block text-xl text-error-600",children:x.errors.length}),e.jsx("span",{className:"text-xs text-gray-500",children:d("crm.import.errors","Errors")})]})]}),x.errors.length>0&&e.jsx("ul",{className:"mt-4 max-h-40 overflow-y-auto text-sm text-error-600",children:x.errors.slice(0,30).map((n,j)=>e.jsxs("li",{children:[d("crm.import.row","Row")," ",n.row,": ",n.message]},`${n.row}-${j}`))})]}),N&&e.jsx("p",{role:"status",className:"mt-4 rounded-lg bg-success-50 p-3 text-sm text-success-700 dark:bg-success-500/15 dark:text-success-400",children:d("crm.import.complete",{defaultValue:"Import complete: {{created}} created and {{updated}} updated.",...N})}),f&&e.jsx("p",{role:"alert",className:"mt-4 rounded-lg bg-error-50 p-3 text-sm text-error-700 dark:bg-error-500/15 dark:text-error-400",children:f}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(E,{variant:"outline",onClick:o,children:d("common.close","Close")}),e.jsx(E,{disabled:!x?.rows.length||c,onClick:()=>void b(),children:c?d("crm.import.importing","Importingâ¦"):d("crm.import.confirm","Confirm import")})]})]})}function We({contact:t,company:o,owner:m,repositories:g,onClose:l,onActivityCreated:u}){const{t:r}=H(),d=i.useRef(null),[k,x]=i.useState([]);if(i.useEffect(()=>{if(!t)return;let p=!0;return Ce(t.id).then(c=>{p&&x(c)}).catch(c=>console.error("Failed to load activities",c)),()=>{p=!1}},[t]),i.useEffect(()=>{if(!t)return;const p=document.activeElement,c=w=>{if(w.key==="Escape"&&l(),w.key!=="Tab"||!d.current)return;const N=Array.from(d.current.querySelectorAll('a[href],button:not([disabled]),input
2:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])'));if(!N.length)return;const v=N[0],f=N[N.length-1];w.shiftKey&&document.activeElement===v?(w.preventDefault(),f.focus()):!w.shiftKey&&document.activeElement===f&&(w.preventDefault(),v.focus())};return document.addEventListener("keydown",c),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",c),document.body.style.overflow="",p?.focus()}},[t,l]),!t)return null;const a=g.filter(p=>t.repositoryIds?.includes(p.id)),h=[[r("crm.contact.fields.email"),t.email||"â"],[r("crm.contact.fields.phone"),t.phone||"â"],[r("crm.contact.fields.country","Country"),e.jsx(ae,{code:t.countryISOA3})],[r("crm.contact.fields.preferred_language"),t.preferredLanguage||"â"],[r("crm.contact.fields.specialisms","Specialisms"),t.specialisms?.join(", ")||"â"],[r("crm.contact.fields.source","Source"),t.contactSource||"â"],[r("crm.contact.fields.owner","Owner"),ke(m)]];return e.jsxs("div",{className:"fixed inset-0 z-99999",role:"presentation",children:[e.jsx("button",{className:"absolute inset-0 bg-gray-950/50","aria-label":r("common.aria_close_dialog"),onClick:l}),e.jsxs("aside",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"contact-drawer-title",className:"absolute inset-y-0 right-0 w-full overflow-y-auto border-l border-gray-200 bg-white p-5 shadow-theme-xl dark:border-gray-800 dark:bg-gray-950 sm:w-[460px] sm:p-6",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"flex size-12 shrink-0 items-center justify-center rounded-full bg-brand-50 font-semibold text-brand-700 dark:bg-brand-500/15 dark:text-brand-300",children:Se(t)}),e.jsxs("div",{children:[e.jsx("h2",{id:"contact-drawer-title",className:"font-semibold text-gray-900 dark:text-white",children:Y(t)}),e.jsx("p",{className:"text-sm text-gray-500",children:t.jobTitle||"â"}),e.jsx("p",{className:"text-sm text-gray-500",children:o?.name||"â"})]})]}),e.jsx("button",{autoFocus:!0,"aria-label":r("common.aria_close_dialog"),onClick:l,className:"flex size-8 items-center justify-center rounded-lg border border-gray-200 text-gray-500 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-brand-500 dark:border-gray-700 dark:hover:bg-gray-800",children:e.jsx(Fe,{className:"size-4"})})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-1.5",children:[e.jsx(Ie,{type:t.type}),e.jsx(re,{stage:t.lifecycleStage}),e.jsx(Ee,{status:t.marketingConsent?.status})]}),e.jsx("dl",{className:"mt-5 grid grid-cols-[112px_1fr] gap-x-3 gap-y-2 text-sm",children:h.map(([p,c])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-gray-500",children:p}),e.jsx("dd",{className:"break-words text-gray-800 dark:text-gray-200",children:c})]},p))}),e.jsxs("section",{className:"mt-6",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wider text-gray-500",children:r("crm.repositories.title","Repository access")}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:a.length?a.map(p=>e.jsx("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs text-gray-700 dark:bg-gray-800 dark:text-gray-200",children:p.name},p.id)):e.jsx("span",{className:"text-sm text-gray-500",children:r("crm.repositories.empty","No repository access recorded.")})})]}),e.jsxs("section",{className:"mt-6",children:[e.jsx("h3",{className:"mb-2 text-xs font-medium uppercase tracking-wider text-gray-500",children:r("crm.activity.log","Log an interaction")}),e.jsx(Ue,{contactId:t.id,activities:k.slice(0,3),compact:!0,onCreated:p=>{x(c=>[p,...c]),u?.(p)}})]}),e.jsx("footer",{className:"mt-6 border-t border-gray-100 pt-4 dark:border-gray-800",children:e.jsx(se,{to:`/contact/${t.id}`,className:Be({variant:"outline",size:"sm"}),children:r("crm.contacts.open_profile","Open full profile")})})]})]})}function He(t,o){const m=new Map(o.companies.map(r=>[r.id,r])),g=new Map(o.repositories.map(r=>[r.id,r])),l=new Map(o.owners.map(r=>[r.id,r])),u=t.map(r=>({firstName:r.firstName,lastName:r.lastName,salutation:r.salutation??"",jobTitle:r.jobTitle,email:r.email??"",phone:r.phone??"",company:m.get(r.companyId??"")?.name??"",type:r.type??"",countryISOA3:r.countryISOA3?.trim().toUpperCase()??"",preferredLanguage:r.preferredLanguage??"",specialisms:(r.specialisms??[]).join(";"),source:r.contactSource??"",ownerEmail:l.get(r.ownerId??"")?.email??"",stage:r.lifecycleStage??"",tags:(r.tags??[]).join(";"),repositoryCodes:(r.repositoryIds??[]).map(d=>
2g.get(d)?.repositoryCode??"").filter(Boolean).join(";"),consentStatus:r.marketingConsent?.status??"",consentEvidence:r.marketingConsent?.evidence??"",internalNote:r.internalNote??""}));return oe.unparse({fields:[...le],data:u})}function Je(t,o){const m=new Blob([t],{type:"text/csv;charset=utf-8;"}),g=URL.createObjectURL(m),l=document.createElement("a");l.href=g,l.download=o,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(g)}const K=8;function gt(){const{t,i18n:o}=H(),[m,g]=i.useState([]),[l,u]=i.useState([]),[r,d]=i.useState([]),[k,x]=i.useState([]),[a,h]=i.useState(!0),[p,c]=i.useState(!1),[w,N]=i.useState(0),[v,f]=i.useState(""),[I,O]=i.useState(""),[S,b]=i.useState(""),[n,j]=i.useState(""),[P,ce]=i.useState(""),[me,$]=i.useState(1),[de,z]=i.useState(null),[pe,J]=i.useState(!1),{owners:D}=De(k);i.useEffect(()=>{h(!0),c(!1),Promise.all([Ae(),_e(),ze(),we()]).then(([s,y,C,G])=>{g(s),u(y),d(C),x(G)}).catch(s=>{console.error("Failed to load CRM contacts",s),c(!0)}).finally(()=>h(!1))},[w]);const Q=i.useMemo(()=>new Map(l.map(s=>[s.id,s])),[l]),Z=i.useMemo(()=>new Map(D.map(s=>[s.id,s])),[D]),X=i.useMemo(()=>new Map(r.map(s=>[s.id,s.name])),[r]),ee=i.useMemo(()=>new Map(l.map(s=>[s.id,s.name])),[l]),T=i.useMemo(()=>Ve(m),[m]),ue=i.useMemo(()=>[...new Set(m.map(y=>y.countryISOA3?.trim().toUpperCase()).filter(Boolean))].map(y=>{const C=je.find(G=>G.isoCode3===y);return{value:y,label:C?t(`countries.${C.name}`,C.name):y}}).sort((y,C)=>y.label.localeCompare(C.label,o.language)),[m,o.language,t]),xe=i.useMemo(()=>m.some(s=>!s.countryISOA3?.trim()),[m]),A=i.useMemo(()=>Ge(m,{query:v,type:I,stage:S,repository:n,country:P},ee,X).slice().sort((s,y)=>s.lastName.localeCompare(y.lastName)||s.firstName.localeCompare(y.firstName)),[ee,m,P,v,n,X,S,I]),M=Math.max(1,Math.ceil(A.length/K)),R=Math.min(me,M),F=(R-1)*K,V=A.slice(F,F+K),_=m.find(s=>s.id===de)??null,L=()=>$(1),ge=()=>{const s=He(A,{companies:l,repositories:r,owners:D});Je(s,`contacts-${new Date().toISOString().slice(0,10)}.csv`)},he=[[t("crm.contacts.summary.all","All contacts"),T.total],[t("crm.contacts.summary.professionals","Professional genealogists"),T.professionals],[t("crm.contacts.summary.repositories","Contacts with repository access"),T.repositoryAccess],[t("crm.contacts.summary.no_consent","No consent on file"),T.withoutGrantedConsent]];return e.jsxs(e.Fragment,{children:[e.jsx(Ne,{title:t("crm.contacts.meta_title"),description:t("crm.contacts.meta_description")}),e.jsxs("div",{className:"mx-auto max-w-[1440px]",children:[e.jsxs("header",{className:"mb-5 flex flex-col justify-between gap-4 sm:flex-row sm:items-end",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[.06em] text-gray-500",children:"CRM"}),e.jsx("h1",{className:"mt-1 text-2xl font-semibold text-gray-900 dark:text-white",children:t("crm.contacts.title")}),e.jsx("p",{className:"mt-1 max-w-xl text-sm text-gray-500",children:t("crm.contacts.description","Individuals we track: professional genealogists, amateur researchers, press, partner staff and prospects.")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{size:"sm",variant:"outline",startIcon:e.jsx($e,{}),disabled:a||p||!A.length,onClick:ge,children:t("actions.export_csv","Export CSV")}),e.jsx(E,{size:"sm",variant:"outline",onClick:()=>J(!0),children:t("crm.contacts.import_csv","Import CSV")}),e.jsx(se,{to:"/crm/contacts/new",children:e.jsxs(E,{size:"sm",children:[e.jsx(Pe,{}),t("crm.contacts.new")]})})]})]}),e.jsx("section",{"aria-label":t("crm.contacts.summary.label","Contact summary"),className:"mb-5 grid grid-cols-2 gap-3 xl:grid-cols-4",children:he.map(([s,y],C)=>e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white px-4 py-3 dark:border-gray-800 dark:bg-white/[.03]",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-500",children:s}),e.jsx("p",{className:`mt-1 text-[22px] font-semibold ${C===3?"text-warning-600":"text-gray-900 dark:text-white"}`,children:y.toLocaleString(o.language)})]},s))}),e.jsxs("section",{className:"overflow-hidden rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/[.03]",children:[e.jsxs("div",{className:"flex flex-wrap gap-3 border-b border-gray-100 p-4 dark:border-gray-800",children:[e.jsx("input",{"aria-label":t("crm.contacts.search"),placeholder:t("crm.contacts.search","Search name, email, company, specialism"),value:v,onCh
2ange:s=>{f(s.target.value),L()},className:"h-10 min-w-60 flex-1 rounded-lg border border-gray-300 bg-transparent px-3 text-sm outline-none focus:border-brand-400 dark:border-gray-700 dark:bg-gray-900 dark:text-white"}),e.jsxs("select",{"aria-label":t("crm.contacts.type_filter","Filter by type"),value:I,onChange:s=>{O(s.target.value),L()},className:"h-10 rounded-lg border border-gray-300 bg-transparent px-3 text-sm dark:border-gray-700 dark:bg-gray-900 dark:text-white",children:[e.jsx("option",{value:"",children:t("crm.contacts.all_types","All types")}),ne.map(s=>e.jsx("option",{value:s,children:t(`crm.contact.types.${s}`,Le[s])},s))]}),e.jsxs("select",{"aria-label":t("crm.contacts.stage_filter","Filter by stage"),value:S,onChange:s=>{b(s.target.value),L()},className:"h-10 rounded-lg border border-gray-300 bg-transparent px-3 text-sm dark:border-gray-700 dark:bg-gray-900 dark:text-white",children:[e.jsx("option",{value:"",children:t("crm.contacts.all_stages","All stages")}),ie.map(s=>e.jsx("option",{value:s,children:t(`crm.contact.stages.${s}`,Oe[s])},s))]}),e.jsxs("select",{"aria-label":t("crm.contacts.repository_filter","Filter by repository access"),value:n,onChange:s=>{j(s.target.value),L()},className:"h-10 rounded-lg border border-gray-300 bg-transparent px-3 text-sm dark:border-gray-700 dark:bg-gray-900 dark:text-white",children:[e.jsx("option",{value:"",children:t("crm.contacts.repository_any","Any repository access")}),e.jsx("option",{value:"with",children:t("crm.contacts.repository_with","With repository access")}),e.jsx("option",{value:"without",children:t("crm.contacts.repository_without","No repository access")})]}),e.jsxs("select",{"aria-label":t("crm.contacts.country_filter","Filter by country"),value:P,onChange:s=>{ce(s.target.value),L()},className:"h-10 rounded-lg border border-gray-300 bg-transparent px-3 text-sm dark:border-gray-700 dark:bg-gray-900 dark:text-white",children:[e.jsx("option",{value:"",children:t("crm.contacts.all_countries","All countries")}),ue.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value)),xe&&e.jsx("option",{value:W,children:t("crm.contacts.no_country","No country")})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[980px] text-left",children:[e.jsx("thead",{className:"border-b border-gray-100 bg-gray-25 text-xs uppercase tracking-wide text-gray-500 dark:border-gray-800 dark:bg-gray-900",children:e.jsx("tr",{children:["name","type","company","country","stage","owner","last_activity"].map(s=>e.jsx("th",{className:"px-4 py-3 font-medium",children:t(`crm.contacts.columns.${s}`,s.replace("_"," "))},s))})}),e.jsxs("tbody",{children:[a&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-sm",children:t("common.loading")})}),!a&&p&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-sm text-error-600",children:t("crm.contacts.load_error")})}),!a&&!p&&!V.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-sm text-gray-500",children:t("crm.contacts.empty")})}),V.map(s=>e.jsxs("tr",{tabIndex:0,role:"button","aria-label":t("crm.contacts.open_contact",{defaultValue:"Open {{name}}",name:Y(s)}),onClick:()=>z(s.id),onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),z(s.id))},className:"border-b border-gray-100 text-sm outline-none transition-colors hover:bg-gray-50 focus:bg-brand-25 dark:border-gray-800 dark:hover:bg-white/[.03] dark:focus:bg-brand-500/10",children:[e.jsxs("td",{className:"px-5 py-3",children:[e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:Y(s)}),e.jsx("p",{className:"text-xs text-gray-500",children:s.jobTitle||"â"})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(Te,{type:s.type})}),e.jsx("td",{className:"px-4 py-3 text-gray-700 dark:text-gray-300",children:Q.get(s.companyId??"")?.name||"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(ae,{code:s.countryISOA3})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(re,{stage:s.lifecycleStage})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(Me,{owner:Z.get(s.ownerId??"")})}),e.jsx("td",{className:"px-4 py-3 text-xs text-gray-500",children:s.lastActivityAt?new Intl.DateTimeFormat(o.language,{day:"2-digit",month:"short",year:"numeric"}).format(s.lastActivityAt):"â"})]},s.id))]})]})}),e.jsxs("footer",{className:"flex flex-col items-center justify-between gap-3 border-t border-gray-100 px-4 py-3 text-sm text-gray-500 dark:border-gray-800 sm:flex-row",children:[e.jsx("span",{children:A.length?t("common.showing_entr
2ies",{from:F+1,to:F+V.length,total:A.length}):t("crm.contacts.no_matches","No contacts match these filters")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{size:"sm",variant:"outline",disabled:R<=1,onClick:()=>$(s=>Math.max(1,s-1)),children:t("common.previous","Previous")}),e.jsx("span",{className:"min-w-20 text-center",children:t("crm.contacts.page",{defaultValue:"Page {{page}} of {{total}}",page:R,total:M})}),e.jsx(E,{size:"sm",variant:"outline",disabled:R>=M,onClick:()=>$(s=>Math.min(M,s+1)),children:t("common.next","Next")})]})]})]})]}),e.jsx(We,{contact:_,company:_?Q.get(_.companyId??""):void 0,owner:_?Z.get(_.ownerId??""):void 0,repositories:r,onClose:()=>z(null),onActivityCreated:s=>g(y=>y.map(C=>C.id===_?.id?{...C,lastActivityAt:s.createdAt,lastActivitySummary:s.text}:C))}),e.jsx(Ye,{open:pe,onClose:()=>J(!1),contacts:m,companies:l,repositories:r,owners:k,onImported:()=>N(s=>s+1)})]})}export{gt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.