"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2063],{62063:(e,t,s)=>{s.r(t),s.d(t,{default:()=>tr});var a=s(95155),r=s(12115),l=s(50910),n=s(73321),o=s(40091),i=s(7810),c=s(41585),d=s(80723),u=s(4474),m=s(76715),x=s(2128),h=s(55510),p=s(29857),f=s(58515),g=s(36201),b=s(61878),j=s(33210),v=s(92622),y=s(9199),k=s(92289),N=s(85118),w=s(17243),C=s(6962),_=s(68459),A=s(75517),S=s(57684),O=s(39658),M=s(95885),z=s(91337),I=s(64317);function $({contact:e,isSelected:t,isChecked:s,hasSelection:l,density:n,selectedContactIds:o,onClick:i,onCheckboxClick:c,onContextMenu:d}){let u=(0,I.YM)(e),m=(0,I.Bp)(e),x=e.organizations?Object.values(e.organizations)[0]?.name:void 0,h=(0,r.useCallback)(t=>{let s=o.has(e.id)?Array.from(o):[e.id];t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setData("application/x-contact-ids",JSON.stringify(s)),t.dataTransfer.setData("text/plain",u||m||e.id);let a=document.createElement("div");a.style.cssText=`
      position: fixed; top: -9999px; left: 0;
      padding: 8px 16px; background-color: var(--color-primary, #3b82f6);
      color: var(--color-primary-foreground, #ffffff); border-radius: 8px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.15); font-size: 14px; font-weight: 500;
      z-index: 9999; white-space: nowrap; pointer-events: none;
    `,a.textContent=1===s.length?u||"1 contact":`${s.length} contacts`,document.body.appendChild(a),t.dataTransfer.setDragImage(a,0,0),requestAnimationFrame(()=>a.remove())},[e.id,u,m,o]);return(0,a.jsxs)("div",{draggable:!0,onDragStart:h,onClick:i,onContextMenu:d?t=>d(t,e):void 0,className:(0,z.cn)("w-full flex items-center cursor-pointer select-none transition-all duration-200 border-b border-border",t?"bg-selection shadow-sm":"bg-background hover:bg-muted hover:shadow-sm",s&&!t&&"ring-2 ring-primary/20 bg-selection/60"),style:{gap:"var(--density-item-gap)",paddingInline:"16px",paddingBlock:"var(--density-item-py)"},children:[l&&(0,a.jsx)("button",{onClick:c,className:(0,z.cn)("p-1 rounded flex-shrink-0 transition-all duration-200","hover:bg-muted/50 hover:scale-110","active:scale-95","animate-in fade-in zoom-in-95 duration-150",s&&"text-primary"),children:s?(0,a.jsx)(f.A,{className:"w-4 h-4 animate-in zoom-in-50 duration-200"}):(0,a.jsx)(g.A,{className:"w-4 h-4 text-muted-foreground opacity-60 hover:opacity-100 transition-opacity"})}),"extra-compact"!==n&&(0,a.jsx)(M.e,{name:u,email:m,size:"sm",className:"flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-sm font-medium truncate",children:u||m||"-"}),"extra-compact"!==n&&m&&u&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:m}),"comfortable"===n&&x&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:x})]})]})}var B=s(97497),T=s(7915),D=s(49387),E=s(13986),L=s(67635),R=s(81262),F=s(33010);function U(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Y(e,t){let s=window.open("","_blank");if(!s)return;let a=t||(0,I.YM)(e),r=(0,I.$q)(e),l=e.emails?Object.values(e.emails):[],n=e.phones?Object.values(e.phones):[],o=e.organizations?Object.values(e.organizations):[],i=e.titles?Object.values(e.titles):[],c=e.addresses?Object.values(e.addresses):[],d=e.onlineServices?Object.values(e.onlineServices):[],u=e.notes?Object.values(e.notes):[],m=e.anniversaries?Object.values(e.anniversaries):[],x=[],h=(e,t)=>{0!==t.length&&x.push(`<section><h2>${U(e)}</h2><dl>${t.join("")}</dl></section>`)},p=(e,t)=>`<dt>${U(e)}</dt><dd>${U(t)}</dd>`;h("Email",l.map(e=>p(e.label||"Email",e.address||""))),h("Phone",n.map(e=>p(e.label||"Phone",e.number||""))),h("Organization",o.map(e=>{let t=e.units?Object.values(e.units).map(e=>e.name).filter(Boolean).join(", "):"";return p("Organization",[e.name,t].filter(Boolean).join(" — "))})),h("Title",i.map(e=>p("role"===e.kind?"Role":"Title",e.name||""))),h("Address",c.map(e=>{let t=[e.street,e.locality,e.region,e.postcode,e.country].map(e=>"string"==typeof e?e:"").filter(Boolean);return p(e.label||"Address",t.join(", "))})),h("Online",d.map(e=>p(e.label||e.service||"Online",e.uri||e.user||""))),h("Anniversary",m.map(e=>{let t=e.date,s="";if("object"==typeof t&&null!==t)if("utc"in t&&"string"==typeof t.utc)s=t.utc;else{let e=[];t.year&&e.push(String(t.year)),t.month&&e.push(String(t.month).padStart(2,"0")),t.day&&e.push(String(t.day).padStart(2,"0")),s=e.join("-")}else t&&(s=String(t));return p(e.kind||"Date",s)})),h("Notes",u.map(e=>p("",e.note||"")));let f=r?`<img class="photo" src="${U(r)}" alt="" />`:`<div class="photo placeholder">${U((a||"?").charAt(0).toUpperCase())}</div>`,g=`<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>${U(a||"Contact")}</title>
<style>
  * { box-sizing: border-box; }
  body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #111; margin: 32px; }
  header { display: flex; align-items: center; gap: 20px; padding-bottom: 16px; border-bottom: 1px solid #ccc; }
  .photo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
  .photo.placeholder { background: #e5e7eb; color: #4b5563; display: flex; align-items: center; justify-content: center; font-size: 36px; font-weight: 600; }
  h1 { margin: 0; font-size: 22px; }
  section { margin-top: 20px; }
  h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #555; margin: 0 0 8px; }
  dl { margin: 0; display: grid; grid-template-columns: 140px 1fr; row-gap: 6px; column-gap: 16px; font-size: 14px; }
  dt { color: #555; }
  dd { margin: 0; word-break: break-word; }
  @media print { body { margin: 16mm; } }
</style>
</head>
<body>
<header>
  ${f}
  <div><h1>${U(a||"Contact")}</h1></div>
</header>
${x.join("")}
</body>
</html>`;s.document.write(g),s.document.close(),s.focus(),s.print()}var P=s(1506);function G({contact:e,position:t,isOpen:s,onClose:r,menuRef:n,isMultiSelect:o=!1,selectedCount:c=1,onOpen:d,onEdit:u,onDelete:m,onAddToGroup:x,onDuplicate:h,onBatchExport:p,onBatchAddToGroup:f,onBatchDelete:g}){let b=(0,l.c)("contacts"),j=(0,I.Bp)(e),v=e.phones&&Object.values(e.phones)[0]?.number||"",y=e=>()=>{e(),r()},w=async e=>{if(e)try{await navigator.clipboard.writeText(e),P.o.success(b("detail.copied"))}catch{P.o.error(b("detail.copy_failed"))}};return o&&c>1?(0,a.jsxs)(B.tz,{ref:n,isOpen:s,position:t,onClose:r,children:[(0,a.jsx)(B.Sp,{children:b("bulk.selected",{count:c})}),(0,a.jsx)(B.kt,{icon:i.A,label:b("bulk.add_to_group"),onClick:y(()=>f?.()),disabled:!f}),(0,a.jsx)(B.kt,{icon:C.A,label:b("bulk.export"),onClick:y(()=>p?.()),disabled:!p}),(0,a.jsx)(B.K5,{}),(0,a.jsx)(B.kt,{icon:_.A,label:b("bulk.delete"),onClick:y(()=>g?.()),disabled:!g,destructive:!0})]}):(0,a.jsxs)(B.tz,{ref:n,isOpen:s,position:t,onClose:r,children:[(0,a.jsx)(B.kt,{icon:T.A,label:b("context_menu.open"),onClick:y(d)}),(0,a.jsx)(B.kt,{icon:D.A,label:b("context_menu.edit"),onClick:y(u)}),(j||v)&&(0,a.jsx)(B.K5,{}),j&&(0,a.jsx)(B.kt,{icon:k.A,label:b("context_menu.send_email"),onClick:y(()=>{j&&(window.location.href=`mailto:${j}`)})}),v&&(0,a.jsx)(B.kt,{icon:N.A,label:b("context_menu.call"),onClick:y(()=>{v&&(window.location.href=`tel:${v}`)})}),j&&(0,a.jsx)(B.kt,{icon:E.A,label:b("detail.copy_email"),onClick:y(()=>w(j))}),v&&(0,a.jsx)(B.kt,{icon:E.A,label:b("detail.copy_phone"),onClick:y(()=>w(v))}),(0,a.jsx)(B.K5,{}),(0,a.jsx)(B.kt,{icon:i.A,label:b("context_menu.add_to_group"),onClick:y(x)}),h&&(0,a.jsx)(B.kt,{icon:L.A,label:b("context_menu.duplicate"),onClick:y(h)}),(0,a.jsx)(B.kt,{icon:C.A,label:b("context_menu.export_vcard"),onClick:y(()=>{(0,F.J)(e),P.o.success(b("export.success",{count:1}))})}),(0,a.jsx)(B.kt,{icon:R.A,label:b("context_menu.print"),onClick:y(()=>{Y(e)})}),(0,a.jsx)(B.K5,{}),(0,a.jsx)(B.kt,{icon:_.A,label:b("context_menu.delete"),onClick:y(m),destructive:!0})]})}var K=s(74530),W=s(88230);let J={organization:"",jobTitle:"",location:"",emailDomain:"",birthdayMonth:null,hasEmail:null,hasPhone:null,hasPhoto:null};function q(e){return null===e||!0!==e&&null}function H(e,t){return null===t||e===t}function V({icon:e,label:t,value:s,onClick:r}){return(0,a.jsxs)("button",{type:"button",onClick:r,className:(0,z.cn)("inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs transition-colors border",!0===s&&"bg-primary/10 border-primary/30 text-primary",!1===s&&"bg-muted border-border text-muted-foreground line-through",null===s&&"bg-background border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),children:[e,t]})}function Z({contacts:e,selectedContactId:t,searchQuery:s,onSearchChange:n,onSelectContact:o,onCreateNew:c,className:d,selectedContactIds:m,onToggleSelection:x,onSelectRangeContacts:M,onSelectAll:B,onClearSelection:T,onBulkDelete:D,onBulkAddToGroup:E,onBulkExport:L,onEditContact:R,onDeleteContact:F,onAddContactToGroup:U,onMenuClick:Y}){let P,X,Q=(0,l.c)("contacts"),ee=(0,h.Ym)(),et=(0,W.C$)(e=>e.density),es=(0,W.C$)(e=>e.groupContactsByLetter),{contextMenu:ea,openContextMenu:er,closeContextMenu:el,menuRef:en}=(0,K.E)(),[eo,ei]=(0,r.useState)(!1),[ec,ed]=(0,r.useState)(J),eu=(P=0,ec.organization.trim()&&P++,ec.jobTitle.trim()&&P++,ec.location.trim()&&P++,ec.emailDomain.trim()&&P++,null!==ec.birthdayMonth&&P++,null!==ec.hasEmail&&P++,null!==ec.hasPhone&&P++,null!==ec.hasPhoto&&P++,P),em=(0,r.useMemo)(()=>{let e=new Intl.DateTimeFormat(ee,{month:"long"});return Array.from({length:12},(t,s)=>e.format(new Date(2e3,s,1)))},[ee]),ex=(0,r.useMemo)(()=>{let t=s.trim().toLowerCase(),a=ec.organization.trim().toLowerCase(),r=ec.jobTitle.trim().toLowerCase(),l=ec.location.trim().toLowerCase(),n=ec.emailDomain.trim().toLowerCase().replace(/^@/,"");return e.filter(e=>{let s=e.emails?Object.values(e.emails):[],o=e.phones?Object.values(e.phones):[],i=e.organizations?Object.values(e.organizations):[],c=e.titles?Object.values(e.titles):[],d=e.addresses?Object.values(e.addresses):[],u=e.anniversaries?Object.values(e.anniversaries):[];if(!H(s.length>0,ec.hasEmail)||!H(o.length>0,ec.hasPhone)||!H(!!(0,I.$q)(e),ec.hasPhoto)||a&&!i.some(e=>!!(e.name?.toLowerCase().includes(a)||e.units?.some(e=>e.name?.toLowerCase().includes(a))))||r&&!c.some(e=>e.name?.toLowerCase().includes(r))||l&&!d.some(e=>{let t=[];if(e.full&&t.push(e.full),e.fullAddress&&t.push(e.fullAddress),e.locality&&t.push(e.locality),e.region&&t.push(e.region),e.country&&t.push(e.country),e.postcode&&t.push(e.postcode),e.street&&t.push(e.street),e.components)for(let s of e.components)s.value&&t.push(s.value);return t.some(e=>e.toLowerCase().includes(l))})||n&&!s.some(e=>{let t=e.address?.toLowerCase().split("@");return t&&t.length>1&&t[1].includes(n)}))return!1;if(null!==ec.birthdayMonth){let e=ec.birthdayMonth;if(!u.some(t=>"birth"===t.kind&&function(e){if("string"==typeof e){let t=e.match(/^(\d{4})-(\d{2})/);if(t)return parseInt(t[2],10);let s=e.match(/^--(\d{2})/);return s?parseInt(s[1],10):null}if("month"in e&&e.month)return e.month;if("utc"in e&&e.utc){let t=new Date(e.utc);return isNaN(t.getTime())?null:t.getMonth()+1}return null}(t.date)===e))return!1}return!!(!t||(0,I.YM)(e).toLowerCase().includes(t)||s.some(e=>e.address?.toLowerCase().includes(t))||o.some(e=>e.number?.toLowerCase().includes(t))||i.some(e=>e.name?.toLowerCase().includes(t)))})},[e,s,ec]),eh=(0,r.useMemo)(()=>[...ex].sort((e,t)=>{let s=(0,I.YM)(e).toLowerCase(),a=(0,I.YM)(t).toLowerCase();return s.localeCompare(a)}),[ex]),ep=(0,r.useMemo)(()=>eh.map(e=>e.id),[eh]),ef=(0,r.useMemo)(()=>{let e=new Intl.Collator(ee,{sensitivity:"base"}),t=new Map;for(let e of eh){let s=(0,I.YM)(e).trim().charAt(0),a=s&&s.toLocaleUpperCase(ee).match(/\p{L}/u)?s.toLocaleUpperCase(ee):"#",r=t.get(a);r?r.push(e):t.set(a,[e])}return Array.from(t.entries()).sort(([t],[s])=>"#"===t?1:"#"===s?-1:e.compare(t,s)).map(([e,t])=>({letter:e,items:t}))},[eh,ee]),eg=m.size>0,eb=eh.length>0&&eh.every(e=>m.has(e.id));return(0,a.jsxs)("div",{className:(0,z.cn)("flex flex-col h-full",d),children:[(0,a.jsx)("div",{className:"border-b border-border bg-background",children:(0,a.jsx)("div",{className:"px-3 py-3",children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[Y&&(0,a.jsx)("button",{type:"button",onClick:Y,className:"flex-shrink-0 p-2 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors","aria-label":Q("open_categories"),children:(0,a.jsx)(p.A,{className:"w-4 h-4"})}),(0,a.jsx)("button",{type:"button",onClick:()=>{eg?eb?T():B(ep):ep.length>0&&x(t&&ep.includes(t)?t:ep[0])},className:(0,z.cn)("flex-shrink-0 p-2 rounded-md transition-colors",eg?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:Q(eg?eb?"bulk.clear":"bulk.select_all":"filters.select"),children:eg?(0,a.jsx)(f.A,{className:"w-4 h-4"}):(0,a.jsx)(g.A,{className:"w-4 h-4"})}),(0,a.jsxs)("div",{className:"relative flex-1",children:[(0,a.jsx)(b.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),(0,a.jsx)(O.p,{type:"text",placeholder:Q("search_placeholder"),value:s,onChange:e=>n(e.target.value),className:(0,z.cn)("ps-9 h-9",s&&"pe-8")}),s&&(0,a.jsx)("button",{type:"button",onClick:()=>n(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded-full hover:bg-muted text-muted-foreground hover:text-foreground transition-colors","aria-label":Q("clear_search"),children:(0,a.jsx)(j.A,{className:"w-4 h-4"})})]}),(0,a.jsxs)("button",{type:"button",onClick:()=>ei(e=>!e),className:(0,z.cn)("relative flex-shrink-0 p-2 rounded-md transition-colors",eo||eu>0?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:Q("filters.toggle"),"aria-label":Q("filters.toggle"),children:[(0,a.jsx)(v.A,{className:"w-4 h-4"}),!eo&&eu>0&&(0,a.jsx)("span",{className:"absolute -top-1 -right-1 flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded-full bg-primary text-primary-foreground",children:eu})]})]})})}),eo&&(0,a.jsx)("div",{className:"border-b border-border bg-muted/30 animate-in slide-in-from-top-2 fade-in duration-200",children:(0,a.jsxs)("div",{className:"px-4 py-3 space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-foreground",children:Q("filters.title")}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsxs)(u.$,{variant:"ghost",size:"sm",onClick:()=>ed(J),className:"h-7 px-2 text-xs",children:[(0,a.jsx)(y.A,{className:"w-3 h-3 me-1"}),Q("filters.clear")]}),(0,a.jsx)(u.$,{variant:"ghost",size:"icon",onClick:()=>ei(!1),className:"h-7 w-7","aria-label":Q("filters.close"),children:(0,a.jsx)(j.A,{className:"w-4 h-4"})})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:Q("filters.organization")}),(0,a.jsx)(O.p,{value:ec.organization,onChange:e=>ed(t=>({...t,organization:e.target.value})),placeholder:Q("filters.organization_placeholder"),className:"h-8 text-sm"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:Q("filters.job_title")}),(0,a.jsx)(O.p,{value:ec.jobTitle,onChange:e=>ed(t=>({...t,jobTitle:e.target.value})),placeholder:Q("filters.job_title_placeholder"),className:"h-8 text-sm"})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:Q("filters.location")}),(0,a.jsx)(O.p,{value:ec.location,onChange:e=>ed(t=>({...t,location:e.target.value})),placeholder:Q("filters.location_placeholder"),className:"h-8 text-sm"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:Q("filters.email_domain")}),(0,a.jsx)(O.p,{value:ec.emailDomain,onChange:e=>ed(t=>({...t,emailDomain:e.target.value})),placeholder:Q("filters.email_domain_placeholder"),className:"h-8 text-sm"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:Q("filters.birthday_month")}),(0,a.jsxs)("select",{value:ec.birthdayMonth??"",onChange:e=>ed(t=>({...t,birthdayMonth:""===e.target.value?null:Number(e.target.value)})),className:"h-8 w-full text-sm rounded-md border border-input bg-background px-2","aria-label":Q("filters.birthday_month"),children:[(0,a.jsx)("option",{value:"",children:Q("filters.any_month")}),em.map((e,t)=>(0,a.jsx)("option",{value:t+1,children:e},t))]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,a.jsx)(V,{icon:(0,a.jsx)(k.A,{className:"w-3.5 h-3.5"}),label:Q("filters.has_email"),value:ec.hasEmail,onClick:()=>ed(e=>({...e,hasEmail:q(e.hasEmail)}))}),(0,a.jsx)(V,{icon:(0,a.jsx)(N.A,{className:"w-3.5 h-3.5"}),label:Q("filters.has_phone"),value:ec.hasPhone,onClick:()=>ed(e=>({...e,hasPhone:q(e.hasPhone)}))}),(0,a.jsx)(V,{icon:(0,a.jsx)(w.A,{className:"w-3.5 h-3.5"}),label:Q("filters.has_photo"),value:ec.hasPhoto,onClick:()=>ed(e=>({...e,hasPhoto:q(e.hasPhoto)}))})]})]})}),eg&&(0,a.jsxs)("div",{className:"px-3 py-1.5 border-b border-border bg-accent/30 flex items-center gap-2 flex-wrap",children:[(0,a.jsx)("button",{onClick:()=>{eb?T():B(ep)},className:"p-1 rounded hover:bg-muted/50 transition-colors",children:eb?(0,a.jsx)(f.A,{className:"w-4 h-4 text-primary"}):(0,a.jsx)(g.A,{className:"w-4 h-4 text-muted-foreground"})}),(0,a.jsx)("span",{className:"text-xs font-medium text-foreground",children:Q("bulk.selected",{count:m.size})}),(0,a.jsx)("div",{className:"flex-1"}),(0,a.jsxs)(u.$,{variant:"ghost",size:"sm",onClick:E,className:"h-7 text-xs",children:[(0,a.jsx)(i.A,{className:"w-3.5 h-3.5 me-1"}),Q("bulk.add_to_group")]}),(0,a.jsxs)(u.$,{variant:"ghost",size:"sm",onClick:L,className:"h-7 text-xs",children:[(0,a.jsx)(C.A,{className:"w-3.5 h-3.5 me-1"}),Q("bulk.export")]}),(0,a.jsxs)(u.$,{variant:"ghost",size:"sm",onClick:D,className:"h-7 text-xs text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300",children:[(0,a.jsx)(_.A,{className:"w-3.5 h-3.5 me-1"}),Q("bulk.delete")]}),(0,a.jsx)(u.$,{variant:"ghost",size:"icon",onClick:T,className:"h-7 w-7",children:(0,a.jsx)(j.A,{className:"w-3.5 h-3.5"})})]}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===eh.length?(0,a.jsx)("div",{className:"flex flex-col items-center justify-center h-full px-6 text-center",children:s||eu>0?(0,a.jsxs)(a.Fragment,{children:[eu>0&&!s?(0,a.jsx)(v.A,{className:"w-10 h-10 mb-3 text-muted-foreground/30"}):(0,a.jsx)(b.A,{className:"w-10 h-10 mb-3 text-muted-foreground/30"}),(0,a.jsx)("p",{className:"text-sm font-medium text-foreground",children:Q(s?"empty_search":"empty_filtered")}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:Q(s?"empty_search_hint":"empty_filtered_hint")}),(0,a.jsxs)("div",{className:"flex gap-2 mt-3",children:[s&&(0,a.jsx)(u.$,{variant:"outline",size:"sm",onClick:()=>n(""),children:Q("clear_search")}),eu>0&&(0,a.jsxs)(u.$,{variant:"outline",size:"sm",onClick:()=>ed(J),children:[(0,a.jsx)(y.A,{className:"w-3.5 h-3.5 me-1"}),Q("filters.clear")]})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(A.A,{className:"w-10 h-10 mb-3 text-muted-foreground/30"}),(0,a.jsx)("p",{className:"text-sm font-medium text-foreground",children:Q("empty_state_title")}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:Q("empty_state_subtitle")}),(0,a.jsxs)(u.$,{size:"sm",className:"mt-3",onClick:c,children:[(0,a.jsx)(S.A,{className:"w-4 h-4 me-1.5"}),Q("create_new")]})]})}):(X=e=>(0,a.jsx)($,{contact:e,isSelected:e.id===t,isChecked:m.has(e.id),hasSelection:eg,density:et,selectedContactIds:m,onClick:t=>{t.ctrlKey||t.metaKey?(t.preventDefault(),x(e.id)):t.shiftKey?(t.preventDefault(),M(e.id,ep)):(eg&&T(),o(e.id))},onCheckboxClick:t=>{t.stopPropagation(),x(e.id)},onContextMenu:(e,t)=>er(e,t)},e.id),es?(0,a.jsx)("div",{children:ef.map(({letter:e,items:t})=>(0,a.jsxs)("section",{children:[(0,a.jsx)("div",{className:"sticky top-0 z-10 px-4 py-0.5 bg-background/90 backdrop-blur-sm text-[11px] font-medium text-muted-foreground/70 uppercase tracking-wide",children:e}),t.map(X)]},e))}):(0,a.jsx)("div",{children:eh.map(X)}))}),ea.data&&(0,a.jsx)(G,{contact:ea.data,position:ea.position,isOpen:ea.isOpen,onClose:el,menuRef:en,isMultiSelect:m.has(ea.data.id),selectedCount:m.size,onOpen:()=>o(ea.data.id),onEdit:()=>R(ea.data.id),onDelete:()=>F(ea.data),onAddToGroup:()=>U(ea.data.id),onBatchExport:L,onBatchAddToGroup:E,onBatchDelete:D})]})}var X=s(56204),Q=s(24538),ee=s(92451),et=s(1610),es=s(89974),ea=s(26878),er=s(94338),el=s(27413),en=s(7686),eo=s(35756),ei=s(57420),ec=s(88444),ed=s(60285),eu=s(6296),em=s(555),ex=s(86385),eh=s(64223);function ep({contact:e}){let t=(0,l.c)("contacts.activity"),s=(0,l.k)(),n=(0,o.rd)(),i=(0,em.useAuthStore)(e=>e.client),c=(0,ex.useEmailStore)(e=>e.selectEmail),d=(0,eh.V)(e=>e.setSelectedEventId),u=(0,eh.V)(e=>e.setSelectedDate),[m,x]=(0,r.useState)(null),[h,p]=(0,r.useState)(null),[f,g]=(0,r.useState)(!1),[b,j]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[k,N]=(0,r.useState)(!1),w=function(e){if(!e.emails)return[];let t=new Set,s=[];for(let a of Object.values(e.emails)){let e=a.address?.trim().toLowerCase();e&&!t.has(e)&&(t.add(e),s.push(e))}return s}(e),C=w.join(",");if((0,r.useEffect)(()=>{if(!i||0===w.length)return void x([]);let e=!1;return g(!0),y(!1),i.advancedSearchEmails(function(e){let t=[];for(let s of e)t.push({from:s}),t.push({to:s});return 1===t.length?t[0]:{operator:"OR",conditions:t}}(w),void 0,5,0).then(t=>{e||x(t.emails)}).catch(()=>{e||(y(!0),x([]))}).finally(()=>{e||g(!1)}),()=>{e=!0}},[i,C]),(0,r.useEffect)(()=>{if(!i||0===w.length)return void p([]);let e=!1;j(!0),N(!1);let t=new Date,s=new Date(t.getTime()+31536e6),a=new Set(w);return i.queryAllCalendarEvents({after:t.toISOString(),before:s.toISOString()},[{property:"start",isAscending:!0}],500).then(t=>{e||p(t.filter(e=>(function(e,t){if(e.participants)for(let s of Object.values(e.participants)){let e=s.email?.trim().toLowerCase();if(e&&t.has(e))return!0;if(s.sendTo)for(let e of Object.values(s.sendTo)){let s="string"==typeof e?e.match(/mailto:(.+)/i):null;if(s&&t.has(s[1].trim().toLowerCase()))return!0}}if(e.organizerCalendarAddress){let s=e.organizerCalendarAddress.match(/mailto:(.+)/i),a=s?s[1].trim().toLowerCase():e.organizerCalendarAddress.trim().toLowerCase();if(t.has(a))return!0}return!1})(e,a)).sort((e,t)=>e.start.localeCompare(t.start)).slice(0,5))}).catch(()=>{e||(N(!0),p([]))}).finally(()=>{e||j(!1)}),()=>{e=!0}},[i,C]),0===w.length)return null;let _=h?Array.from((function(e){let t=new Map;for(let s of e){let e=new Date(s.start),a=isNaN(e.getTime())?s.start:e.toISOString().slice(0,10),r=t.get(a)||[];r.push(s),t.set(a,r)}return t})(h).entries()):[];return(0,a.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 lg:gap-x-8",children:[(0,a.jsx)(ev,{title:t("recent_emails"),children:f?(0,a.jsx)(ef,{}):v?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:t("load_failed")}):m&&0!==m.length?(0,a.jsx)("div",{className:"-mx-2",children:m.map(e=>{let r,l=(r=e.from?.[0],{name:r?.name?.trim()||r?.email||"",address:r?.email||""});return(0,a.jsxs)("button",{type:"button",onClick:()=>{c(e),n.push("/")},className:"w-full text-start flex items-start gap-3 px-2 py-2 rounded-md hover:bg-muted/60 transition-colors touch-manipulation",children:[(0,a.jsx)(M.e,{name:l.name,email:l.address,size:"sm"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-baseline justify-between gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium truncate",children:l.name||t("unknown_sender")}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:(e=>{let t=new Date(e);if(isNaN(t.getTime()))return e;let a=new Date,r=t.getFullYear()===a.getFullYear();return s.dateTime(t,r?{month:"short",day:"numeric"}:{year:"numeric",month:"short",day:"numeric"})})(e.receivedAt)})]}),(0,a.jsx)("div",{className:"text-sm truncate",children:e.subject||t("no_subject")}),e.preview&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:e.preview})]})]},e.id)})}):(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:t("no_emails")})}),(0,a.jsx)(ev,{title:t("upcoming_events"),children:b?(0,a.jsx)(ef,{}):k?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:t("load_failed")}):h&&0!==h.length?(0,a.jsx)("div",{className:"space-y-4",children:_.map(([e,r])=>(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:(e=>{let t=new Date(e);if(isNaN(t.getTime()))return e;let a=new Date,r=t.getFullYear()===a.getFullYear();return s.dateTime(t,r?{weekday:"long",month:"long",day:"numeric"}:{weekday:"long",year:"numeric",month:"long",day:"numeric"})})(e)}),(0,a.jsx)("div",{className:"-mx-2",children:r.map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>{let t;!isNaN((t=new Date(e.start)).getTime())&&u(t),d(e.id),n.push("/calendar")},className:"w-full text-start flex items-baseline gap-3 px-2 py-2 rounded-md hover:bg-muted/60 transition-colors touch-manipulation",children:[(0,a.jsx)("span",{className:"text-xs text-muted-foreground tabular-nums w-20 flex-shrink-0",children:(e=>{if(e.showWithoutTime)return t("all_day");let a=new Date(e.start);return isNaN(a.getTime())?"":s.dateTime(a,{hour:"numeric",minute:"2-digit"})})(e)}),(0,a.jsx)("span",{className:"text-sm truncate flex-1 min-w-0",children:e.title||t("no_title")})]},e.id))})]},e))}):(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:t("no_events")})})]})}function ef(){return(0,a.jsx)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:(0,a.jsx)(eu.A,{className:"w-4 h-4 animate-spin"})})}function eg(e){if("object"==typeof e&&null!==e){if("Timestamp"===e["@type"]&&"string"==typeof e.utc){try{let t=new Date(e.utc);if(!isNaN(t.getTime()))return t.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{}return String(e.utc)}let t=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],s=[];return e.month&&t[e.month-1]&&s.push(t[e.month-1]),e.day&&s.push(String(e.day)),e.year&&s.push(String(e.year)),s.join(" ")||String(e)}let t=String(e);if(t.startsWith("--")){let e=t.substring(2).split("-"),s=parseInt(e[0],10),a=e[1]?parseInt(e[1],10):void 0,r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return a?`${r[s-1]} ${a}`:r[s-1]}try{let e=new Date(t);if(!isNaN(e.getTime()))return e.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{}return t}function eb({contact:e,onEdit:t,onDelete:s,onAddToGroup:r,onDuplicate:n,onCompose:o,isMobile:c,className:d}){let m,x=(0,l.c)("contacts"),h=e?.cryptoKeys?Object.values(e.cryptoKeys):[];if(!e)return(0,a.jsxs)("div",{className:(0,z.cn)("flex flex-col items-center justify-center h-full text-muted-foreground",d),children:[(0,a.jsx)(A.A,{className:"w-16 h-16 mb-4 opacity-20"}),(0,a.jsx)("p",{className:"text-sm",children:x("detail.no_contact_selected")})]});let p=(0,I.YM)(e),f=(0,I.Bp)(e),g=(0,I.$q)(e),b=e.phones?Object.values(e.phones)[0]?.number:void 0,j=[];r&&j.push({icon:i.A,label:x("context_menu.add_to_group"),onClick:r}),n&&j.push({icon:L.A,label:x("context_menu.duplicate"),onClick:n}),j.push({icon:C.A,label:x("context_menu.export_vcard"),onClick:()=>{(0,F.J)(e),P.o.success(x("export.success",{count:1}))}}),j.push({icon:R.A,label:x("context_menu.print"),onClick:()=>{Y(e,p)}}),j.push({separator:!0}),j.push({icon:_.A,label:x("context_menu.delete"),onClick:s,destructive:!0});let v=e.emails?Object.values(e.emails):[],y=e.phones?Object.values(e.phones):[],w=e.organizations?Object.values(e.organizations):[],S=e.addresses?Object.values(e.addresses):[],O=e.notes?Object.values(e.notes):[],$=e.titles?Object.values(e.titles):[],B=$.filter(e=>"role"!==e.kind),T=e.onlineServices?Object.values(e.onlineServices):[],E=e.anniversaries?Object.values(e.anniversaries):[],U=e.keywords?Object.keys(e.keywords).filter(t=>e.keywords[t]):[],G=e.relatedTo?Object.entries(e.relatedTo):[],K=e.preferredLanguages?Object.values(e.preferredLanguages):[],W=e.personalInfo?Object.values(e.personalInfo):[],J=e.nicknames?Object.values(e.nicknames):[],q=J.length>0,H=[B.length>0?B.map(e=>e.name).join(", "):void 0,w[0]?.name].filter(Boolean),V=v.length>0||y.length>0||S.length>0||T.length>0,Z=$.length>0||w.length>0,ed=!!(e.speakToAs&&(e.speakToAs.grammaticalGender||e.speakToAs.pronouns)),eu=E.length>0||W.length>0||ed||K.length>0;return(0,a.jsxs)("div",{className:(0,z.cn)("flex flex-col h-full overflow-y-auto",d),children:[(0,a.jsx)("div",{className:(0,z.cn)("border-b border-border",c?"px-4 py-4":"px-6 py-6"),children:(0,a.jsxs)("div",{className:(0,z.cn)("flex gap-4",c?"flex-col":"items-start justify-between"),children:[(0,a.jsxs)("div",{className:"flex items-center gap-4 min-w-0 flex-1",children:[(0,a.jsx)(M.e,{name:p,email:f,contactPhotoUri:g,size:c?"md":"lg"}),(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)("h2",{className:(0,z.cn)("font-semibold truncate",c?"text-lg":"text-xl"),children:p||"-"}),q&&(0,a.jsxs)("p",{className:"text-sm text-muted-foreground truncate",children:["“",J.map(e=>e.name).join(", "),"”"]}),H.length>0&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground truncate",children:H.join(" \xb7 ")})]})]}),(0,a.jsxs)("div",{className:"flex gap-2 flex-shrink-0 flex-wrap",children:[f&&o&&(0,a.jsxs)(u.$,{variant:"outline",size:"sm",onClick:o,className:"touch-manipulation",children:[(0,a.jsx)(X.A,{className:"w-4 h-4 me-1"}),x("detail.compose_email")]}),b&&(0,a.jsxs)("a",{href:`tel:${b}`,className:"inline-flex items-center justify-center rounded-md font-medium h-9 px-3 text-sm border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors touch-manipulation",children:[(0,a.jsx)(N.A,{className:"w-4 h-4 me-1"}),x("context_menu.call")]}),(0,a.jsxs)(u.$,{variant:"outline",size:"sm",onClick:t,className:"touch-manipulation",children:[(0,a.jsx)(D.A,{className:"w-4 h-4 me-1"}),x("form.edit_title")]}),(0,a.jsx)(eN,{items:j,label:x("detail.more_actions")})]})]})}),(0,a.jsxs)("div",{className:(0,z.cn)("divide-y divide-border/60",c?"px-4":"px-6"),children:[V&&(0,a.jsx)(ev,{title:x("detail.section_contact"),children:(0,a.jsxs)("div",{className:"space-y-3",children:[v.map((e,t)=>(0,a.jsx)(ey,{icon:k.A,label:e.label||ej(e.contexts)||x("detail.email_default_label"),children:(0,a.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,a.jsx)("a",{href:`mailto:${e.address}`,className:"text-sm text-primary hover:underline break-all",children:e.address}),(0,a.jsxs)(ek,{children:[(0,a.jsx)("a",{href:`mailto:${e.address}`,className:"p-1.5 rounded hover:bg-muted transition-colors touch-manipulation",title:x("detail.compose_email"),"aria-label":x("detail.compose_email"),children:(0,a.jsx)(X.A,{className:"w-3.5 h-3.5 text-muted-foreground"})}),(0,a.jsx)(ew,{value:e.address,label:x("detail.copy_email"),successMsg:x("detail.copied"),failMsg:x("detail.copy_failed")})]})]})},`em${t}`)),y.map((e,t)=>{var s;let r=(s=e.features)?Object.keys(s).filter(e=>s[e]).join(", "):"",l=[e.label,ej(e.contexts),r].filter(Boolean);return(0,a.jsx)(ey,{icon:N.A,label:l.length?l.join(" \xb7 "):x("detail.phone_default_label"),children:(0,a.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,a.jsx)("a",{href:`tel:${e.number}`,className:"text-sm text-primary hover:underline",children:e.number}),(0,a.jsx)(ek,{children:(0,a.jsx)(ew,{value:e.number,label:x("detail.copy_phone"),successMsg:x("detail.copied"),failMsg:x("detail.copy_failed")})})]})},`ph${t}`)}),S.map((e,t)=>{let s=[];if(e.full||e.fullAddress)s.push(e.full||e.fullAddress);else if(e.components&&e.components.length>0){let t=e.components.filter(e=>"separator"!==e.kind).map(e=>e.value).filter(Boolean).join(", ");t&&s.push(t)}else{let t=[e.street,[e.postcode,e.locality].filter(Boolean).join(" "),e.region,e.country].map(e=>"string"==typeof e?e.trim():"").filter(Boolean);s.push(...t)}return(0,a.jsx)(ey,{icon:Q.A,label:ej(e.contexts)||x("detail.address_default_label"),children:(0,a.jsxs)("div",{className:"text-sm space-y-0.5",children:[s.map((e,t)=>(0,a.jsx)("div",{children:e},t)),e.timeZone&&(0,a.jsxs)("div",{className:"text-xs text-muted-foreground",children:[x("detail.timezone"),": ",e.timeZone]})]})},`ad${t}`)}),T.map((e,t)=>(0,a.jsx)(ey,{icon:ee.A,label:[e.service,ej(e.contexts)].filter(Boolean).join(" \xb7 ")||x("detail.online_service_default_label"),children:(0,a.jsxs)("div",{className:"flex items-center gap-2 group",children:["string"==typeof e.uri&&e.uri.startsWith("http")?(0,a.jsx)("a",{href:e.uri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:e.user||e.uri}):(0,a.jsx)("span",{className:"text-sm break-all",children:e.user||String(e.uri??"")}),(0,a.jsx)(ek,{children:(0,a.jsx)(ew,{value:e.user||e.uri,label:x("detail.copy_url"),successMsg:x("detail.copied"),failMsg:x("detail.copy_failed")})})]})},`os${t}`))]})}),Z&&(0,a.jsx)(ev,{title:x("detail.section_work"),children:(0,a.jsxs)("div",{className:"space-y-3",children:[w.map((e,t)=>(0,a.jsx)(ey,{icon:et.A,label:x("detail.organization_label"),children:(0,a.jsxs)("div",{className:"text-sm",children:[e.name,e.units&&e.units.length>0&&(0,a.jsxs)("span",{className:"text-muted-foreground",children:[" \xb7 ",e.units.map(e=>e.name).join(", ")]})]})},`org${t}`)),$.map((e,t)=>(0,a.jsx)(ey,{icon:es.A,label:"role"===e.kind?x("detail.role_label"):x("detail.title_label"),children:(0,a.jsx)("div",{className:"text-sm",children:e.name})},`tl${t}`))]})}),eu&&(0,a.jsx)(ev,{title:x("detail.section_personal"),children:(0,a.jsxs)("div",{className:"space-y-3",children:[E.map((e,t)=>{let s=function(e){let{year:t,month:s,day:a}=function(e){if("object"==typeof e&&null!==e){if("Timestamp"===e["@type"]&&"string"==typeof e.utc){let t=new Date(e.utc);return isNaN(t.getTime())?{}:{year:t.getUTCFullYear(),month:t.getUTCMonth()+1,day:t.getUTCDate()}}return{year:e.year,month:e.month,day:e.day}}let t=String(e);if(t.startsWith("--")){let e=t.substring(2).split("-");return{month:parseInt(e[0],10),day:e[1]?parseInt(e[1],10):void 0}}let s=new Date(t);return isNaN(s.getTime())?{}:{year:s.getFullYear(),month:s.getMonth()+1,day:s.getDate()}}(e);if(!t)return null;let r=new Date,l=r.getFullYear()-t,n=s??1,o=r.getMonth()+1,i=r.getDate();return((o<n||o===n&&i<(a??1))&&(l-=1),l<0)?null:l}(e.date),r="birth"===e.kind?"detail.age_years":"detail.years_since";return(0,a.jsx)(ey,{icon:ea.A,label:x(`detail.anniversary_${e.kind}`),children:(0,a.jsxs)("div",{className:"text-sm",children:[eg(e.date),null!==s&&(0,a.jsxs)("span",{className:"text-muted-foreground",children:[" \xb7 ",x(r,{count:s})]})]})},`an${t}`)}),ed&&(0,a.jsx)(ey,{icon:er.A,label:x("detail.gender"),children:(0,a.jsxs)("div",{className:"text-sm",children:[e.speakToAs?.grammaticalGender&&(0,a.jsx)("span",{children:x(`detail.gender_${e.speakToAs.grammaticalGender}`,{defaultValue:e.speakToAs.grammaticalGender})}),e.speakToAs?.pronouns&&((m=Object.values(e.speakToAs.pronouns)[0]?.pronouns)?(0,a.jsxs)("span",{className:"text-muted-foreground",children:[e.speakToAs.grammaticalGender?" \xb7 ":"",m]}):null)]})}),K.map((e,t)=>(0,a.jsx)(ey,{icon:el.A,label:ej(e.contexts)||x("detail.language_label"),children:(0,a.jsx)("div",{className:"text-sm",children:e.language})},`lg${t}`)),W.map((e,t)=>(0,a.jsx)(ey,{icon:en.A,label:`${x(`detail.personal_${e.kind}`)}${e.level?` \xb7 ${e.level}`:""}`,children:(0,a.jsx)("div",{className:"text-sm",children:e.value})},`pi${t}`))]})}),U.length>0&&(0,a.jsx)(ev,{title:x("detail.categories"),children:(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5",children:U.map((e,t)=>(0,a.jsx)("span",{className:"text-xs px-2 py-1 rounded-full bg-primary/10 text-primary",children:e},t))})}),G.length>0&&(0,a.jsx)(ev,{title:x("detail.related_contacts"),children:(0,a.jsx)("div",{className:"space-y-2",children:G.map(([e,t],s)=>{let r=t.relation?Object.keys(t.relation).find(e=>t.relation[e]):void 0;return(0,a.jsx)(ey,{icon:i.A,label:r||x("detail.related_default_label"),children:(0,a.jsx)("div",{className:"text-sm break-all",children:e})},`rel${s}`)})})}),h.length>0&&(0,a.jsx)(ev,{title:x("detail.crypto_keys"),children:(0,a.jsx)("div",{className:"space-y-3",children:h.map((e,t)=>(0,a.jsx)("div",{className:"rounded-md border border-border/60 bg-muted/30 p-3 space-y-1",children:(0,a.jsxs)("div",{className:"flex items-start gap-2 text-sm break-all",children:[(0,a.jsx)(eo.A,{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0"}),"string"==typeof e.uri&&e.uri.startsWith("http")?(0,a.jsx)("a",{href:e.uri,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:e.uri}):(0,a.jsx)("span",{className:"text-muted-foreground",children:"string"==typeof e.uri?`${e.uri.substring(0,80)}${e.uri.length>80?"…":""}`:String(e.uri??"")})]})},t))})}),(e.calendarUri||e.schedulingUri||e.freeBusyUri)&&(0,a.jsx)(ev,{title:x("detail.calendar"),children:(0,a.jsxs)("div",{className:"space-y-3",children:[e.calendarUri&&(0,a.jsx)(ey,{icon:ei.A,label:x("detail.calendar_uri"),children:(0,a.jsx)("a",{href:e.calendarUri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:e.calendarUri})}),e.schedulingUri&&(0,a.jsx)(ey,{icon:ei.A,label:x("detail.scheduling_uri"),children:(0,a.jsx)("a",{href:e.schedulingUri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:e.schedulingUri})}),e.freeBusyUri&&(0,a.jsx)(ey,{icon:ei.A,label:x("detail.freebusy_uri"),children:(0,a.jsx)("a",{href:e.freeBusyUri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:e.freeBusyUri})})]})}),O.length>0&&(0,a.jsx)(ev,{title:x("detail.notes"),children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(ec.A,{className:"w-4 h-4 text-muted-foreground mt-1 flex-shrink-0"}),(0,a.jsx)("div",{className:"text-sm space-y-2 flex-1 min-w-0",children:O.map((e,t)=>(0,a.jsx)("p",{className:"whitespace-pre-wrap",children:e.note},t))})]})}),(0,a.jsx)(ep,{contact:e}),(e.created||e.updated)&&(0,a.jsxs)("div",{className:"py-4 text-xs text-muted-foreground space-y-1",children:[e.created&&(0,a.jsxs)("div",{children:[x("detail.created"),": ",eg(e.created)]}),e.updated&&(0,a.jsxs)("div",{children:[x("detail.updated"),": ",eg(e.updated)]})]})]})]})}function ej(e){return e?Object.keys(e).filter(t=>e[t]).join(", "):""}function ev({title:e,children:t,className:s}){return(0,a.jsxs)("section",{className:(0,z.cn)("py-6",s),children:[(0,a.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-3",children:e}),t]})}function ey({icon:e,label:t,children:s}){return(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(e,{className:"w-4 h-4 text-muted-foreground mt-1 flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[t&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground mb-0.5",children:t}),s]})]})}function ek({children:e}){return(0,a.jsx)("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:e})}function eN({items:e,label:t}){let[s,l]=(0,r.useState)(!1),n=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!s)return;let e=e=>{n.current?.contains(e.target)||l(!1)},t=e=>{"Escape"===e.key&&l(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[s]),0===e.length)?null:(0,a.jsxs)("div",{ref:n,className:"relative",children:[(0,a.jsx)(u.$,{variant:"outline",size:"sm",onClick:()=>l(e=>!e),title:t,"aria-label":t,"aria-haspopup":"menu","aria-expanded":s,className:"touch-manipulation",children:(0,a.jsx)(ed.A,{className:"w-4 h-4"})}),s&&(0,a.jsx)("div",{role:"menu",className:"absolute right-0 top-full mt-1 z-30 min-w-[200px] rounded-md border border-border bg-popover text-popover-foreground shadow-lg py-1 animate-in fade-in-0 zoom-in-95 duration-100",children:e.map((e,t)=>e.separator?(0,a.jsx)("div",{role:"separator",className:"my-1 h-px bg-border"},t):(0,a.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{e.onClick(),l(!1)},className:(0,z.cn)("w-full flex items-center gap-2 px-3 py-1.5 text-sm text-start hover:bg-muted focus:bg-muted focus:outline-none transition-colors",e.destructive&&"text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950 focus:bg-red-50 dark:focus:bg-red-950"),children:[(0,a.jsx)(e.icon,{className:(0,z.cn)("w-4 h-4 flex-shrink-0",e.destructive?"text-red-600 dark:text-red-400":"text-muted-foreground")}),(0,a.jsx)("span",{className:"flex-1",children:e.label})]},t))})]})}function ew({value:e,label:t,successMsg:s,failMsg:r,className:l}){return(0,a.jsx)("button",{onClick:async()=>{try{await navigator.clipboard.writeText(e),P.o.success(s)}catch{P.o.error(r)}},className:(0,z.cn)("p-1.5 rounded hover:bg-muted transition-colors touch-manipulation",l),title:t,"aria-label":t,children:(0,a.jsx)(L.A,{className:"w-3.5 h-3.5 text-muted-foreground"})})}var eC=s(66088),e_=s(21362),eA=s(78697),eS=s(23763),eO=s(42869),eM=s(51914),ez=s(52530);function eI({icon:e,title:t,children:s,collapsible:l,defaultOpen:n=!0}){let[o,i]=(0,r.useState)(n);return(0,a.jsxs)("section",{className:"py-5",children:[(0,a.jsxs)("button",{type:"button",className:(0,z.cn)("flex items-center gap-2 w-full text-start",l?"cursor-pointer":"cursor-default"),onClick:()=>l&&i(!o),tabIndex:l?0:-1,children:[(0,a.jsx)(e,{className:"w-4 h-4 text-muted-foreground shrink-0"}),(0,a.jsx)("h3",{className:"flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t}),l&&(o?(0,a.jsx)(eC.A,{className:"w-3.5 h-3.5 text-muted-foreground"}):(0,a.jsx)(e_.A,{className:"w-3.5 h-3.5 text-muted-foreground"}))]}),(o||!l)&&(0,a.jsx)("div",{className:"space-y-3 mt-3",children:s})]})}async function e$(e){return new Promise((t,s)=>{let a=new FileReader;a.onload=()=>{let e=new Image;e.onload=()=>{let a=Math.min(1,512/Math.max(e.width,e.height)),r=Math.max(1,Math.round(e.width*a)),l=Math.max(1,Math.round(e.height*a)),n=document.createElement("canvas");n.width=r,n.height=l;let o=n.getContext("2d");o?(o.drawImage(e,0,0,r,l),t({uri:n.toDataURL("image/jpeg",.85),mediaType:"image/jpeg"})):s(Error("canvas-unsupported"))},e.onerror=()=>s(Error("invalid-image")),e.src=a.result},a.onerror=()=>s(Error("read-failed")),a.readAsDataURL(e)})}function eB({value:e,onChange:t,children:s,className:r}){return(0,a.jsx)("select",{value:e,onChange:t,className:(0,z.cn)("text-sm bg-transparent border border-input rounded-md px-2.5 py-2 text-foreground","focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-1","hover:border-muted-foreground/50 transition-colors",r),children:s})}function eT({contact:e,addressBooks:t,allKeywords:s,defaultAddressBookId:n,prefill:o,onSave:i,onCancel:c}){let d=(0,l.c)("contacts.form"),m=!!e,x=e||!o?.name?"":o.name.trim().split(/\s+/)[0]||"",h=e||!o?.name?"":o.name.trim().split(/\s+/).slice(1).join(" "),p=(...t)=>e?.name?.components?.find(e=>t.includes(e.kind))?.value||"",[f,g]=(0,r.useState)(p("title","prefix")),[b,v]=(0,r.useState)(p("given")||x),[y,w]=(0,r.useState)(p("given2","additional","middle")),[C,A]=(0,r.useState)(p("surname")||h),[S,$]=(0,r.useState)(p("generation","suffix")),[B,T]=(0,r.useState)(e?.nicknames&&Object.values(e.nicknames)[0]?.name||""),[D,E]=(0,r.useState)(()=>e?.emails?Object.values(e.emails).map(e=>({address:e.address,context:e.contexts?.work?"work":e.contexts?.private?"private":""})):[{address:o?.email||"",context:""}]),[L,R]=(0,r.useState)(()=>e?.phones?Object.values(e.phones).map(e=>({number:e.number,context:e.contexts?.work?"work":e.contexts?.private?"private":"",feature:e.features?.cell?"cell":e.features?.fax?"fax":e.features?.pager?"pager":e.features?.video?"video":e.features?.text?"text":e.features?.voice?"voice":""})):[]),[F,U]=(0,r.useState)(e?.organizations&&Object.values(e.organizations)[0]?.name||""),[Y,P]=(0,r.useState)(e?.organizations&&Object.values(e.organizations)[0]?.units?.[0]?.name||""),[G,K]=(0,r.useState)(()=>{if(e?.titles){let t=Object.values(e.titles).find(e=>"role"!==e.kind);return t?.name||""}return""}),[W,J]=(0,r.useState)(()=>{if(e?.titles){let t=Object.values(e.titles).find(e=>"role"===e.kind);return t?.name||""}return""}),[q,H]=(0,r.useState)(()=>e?.addresses?Object.values(e.addresses).map(e=>(function(e){if(e.components&&e.components.length>0){let t=t=>e.components.filter(e=>e.kind===t).map(e=>e.value).join(" ");return{street:t("name")||t("number")?[t("number"),t("name")].filter(Boolean).join(" "):"",locality:t("locality"),region:t("region"),postcode:t("postcode"),country:t("country"),context:e.contexts?.work?"work":e.contexts?.private?"private":""}}return{street:e.street||"",locality:e.locality||"",region:e.region||"",postcode:e.postcode||"",country:e.country||"",context:e.contexts?.work?"work":e.contexts?.private?"private":""}})(e)):[]),[V,Z]=(0,r.useState)(()=>e?.onlineServices?Object.values(e.onlineServices).map(e=>({uri:e.uri,service:e.service||"",label:e.label||""})):[]),[X,es]=(0,r.useState)(()=>e?.anniversaries?Object.values(e.anniversaries).map(e=>({date:function(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){if("@type"in e&&"Timestamp"===e["@type"]&&"utc"in e)return e.utc.split("T")[0];if(e.year&&e.month&&e.day)return`${String(e.year).padStart(4,"0")}-${String(e.month).padStart(2,"0")}-${String(e.day).padStart(2,"0")}`;if(e.month&&e.day)return`--${String(e.month).padStart(2,"0")}-${String(e.day).padStart(2,"0")}`;if(e.year&&e.month)return`${String(e.year).padStart(4,"0")}-${String(e.month).padStart(2,"0")}`;if(e.year)return String(e.year)}return String(e)}(e.date),kind:e.kind})):[]),[el,eo]=(0,r.useState)(()=>e?.personalInfo?Object.values(e.personalInfo).map(e=>({value:e.value,kind:e.kind,level:e.level||""})):[]),[ed,eu]=(0,r.useState)(e?.keywords?Object.keys(e.keywords).filter(t=>e.keywords[t]).join(", "):""),[em,ex]=(0,r.useState)(e?.notes&&Object.values(e.notes)[0]?.note||""),[eh,ep]=(0,r.useState)(e?.speakToAs?.grammaticalGender||""),[ef,eg]=(0,r.useState)(e?.speakToAs?.pronouns&&Object.values(e.speakToAs.pronouns)[0]?.pronouns||""),[eb,ej]=(0,r.useState)(e?.calendarUri||""),[ev,ey]=(0,r.useState)(e?.schedulingUri||""),[ek,eN]=(0,r.useState)(e?.freeBusyUri||""),ew=(0,r.useMemo)(()=>{if(e?.addressBookIds){let t=Object.keys(e.addressBookIds).filter(t=>e.addressBookIds[t]);if(t.length>0)return t[0]}return n&&t?.some(e=>e.id===n)?n:""},[e,n,t]),[eC,e_]=(0,r.useState)(ew),eE=(0,r.useMemo)(()=>{if(!e?.media)return null;for(let[t,s]of Object.entries(e.media))if("photo"===s.kind&&s.uri)return{key:t,uri:(0,I.yd)(s.uri,s.mediaType),mediaType:s.mediaType};return null},[e]),[eL,eR]=(0,r.useState)(eE?.uri),[eF,eU]=(0,r.useState)(eE?.mediaType),[eY,eP]=(0,r.useState)(null),[eG,eK]=(0,r.useState)(!1),eW=(0,r.useRef)(null),[eJ,eq]=(0,r.useState)(!1),[eH,eV]=(0,r.useState)(null),[eZ,eX]=(0,r.useState)({}),eQ=async e=>{let t=e.target.files?.[0];if(e.target.value="",t){if(!t.type.startsWith("image/"))return void eP(d("photo_invalid"));if(t.size>0xa00000)return void eP(d("photo_too_large"));eP(null),eK(!0);try{let{uri:e,mediaType:s}=await e$(t);eR(e),eU(s)}catch{eP(d("photo_invalid"))}finally{eK(!1)}}},e0=async t=>{if(t.preventDefault(),eV(null),!b.trim()&&!C.trim())return void eV(d("name_required"));let s=D.filter(e=>e.address.trim());for(let e of s)if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.address.trim()))return void eV(d("email_invalid"));let a={};s.forEach((e,t)=>{let s={address:e.address.trim()};e.context&&(s.contexts={[e.context]:!0}),a[`e${t}`]=s});let r=L.filter(e=>e.number.trim()),l={};r.forEach((e,t)=>{let s={number:e.number.trim()};e.context&&(s.contexts={[e.context]:!0}),e.feature&&(s.features={[e.feature]:!0}),l[`p${t}`]=s});let n=[];f.trim()&&n.push({kind:"title",value:f.trim()}),b.trim()&&n.push({kind:"given",value:b.trim()}),y.trim()&&n.push({kind:"given2",value:y.trim()}),C.trim()&&n.push({kind:"surname",value:C.trim()}),S.trim()&&n.push({kind:"generation",value:S.trim()});let o={};G.trim()&&(o.t0={name:G.trim(),kind:"title"}),W.trim()&&(o.t1={name:W.trim(),kind:"role"});let c=Y.trim()?[{name:Y.trim()}]:void 0,u={};q.filter(e=>e.street.trim()||e.locality.trim()||e.country.trim()).forEach((e,t)=>{let s=[];e.street.trim()&&s.push({kind:"name",value:e.street.trim()}),e.locality.trim()&&s.push({kind:"locality",value:e.locality.trim()}),e.region.trim()&&s.push({kind:"region",value:e.region.trim()}),e.postcode.trim()&&s.push({kind:"postcode",value:e.postcode.trim()}),e.country.trim()&&s.push({kind:"country",value:e.country.trim()});let a={components:s,isOrdered:!0,defaultSeparator:", "};e.context&&(a.contexts={[e.context]:!0}),u[`a${t}`]=a});let m={};V.filter(e=>e.uri.trim()).forEach((e,t)=>{let s={uri:e.uri.trim()};e.service.trim()&&(s.service=e.service.trim()),e.label.trim()&&(s.label=e.label.trim()),m[`os${t}`]=s});let x={};X.filter(e=>e.date.trim()).forEach((e,t)=>{x[`an${t}`]={date:function(e){if(e.startsWith("--")){let t=e.substring(2).split("-"),s={month:parseInt(t[0],10)};return t[1]&&(s.day=parseInt(t[1],10)),s}let t=e.split("-"),s={};return t[0]&&(s.year=parseInt(t[0],10)),t[1]&&(s.month=parseInt(t[1],10)),t[2]&&(s.day=parseInt(t[2],10)),s}(e.date.trim()),kind:e.kind}});let h={};el.filter(e=>e.value.trim()).forEach((e,t)=>{let s={value:e.value.trim(),kind:e.kind};e.level&&(s.level=e.level),h[`pi${t}`]=s});let p={};ed.trim()&&ed.split(",").map(e=>e.trim()).filter(Boolean).forEach(e=>{p[e]=!0});let g={};if(e?.media)for(let[t,s]of Object.entries(e.media))"photo"!==s.kind&&(g[t]=s);eL&&(g[eE?.key||"photo"]={kind:"photo",uri:eL,mediaType:eF});let j=!!e?.media&&Object.keys(e.media).length>0,v=Object.keys(g).length>0?g:j?null:void 0,k={name:{components:n,isOrdered:!0},nicknames:B.trim()?{n0:{name:B.trim()}}:void 0,emails:Object.keys(a).length>0?a:void 0,phones:Object.keys(l).length>0?l:void 0,titles:Object.keys(o).length>0?o:void 0,organizations:F.trim()?{o0:{name:F.trim(),units:c}}:void 0,addresses:Object.keys(u).length>0?u:void 0,onlineServices:Object.keys(m).length>0?m:void 0,anniversaries:Object.keys(x).length>0?x:void 0,personalInfo:Object.keys(h).length>0?h:void 0,keywords:Object.keys(p).length>0?p:void 0,notes:em.trim()?{n0:{note:em.trim()}}:void 0,speakToAs:eh.trim()||ef.trim()?{grammaticalGender:eh.trim()||void 0,pronouns:ef.trim()?{p0:{pronouns:ef.trim()}}:void 0}:void 0,calendarUri:eb.trim()||void 0,schedulingUri:ev.trim()||void 0,freeBusyUri:ek.trim()||void 0,media:v,...eC?{addressBookIds:{[eC]:!0}}:{}};eq(!0);try{await i(k)}catch(e){eV(e instanceof Error?e.message:d("save_failed"))}finally{eq(!1)}},e1=[b,C].filter(Boolean).join(" ").trim(),e3=D.find(e=>e.address.trim())?.address.trim()||"";return(0,a.jsxs)("form",{onSubmit:e0,className:"flex flex-col h-full bg-background",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border flex-shrink-0",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:m?d("edit_title"):d("create_title")}),(0,a.jsx)("button",{type:"button",onClick:c,className:"p-1.5 rounded-md hover:bg-muted transition-colors duration-150 text-muted-foreground hover:text-foreground",children:(0,a.jsx)(j.A,{className:"w-5 h-5"})})]}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,a.jsxs)("div",{className:"px-6 py-4 max-w-3xl",children:[eH&&(0,a.jsx)("div",{className:"text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950 px-3 py-2 rounded-lg border border-red-200 dark:border-red-900 mb-4",children:eH}),(0,a.jsxs)("div",{className:"flex items-center gap-4 pb-4",children:[(0,a.jsxs)("button",{type:"button",onClick:()=>eW.current?.click(),disabled:eG,className:"relative group rounded-full focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-60",title:d("upload_photo"),"aria-label":d("upload_photo"),children:[(0,a.jsx)(M.e,{name:e1||void 0,email:e3||void 0,contactPhotoUri:eL,size:"lg",className:"!w-20 !h-20 !text-xl"}),(0,a.jsxs)("span",{"aria-hidden":"true",className:"absolute inset-0 rounded-full bg-black/55 text-white flex flex-col items-center justify-center gap-0.5 opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100 transition-opacity",children:[(0,a.jsx)(eA.A,{className:"w-5 h-5"}),(0,a.jsx)("span",{className:"text-[10px] font-medium leading-none",children:d("change_photo")})]}),(0,a.jsx)("input",{ref:eW,type:"file",accept:"image/*",className:"hidden",onChange:eQ})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:d("photo_hint")}),eY&&(0,a.jsx)("p",{className:"text-xs text-red-600 dark:text-red-400",children:eY}),eL&&(0,a.jsxs)("button",{type:"button",onClick:()=>{eR(void 0),eU(void 0),eP(null)},className:"inline-flex items-center gap-1 self-start text-xs text-muted-foreground hover:text-destructive transition-colors",children:[(0,a.jsx)(_.A,{className:"w-3 h-3"}),d("remove_photo")]})]})]}),(0,a.jsxs)("div",{className:"divide-y divide-border/60",children:[t&&t.length>1&&(0,a.jsx)(eI,{icon:eS.A,title:d("section_address_book")||"Directory",children:(0,a.jsxs)("select",{value:eC,onChange:e=>e_(e.target.value),className:"w-full px-3 py-2 rounded-md border border-border bg-background text-sm focus:outline-none focus:ring-2 focus:ring-primary/50",children:[(0,a.jsx)("option",{value:"",children:d("select_address_book")||"Select a directory..."}),t.map(e=>(0,a.jsx)("option",{value:e.id,children:e.accountName?`${e.name} (${e.accountName})`:e.name},e.id))]})}),(0,a.jsxs)(eI,{icon:eO.A,title:d("section_identity"),children:[(0,a.jsxs)("div",{className:"grid grid-cols-[auto_1fr_1fr_auto] gap-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("prefix")}),(0,a.jsx)(O.p,{value:f,onChange:e=>g(e.target.value),placeholder:d("prefix_placeholder"),className:"w-20"})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{className:"text-xs text-muted-foreground mb-1 block",children:[d("given_name")," ",(0,a.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,a.jsx)(O.p,{value:b,onChange:e=>v(e.target.value),placeholder:d("given_name"),autoFocus:!0})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{className:"text-xs text-muted-foreground mb-1 block",children:[d("surname")," ",(0,a.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,a.jsx)(O.p,{value:C,onChange:e=>A(e.target.value),placeholder:d("surname")})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("suffix")}),(0,a.jsx)(O.p,{value:S,onChange:e=>$(e.target.value),placeholder:d("suffix_placeholder"),className:"w-20"})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("middle_name")}),(0,a.jsx)(O.p,{value:y,onChange:e=>w(e.target.value),placeholder:d("middle_name")})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("nickname")}),(0,a.jsx)(O.p,{value:B,onChange:e=>T(e.target.value),placeholder:d("nickname_placeholder")})]})]})]}),(0,a.jsx)(eI,{icon:k.A,title:d("email"),children:(0,a.jsxs)("div",{className:"space-y-2",children:[D.map((e,t)=>(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(O.p,{type:"email",inputMode:"email",value:e.address,onChange:e=>{let s=[...D];s[t]={...s[t],address:e.target.value},E(s),eZ[t]&&eX(e=>{let s={...e};return delete s[t],s})},onBlur:()=>((e,t)=>{t.trim()&&!(!t.trim()||/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim()))?eX(t=>({...t,[e]:d("email_error_inline")})):eX(t=>{let s={...t};return delete s[e],s})})(t,e.address),placeholder:d("email_placeholder"),className:(0,z.cn)("flex-1",eZ[t]&&"border-red-500 focus:ring-red-500")}),(0,a.jsxs)(eB,{value:e.context,onChange:e=>{let s=[...D];s[t]={...s[t],context:e.target.value},E(s)},children:[(0,a.jsx)("option",{value:"",children:"-"}),(0,a.jsx)("option",{value:"work",children:d("context_work")}),(0,a.jsx)("option",{value:"private",children:d("context_private")})]}),D.length>1&&(0,a.jsx)(u.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>E(D.filter((e,s)=>s!==t)),className:"h-8 w-8 shrink-0",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})})]}),eZ[t]&&(0,a.jsx)("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1 ms-1",children:eZ[t]})]},t)),(0,a.jsxs)(u.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>E([...D,{address:"",context:""}]),className:"text-xs",children:[(0,a.jsx)(eM.A,{className:"w-3 h-3 me-1"}),d("add_email")]})]})}),(0,a.jsx)(eI,{icon:N.A,title:d("phone"),children:(0,a.jsxs)("div",{className:"space-y-2",children:[L.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(O.p,{type:"tel",inputMode:"tel",value:e.number,onChange:e=>{let s=[...L];s[t]={...s[t],number:e.target.value},R(s)},placeholder:d("phone_placeholder"),className:"flex-1"}),(0,a.jsxs)(eB,{value:e.feature,onChange:e=>{let s=[...L];s[t]={...s[t],feature:e.target.value},R(s)},className:"w-[5.5rem]",children:[(0,a.jsx)("option",{value:"",children:d("phone_type")}),(0,a.jsx)("option",{value:"voice",children:d("phone_voice")}),(0,a.jsx)("option",{value:"cell",children:d("phone_cell")}),(0,a.jsx)("option",{value:"fax",children:d("phone_fax")}),(0,a.jsx)("option",{value:"pager",children:d("phone_pager")}),(0,a.jsx)("option",{value:"video",children:d("phone_video")}),(0,a.jsx)("option",{value:"text",children:d("phone_text")})]}),(0,a.jsxs)(eB,{value:e.context,onChange:e=>{let s=[...L];s[t]={...s[t],context:e.target.value},R(s)},children:[(0,a.jsx)("option",{value:"",children:"-"}),(0,a.jsx)("option",{value:"work",children:d("context_work")}),(0,a.jsx)("option",{value:"private",children:d("context_private")})]}),(0,a.jsx)(u.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>R(L.filter((e,s)=>s!==t)),className:"h-8 w-8 shrink-0",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})})]},t)),(0,a.jsxs)(u.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>R([...L,{number:"",context:"",feature:""}]),className:"text-xs",children:[(0,a.jsx)(eM.A,{className:"w-3 h-3 me-1"}),d("add_phone")]})]})}),(0,a.jsx)(eI,{icon:et.A,title:d("section_work"),collapsible:!0,defaultOpen:!!(F||Y||G||W),children:(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("organization")}),(0,a.jsx)(O.p,{value:F,onChange:e=>U(e.target.value),placeholder:d("organization_placeholder")})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("department")}),(0,a.jsx)(O.p,{value:Y,onChange:e=>P(e.target.value),placeholder:d("department_placeholder")})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("job_title")}),(0,a.jsx)(O.p,{value:G,onChange:e=>K(e.target.value),placeholder:d("job_title_placeholder")})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("role")}),(0,a.jsx)(O.p,{value:W,onChange:e=>J(e.target.value),placeholder:d("role_placeholder")})]})]})}),(0,a.jsx)(eI,{icon:Q.A,title:d("addresses"),collapsible:!0,defaultOpen:q.length>0,children:(0,a.jsxs)("div",{className:"space-y-3",children:[q.map((e,t)=>(0,a.jsxs)("div",{className:"rounded-md border border-border/60 bg-muted/20 p-3 space-y-2 relative",children:[(0,a.jsx)(u.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>H(q.filter((e,s)=>s!==t)),className:"h-6 w-6 absolute top-2 right-2",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})}),(0,a.jsx)(O.p,{value:e.street,onChange:e=>{let s=[...q];s[t]={...s[t],street:e.target.value},H(s)},placeholder:d("street")}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,a.jsx)(O.p,{value:e.locality,onChange:e=>{let s=[...q];s[t]={...s[t],locality:e.target.value},H(s)},placeholder:d("city")}),(0,a.jsx)(O.p,{value:e.region,onChange:e=>{let s=[...q];s[t]={...s[t],region:e.target.value},H(s)},placeholder:d("region")})]}),(0,a.jsxs)("div",{className:"grid grid-cols-3 gap-2",children:[(0,a.jsx)(O.p,{value:e.postcode,onChange:e=>{let s=[...q];s[t]={...s[t],postcode:e.target.value},H(s)},placeholder:d("postcode")}),(0,a.jsx)(O.p,{value:e.country,onChange:e=>{let s=[...q];s[t]={...s[t],country:e.target.value},H(s)},placeholder:d("country")}),(0,a.jsxs)(eB,{value:e.context,onChange:e=>{let s=[...q];s[t]={...s[t],context:e.target.value},H(s)},children:[(0,a.jsx)("option",{value:"",children:"-"}),(0,a.jsx)("option",{value:"work",children:d("context_work")}),(0,a.jsx)("option",{value:"private",children:d("context_private")})]})]})]},t)),(0,a.jsxs)(u.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>H([...q,{street:"",locality:"",region:"",postcode:"",country:"",context:""}]),className:"text-xs",children:[(0,a.jsx)(eM.A,{className:"w-3 h-3 me-1"}),d("add_address")]})]})}),(0,a.jsx)(eI,{icon:ee.A,title:d("online_services"),collapsible:!0,defaultOpen:V.length>0,children:(0,a.jsxs)("div",{className:"space-y-2",children:[V.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(O.p,{value:e.uri,onChange:e=>{let s=[...V];s[t]={...s[t],uri:e.target.value},Z(s)},placeholder:d("url_placeholder"),className:"flex-1"}),(0,a.jsx)(O.p,{value:e.service,onChange:e=>{let s=[...V];s[t]={...s[t],service:e.target.value},Z(s)},placeholder:d("service_placeholder"),className:"w-24"}),(0,a.jsx)(u.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>Z(V.filter((e,s)=>s!==t)),className:"h-8 w-8 shrink-0",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})})]},t)),(0,a.jsxs)(u.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>Z([...V,{uri:"",service:"",label:""}]),className:"text-xs",children:[(0,a.jsx)(eM.A,{className:"w-3 h-3 me-1"}),d("add_online_service")]})]})}),(0,a.jsx)(eI,{icon:ea.A,title:d("anniversaries"),collapsible:!0,defaultOpen:X.length>0,children:(0,a.jsxs)("div",{className:"space-y-2",children:[X.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(O.p,{type:"date",value:e.date,onChange:e=>{let s=[...X];s[t]={...s[t],date:e.target.value},es(s)},className:"flex-1"}),(0,a.jsxs)(eB,{value:e.kind,onChange:e=>{let s=[...X];s[t]={...s[t],kind:e.target.value},es(s)},children:[(0,a.jsx)("option",{value:"birth",children:d("anniversary_birth")}),(0,a.jsx)("option",{value:"wedding",children:d("anniversary_wedding")}),(0,a.jsx)("option",{value:"death",children:d("anniversary_death")}),(0,a.jsx)("option",{value:"other",children:d("anniversary_other")})]}),(0,a.jsx)(u.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>es(X.filter((e,s)=>s!==t)),className:"h-8 w-8 shrink-0",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})})]},t)),(0,a.jsxs)(u.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>es([...X,{date:"",kind:"birth"}]),className:"text-xs",children:[(0,a.jsx)(eM.A,{className:"w-3 h-3 me-1"}),d("add_anniversary")]})]})}),(0,a.jsx)(eI,{icon:en.A,title:d("personal_info"),collapsible:!0,defaultOpen:el.length>0,children:(0,a.jsxs)("div",{className:"space-y-2",children:[el.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(O.p,{value:e.value,onChange:e=>{let s=[...el];s[t]={...s[t],value:e.target.value},eo(s)},placeholder:d("personal_info_placeholder"),className:"flex-1"}),(0,a.jsxs)(eB,{value:e.kind,onChange:e=>{let s=[...el];s[t]={...s[t],kind:e.target.value},eo(s)},children:[(0,a.jsx)("option",{value:"expertise",children:d("personal_expertise")}),(0,a.jsx)("option",{value:"hobby",children:d("personal_hobby")}),(0,a.jsx)("option",{value:"interest",children:d("personal_interest")}),(0,a.jsx)("option",{value:"other",children:d("personal_other")})]}),(0,a.jsxs)(eB,{value:e.level,onChange:e=>{let s=[...el];s[t]={...s[t],level:e.target.value},eo(s)},children:[(0,a.jsx)("option",{value:"",children:d("level")}),(0,a.jsx)("option",{value:"high",children:d("level_high")}),(0,a.jsx)("option",{value:"medium",children:d("level_medium")}),(0,a.jsx)("option",{value:"low",children:d("level_low")})]}),(0,a.jsx)(u.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>eo(el.filter((e,s)=>s!==t)),className:"h-8 w-8 shrink-0",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})})]},t)),(0,a.jsxs)(u.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>eo([...el,{value:"",kind:"hobby",level:""}]),className:"text-xs",children:[(0,a.jsx)(eM.A,{className:"w-3 h-3 me-1"}),d("add_personal_info")]})]})}),(0,a.jsx)(eI,{icon:ez.A,title:d("categories"),collapsible:!0,defaultOpen:!!ed,children:(0,a.jsx)(eD,{keywordsStr:ed,onChange:eu,allKeywords:s||[],placeholder:d("categories_placeholder"),hint:d("categories_hint"),addLabel:d("category_add")})}),(0,a.jsx)(eI,{icon:er.A,title:d("gender"),collapsible:!0,defaultOpen:!!(eh||ef),children:(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("gender_sex")}),(0,a.jsxs)(eB,{value:eh,onChange:e=>ep(e.target.value),className:"w-full",children:[(0,a.jsx)("option",{value:"",children:"-"}),(0,a.jsx)("option",{value:"masculine",children:d("gender_male")}),(0,a.jsx)("option",{value:"feminine",children:d("gender_female")}),(0,a.jsx)("option",{value:"other",children:d("gender_other")}),(0,a.jsx)("option",{value:"none",children:d("gender_none")}),(0,a.jsx)("option",{value:"unknown",children:d("gender_unknown")})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("gender_identity")}),(0,a.jsx)(O.p,{value:ef,onChange:e=>eg(e.target.value),placeholder:d("gender_identity_placeholder")})]})]})}),(0,a.jsx)(eI,{icon:ei.A,title:d("calendar"),collapsible:!0,defaultOpen:!!(eb||ev||ek),children:(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("calendar_uri")}),(0,a.jsx)(O.p,{value:eb,onChange:e=>ej(e.target.value),placeholder:"https://..."})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("scheduling_uri")}),(0,a.jsx)(O.p,{value:ev,onChange:e=>ey(e.target.value),placeholder:"https://..."})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:d("freebusy_uri")}),(0,a.jsx)(O.p,{value:ek,onChange:e=>eN(e.target.value),placeholder:"https://..."})]})]})}),(0,a.jsx)(eI,{icon:ec.A,title:d("note"),collapsible:!0,defaultOpen:!!em,children:(0,a.jsx)("textarea",{value:em,onChange:e=>ex(e.target.value),placeholder:d("note_placeholder"),className:"w-full min-h-[100px] rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground resize-y outline-none focus:ring-2 focus:ring-ring"})})]})]})}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border flex-shrink-0",children:[(0,a.jsx)(u.$,{type:"button",variant:"outline",onClick:c,disabled:eJ,children:d("cancel")}),(0,a.jsx)(u.$,{type:"submit",disabled:eJ,children:eJ?m?d("updating"):d("creating"):d("save")})]})]})}function eD({keywordsStr:e,onChange:t,allKeywords:s,placeholder:l,hint:n,addLabel:o}){let[i,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(""),m=(0,r.useRef)(null),x=(0,r.useMemo)(()=>e.split(",").map(e=>e.trim()).filter(Boolean),[e]),h=(0,r.useMemo)(()=>{let e=d.toLowerCase();return s.filter(t=>!x.includes(t)&&(!e||t.toLowerCase().includes(e)))},[s,x,d]),p=d.trim()&&!x.includes(d.trim())&&!s.some(e=>e.toLowerCase()===d.trim().toLowerCase()),f=(0,r.useCallback)(e=>{let s=e.trim();!s||x.includes(s)||(t([...x,s].join(", ")),u(""))},[x,t]),g=(0,r.useCallback)(e=>{t(x.filter(t=>t!==e).join(", "))},[x,t]);return(0,a.jsxs)("div",{className:"relative",children:[x.length>0&&(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2",children:x.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-primary/10 text-primary border border-primary/20",children:[e,(0,a.jsx)("button",{type:"button",onClick:()=>g(e),className:"hover:text-destructive transition-colors",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})})]},e))}),(0,a.jsx)(O.p,{ref:m,value:d,onChange:e=>{u(e.target.value),c(!0)},onFocus:()=>c(!0),onBlur:()=>c(!1),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),d.trim()&&f(d)):"Escape"===e.key&&c(!1)},placeholder:0===x.length?l:""}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1.5",children:n}),i&&(h.length>0||p)&&(0,a.jsxs)("div",{className:"absolute left-0 right-0 top-[calc(100%-1.5rem)] mt-1 rounded-md border border-border bg-popover text-popover-foreground shadow-md z-50 max-h-48 overflow-y-auto py-1",onMouseDown:e=>e.preventDefault(),children:[h.map(e=>(0,a.jsxs)("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-accent transition-colors text-start",onClick:()=>{f(e),m.current?.focus()},children:[(0,a.jsx)(ez.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),e]},e)),p&&(0,a.jsxs)("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-accent transition-colors text-start text-primary",onClick:()=>{f(d),m.current?.focus()},children:[(0,a.jsx)(eM.A,{className:"w-3.5 h-3.5 flex-shrink-0"}),o,': "',d.trim(),'"']})]})]})}var eE=s(94514);function eL({group:e,individuals:t,currentMemberIds:s=[],onSave:n,onCancel:o}){let i=(0,l.c)("contacts"),c=!!e,[d,m]=(0,r.useState)(e?(0,I.YM)(e):""),[x,h]=(0,r.useState)(new Set(s)),[p,f]=(0,r.useState)(""),[g,v]=(0,r.useState)(!1),[y,k]=(0,r.useState)(null),N=(0,r.useMemo)(()=>{if(!p)return t;let e=p.toLowerCase();return t.filter(t=>{let s=(0,I.YM)(t).toLowerCase(),a=(0,I.Bp)(t).toLowerCase();return s.includes(e)||a.includes(e)})},[t,p]),w=e=>{let t=new Set(x);t.has(e)?t.delete(e):t.add(e),h(t)},C=async e=>{if(e.preventDefault(),k(null),!d.trim())return void k(i("groups.name_required"));v(!0);try{await n(d.trim(),Array.from(x))}catch(e){k(e instanceof Error?e.message:i("groups.save_failed"))}finally{v(!1)}};return(0,a.jsxs)("form",{onSubmit:C,className:"flex flex-col h-full",children:[(0,a.jsx)("div",{className:"px-6 py-4 border-b border-border",children:(0,a.jsx)("h2",{className:"text-lg font-semibold",children:c?i("groups.edit"):i("groups.create")})}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[y&&(0,a.jsx)("div",{className:"text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950 px-3 py-2 rounded",children:y}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-sm text-muted-foreground mb-1 block",children:i("groups.name_label")}),(0,a.jsx)(O.p,{value:d,onChange:e=>m(e.target.value),placeholder:i("groups.name_placeholder"),autoFocus:!0})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{className:"text-sm text-muted-foreground mb-2 block",children:[i("groups.members_label")," (",x.size,")"]}),(0,a.jsxs)("div",{className:"relative mb-2",children:[(0,a.jsx)(b.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),(0,a.jsx)(O.p,{placeholder:i("groups.search_members"),value:p,onChange:e=>f(e.target.value),className:"ps-9"})]}),(0,a.jsx)("div",{className:"border rounded-md max-h-64 overflow-y-auto divide-y divide-border",children:0===N.length?(0,a.jsx)("div",{className:"px-4 py-6 text-sm text-muted-foreground text-center",children:i("empty_search")}):N.map(e=>{let t=(0,I.YM)(e),s=(0,I.Bp)(e),r=x.has(e.id);return(0,a.jsxs)("button",{type:"button",onClick:()=>w(e.id),className:(0,z.cn)("w-full flex items-center gap-3 px-3 py-2.5 text-start transition-colors","hover:bg-muted",r&&"bg-primary/5"),children:[(0,a.jsx)("div",{className:(0,z.cn)("w-5 h-5 rounded border flex items-center justify-center flex-shrink-0 transition-colors",r?"bg-primary border-primary text-primary-foreground":"border-border"),children:r&&(0,a.jsx)(eE.A,{className:"w-3 h-3"})}),(0,a.jsx)(M.e,{name:t,email:s,size:"sm"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-sm font-medium truncate",children:t}),s&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:s})]})]},e.id)})})]}),x.size>0&&(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5",children:Array.from(x).map(e=>{let s=t.find(t=>t.id===e);return s?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-full bg-primary/10 text-primary",children:[(0,I.YM)(s),(0,a.jsx)("button",{type:"button",onClick:()=>w(e),className:"hover:text-red-600 dark:hover:text-red-400",children:(0,a.jsx)(j.A,{className:"w-3 h-3"})})]},e):null})})]}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border",children:[(0,a.jsx)(u.$,{type:"button",variant:"outline",onClick:o,disabled:g,children:i("form.cancel")}),(0,a.jsx)(u.$,{type:"submit",disabled:g,children:g?c?i("form.updating"):i("form.creating"):i("form.save")})]})]})}var eR=s(4972);function eF({group:e,members:t,onEdit:s,onDelete:r,onRemoveMember:n,onSelectMember:o,onComposeGroup:c,isMobile:d,className:m}){let x=(0,l.c)("contacts"),h=(0,I.YM)(e),p=t.some(e=>(0,I.Bp)(e).trim());return(0,a.jsxs)("div",{className:(0,z.cn)("flex flex-col h-full overflow-y-auto",m),children:[(0,a.jsxs)("div",{className:(0,z.cn)("border-b border-border",d?"px-4 py-4":"px-6 py-6"),children:[(0,a.jsxs)("div",{className:(0,z.cn)("flex gap-4",d?"flex-col":"items-start justify-between"),children:[(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsx)("div",{className:(0,z.cn)("rounded-full bg-primary/10 flex items-center justify-center",d?"w-12 h-12":"w-14 h-14"),children:(0,a.jsx)(i.A,{className:(0,z.cn)("text-primary",d?"w-6 h-6":"w-7 h-7")})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:(0,z.cn)("font-semibold",d?"text-lg":"text-xl"),children:h}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:x("groups.member_count",{count:t.length})})]})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)(u.$,{variant:"outline",size:"sm",onClick:s,className:"touch-manipulation",children:[(0,a.jsx)(D.A,{className:"w-4 h-4 me-1"}),x("form.edit_title")]}),(0,a.jsx)(u.$,{variant:"outline",size:"sm",onClick:r,className:"text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-950 touch-manipulation",children:(0,a.jsx)(_.A,{className:"w-4 h-4"})})]})]}),c&&p&&(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mt-4",children:[(0,a.jsx)(k.A,{className:"w-4 h-4 text-muted-foreground","aria-hidden":!0}),(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:x("groups.send_email")}),(0,a.jsx)("div",{className:"inline-flex gap-1",children:["to","cc","bcc"].map(e=>(0,a.jsx)(u.$,{variant:"outline",size:"sm",onClick:()=>c(e),className:"touch-manipulation",children:x(`groups.send_email_${e}`)},e))})]})]}),(0,a.jsxs)("div",{className:"px-6 py-4",children:[(0,a.jsx)("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:x("groups.members_label")}),0===t.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground py-4 text-center",children:x("groups.no_members")}):(0,a.jsx)("div",{className:"space-y-1",children:t.map(e=>{let t=(0,I.YM)(e),s=(0,I.Bp)(e);return(0,a.jsxs)("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md hover:bg-muted group transition-colors",children:[(0,a.jsxs)("button",{className:"flex items-center gap-3 flex-1 min-w-0 text-start",onClick:()=>o(e.id),children:[(0,a.jsx)(M.e,{name:t,email:s,size:"sm"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-sm font-medium truncate",children:t}),s&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:s})]})]}),(0,a.jsx)(u.$,{variant:"ghost",size:"icon",className:(0,z.cn)("h-8 w-8 transition-opacity",d?"opacity-100":"opacity-0 group-hover:opacity-100"),onClick:()=>n(e.id),children:(0,a.jsx)(eR.A,{className:"w-4 h-4 text-muted-foreground"})})]},e.id)})})]})]})}var eU=s(53651),eY=s(81026),eP=s(21975),eG=s(53810),eK=s(89363),eW=s(60062);function eJ(e){let t=[],s=new Map;for(let a of e)if(a.isShared){let e=a.accountId||a.accountName||a.id,t=s.get(e);t?t.books.push(a):s.set(e,{label:a.accountName||e,books:[a]})}else t.push(a);return{owned:t,sharedGroups:Array.from(s.values())}}let eq="contacts-sidebar-collapsed";function eH(){try{let e=localStorage.getItem(eq);return e?JSON.parse(e):{}}catch{return{}}}function eV({groups:e,individuals:t,addressBooks:s,activeCategory:o,onSelectCategory:c,onCreateGroup:d,onCreateContact:m,onCreateAddressBook:x,onImport:h,onEditGroup:p,onDeleteGroup:f,onComposeGroup:g,onDropContacts:b,onDropContactsToCategory:j,onRenameAddressBook:v,onShareAddressBook:y,onCreateContactInBook:N,onDeleteAddressBook:w,onRenameKeyword:C,className:O,multiAccountMode:M}){let $,T,E,L,R,F,U=(0,l.c)("contacts"),Y=(0,n.useRouter)(),{contextMenu:P,openContextMenu:G,closeContextMenu:W,menuRef:J}=(0,K.E)(),{contextMenu:q,openContextMenu:H,closeContextMenu:V,menuRef:Z}=(0,K.E)(),{contextMenu:X,openContextMenu:Q,closeContextMenu:ee,menuRef:et}=(0,K.E)(),[es,ea]=(0,r.useState)(eH),[er,el]=(0,r.useState)(!1),en=(0,r.useRef)(null),eo=(0,r.useRef)(null),ei=(0,r.useCallback)(e=>{ea(t=>{let s={...t,[e]:!t[e]};try{localStorage.setItem(eq,JSON.stringify(s))}catch{}return s})},[]);(0,r.useEffect)(()=>{if(!er)return;let e=e=>{en.current&&!en.current.contains(e.target)&&eo.current&&!eo.current.contains(e.target)&&el(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[er]);let ec=(0,r.useMemo)(()=>[...e].sort((e,t)=>(0,I.YM)(e).localeCompare((0,I.YM)(t))),[e]),ed="all"===o,eu=(0,r.useMemo)(()=>s.filter(e=>!e.isShared),[s]),em=(0,r.useMemo)(()=>{let e=new Map;for(let t of s){if(!t.isShared||!t.accountId)continue;let s=e.get(t.accountId);s?s.books.push(t):e.set(t.accountId,{accountId:t.accountId,accountName:t.accountName||t.accountId,books:[t]})}return Array.from(e.values())},[s]),ex=(0,eW.E)(e=>e.accounts),eh=(0,eW.E)(e=>e.activeAccountId),ep=(0,r.useMemo)(()=>{if(!M)return[];let e=new Map;for(let t of s){let s=t.localAccountId||"__other__",a=e.get(s)??[];a.push(t),e.set(s,a)}let t=[];if(eh&&e.has(eh)){let s=ex.find(e=>e.id===eh);t.push({key:eh,label:s?.label||s?.email||s?.username||eh,split:eJ(e.get(eh))}),e.delete(eh)}for(let s of ex)e.has(s.id)&&(t.push({key:s.id,label:s.label||s.email||s.username,split:eJ(e.get(s.id))}),e.delete(s.id));for(let[s,a]of e.entries()){let e="__other__"===s?U("address_books.title"):a[0]?.accountName||s;t.push({key:s,label:e,split:eJ(a)})}return t},[M,s,ex,eh,U]),ef=(0,r.useMemo)(()=>{let e={};for(let s of t)if(s.addressBookIds)for(let t of Object.keys(s.addressBookIds))s.addressBookIds[t]&&(e[t]=(e[t]||0)+1);return e},[t]),eg=(0,r.useMemo)(()=>{let e={};for(let s of t)if(s.keywords)for(let[t,a]of Object.entries(s.keywords))a&&(e[t]=(e[t]||0)+1);return Object.entries(e).sort(([e],[t])=>e.localeCompare(t))},[t]),eb=(0,r.useMemo)(()=>t.filter(e=>!e.keywords||0===Object.keys(e.keywords).filter(t=>e.keywords[t]).length).length,[t]),ej=(0,r.useMemo)(()=>{let s={};for(let a of e){if(!a.members){s[a.id]=0;continue}let e=Object.keys(a.members).filter(e=>a.members[e]),r=e.map(e=>e.startsWith("urn:uuid:")?e.slice(9):e);s[a.id]=t.filter(t=>{if(e.includes(t.id)||r.includes(t.id))return!0;if(t.uid){let s=t.uid.startsWith("urn:uuid:")?t.uid.slice(9):t.uid;return e.includes(t.uid)||r.includes(s)}return!1}).length}return s},[e,t]);return(0,a.jsxs)("div",{className:(0,z.cn)("flex flex-col h-full bg-secondary",O),children:[(0,a.jsxs)("div",{className:"px-3 border-b border-border flex items-center justify-between",style:{paddingBlock:"var(--density-header-py)"},children:[(0,a.jsx)("span",{className:"text-sm font-semibold truncate",children:U("title")}),(0,a.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,a.jsx)(u.$,{ref:eo,size:"icon",variant:"ghost",onClick:()=>el(e=>!e),className:"h-7 w-7",children:(0,a.jsx)(eM.A,{className:"w-4 h-4"})}),er&&(0,a.jsxs)("div",{ref:en,className:"absolute right-0 top-full mt-1 w-44 rounded-md border border-border bg-background text-foreground shadow-md z-50 py-1",children:[(0,a.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-accent transition-colors text-start",onClick:()=>{el(!1),m()},children:[(0,a.jsx)(S.A,{className:"w-4 h-4"}),U("create_new")]}),(0,a.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-accent transition-colors text-start",onClick:()=>{el(!1),d()},children:[(0,a.jsx)(eU.A,{className:"w-4 h-4"}),U("groups.create")]}),x&&(0,a.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-accent transition-colors text-start",onClick:()=>{el(!1),x()},children:[(0,a.jsx)(eY.A,{className:"w-4 h-4"}),U("address_books.create")]}),h&&(0,a.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-accent transition-colors text-start",onClick:()=>{el(!1),h()},children:[(0,a.jsx)(eP.A,{className:"w-4 h-4"}),U("import.title")]})]})]})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[(0,a.jsxs)("button",{onClick:()=>c("all"),className:(0,z.cn)("w-full flex items-center gap-2 px-3 text-sm transition-colors",ed?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,a.jsx)(A.A,{className:"w-4 h-4 flex-shrink-0"}),(0,a.jsx)("span",{className:"truncate",children:U("tabs.all")}),(0,a.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:t.length})]}),M&&ep.length>0?ep.map(e=>{let t=`account-${e.key}`,s=!es[t],{owned:r,sharedGroups:l}=e.split;return(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsx)("div",{className:"flex items-center px-3 py-1 group",children:(0,a.jsxs)("button",{onClick:()=>ei(t),className:"flex items-center gap-1 flex-1 min-w-0 text-start",children:[s?(0,a.jsx)(eC.A,{className:"w-3 h-3 text-muted-foreground"}):(0,a.jsx)(e_.A,{className:"w-3 h-3 text-muted-foreground"}),(0,a.jsx)(eO.A,{className:"w-3 h-3 text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs font-semibold text-foreground/90 uppercase tracking-wider truncate",children:e.label})]})}),s&&(0,a.jsxs)("div",{className:"ps-2",children:[r.length>0&&(0,a.jsxs)("div",{className:"mt-1",children:[(0,a.jsx)("div",{className:"px-3 py-0.5 text-[10px] font-medium text-muted-foreground/80 uppercase tracking-wider",children:U("address_books.title")}),r.map(e=>(0,a.jsx)(eX,{book:e,isActive:"object"==typeof o&&"addressBookId"in o&&o.addressBookId===e.id,contactCount:ef[e.id]||0,onSelect:()=>c({addressBookId:e.id}),onDropContacts:b,onContextMenu:v||y||N||w?t=>H(t,e):void 0},e.id))]}),l.map(t=>(0,a.jsxs)("div",{className:"mt-1",children:[(0,a.jsxs)("div",{className:"px-3 py-0.5 text-[10px] font-medium text-muted-foreground/80 uppercase tracking-wider flex items-center gap-1",children:[(0,a.jsx)(eG.A,{className:"w-3 h-3"}),t.label]}),t.books.map(e=>(0,a.jsx)(eX,{book:e,isActive:"object"==typeof o&&"addressBookId"in o&&o.addressBookId===e.id,contactCount:ef[e.id]||0,onSelect:()=>c({addressBookId:e.id}),onDropContacts:b,onContextMenu:v||y||N||w?t=>H(t,e):void 0},e.id))]},`${e.key}-shared-${t.label}`))]})]},e.key)}):eu.length>0&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsxs)("div",{className:"flex items-center px-3 py-1 group",children:[(0,a.jsxs)("button",{onClick:()=>ei("addressBooks"),className:"flex items-center gap-1 flex-1 text-start",children:[es.addressBooks?(0,a.jsx)(e_.A,{className:"w-3 h-3 text-muted-foreground"}):(0,a.jsx)(eC.A,{className:"w-3 h-3 text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:U("address_books.title")})]}),(0,a.jsx)("button",{onClick:e=>{e.stopPropagation();try{localStorage.setItem("settings-active-tab","contacts")}catch{}Y.push("/settings")},className:"p-0.5 rounded opacity-0 group-hover:opacity-100 transition-opacity duration-150 hover:bg-muted",title:U("address_books.manage"),children:(0,a.jsx)(eK.A,{className:"w-3 h-3 text-muted-foreground"})})]}),!es.addressBooks&&eu.map(e=>(0,a.jsx)(eX,{book:e,isActive:"object"==typeof o&&"addressBookId"in o&&o.addressBookId===e.id,contactCount:ef[e.id]||0,onSelect:()=>c({addressBookId:e.id}),onDropContacts:b,onContextMenu:v||y||N||w?t=>H(t,e):void 0},e.id))]}),ec.length>0&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsxs)("button",{onClick:()=>ei("groups"),className:"flex items-center gap-1 px-3 py-1 w-full text-start group",children:[es.groups?(0,a.jsx)(e_.A,{className:"w-3 h-3 text-muted-foreground"}):(0,a.jsx)(eC.A,{className:"w-3 h-3 text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:U("tabs.groups")})]}),!es.groups&&ec.map(e=>{let t="object"==typeof o&&"groupId"in o&&o.groupId===e.id,s=ej[e.id]||0;return(0,a.jsxs)("button",{onClick:()=>c({groupId:e.id}),onContextMenu:t=>G(t,e),className:(0,z.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors",t?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,a.jsx)(i.A,{className:"w-4 h-4 flex-shrink-0"}),(0,a.jsx)("span",{className:"truncate",children:(0,I.YM)(e)}),(0,a.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:s})]},e.id)})]}),(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsxs)("button",{onClick:()=>ei("categories"),className:"flex items-center gap-1 px-3 py-1 w-full text-start group",children:[es.categories?(0,a.jsx)(e_.A,{className:"w-3 h-3 text-muted-foreground"}):(0,a.jsx)(eC.A,{className:"w-3 h-3 text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:U("detail.categories")})]}),!es.categories&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{onClick:()=>c("uncategorized"),className:(0,z.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors","uncategorized"===o?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,a.jsx)(ez.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-50"}),(0,a.jsx)("span",{className:"truncate italic",children:U("no_category")}),(0,a.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:eb})]}),eg.map(([e,t])=>{let s="object"==typeof o&&"keyword"in o&&o.keyword===e;return(0,a.jsx)(eZ,{keyword:e,count:t,isActive:s,onSelect:()=>c({keyword:e}),onDropContacts:j,onContextMenu:C?t=>Q(t,e):void 0},e)})]})]}),!M&&em.map(e=>(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsxs)("div",{className:"flex items-center px-3 py-1 group",children:[(0,a.jsxs)("button",{onClick:()=>ei(`shared-${e.accountId}`),className:"flex items-center gap-1 flex-1 min-w-0 text-start",children:[es[`shared-${e.accountId}`]?(0,a.jsx)(e_.A,{className:"w-3 h-3 text-muted-foreground"}):(0,a.jsx)(eC.A,{className:"w-3 h-3 text-muted-foreground"}),(0,a.jsx)(eG.A,{className:"w-3 h-3 text-muted-foreground"}),(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider truncate",children:U("address_books.shared_prefix",{name:e.accountName})})]}),(0,a.jsx)("button",{onClick:e=>{e.stopPropagation();try{localStorage.setItem("settings-active-tab","contacts")}catch{}Y.push("/settings")},className:"p-0.5 rounded opacity-0 group-hover:opacity-100 transition-opacity duration-150 hover:bg-muted",title:U("address_books.manage"),children:(0,a.jsx)(eK.A,{className:"w-3 h-3 text-muted-foreground"})})]}),!es[`shared-${e.accountId}`]&&e.books.map(e=>(0,a.jsx)(eX,{book:e,isActive:"object"==typeof o&&"addressBookId"in o&&o.addressBookId===e.id,contactCount:ef[e.id]||0,onSelect:()=>c({addressBookId:e.id}),onDropContacts:b,onContextMenu:v||y||N||w?t=>H(t,e):void 0},e.id))]},e.accountId))]}),q.data&&(v||y||N||w)&&($=q.data,T=N&&$.myRights?.mayWrite!==!1,E=v&&$.myRights?.mayWrite!==!1,L=y&&$.myRights?.mayShare&&!$.isShared,R=w&&!$.isDefault&&!$.isShared&&$.myRights?.mayDelete!==!1,F=(T||E||L)&&R,(0,a.jsxs)(B.tz,{ref:Z,isOpen:q.isOpen,position:q.position,onClose:V,children:[T&&(0,a.jsx)(B.kt,{icon:S.A,label:U("address_books.new_contact_in_book"),onClick:()=>{V(),N($)}}),E&&(0,a.jsx)(B.kt,{icon:D.A,label:U("address_books.rename"),onClick:()=>{V(),v($)}}),L&&(0,a.jsx)(B.kt,{icon:i.A,label:U("address_books.share"),onClick:()=>{V(),y($)}}),F&&(0,a.jsx)(B.K5,{}),R&&(0,a.jsx)(B.kt,{icon:_.A,label:U("address_books.delete"),onClick:()=>{V(),w($)},destructive:!0})]})),X.data&&C&&(0,a.jsx)(B.tz,{ref:et,isOpen:X.isOpen,position:X.position,onClose:ee,children:(0,a.jsx)(B.kt,{icon:D.A,label:U("rename_category"),onClick:()=>{let e=X.data;ee(),C(e)}})}),P.data&&(0,a.jsxs)(B.tz,{ref:J,isOpen:P.isOpen,position:P.position,onClose:W,children:[(0,a.jsx)(B.kt,{icon:D.A,label:U("groups.edit"),onClick:()=>{W(),p?.(P.data.id)}}),g&&(0,a.jsx)(B.qu,{icon:k.A,label:U("groups.send_email"),children:["to","cc","bcc"].map(e=>(0,a.jsx)(B.kt,{label:U(`groups.send_email_${e}`),onClick:()=>{let t=P.data.id;W(),g(t,e)}},e))}),(0,a.jsx)(B.K5,{}),(0,a.jsx)(B.kt,{icon:_.A,label:U("form.delete"),onClick:()=>{W(),f?.(P.data.id)},destructive:!0})]})]})}function eZ({keyword:e,count:t,isActive:s,onSelect:l,onDropContacts:n,onContextMenu:o}){let[i,c]=(0,r.useState)(!1),d=(0,r.useCallback)(e=>{e.dataTransfer.types.includes("application/x-contact-ids")&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",c(!0))},[]),u=(0,r.useCallback)(()=>{c(!1)},[]),m=(0,r.useCallback)(t=>{t.preventDefault(),c(!1);let s=t.dataTransfer.getData("application/x-contact-ids");if(s&&n)try{let t=JSON.parse(s);t.length>0&&n(t,e)}catch{}},[e,n]);return(0,a.jsxs)("button",{onClick:l,onContextMenu:o,onDragOver:d,onDragLeave:u,onDrop:m,className:(0,z.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors",s?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted",i&&"bg-primary/20 ring-2 ring-primary/50"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,a.jsx)(ez.A,{className:"w-3.5 h-3.5 flex-shrink-0"}),(0,a.jsx)("span",{className:"truncate",children:e}),(0,a.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:t})]})}function eX({book:e,isActive:t,contactCount:s,onSelect:l,onDropContacts:n,onContextMenu:o}){let[c,d]=(0,r.useState)(!1),u=(0,r.useCallback)(e=>{e.dataTransfer.types.includes("application/x-contact-ids")&&(e.preventDefault(),e.dataTransfer.dropEffect="move",d(!0))},[]),m=(0,r.useCallback)(()=>{d(!1)},[]),x=(0,r.useCallback)(t=>{t.preventDefault(),d(!1);let s=t.dataTransfer.getData("application/x-contact-ids");if(s&&n)try{let t=JSON.parse(s);t.length>0&&n(t,e)}catch{}},[e,n]);return(0,a.jsxs)("button",{onClick:l,onContextMenu:o,onDragOver:u,onDragLeave:m,onDrop:x,className:(0,z.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors",t?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted",c&&"bg-primary/20 ring-2 ring-primary/50"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,a.jsx)(eS.A,{className:"w-4 h-4 flex-shrink-0"}),(0,a.jsx)("span",{className:"truncate",children:e.name}),!e.isShared&&Object.keys(e.shareWith||{}).length>0&&(0,a.jsx)(i.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0 ms-auto"}),(0,a.jsx)("span",{className:(0,z.cn)("text-xs text-muted-foreground tabular-nums",!(!e.isShared&&Object.keys(e.shareWith||{}).length>0)&&"ms-auto"),children:s})]})}var eQ=s(34620),e0=s(76416),e1=s(96449),e3=s(73525),e2=s(11141),e5=s(23837),e4=s(20529),e6=s(54643),e8=s(5671),e9=s(31760),e7=s(43540),te=s(4361),tt=s(19284),ts=s(60128),ta=s(56540);function tr(){let e,t,s,h,p,f,g,b,j,v=(0,l.c)("contacts"),y=(0,e5.V)(e=>e.isFeatureEnabled("contactsEnabled")),{client:k,isAuthenticated:N,logout:w,checkAuth:C,isLoading:_}=(0,em.useAuthStore)(),{showAppsModal:A,inlineApp:S,loadedApps:O,handleManageApps:M,handleInlineApp:$,closeInlineApp:B,closeAppsModal:T}=(0,e9.s)(),[D,E]=(0,r.useState)(()=>em.useAuthStore.getState().isAuthenticated&&!!em.useAuthStore.getState().client),{quota:L,isPushConnected:R}=(0,ex.useEmailStore)(),{contacts:U,addressBooks:Y,selectedContactId:G,searchQuery:K,supportsSync:J,selectedContactIds:q,setSelectedContact:H,setSearchQuery:V,fetchContacts:X,createContact:Q,updateContact:ee,deleteContact:et,addLocalContact:es,updateLocalContact:ea,deleteLocalContact:er,getGroupMembers:el,createGroup:en,updateGroup:eo,addMembersToGroup:ei,removeMembersFromGroup:ec,deleteGroup:ed,toggleContactSelection:eu,selectRangeContacts:eh,selectAllContacts:ep,clearSelection:ef,bulkDeleteContacts:eg,bulkAddToGroup:ej,moveContactToAddressBook:ev,createAddressBook:ey,renameAddressBook:ek,removeAddressBook:eN,shareAddressBook:ew,renameKeyword:eC,importContacts:e_}=(0,I.pc)(),[eA,eS]=(0,r.useState)("list"),[eO,eM]=(0,r.useState)("all"),[ez,eI]=(0,r.useState)(!1),[e$,eB]=(0,r.useState)(null),[eD,eE]=(0,r.useState)(!1),[eR,eU]=(0,r.useState)(null),[eY,eP]=(0,r.useState)(void 0),[eG,eK]=(0,r.useState)(void 0),[eJ,eq]=(0,r.useState)(!1),[eH,eZ]=(0,r.useState)(null),[eX,tr]=(0,r.useState)(null),tl=(0,r.useRef)(!1),{dialogProps:tn,confirm:to}=(0,x.G)(),ti=(0,tt.al)(),tc=(0,tt.GM)(),td=(0,e7.E)(),tu=(0,o.rd)(),tm=(0,n.useSearchParams)(),tx=(0,r.useRef)(!1),th=!tc,[tp,tf]=(0,r.useState)(!1);(0,r.useEffect)(()=>{th||tf(!1)},[th]);let[tg,tb]=(0,r.useState)(()=>{try{let e=localStorage.getItem("contacts-sidebar-width");return e?Number(e):256}catch{return 256}}),[tj,tv]=(0,r.useState)(!1),ty=(0,r.useRef)(256),[tk,tN]=(0,r.useState)(()=>{try{let e=localStorage.getItem("contacts-list-width");return e?Number(e):384}catch{return 384}}),[tw,tC]=(0,r.useState)(!1),t_=(0,r.useRef)(384);(0,r.useEffect)(()=>{let e=em.useAuthStore.getState();e.isAuthenticated&&e.client?E(!0):C().finally(()=>{E(!0)})},[C]),(0,r.useEffect)(()=>{if(D&&!N&&!_){try{sessionStorage.setItem("redirect_after_login",window.location.pathname)}catch{}(0,em.redirectToLogin)()}},[D,N,_]);let{enabled:tA,accountClients:tS}=(e=(0,e7.E)(),t=(0,W.C$)(e=>e.proInterface),s=(0,eW.E)(e=>e.accounts),h=(0,em.useAuthStore)(e=>e.activeAccountId),p=(0,I.pc)(e=>e.fetchAllAccountsAddressBooks),f=(0,I.pc)(e=>e.fetchAllAccountsContacts),g=t||e,b=(0,r.useMemo)(()=>{if(!g)return[];let e=em.useAuthStore.getState().getClientForAccount,t=[];for(let a of s){if(!a.isConnected)continue;let s=e(a.id);s&&s.supportsContacts()&&t.push({localAccountId:a.id,client:s})}return t},[g,s]),(0,r.useEffect)(()=>{g&&h&&0!==b.length&&(p(b,h),f(b,h))},[g,h,b,p,f]),{enabled:g,accountClients:b});(0,r.useEffect)(()=>{!td&&k&&J&&!tl.current&&(tl.current=!0,X(k))},[k,J,X,td]),(0,r.useEffect)(()=>{if(tx.current)return;let e=tm.get("contactId"),t=tm.get("addEmail"),s=tm.get("addName"),a=tm.get("from"),r=tm.get("view");(e||t||a)&&(tx.current=!0,"email"===a&&eq(!0),e?(H(e),eS("edit"===r?"edit":"detail")):t&&(eK({email:t,name:s??void 0}),H(null),eS("create")),tu.replace("/contacts"))},[tm,tu,H]),(0,ts.A)({enabled:N&&!!k&&J,onRefresh:async()=>{if(k){if(tA&&tS.length>0){let e=em.useAuthStore.getState().activeAccountId;if(e){let{fetchAllAccountsContacts:t,fetchAllAccountsAddressBooks:s}=I.pc.getState();await Promise.all([s(tS,e),t(tS,e)]);return}}await X(k)}}});let tO=(0,r.useMemo)(()=>U.filter(e=>"group"===e.kind),[U]),tM=(0,r.useMemo)(()=>U.filter(e=>"group"!==e.kind),[U]),tz=U.find(e=>e.id===G)||null,tI=eX&&U.find(e=>e.id===eX)||null,t$=(0,r.useMemo)(()=>eX?el(eX):[],[eX,el]),tB=(0,r.useMemo)(()=>{let e=new Set;for(let t of tM)if(t.keywords)for(let[s,a]of Object.entries(t.keywords))a&&e.add(s);return Array.from(e).sort((e,t)=>e.localeCompare(t))},[tM]),tT=(0,r.useMemo)(()=>{if("all"===eO)return tM;if("uncategorized"===eO)return tM.filter(e=>!e.keywords||0===Object.keys(e.keywords).filter(t=>e.keywords[t]).length);if("addressBookId"in eO){let e=eO.addressBookId;return tM.filter(t=>!!t.addressBookIds&&!0===t.addressBookIds[e])}return"keyword"in eO?tM.filter(e=>e.keywords?.[eO.keyword]):el(eO.groupId)},[eO,tM,el]),tD=(0,r.useCallback)(e=>{eM(e),ef(),"object"==typeof e&&"groupId"in e?(tr(e.groupId),eS("group-detail")):tr(null),tf(!1)},[ef]),tE=(0,r.useCallback)(async(e,t)=>{if(k)try{await ev(k,e,t);let s=1===e.length?v("address_books.moved",{name:t.name}):v("address_books.moved_plural",{count:e.length,name:t.name});P.o.success(s)}catch(e){console.error("Failed to move contacts:",e),P.o.error(v("address_books.move_failed"))}},[k,ev,v]),tL=(0,r.useCallback)(async(e,t)=>{if(k||!J)try{for(let s of e){let e=U.find(e=>e.id===s);if(!e)continue;let a=e.keywords||{};if(a[t])continue;let r={...a,[t]:!0};J&&k?await ee(k,s,{keywords:r}):ea(s,{keywords:r})}let s=1===e.length?v("category_added",{name:t}):v("category_added_plural",{count:e.length,name:t});P.o.success(s)}catch(e){console.error("Failed to add contacts to category:",e),P.o.error(v("toast.error_update"))}},[k,J,U,ee,ea,v]),tR=(0,r.useCallback)(async()=>{if(k){if(tA&&tS.length>0){let e=em.useAuthStore.getState().activeAccountId;if(e){let{fetchAllAccountsAddressBooks:t}=I.pc.getState();await t(tS,e);return}}await I.pc.getState().fetchAddressBooks(k)}},[k,tA,tS]),tF=(0,r.useCallback)(async e=>{if(k)try{await ey(k,e),await tR(),P.o.success(v("address_books.created")),eE(!1)}catch(e){console.error("Failed to create address book:",e),P.o.error(v("address_books.create_failed"))}},[k,ey,tR,v]),tU=(0,r.useCallback)(async e=>e_(J&&k?k:null,e),[J,k,e_]),tY=()=>{H(null),eS("create")},tP=()=>{eS("edit")},tG=(0,r.useCallback)(async e=>{if(await to({title:v("delete_confirm_title"),message:v("delete_confirm"),confirmText:v("form.delete"),variant:"destructive"}))try{J&&k?await et(k,e):er(e),P.o.success(v("toast.deleted")),G===e&&eS("list")}catch(e){console.error("Failed to delete contact:",e),P.o.error(v("toast.error_delete"))}},[to,v,J,k,et,er,G]),tK=async()=>{tz&&await tG(tz.id)},tW=(0,r.useCallback)(e=>{H(e),eS("edit")},[H]),tJ=(0,r.useCallback)(e=>{tG(e.id)},[tG]),tq=(0,r.useCallback)(e=>{(ef(),eu(e),0===tO.length)?eS("group-create"):eS("bulk-add-to-group")},[ef,eu,tO.length]),tH=(0,r.useCallback)(async e=>{let{id:t,created:s,updated:a,...r}=e,l=JSON.parse(JSON.stringify(r));J&&k?await Q(k,l):es({id:`local-${(0,z.lk)()}`,addressBookIds:l.addressBookIds||{},...l}),P.o.success(v("toast.created"))},[J,k,Q,es,v]),tV=(0,r.useCallback)(async e=>{if(J&&k?await Q(k,e):es({id:`local-${(0,z.lk)()}`,addressBookIds:{},...e}),P.o.success(v("toast.created")),eP(void 0),eK(void 0),eJ){eq(!1),tu.back();return}eS("list")},[J,k,Q,es,v,eJ,tu]),tZ=(0,r.useCallback)(async e=>{tz&&(J&&k?await ee(k,tz.id,e):ea(tz.id,e),P.o.success(v("toast.updated")),eS("detail"))},[J,k,tz,ee,ea,v]),tX=()=>{if(eP(void 0),eJ&&"create"===eA){eK(void 0),eq(!1),tu.back();return}"create"===eA&&eK(void 0),"group-create"===eA||"group-edit"===eA?eS(tI?"group-detail":"list"):"bulk-add-to-group"===eA?eS("list"):eS(tz?"detail":"list")},tQ=()=>{eS("group-edit")},t0=(0,r.useCallback)(e=>{tr(e),eM({groupId:e}),eS("group-edit")},[]),t1=(0,r.useCallback)((e,t)=>{(0,e3.B2)({to:"to"===t?e:[],cc:"cc"===t?e:[],bcc:"bcc"===t?e:[],subject:"",body:""}),tu.push("/")},[tu]),t3=(0,r.useCallback)((e,t)=>{let s=new Set,a=[];for(let t of el(e)){let e=(0,I.Bp)(t).trim(),r=e.toLowerCase();if(!e||s.has(r))continue;s.add(r);let l=(0,I.YM)(t);a.push({name:l&&l!==e?l:void 0,email:e})}if(0===a.length)return void P.o.error(v("groups.no_member_emails"));let r=I.pc.getState().contacts.find(t=>t.id===e),l={name:r&&(0,I.YM)(r)||"Group",email:"",group:{members:a}};t1([(0,e2.Rx)(l)],t)},[el,v,t1]),t2=(0,r.useCallback)(e=>{let t=(0,I.Bp)(e).trim();t&&t1([(0,e2.jZ)((0,I.YM)(e),t)],"to")},[t1]),t5=(0,r.useCallback)(async e=>{if(await to({title:v("groups.delete_confirm_title"),message:v("groups.delete_confirm"),confirmText:v("form.delete"),variant:"destructive"}))try{await ed(J&&k?k:null,e),P.o.success(v("toast.deleted")),eX===e&&(tr(null),eM("all"),eS("list"))}catch(e){console.error("Failed to delete group:",e),P.o.error(v("toast.error_delete"))}},[to,ed,J,k,eX,v]),t4=async()=>{if(tI&&await to({title:v("groups.delete_confirm_title"),message:v("groups.delete_confirm"),confirmText:v("form.delete"),variant:"destructive"}))try{await ed(J&&k?k:null,tI.id),P.o.success(v("toast.deleted")),tr(null),eS("list")}catch(e){console.error("Failed to delete group:",e),P.o.error(v("toast.error_delete"))}},t6=(0,r.useCallback)(async(e,t)=>{let s=J&&k?k:null;if("group-edit"===eA&&tI){await eo(s,tI.id,e);let a=t$.map(e=>e.id),r=t.filter(e=>!a.includes(e)),l=a.filter(e=>!t.includes(e));r.length>0&&await ei(s,tI.id,r),l.length>0&&await ec(s,tI.id,l),P.o.success(v("toast.updated")),eS("group-detail")}else await en(s,e,t),P.o.success(v("toast.created")),eS("list")},[eA,tI,t$,J,k,en,eo,ei,ec,v]),t8=async e=>{if(tI)try{await ec(J&&k?k:null,tI.id,[e]),P.o.success(v("toast.updated"))}catch(e){console.error("Failed to remove group member:",e),P.o.error(v("toast.error_update"))}},t9=async()=>{if(0!==q.size&&await to({title:v("bulk.delete_confirm_title"),message:v("bulk.delete_confirm",{count:q.size}),confirmText:v("bulk.delete"),variant:"destructive"}))try{await eg(J&&k?k:null,Array.from(q)),P.o.success(v("bulk.deleted",{count:q.size})),eS("list")}catch(e){console.error("Failed to bulk delete contacts:",e),P.o.error(v("toast.error_delete"))}},t7=async e=>{try{await ej(J&&k?k:null,e,Array.from(q)),P.o.success(v("bulk.added_to_group")),eS("list")}catch(e){console.error("Failed to add contacts to group:",e),P.o.error(v("toast.error_update"))}};if(!N)return null;if(!y)return(0,a.jsx)("div",{className:"flex h-dvh items-center justify-center bg-background p-6",children:(0,a.jsxs)("div",{className:"max-w-lg text-center space-y-3",children:[(0,a.jsx)(c.A,{className:"w-10 h-10 text-yellow-500 mx-auto"}),(0,a.jsx)("p",{className:"text-sm font-medium",children:"Contacts feature is disabled by your administrator"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Please contact your administrator if you need access."})]})});let se=!ti||"list"===eA,st=!ti||"list"!==eA;return(0,a.jsxs)("div",{className:(0,z.cn)("flex flex-col bg-background overflow-hidden pt-[env(safe-area-inset-top)]",td?"h-full":"h-dvh"),children:[(0,a.jsx)(e1.T,{}),(0,a.jsxs)("div",{className:(0,z.cn)("flex flex-1 min-h-0 overflow-hidden",ti&&"flex-col"),children:[!ti&&!td&&(0,a.jsx)("div",{className:"w-14 bg-secondary flex flex-col flex-shrink-0",style:{borderRight:"1px solid rgba(128, 128, 128, 0.3)"},children:(0,a.jsx)(e4.t,{collapsed:!0,quota:L,isPushConnected:R,onLogout:w,onManageApps:M,onInlineApp:$,onCloseInlineApp:B,activeAppId:S?.id??null})}),(0,a.jsxs)("div",{className:"flex flex-col flex-1 min-w-0 min-h-0",children:[S&&(0,a.jsx)(e8.G,{apps:O,activeAppId:S.id,onClose:B}),(0,a.jsxs)("div",{className:(0,z.cn)("relative flex flex-1 min-h-0",S&&"hidden"),children:[th&&tp&&(0,a.jsx)("div",{className:(0,z.cn)("inset-0 bg-black/50 z-40",td?"absolute":"fixed"),onClick:()=>tf(!1)}),se&&(0,a.jsxs)(a.Fragment,{children:[(!ti||th)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:(0,z.cn)("border-e border-border flex flex-col flex-shrink-0 bg-background",!tj&&"transition-[width] duration-300",th&&(0,z.cn)("absolute inset-y-0 left-0 z-50 w-72 pt-[env(safe-area-inset-top)]","transform transition-transform duration-300 ease-in-out",!tp&&"-translate-x-full")),style:th?void 0:{width:`${tg}px`},children:(0,a.jsx)(eV,{groups:tO,individuals:tM,addressBooks:Y,activeCategory:eO,onSelectCategory:tD,onCreateGroup:()=>{tr(null),eS("group-create")},onCreateContact:tY,onCreateAddressBook:k?()=>eE(!0):void 0,onImport:()=>eI(!0),onEditGroup:t0,onDeleteGroup:t5,onComposeGroup:t3,onDropContacts:tE,onDropContactsToCategory:tL,onRenameAddressBook:k?e=>eB(e):void 0,onShareAddressBook:k?e=>eU(e.id):void 0,onCreateContactInBook:e=>{eP(e.id),tY()},onDeleteAddressBook:k?async e=>{if(await to({title:v("address_books.delete"),message:v("address_books.confirm_delete",{name:e.name}),variant:"destructive",confirmText:v("address_books.delete")}))try{await eN(k,e),P.o.success(v("address_books.deleted"))}catch{P.o.error(v("address_books.delete_failed"))}}:void 0,onRenameKeyword:e=>eZ(e),multiAccountMode:tA&&tS.length>1})}),!th&&(0,a.jsx)(te.X,{onResizeStart:()=>{ty.current=tg,tv(!0)},onResize:e=>tb(Math.max(180,Math.min(400,ty.current+e))),onResizeEnd:()=>{tv(!1),localStorage.setItem("contacts-sidebar-width",String(tg))},onDoubleClick:()=>{tb(256),localStorage.setItem("contacts-sidebar-width","256")}})]}),(0,a.jsx)("div",{"data-tour":"contacts-list",className:(0,z.cn)("border-e border-border bg-background flex flex-col flex-shrink-0",ti?"w-full":"",!tw&&!ti&&"transition-[width] duration-300"),style:ti?void 0:{width:`${tk}px`},children:(0,a.jsx)(Z,{contacts:tT,selectedContactId:G,searchQuery:K,onSearchChange:V,onSelectContact:e=>{H(e),ef(),eS("detail")},onCreateNew:tY,className:"flex-1",selectedContactIds:q,onToggleSelection:eu,onSelectRangeContacts:eh,onSelectAll:ep,onClearSelection:ef,onBulkDelete:t9,onBulkAddToGroup:()=>{if(0!==q.size){if(0===tO.length)return void eS("group-create");eS("bulk-add-to-group")}},onBulkExport:()=>{let e=U.filter(e=>q.has(e.id));e.length>0&&((0,F.W)(e),P.o.success(v("export.success",{count:e.length})),ef())},onEditContact:tW,onDeleteContact:tJ,onAddContactToGroup:tq,onMenuClick:th?()=>tf(!0):void 0})}),!ti&&(0,a.jsx)(te.X,{onResizeStart:()=>{t_.current=tk,tC(!0)},onResize:e=>tN(Math.max(220,Math.min(500,t_.current+e))),onResizeEnd:()=>{tC(!1),localStorage.setItem("contacts-list-width",String(tk))},onDoubleClick:()=>{tN(384),localStorage.setItem("contacts-list-width","384")}})]}),st&&(0,a.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[ti&&(0,a.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,a.jsxs)(u.$,{variant:"ghost",size:"sm",onClick:()=>{if(eJ){eq(!1),eK(void 0),tu.back();return}eS("list"),ef()},className:"touch-manipulation",children:[(0,a.jsx)(d.A,{className:"w-4 h-4 me-2"}),eJ?v("back_to_email"):v("back_to_contacts")]})}),(0,a.jsx)("div",{className:"flex-1 min-h-0",children:(()=>{switch(eA){case"create":return(0,a.jsx)(eT,{addressBooks:Y,allKeywords:tB,defaultAddressBookId:eY,prefill:eG,onSave:tV,onCancel:tX});case"edit":if(!tz)return null;return(0,a.jsx)(eT,{contact:tz,addressBooks:Y,allKeywords:tB,onSave:tZ,onCancel:tX});case"group-detail":if(!tI)return null;return(0,a.jsx)(eF,{group:tI,members:t$,onEdit:tQ,onDelete:t4,onRemoveMember:t8,onComposeGroup:e=>t3(tI.id,e),isMobile:ti,onSelectMember:e=>{H(e),eS("detail")}});case"group-create":return(0,a.jsx)(eL,{individuals:tM,onSave:t6,onCancel:tX});case"group-edit":if(!tI)return null;return(0,a.jsx)(eL,{group:tI,individuals:tM,currentMemberIds:t$.map(e=>e.id),onSave:t6,onCancel:tX});case"bulk-add-to-group":return(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"px-6 py-4 border-b border-border",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:v("bulk.choose_group")}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:v("bulk.adding_contacts",{count:q.size})})]}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto divide-y divide-border",children:tO.map(e=>{let t=(0,I.YM)(e),s=e.members?Object.values(e.members).filter(Boolean).length:0;return(0,a.jsxs)("button",{onClick:()=>t7(e.id),className:"w-full flex items-center gap-3 px-6 py-3 text-start hover:bg-muted transition-colors",children:[(0,a.jsx)("div",{className:"w-9 h-9 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0",children:(0,a.jsx)(i.A,{className:"w-4 h-4 text-primary"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-sm font-medium truncate",children:t}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:v("groups.member_count",{count:s})})]})]},e.id)})}),(0,a.jsx)("div",{className:"px-6 py-4 border-t border-border",children:(0,a.jsx)(u.$,{variant:"outline",onClick:tX,className:"w-full",children:v("form.cancel")})})]});default:return(0,a.jsx)(eb,{contact:tz,onEdit:tP,onDelete:tK,onCompose:tz?()=>t2(tz):void 0,onAddToGroup:tz?()=>tq(tz.id):void 0,onDuplicate:tz?()=>void tH(tz):void 0,isMobile:ti})}})()})]})]}),ti&&!td&&(0,a.jsx)(e4.t,{orientation:"horizontal",onManageApps:M,onInlineApp:$,onCloseInlineApp:B,activeAppId:S?.id??null})]}),(0,a.jsx)(e6.E,{isOpen:A,onClose:T}),(0,a.jsx)(m.T,{...tn}),null!==eH&&(0,a.jsx)(e0.L,{currentName:eH,title:v("rename_category"),label:v("category_name_label"),onCancel:()=>eZ(null),onConfirm:async e=>{try{await eC(J&&k?k:null,eH,e),P.o.success(v("category_renamed")),"object"==typeof eO&&"keyword"in eO&&eO.keyword===eH&&eM({keyword:e.trim()}),eZ(null)}catch(e){console.error("Failed to rename category:",e),P.o.error(v("category_rename_failed"))}}}),eD&&(0,a.jsx)(e0.L,{currentName:"",title:v("address_books.create"),label:v("address_books.name_label"),onCancel:()=>eE(!1),onConfirm:tF}),e$&&(0,a.jsx)(e0.L,{currentName:e$.name,title:v("address_books.rename"),label:v("address_books.name_label"),onCancel:()=>eB(null),onConfirm:async e=>{if(k)try{await ek(k,e$,e),P.o.success(v("address_books.renamed")),eB(null)}catch(e){console.error("Failed to rename address book:",e),P.o.error(v("address_books.rename_failed"))}}}),ez&&(0,a.jsx)("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:(0,a.jsx)("div",{className:"bg-background rounded-lg border border-border shadow-xl w-full max-w-2xl max-h-[80vh] overflow-hidden",children:(0,a.jsx)(eQ.m,{existingContacts:U,onImport:tU,onClose:()=>eI(!1)})})}),eR&&k&&((j=Y.find(e=>e.id===eR))?(0,a.jsx)(ta.S,{client:k,kind:"addressBook",collectionName:j.name,shareWith:j.shareWith,ownAccountId:k.getAccountId(),onShare:async(e,t)=>{await ew(k,j,e,t)},onClose:()=>eU(null)}):null)]})]})}}}]);