"use strict";exports.id=8637,exports.ids=[8637],exports.modules={88637:(a,b,c)=>{c.r(b),c.d(b,{default:()=>be});var d=c(48249),e=c(67484),f=c(77360),g=c(19099),h=c(88513),i=c(68762),j=c(31675),k=c(51381),l=c(26284),m=c(2145),n=c(43828),o=c(16231),p=c(9915),q=c(99941),r=c(44643),s=c(10316),t=c(46674),u=c(56692),v=c(89165),w=c(28147),x=c(25378),y=c(33407),z=c(84248),A=c(59347),B=c(61349),C=c(35388),D=c(8422),E=c(62407),F=c(33191),G=c(39165);function H({contact:a,isSelected:b,isChecked:c,hasSelection:f,density:g,selectedContactIds:h,onClick:i,onCheckboxClick:j,onContextMenu:k}){let l=(0,G.YM)(a),m=(0,G.Bp)(a),n=a.organizations?Object.values(a.organizations)[0]?.name:void 0,o=(0,e.useCallback)(b=>{let c=h.has(a.id)?Array.from(h):[a.id];b.dataTransfer.effectAllowed="copyMove",b.dataTransfer.setData("application/x-contact-ids",JSON.stringify(c)),b.dataTransfer.setData("text/plain",l||m||a.id);let d=document.createElement("div");d.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;
    `,d.textContent=1===c.length?l||"1 contact":`${c.length} contacts`,document.body.appendChild(d),b.dataTransfer.setDragImage(d,0,0),requestAnimationFrame(()=>d.remove())},[a.id,l,m,h]);return(0,d.jsxs)("div",{draggable:!0,onDragStart:o,onClick:i,onContextMenu:k?b=>k(b,a):void 0,className:(0,F.cn)("w-full flex items-center cursor-pointer select-none transition-all duration-200 border-b border-border",b?"bg-selection shadow-sm":"bg-background hover:bg-muted hover:shadow-sm",c&&!b&&"ring-2 ring-primary/20 bg-selection/60"),style:{gap:"var(--density-item-gap)",paddingInline:"16px",paddingBlock:"var(--density-item-py)"},children:[f&&(0,d.jsx)("button",{onClick:j,className:(0,F.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",c&&"text-primary"),children:c?(0,d.jsx)(q.A,{className:"w-4 h-4 animate-in zoom-in-50 duration-200"}):(0,d.jsx)(r.A,{className:"w-4 h-4 text-muted-foreground opacity-60 hover:opacity-100 transition-opacity"})}),"extra-compact"!==g&&(0,d.jsx)(E.e,{name:l,email:m,size:"sm",className:"flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("div",{className:"text-sm font-medium truncate",children:l||m||"-"}),"extra-compact"!==g&&m&&l&&(0,d.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:m}),"comfortable"===g&&n&&(0,d.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:n})]})]})}var I=c(46311),J=c(61075),K=c(12625),L=c(79888),M=c(15273),N=c(19366),O=c(58236);function P(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Q(a,b){let c=window.open("","_blank");if(!c)return;let d=b||(0,G.YM)(a),e=(0,G.$q)(a),f=a.emails?Object.values(a.emails):[],g=a.phones?Object.values(a.phones):[],h=a.organizations?Object.values(a.organizations):[],i=a.titles?Object.values(a.titles):[],j=a.addresses?Object.values(a.addresses):[],k=a.onlineServices?Object.values(a.onlineServices):[],l=a.notes?Object.values(a.notes):[],m=a.anniversaries?Object.values(a.anniversaries):[],n=[],o=(a,b)=>{0!==b.length&&n.push(`<section><h2>${P(a)}</h2><dl>${b.join("")}</dl></section>`)},p=(a,b)=>`<dt>${P(a)}</dt><dd>${P(b)}</dd>`;o("Email",f.map(a=>p(a.label||"Email",a.address||""))),o("Phone",g.map(a=>p(a.label||"Phone",a.number||""))),o("Organization",h.map(a=>{let b=a.units?Object.values(a.units).map(a=>a.name).filter(Boolean).join(", "):"";return p("Organization",[a.name,b].filter(Boolean).join(" — "))})),o("Title",i.map(a=>p("role"===a.kind?"Role":"Title",a.name||""))),o("Address",j.map(a=>{let b=[a.street,a.locality,a.region,a.postcode,a.country].map(a=>"string"==typeof a?a:"").filter(Boolean);return p(a.label||"Address",b.join(", "))})),o("Online",k.map(a=>p(a.label||a.service||"Online",a.uri||a.user||""))),o("Anniversary",m.map(a=>{let b=a.date,c="";if("object"==typeof b&&null!==b)if("utc"in b&&"string"==typeof b.utc)c=b.utc;else{let a=[];b.year&&a.push(String(b.year)),b.month&&a.push(String(b.month).padStart(2,"0")),b.day&&a.push(String(b.day).padStart(2,"0")),c=a.join("-")}else b&&(c=String(b));return p(a.kind||"Date",c)})),o("Notes",l.map(a=>p("",a.note||"")));let q=e?`<img class="photo" src="${P(e)}" alt="" />`:`<div class="photo placeholder">${P((d||"?").charAt(0).toUpperCase())}</div>`,r=`<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>${P(d||"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>
  ${q}
  <div><h1>${P(d||"Contact")}</h1></div>
</header>
${n.join("")}
</body>
</html>`;c.document.write(r),c.document.close(),c.focus(),c.print()}var R=c(64866);function S({contact:a,position:b,isOpen:c,onClose:e,menuRef:g,isMultiSelect:h=!1,selectedCount:j=1,onOpen:k,onEdit:l,onDelete:m,onAddToGroup:n,onDuplicate:o,onBatchExport:p,onBatchAddToGroup:q,onBatchDelete:r}){let s=(0,f.c)("contacts"),t=(0,G.Bp)(a),u=a.phones&&Object.values(a.phones)[0]?.number||"",v=a=>()=>{a(),e()},y=async a=>{if(a)try{await navigator.clipboard.writeText(a),R.o.success(s("detail.copied"))}catch{R.o.error(s("detail.copy_failed"))}};return h&&j>1?(0,d.jsxs)(I.tz,{ref:g,isOpen:c,position:b,onClose:e,children:[(0,d.jsx)(I.Sp,{children:s("bulk.selected",{count:j})}),(0,d.jsx)(I.kt,{icon:i.A,label:s("bulk.add_to_group"),onClick:v(()=>q?.()),disabled:!q}),(0,d.jsx)(I.kt,{icon:z.A,label:s("bulk.export"),onClick:v(()=>p?.()),disabled:!p}),(0,d.jsx)(I.K5,{}),(0,d.jsx)(I.kt,{icon:A.A,label:s("bulk.delete"),onClick:v(()=>r?.()),disabled:!r,destructive:!0})]}):(0,d.jsxs)(I.tz,{ref:g,isOpen:c,position:b,onClose:e,children:[(0,d.jsx)(I.kt,{icon:J.A,label:s("context_menu.open"),onClick:v(k)}),(0,d.jsx)(I.kt,{icon:K.A,label:s("context_menu.edit"),onClick:v(l)}),(t||u)&&(0,d.jsx)(I.K5,{}),t&&(0,d.jsx)(I.kt,{icon:w.A,label:s("context_menu.send_email"),onClick:v(()=>{t&&(window.location.href=`mailto:${t}`)})}),u&&(0,d.jsx)(I.kt,{icon:x.A,label:s("context_menu.call"),onClick:v(()=>{u&&(window.location.href=`tel:${u}`)})}),t&&(0,d.jsx)(I.kt,{icon:L.A,label:s("detail.copy_email"),onClick:v(()=>y(t))}),u&&(0,d.jsx)(I.kt,{icon:L.A,label:s("detail.copy_phone"),onClick:v(()=>y(u))}),(0,d.jsx)(I.K5,{}),(0,d.jsx)(I.kt,{icon:i.A,label:s("context_menu.add_to_group"),onClick:v(n)}),o&&(0,d.jsx)(I.kt,{icon:M.A,label:s("context_menu.duplicate"),onClick:v(o)}),(0,d.jsx)(I.kt,{icon:z.A,label:s("context_menu.export_vcard"),onClick:v(()=>{(0,O.J)(a),R.o.success(s("export.success",{count:1}))})}),(0,d.jsx)(I.kt,{icon:N.A,label:s("context_menu.print"),onClick:v(()=>{Q(a)})}),(0,d.jsx)(I.K5,{}),(0,d.jsx)(I.kt,{icon:A.A,label:s("context_menu.delete"),onClick:v(m),destructive:!0})]})}var T=c(91326),U=c(2840);let V={organization:"",jobTitle:"",location:"",emailDomain:"",birthdayMonth:null,hasEmail:null,hasPhone:null,hasPhoto:null};function W(a){return null===a||!0!==a&&null}function X(a,b){return null===b||a===b}function Y({icon:a,label:b,value:c,onClick:e}){return(0,d.jsxs)("button",{type:"button",onClick:e,className:(0,F.cn)("inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs transition-colors border",!0===c&&"bg-primary/10 border-primary/30 text-primary",!1===c&&"bg-muted border-border text-muted-foreground line-through",null===c&&"bg-background border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),children:[a,b]})}function Z({contacts:a,selectedContactId:b,searchQuery:c,onSearchChange:g,onSelectContact:h,onCreateNew:j,className:k,selectedContactIds:m,onToggleSelection:n,onSelectRangeContacts:E,onSelectAll:I,onClearSelection:J,onBulkDelete:K,onBulkAddToGroup:L,onBulkExport:M,onEditContact:N,onDeleteContact:O,onAddContactToGroup:P,onMenuClick:Q}){let R,$,_=(0,f.c)("contacts"),aa=(0,o.Ym)(),ab=(0,U.C$)(a=>a.density),ac=(0,U.C$)(a=>a.groupContactsByLetter),{contextMenu:ad,openContextMenu:ae,closeContextMenu:af,menuRef:ag}=(0,T.E)(),[ah,ai]=(0,e.useState)(!1),[aj,ak]=(0,e.useState)(V),al=(R=0,aj.organization.trim()&&R++,aj.jobTitle.trim()&&R++,aj.location.trim()&&R++,aj.emailDomain.trim()&&R++,null!==aj.birthdayMonth&&R++,null!==aj.hasEmail&&R++,null!==aj.hasPhone&&R++,null!==aj.hasPhoto&&R++,R),am=(0,e.useMemo)(()=>{let a=new Intl.DateTimeFormat(aa,{month:"long"});return Array.from({length:12},(b,c)=>a.format(new Date(2e3,c,1)))},[aa]),an=(0,e.useMemo)(()=>{let b=c.trim().toLowerCase(),d=aj.organization.trim().toLowerCase(),e=aj.jobTitle.trim().toLowerCase(),f=aj.location.trim().toLowerCase(),g=aj.emailDomain.trim().toLowerCase().replace(/^@/,"");return a.filter(a=>{let c=a.emails?Object.values(a.emails):[],h=a.phones?Object.values(a.phones):[],i=a.organizations?Object.values(a.organizations):[],j=a.titles?Object.values(a.titles):[],k=a.addresses?Object.values(a.addresses):[],l=a.anniversaries?Object.values(a.anniversaries):[];if(!X(c.length>0,aj.hasEmail)||!X(h.length>0,aj.hasPhone)||!X(!!(0,G.$q)(a),aj.hasPhoto)||d&&!i.some(a=>!!(a.name?.toLowerCase().includes(d)||a.units?.some(a=>a.name?.toLowerCase().includes(d))))||e&&!j.some(a=>a.name?.toLowerCase().includes(e))||f&&!k.some(a=>{let b=[];if(a.full&&b.push(a.full),a.fullAddress&&b.push(a.fullAddress),a.locality&&b.push(a.locality),a.region&&b.push(a.region),a.country&&b.push(a.country),a.postcode&&b.push(a.postcode),a.street&&b.push(a.street),a.components)for(let c of a.components)c.value&&b.push(c.value);return b.some(a=>a.toLowerCase().includes(f))})||g&&!c.some(a=>{let b=a.address?.toLowerCase().split("@");return b&&b.length>1&&b[1].includes(g)}))return!1;if(null!==aj.birthdayMonth){let a=aj.birthdayMonth;if(!l.some(b=>"birth"===b.kind&&function(a){if("string"==typeof a){let b=a.match(/^(\d{4})-(\d{2})/);if(b)return parseInt(b[2],10);let c=a.match(/^--(\d{2})/);return c?parseInt(c[1],10):null}if("month"in a&&a.month)return a.month;if("utc"in a&&a.utc){let b=new Date(a.utc);return isNaN(b.getTime())?null:b.getMonth()+1}return null}(b.date)===a))return!1}return!!(!b||(0,G.YM)(a).toLowerCase().includes(b)||c.some(a=>a.address?.toLowerCase().includes(b))||h.some(a=>a.number?.toLowerCase().includes(b))||i.some(a=>a.name?.toLowerCase().includes(b)))})},[a,c,aj]),ao=(0,e.useMemo)(()=>[...an].sort((a,b)=>{let c=(0,G.YM)(a).toLowerCase(),d=(0,G.YM)(b).toLowerCase();return c.localeCompare(d)}),[an]),ap=(0,e.useMemo)(()=>ao.map(a=>a.id),[ao]),aq=(0,e.useMemo)(()=>{let a=new Intl.Collator(aa,{sensitivity:"base"}),b=new Map;for(let a of ao){let c=(0,G.YM)(a).trim().charAt(0),d=c&&c.toLocaleUpperCase(aa).match(/\p{L}/u)?c.toLocaleUpperCase(aa):"#",e=b.get(d);e?e.push(a):b.set(d,[a])}return Array.from(b.entries()).sort(([b],[c])=>"#"===b?1:"#"===c?-1:a.compare(b,c)).map(([a,b])=>({letter:a,items:b}))},[ao,aa]),ar=m.size>0,as=ao.length>0&&ao.every(a=>m.has(a.id));return(0,d.jsxs)("div",{className:(0,F.cn)("flex flex-col h-full",k),children:[(0,d.jsx)("div",{className:"border-b border-border bg-background",children:(0,d.jsx)("div",{className:"px-3 py-3",children:(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[Q&&(0,d.jsx)("button",{type:"button",onClick:Q,className:"flex-shrink-0 p-2 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors","aria-label":_("open_categories"),children:(0,d.jsx)(p.A,{className:"w-4 h-4"})}),(0,d.jsx)("button",{type:"button",onClick:()=>{ar?as?J():I(ap):ap.length>0&&n(b&&ap.includes(b)?b:ap[0])},className:(0,F.cn)("flex-shrink-0 p-2 rounded-md transition-colors",ar?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:_(ar?as?"bulk.clear":"bulk.select_all":"filters.select"),children:ar?(0,d.jsx)(q.A,{className:"w-4 h-4"}):(0,d.jsx)(r.A,{className:"w-4 h-4"})}),(0,d.jsxs)("div",{className:"relative flex-1",children:[(0,d.jsx)(s.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),(0,d.jsx)(D.p,{type:"text",placeholder:_("search_placeholder"),value:c,onChange:a=>g(a.target.value),className:(0,F.cn)("ps-9 h-9",c&&"pe-8")}),c&&(0,d.jsx)("button",{type:"button",onClick:()=>g(""),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":_("clear_search"),children:(0,d.jsx)(t.A,{className:"w-4 h-4"})})]}),(0,d.jsxs)("button",{type:"button",onClick:()=>ai(a=>!a),className:(0,F.cn)("relative flex-shrink-0 p-2 rounded-md transition-colors",ah||al>0?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:_("filters.toggle"),"aria-label":_("filters.toggle"),children:[(0,d.jsx)(u.A,{className:"w-4 h-4"}),!ah&&al>0&&(0,d.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:al})]})]})})}),ah&&(0,d.jsx)("div",{className:"border-b border-border bg-muted/30 animate-in slide-in-from-top-2 fade-in duration-200",children:(0,d.jsxs)("div",{className:"px-4 py-3 space-y-3",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between",children:[(0,d.jsx)("span",{className:"text-sm font-medium text-foreground",children:_("filters.title")}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsxs)(l.$,{variant:"ghost",size:"sm",onClick:()=>ak(V),className:"h-7 px-2 text-xs",children:[(0,d.jsx)(v.A,{className:"w-3 h-3 me-1"}),_("filters.clear")]}),(0,d.jsx)(l.$,{variant:"ghost",size:"icon",onClick:()=>ai(!1),className:"h-7 w-7","aria-label":_("filters.close"),children:(0,d.jsx)(t.A,{className:"w-4 h-4"})})]})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:_("filters.organization")}),(0,d.jsx)(D.p,{value:aj.organization,onChange:a=>ak(b=>({...b,organization:a.target.value})),placeholder:_("filters.organization_placeholder"),className:"h-8 text-sm"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:_("filters.job_title")}),(0,d.jsx)(D.p,{value:aj.jobTitle,onChange:a=>ak(b=>({...b,jobTitle:a.target.value})),placeholder:_("filters.job_title_placeholder"),className:"h-8 text-sm"})]})]}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:_("filters.location")}),(0,d.jsx)(D.p,{value:aj.location,onChange:a=>ak(b=>({...b,location:a.target.value})),placeholder:_("filters.location_placeholder"),className:"h-8 text-sm"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:_("filters.email_domain")}),(0,d.jsx)(D.p,{value:aj.emailDomain,onChange:a=>ak(b=>({...b,emailDomain:a.target.value})),placeholder:_("filters.email_domain_placeholder"),className:"h-8 text-sm"})]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:_("filters.birthday_month")}),(0,d.jsxs)("select",{value:aj.birthdayMonth??"",onChange:a=>ak(b=>({...b,birthdayMonth:""===a.target.value?null:Number(a.target.value)})),className:"h-8 w-full text-sm rounded-md border border-input bg-background px-2","aria-label":_("filters.birthday_month"),children:[(0,d.jsx)("option",{value:"",children:_("filters.any_month")}),am.map((a,b)=>(0,d.jsx)("option",{value:b+1,children:a},b))]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,d.jsx)(Y,{icon:(0,d.jsx)(w.A,{className:"w-3.5 h-3.5"}),label:_("filters.has_email"),value:aj.hasEmail,onClick:()=>ak(a=>({...a,hasEmail:W(a.hasEmail)}))}),(0,d.jsx)(Y,{icon:(0,d.jsx)(x.A,{className:"w-3.5 h-3.5"}),label:_("filters.has_phone"),value:aj.hasPhone,onClick:()=>ak(a=>({...a,hasPhone:W(a.hasPhone)}))}),(0,d.jsx)(Y,{icon:(0,d.jsx)(y.A,{className:"w-3.5 h-3.5"}),label:_("filters.has_photo"),value:aj.hasPhoto,onClick:()=>ak(a=>({...a,hasPhoto:W(a.hasPhoto)}))})]})]})}),ar&&(0,d.jsxs)("div",{className:"px-3 py-1.5 border-b border-border bg-accent/30 flex items-center gap-2 flex-wrap",children:[(0,d.jsx)("button",{onClick:()=>{as?J():I(ap)},className:"p-1 rounded hover:bg-muted/50 transition-colors",children:as?(0,d.jsx)(q.A,{className:"w-4 h-4 text-primary"}):(0,d.jsx)(r.A,{className:"w-4 h-4 text-muted-foreground"})}),(0,d.jsx)("span",{className:"text-xs font-medium text-foreground",children:_("bulk.selected",{count:m.size})}),(0,d.jsx)("div",{className:"flex-1"}),(0,d.jsxs)(l.$,{variant:"ghost",size:"sm",onClick:L,className:"h-7 text-xs",children:[(0,d.jsx)(i.A,{className:"w-3.5 h-3.5 me-1"}),_("bulk.add_to_group")]}),(0,d.jsxs)(l.$,{variant:"ghost",size:"sm",onClick:M,className:"h-7 text-xs",children:[(0,d.jsx)(z.A,{className:"w-3.5 h-3.5 me-1"}),_("bulk.export")]}),(0,d.jsxs)(l.$,{variant:"ghost",size:"sm",onClick:K,className:"h-7 text-xs text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300",children:[(0,d.jsx)(A.A,{className:"w-3.5 h-3.5 me-1"}),_("bulk.delete")]}),(0,d.jsx)(l.$,{variant:"ghost",size:"icon",onClick:J,className:"h-7 w-7",children:(0,d.jsx)(t.A,{className:"w-3.5 h-3.5"})})]}),(0,d.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===ao.length?(0,d.jsx)("div",{className:"flex flex-col items-center justify-center h-full px-6 text-center",children:c||al>0?(0,d.jsxs)(d.Fragment,{children:[al>0&&!c?(0,d.jsx)(u.A,{className:"w-10 h-10 mb-3 text-muted-foreground/30"}):(0,d.jsx)(s.A,{className:"w-10 h-10 mb-3 text-muted-foreground/30"}),(0,d.jsx)("p",{className:"text-sm font-medium text-foreground",children:_(c?"empty_search":"empty_filtered")}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:_(c?"empty_search_hint":"empty_filtered_hint")}),(0,d.jsxs)("div",{className:"flex gap-2 mt-3",children:[c&&(0,d.jsx)(l.$,{variant:"outline",size:"sm",onClick:()=>g(""),children:_("clear_search")}),al>0&&(0,d.jsxs)(l.$,{variant:"outline",size:"sm",onClick:()=>ak(V),children:[(0,d.jsx)(v.A,{className:"w-3.5 h-3.5 me-1"}),_("filters.clear")]})]})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(B.A,{className:"w-10 h-10 mb-3 text-muted-foreground/30"}),(0,d.jsx)("p",{className:"text-sm font-medium text-foreground",children:_("empty_state_title")}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:_("empty_state_subtitle")}),(0,d.jsxs)(l.$,{size:"sm",className:"mt-3",onClick:j,children:[(0,d.jsx)(C.A,{className:"w-4 h-4 me-1.5"}),_("create_new")]})]})}):($=a=>(0,d.jsx)(H,{contact:a,isSelected:a.id===b,isChecked:m.has(a.id),hasSelection:ar,density:ab,selectedContactIds:m,onClick:b=>{b.ctrlKey||b.metaKey?(b.preventDefault(),n(a.id)):b.shiftKey?(b.preventDefault(),E(a.id,ap)):(ar&&J(),h(a.id))},onCheckboxClick:b=>{b.stopPropagation(),n(a.id)},onContextMenu:(a,b)=>ae(a,b)},a.id),ac?(0,d.jsx)("div",{children:aq.map(({letter:a,items:b})=>(0,d.jsxs)("section",{children:[(0,d.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:a}),b.map($)]},a))}):(0,d.jsx)("div",{children:ao.map($)}))}),ad.data&&(0,d.jsx)(S,{contact:ad.data,position:ad.position,isOpen:ad.isOpen,onClose:af,menuRef:ag,isMultiSelect:m.has(ad.data.id),selectedCount:m.size,onOpen:()=>h(ad.data.id),onEdit:()=>N(ad.data.id),onDelete:()=>O(ad.data),onAddToGroup:()=>P(ad.data.id),onBatchExport:M,onBatchAddToGroup:L,onBatchDelete:K})]})}var $=c(74118),_=c(60802),aa=c(41023),ab=c(19864),ac=c(5362),ad=c(90664),ae=c(22518),af=c(21393),ag=c(77650),ah=c(48684),ai=c(75154),aj=c(75428),ak=c(24703),al=c(40560),am=c(83403),an=c(41867),ao=c(47159);function ap({contact:a}){let b=(0,f.c)("contacts.activity"),c=(0,f.k)(),g=(0,h.rd)();(0,am.useAuthStore)(a=>a.client);let i=(0,an.useEmailStore)(a=>a.selectEmail),j=(0,ao.V)(a=>a.setSelectedEventId),k=(0,ao.V)(a=>a.setSelectedDate),[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(!1),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(!1),x=function(a){if(!a.emails)return[];let b=new Set,c=[];for(let d of Object.values(a.emails)){let a=d.address?.trim().toLowerCase();a&&!b.has(a)&&(b.add(a),c.push(a))}return c}(a);if(x.join(","),0===x.length)return null;let y=n?Array.from((function(a){let b=new Map;for(let c of a){let a=new Date(c.start),d=isNaN(a.getTime())?c.start:a.toISOString().slice(0,10),e=b.get(d)||[];e.push(c),b.set(d,e)}return b})(n).entries()):[];return(0,d.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 lg:gap-x-8",children:[(0,d.jsx)(au,{title:b("recent_emails"),children:p?(0,d.jsx)(aq,{}):t?(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:b("load_failed")}):l&&0!==l.length?(0,d.jsx)("div",{className:"-mx-2",children:l.map(a=>{let e,f=(e=a.from?.[0],{name:e?.name?.trim()||e?.email||"",address:e?.email||""});return(0,d.jsxs)("button",{type:"button",onClick:()=>{i(a),g.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,d.jsx)(E.e,{name:f.name,email:f.address,size:"sm"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex items-baseline justify-between gap-2",children:[(0,d.jsx)("span",{className:"text-sm font-medium truncate",children:f.name||b("unknown_sender")}),(0,d.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:(a=>{let b=new Date(a);if(isNaN(b.getTime()))return a;let d=new Date,e=b.getFullYear()===d.getFullYear();return c.dateTime(b,e?{month:"short",day:"numeric"}:{year:"numeric",month:"short",day:"numeric"})})(a.receivedAt)})]}),(0,d.jsx)("div",{className:"text-sm truncate",children:a.subject||b("no_subject")}),a.preview&&(0,d.jsx)("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:a.preview})]})]},a.id)})}):(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:b("no_emails")})}),(0,d.jsx)(au,{title:b("upcoming_events"),children:r?(0,d.jsx)(aq,{}):v?(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:b("load_failed")}):n&&0!==n.length?(0,d.jsx)("div",{className:"space-y-4",children:y.map(([a,e])=>(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:(a=>{let b=new Date(a);if(isNaN(b.getTime()))return a;let d=new Date,e=b.getFullYear()===d.getFullYear();return c.dateTime(b,e?{weekday:"long",month:"long",day:"numeric"}:{weekday:"long",year:"numeric",month:"long",day:"numeric"})})(a)}),(0,d.jsx)("div",{className:"-mx-2",children:e.map(a=>(0,d.jsxs)("button",{type:"button",onClick:()=>{let b;!isNaN((b=new Date(a.start)).getTime())&&k(b),j(a.id),g.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,d.jsx)("span",{className:"text-xs text-muted-foreground tabular-nums w-20 flex-shrink-0",children:(a=>{if(a.showWithoutTime)return b("all_day");let d=new Date(a.start);return isNaN(d.getTime())?"":c.dateTime(d,{hour:"numeric",minute:"2-digit"})})(a)}),(0,d.jsx)("span",{className:"text-sm truncate flex-1 min-w-0",children:a.title||b("no_title")})]},a.id))})]},a))}):(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:b("no_events")})})]})}function aq(){return(0,d.jsx)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:(0,d.jsx)(al.A,{className:"w-4 h-4 animate-spin"})})}function ar(a){if("object"==typeof a&&null!==a){if("Timestamp"===a["@type"]&&"string"==typeof a.utc){try{let b=new Date(a.utc);if(!isNaN(b.getTime()))return b.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{}return String(a.utc)}let b=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=[];return a.month&&b[a.month-1]&&c.push(b[a.month-1]),a.day&&c.push(String(a.day)),a.year&&c.push(String(a.year)),c.join(" ")||String(a)}let b=String(a);if(b.startsWith("--")){let a=b.substring(2).split("-"),c=parseInt(a[0],10),d=a[1]?parseInt(a[1],10):void 0,e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return d?`${e[c-1]} ${d}`:e[c-1]}try{let a=new Date(b);if(!isNaN(a.getTime()))return a.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{}return b}function as({contact:a,onEdit:b,onDelete:c,onAddToGroup:e,onDuplicate:g,onCompose:h,isMobile:j,className:k}){let m,n=(0,f.c)("contacts"),o=a?.cryptoKeys?Object.values(a.cryptoKeys):[];if(!a)return(0,d.jsxs)("div",{className:(0,F.cn)("flex flex-col items-center justify-center h-full text-muted-foreground",k),children:[(0,d.jsx)(B.A,{className:"w-16 h-16 mb-4 opacity-20"}),(0,d.jsx)("p",{className:"text-sm",children:n("detail.no_contact_selected")})]});let p=(0,G.YM)(a),q=(0,G.Bp)(a),r=(0,G.$q)(a),s=a.phones?Object.values(a.phones)[0]?.number:void 0,t=[];e&&t.push({icon:i.A,label:n("context_menu.add_to_group"),onClick:e}),g&&t.push({icon:M.A,label:n("context_menu.duplicate"),onClick:g}),t.push({icon:z.A,label:n("context_menu.export_vcard"),onClick:()=>{(0,O.J)(a),R.o.success(n("export.success",{count:1}))}}),t.push({icon:N.A,label:n("context_menu.print"),onClick:()=>{Q(a,p)}}),t.push({separator:!0}),t.push({icon:A.A,label:n("context_menu.delete"),onClick:c,destructive:!0});let u=a.emails?Object.values(a.emails):[],v=a.phones?Object.values(a.phones):[],y=a.organizations?Object.values(a.organizations):[],C=a.addresses?Object.values(a.addresses):[],D=a.notes?Object.values(a.notes):[],H=a.titles?Object.values(a.titles):[],I=H.filter(a=>"role"!==a.kind),J=a.onlineServices?Object.values(a.onlineServices):[],L=a.anniversaries?Object.values(a.anniversaries):[],P=a.keywords?Object.keys(a.keywords).filter(b=>a.keywords[b]):[],S=a.relatedTo?Object.entries(a.relatedTo):[],T=a.preferredLanguages?Object.values(a.preferredLanguages):[],U=a.personalInfo?Object.values(a.personalInfo):[],V=a.nicknames?Object.values(a.nicknames):[],W=V.length>0,X=[I.length>0?I.map(a=>a.name).join(", "):void 0,y[0]?.name].filter(Boolean),Y=u.length>0||v.length>0||C.length>0||J.length>0,Z=H.length>0||y.length>0,ak=!!(a.speakToAs&&(a.speakToAs.grammaticalGender||a.speakToAs.pronouns)),al=L.length>0||U.length>0||ak||T.length>0;return(0,d.jsxs)("div",{className:(0,F.cn)("flex flex-col h-full overflow-y-auto",k),children:[(0,d.jsx)("div",{className:(0,F.cn)("border-b border-border",j?"px-4 py-4":"px-6 py-6"),children:(0,d.jsxs)("div",{className:(0,F.cn)("flex gap-4",j?"flex-col":"items-start justify-between"),children:[(0,d.jsxs)("div",{className:"flex items-center gap-4 min-w-0 flex-1",children:[(0,d.jsx)(E.e,{name:p,email:q,contactPhotoUri:r,size:j?"md":"lg"}),(0,d.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,d.jsx)("h2",{className:(0,F.cn)("font-semibold truncate",j?"text-lg":"text-xl"),children:p||"-"}),W&&(0,d.jsxs)("p",{className:"text-sm text-muted-foreground truncate",children:["“",V.map(a=>a.name).join(", "),"”"]}),X.length>0&&(0,d.jsx)("p",{className:"text-sm text-muted-foreground truncate",children:X.join(" \xb7 ")})]})]}),(0,d.jsxs)("div",{className:"flex gap-2 flex-shrink-0 flex-wrap",children:[q&&h&&(0,d.jsxs)(l.$,{variant:"outline",size:"sm",onClick:h,className:"touch-manipulation",children:[(0,d.jsx)($.A,{className:"w-4 h-4 me-1"}),n("detail.compose_email")]}),s&&(0,d.jsxs)("a",{href:`tel:${s}`,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,d.jsx)(x.A,{className:"w-4 h-4 me-1"}),n("context_menu.call")]}),(0,d.jsxs)(l.$,{variant:"outline",size:"sm",onClick:b,className:"touch-manipulation",children:[(0,d.jsx)(K.A,{className:"w-4 h-4 me-1"}),n("form.edit_title")]}),(0,d.jsx)(ax,{items:t,label:n("detail.more_actions")})]})]})}),(0,d.jsxs)("div",{className:(0,F.cn)("divide-y divide-border/60",j?"px-4":"px-6"),children:[Y&&(0,d.jsx)(au,{title:n("detail.section_contact"),children:(0,d.jsxs)("div",{className:"space-y-3",children:[u.map((a,b)=>(0,d.jsx)(av,{icon:w.A,label:a.label||at(a.contexts)||n("detail.email_default_label"),children:(0,d.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,d.jsx)("a",{href:`mailto:${a.address}`,className:"text-sm text-primary hover:underline break-all",children:a.address}),(0,d.jsxs)(aw,{children:[(0,d.jsx)("a",{href:`mailto:${a.address}`,className:"p-1.5 rounded hover:bg-muted transition-colors touch-manipulation",title:n("detail.compose_email"),"aria-label":n("detail.compose_email"),children:(0,d.jsx)($.A,{className:"w-3.5 h-3.5 text-muted-foreground"})}),(0,d.jsx)(ay,{value:a.address,label:n("detail.copy_email"),successMsg:n("detail.copied"),failMsg:n("detail.copy_failed")})]})]})},`em${b}`)),v.map((a,b)=>{var c;let e=(c=a.features)?Object.keys(c).filter(a=>c[a]).join(", "):"",f=[a.label,at(a.contexts),e].filter(Boolean);return(0,d.jsx)(av,{icon:x.A,label:f.length?f.join(" \xb7 "):n("detail.phone_default_label"),children:(0,d.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,d.jsx)("a",{href:`tel:${a.number}`,className:"text-sm text-primary hover:underline",children:a.number}),(0,d.jsx)(aw,{children:(0,d.jsx)(ay,{value:a.number,label:n("detail.copy_phone"),successMsg:n("detail.copied"),failMsg:n("detail.copy_failed")})})]})},`ph${b}`)}),C.map((a,b)=>{let c=[];if(a.full||a.fullAddress)c.push(a.full||a.fullAddress);else if(a.components&&a.components.length>0){let b=a.components.filter(a=>"separator"!==a.kind).map(a=>a.value).filter(Boolean).join(", ");b&&c.push(b)}else{let b=[a.street,[a.postcode,a.locality].filter(Boolean).join(" "),a.region,a.country].map(a=>"string"==typeof a?a.trim():"").filter(Boolean);c.push(...b)}return(0,d.jsx)(av,{icon:_.A,label:at(a.contexts)||n("detail.address_default_label"),children:(0,d.jsxs)("div",{className:"text-sm space-y-0.5",children:[c.map((a,b)=>(0,d.jsx)("div",{children:a},b)),a.timeZone&&(0,d.jsxs)("div",{className:"text-xs text-muted-foreground",children:[n("detail.timezone"),": ",a.timeZone]})]})},`ad${b}`)}),J.map((a,b)=>(0,d.jsx)(av,{icon:aa.A,label:[a.service,at(a.contexts)].filter(Boolean).join(" \xb7 ")||n("detail.online_service_default_label"),children:(0,d.jsxs)("div",{className:"flex items-center gap-2 group",children:["string"==typeof a.uri&&a.uri.startsWith("http")?(0,d.jsx)("a",{href:a.uri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:a.user||a.uri}):(0,d.jsx)("span",{className:"text-sm break-all",children:a.user||String(a.uri??"")}),(0,d.jsx)(aw,{children:(0,d.jsx)(ay,{value:a.user||a.uri,label:n("detail.copy_url"),successMsg:n("detail.copied"),failMsg:n("detail.copy_failed")})})]})},`os${b}`))]})}),Z&&(0,d.jsx)(au,{title:n("detail.section_work"),children:(0,d.jsxs)("div",{className:"space-y-3",children:[y.map((a,b)=>(0,d.jsx)(av,{icon:ab.A,label:n("detail.organization_label"),children:(0,d.jsxs)("div",{className:"text-sm",children:[a.name,a.units&&a.units.length>0&&(0,d.jsxs)("span",{className:"text-muted-foreground",children:[" \xb7 ",a.units.map(a=>a.name).join(", ")]})]})},`org${b}`)),H.map((a,b)=>(0,d.jsx)(av,{icon:ac.A,label:"role"===a.kind?n("detail.role_label"):n("detail.title_label"),children:(0,d.jsx)("div",{className:"text-sm",children:a.name})},`tl${b}`))]})}),al&&(0,d.jsx)(au,{title:n("detail.section_personal"),children:(0,d.jsxs)("div",{className:"space-y-3",children:[L.map((a,b)=>{let c=function(a){let{year:b,month:c,day:d}=function(a){if("object"==typeof a&&null!==a){if("Timestamp"===a["@type"]&&"string"==typeof a.utc){let b=new Date(a.utc);return isNaN(b.getTime())?{}:{year:b.getUTCFullYear(),month:b.getUTCMonth()+1,day:b.getUTCDate()}}return{year:a.year,month:a.month,day:a.day}}let b=String(a);if(b.startsWith("--")){let a=b.substring(2).split("-");return{month:parseInt(a[0],10),day:a[1]?parseInt(a[1],10):void 0}}let c=new Date(b);return isNaN(c.getTime())?{}:{year:c.getFullYear(),month:c.getMonth()+1,day:c.getDate()}}(a);if(!b)return null;let e=new Date,f=e.getFullYear()-b,g=c??1,h=e.getMonth()+1,i=e.getDate();return((h<g||h===g&&i<(d??1))&&(f-=1),f<0)?null:f}(a.date),e="birth"===a.kind?"detail.age_years":"detail.years_since";return(0,d.jsx)(av,{icon:ad.A,label:n(`detail.anniversary_${a.kind}`),children:(0,d.jsxs)("div",{className:"text-sm",children:[ar(a.date),null!==c&&(0,d.jsxs)("span",{className:"text-muted-foreground",children:[" \xb7 ",n(e,{count:c})]})]})},`an${b}`)}),ak&&(0,d.jsx)(av,{icon:ae.A,label:n("detail.gender"),children:(0,d.jsxs)("div",{className:"text-sm",children:[a.speakToAs?.grammaticalGender&&(0,d.jsx)("span",{children:n(`detail.gender_${a.speakToAs.grammaticalGender}`,{defaultValue:a.speakToAs.grammaticalGender})}),a.speakToAs?.pronouns&&((m=Object.values(a.speakToAs.pronouns)[0]?.pronouns)?(0,d.jsxs)("span",{className:"text-muted-foreground",children:[a.speakToAs.grammaticalGender?" \xb7 ":"",m]}):null)]})}),T.map((a,b)=>(0,d.jsx)(av,{icon:af.A,label:at(a.contexts)||n("detail.language_label"),children:(0,d.jsx)("div",{className:"text-sm",children:a.language})},`lg${b}`)),U.map((a,b)=>(0,d.jsx)(av,{icon:ag.A,label:`${n(`detail.personal_${a.kind}`)}${a.level?` \xb7 ${a.level}`:""}`,children:(0,d.jsx)("div",{className:"text-sm",children:a.value})},`pi${b}`))]})}),P.length>0&&(0,d.jsx)(au,{title:n("detail.categories"),children:(0,d.jsx)("div",{className:"flex flex-wrap gap-1.5",children:P.map((a,b)=>(0,d.jsx)("span",{className:"text-xs px-2 py-1 rounded-full bg-primary/10 text-primary",children:a},b))})}),S.length>0&&(0,d.jsx)(au,{title:n("detail.related_contacts"),children:(0,d.jsx)("div",{className:"space-y-2",children:S.map(([a,b],c)=>{let e=b.relation?Object.keys(b.relation).find(a=>b.relation[a]):void 0;return(0,d.jsx)(av,{icon:i.A,label:e||n("detail.related_default_label"),children:(0,d.jsx)("div",{className:"text-sm break-all",children:a})},`rel${c}`)})})}),o.length>0&&(0,d.jsx)(au,{title:n("detail.crypto_keys"),children:(0,d.jsx)("div",{className:"space-y-3",children:o.map((a,b)=>(0,d.jsx)("div",{className:"rounded-md border border-border/60 bg-muted/30 p-3 space-y-1",children:(0,d.jsxs)("div",{className:"flex items-start gap-2 text-sm break-all",children:[(0,d.jsx)(ah.A,{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0"}),"string"==typeof a.uri&&a.uri.startsWith("http")?(0,d.jsx)("a",{href:a.uri,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:a.uri}):(0,d.jsx)("span",{className:"text-muted-foreground",children:"string"==typeof a.uri?`${a.uri.substring(0,80)}${a.uri.length>80?"…":""}`:String(a.uri??"")})]})},b))})}),(a.calendarUri||a.schedulingUri||a.freeBusyUri)&&(0,d.jsx)(au,{title:n("detail.calendar"),children:(0,d.jsxs)("div",{className:"space-y-3",children:[a.calendarUri&&(0,d.jsx)(av,{icon:ai.A,label:n("detail.calendar_uri"),children:(0,d.jsx)("a",{href:a.calendarUri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:a.calendarUri})}),a.schedulingUri&&(0,d.jsx)(av,{icon:ai.A,label:n("detail.scheduling_uri"),children:(0,d.jsx)("a",{href:a.schedulingUri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:a.schedulingUri})}),a.freeBusyUri&&(0,d.jsx)(av,{icon:ai.A,label:n("detail.freebusy_uri"),children:(0,d.jsx)("a",{href:a.freeBusyUri,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline break-all",children:a.freeBusyUri})})]})}),D.length>0&&(0,d.jsx)(au,{title:n("detail.notes"),children:(0,d.jsxs)("div",{className:"flex items-start gap-3",children:[(0,d.jsx)(aj.A,{className:"w-4 h-4 text-muted-foreground mt-1 flex-shrink-0"}),(0,d.jsx)("div",{className:"text-sm space-y-2 flex-1 min-w-0",children:D.map((a,b)=>(0,d.jsx)("p",{className:"whitespace-pre-wrap",children:a.note},b))})]})}),(0,d.jsx)(ap,{contact:a}),(a.created||a.updated)&&(0,d.jsxs)("div",{className:"py-4 text-xs text-muted-foreground space-y-1",children:[a.created&&(0,d.jsxs)("div",{children:[n("detail.created"),": ",ar(a.created)]}),a.updated&&(0,d.jsxs)("div",{children:[n("detail.updated"),": ",ar(a.updated)]})]})]})]})}function at(a){return a?Object.keys(a).filter(b=>a[b]).join(", "):""}function au({title:a,children:b,className:c}){return(0,d.jsxs)("section",{className:(0,F.cn)("py-6",c),children:[(0,d.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-3",children:a}),b]})}function av({icon:a,label:b,children:c}){return(0,d.jsxs)("div",{className:"flex items-start gap-3",children:[(0,d.jsx)(a,{className:"w-4 h-4 text-muted-foreground mt-1 flex-shrink-0"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[b&&(0,d.jsx)("div",{className:"text-xs text-muted-foreground mb-0.5",children:b}),c]})]})}function aw({children:a}){return(0,d.jsx)("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:a})}function ax({items:a,label:b}){let[c,f]=(0,e.useState)(!1),g=(0,e.useRef)(null);return 0===a.length?null:(0,d.jsxs)("div",{ref:g,className:"relative",children:[(0,d.jsx)(l.$,{variant:"outline",size:"sm",onClick:()=>f(a=>!a),title:b,"aria-label":b,"aria-haspopup":"menu","aria-expanded":c,className:"touch-manipulation",children:(0,d.jsx)(ak.A,{className:"w-4 h-4"})}),c&&(0,d.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:a.map((a,b)=>a.separator?(0,d.jsx)("div",{role:"separator",className:"my-1 h-px bg-border"},b):(0,d.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{a.onClick(),f(!1)},className:(0,F.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",a.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,d.jsx)(a.icon,{className:(0,F.cn)("w-4 h-4 flex-shrink-0",a.destructive?"text-red-600 dark:text-red-400":"text-muted-foreground")}),(0,d.jsx)("span",{className:"flex-1",children:a.label})]},b))})]})}function ay({value:a,label:b,successMsg:c,failMsg:e,className:f}){return(0,d.jsx)("button",{onClick:async()=>{try{await navigator.clipboard.writeText(a),R.o.success(c)}catch{R.o.error(e)}},className:(0,F.cn)("p-1.5 rounded hover:bg-muted transition-colors touch-manipulation",f),title:b,"aria-label":b,children:(0,d.jsx)(M.A,{className:"w-3.5 h-3.5 text-muted-foreground"})})}var az=c(44218),aA=c(19794),aB=c(34299),aC=c(12253),aD=c(98631),aE=c(24520),aF=c(33922);function aG({icon:a,title:b,children:c,collapsible:f,defaultOpen:g=!0}){let[h,i]=(0,e.useState)(g);return(0,d.jsxs)("section",{className:"py-5",children:[(0,d.jsxs)("button",{type:"button",className:(0,F.cn)("flex items-center gap-2 w-full text-start",f?"cursor-pointer":"cursor-default"),onClick:()=>f&&i(!h),tabIndex:f?0:-1,children:[(0,d.jsx)(a,{className:"w-4 h-4 text-muted-foreground shrink-0"}),(0,d.jsx)("h3",{className:"flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:b}),f&&(h?(0,d.jsx)(az.A,{className:"w-3.5 h-3.5 text-muted-foreground"}):(0,d.jsx)(aA.A,{className:"w-3.5 h-3.5 text-muted-foreground"}))]}),(h||!f)&&(0,d.jsx)("div",{className:"space-y-3 mt-3",children:c})]})}async function aH(a){return new Promise((b,c)=>{let d=new FileReader;d.onload=()=>{let a=new Image;a.onload=()=>{let d=Math.min(1,512/Math.max(a.width,a.height)),e=Math.max(1,Math.round(a.width*d)),f=Math.max(1,Math.round(a.height*d)),g=document.createElement("canvas");g.width=e,g.height=f;let h=g.getContext("2d");h?(h.drawImage(a,0,0,e,f),b({uri:g.toDataURL("image/jpeg",.85),mediaType:"image/jpeg"})):c(Error("canvas-unsupported"))},a.onerror=()=>c(Error("invalid-image")),a.src=d.result},d.onerror=()=>c(Error("read-failed")),d.readAsDataURL(a)})}function aI({value:a,onChange:b,children:c,className:e}){return(0,d.jsx)("select",{value:a,onChange:b,className:(0,F.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",e),children:c})}function aJ({contact:a,addressBooks:b,allKeywords:c,defaultAddressBookId:g,prefill:h,onSave:i,onCancel:j}){let k=(0,f.c)("contacts.form"),m=!!a,n=a||!h?.name?"":h.name.trim().split(/\s+/)[0]||"",o=a||!h?.name?"":h.name.trim().split(/\s+/).slice(1).join(" "),p=(...b)=>a?.name?.components?.find(a=>b.includes(a.kind))?.value||"",[q,r]=(0,e.useState)(p("title","prefix")),[s,u]=(0,e.useState)(p("given")||n),[v,y]=(0,e.useState)(p("given2","additional","middle")),[z,B]=(0,e.useState)(p("surname")||o),[C,H]=(0,e.useState)(p("generation","suffix")),[I,J]=(0,e.useState)(a?.nicknames&&Object.values(a.nicknames)[0]?.name||""),[K,L]=(0,e.useState)(()=>a?.emails?Object.values(a.emails).map(a=>({address:a.address,context:a.contexts?.work?"work":a.contexts?.private?"private":""})):[{address:h?.email||"",context:""}]),[M,N]=(0,e.useState)(()=>a?.phones?Object.values(a.phones).map(a=>({number:a.number,context:a.contexts?.work?"work":a.contexts?.private?"private":"",feature:a.features?.cell?"cell":a.features?.fax?"fax":a.features?.pager?"pager":a.features?.video?"video":a.features?.text?"text":a.features?.voice?"voice":""})):[]),[O,P]=(0,e.useState)(a?.organizations&&Object.values(a.organizations)[0]?.name||""),[Q,R]=(0,e.useState)(a?.organizations&&Object.values(a.organizations)[0]?.units?.[0]?.name||""),[S,T]=(0,e.useState)(()=>{if(a?.titles){let b=Object.values(a.titles).find(a=>"role"!==a.kind);return b?.name||""}return""}),[U,V]=(0,e.useState)(()=>{if(a?.titles){let b=Object.values(a.titles).find(a=>"role"===a.kind);return b?.name||""}return""}),[W,X]=(0,e.useState)(()=>a?.addresses?Object.values(a.addresses).map(a=>(function(a){if(a.components&&a.components.length>0){let b=b=>a.components.filter(a=>a.kind===b).map(a=>a.value).join(" ");return{street:b("name")||b("number")?[b("number"),b("name")].filter(Boolean).join(" "):"",locality:b("locality"),region:b("region"),postcode:b("postcode"),country:b("country"),context:a.contexts?.work?"work":a.contexts?.private?"private":""}}return{street:a.street||"",locality:a.locality||"",region:a.region||"",postcode:a.postcode||"",country:a.country||"",context:a.contexts?.work?"work":a.contexts?.private?"private":""}})(a)):[]),[Y,Z]=(0,e.useState)(()=>a?.onlineServices?Object.values(a.onlineServices).map(a=>({uri:a.uri,service:a.service||"",label:a.label||""})):[]),[$,ac]=(0,e.useState)(()=>a?.anniversaries?Object.values(a.anniversaries).map(a=>({date:function(a){if("string"==typeof a)return a;if(a&&"object"==typeof a){if("@type"in a&&"Timestamp"===a["@type"]&&"utc"in a)return a.utc.split("T")[0];if(a.year&&a.month&&a.day)return`${String(a.year).padStart(4,"0")}-${String(a.month).padStart(2,"0")}-${String(a.day).padStart(2,"0")}`;if(a.month&&a.day)return`--${String(a.month).padStart(2,"0")}-${String(a.day).padStart(2,"0")}`;if(a.year&&a.month)return`${String(a.year).padStart(4,"0")}-${String(a.month).padStart(2,"0")}`;if(a.year)return String(a.year)}return String(a)}(a.date),kind:a.kind})):[]),[af,ah]=(0,e.useState)(()=>a?.personalInfo?Object.values(a.personalInfo).map(a=>({value:a.value,kind:a.kind,level:a.level||""})):[]),[ak,al]=(0,e.useState)(a?.keywords?Object.keys(a.keywords).filter(b=>a.keywords[b]).join(", "):""),[am,an]=(0,e.useState)(a?.notes&&Object.values(a.notes)[0]?.note||""),[ao,ap]=(0,e.useState)(a?.speakToAs?.grammaticalGender||""),[aq,ar]=(0,e.useState)(a?.speakToAs?.pronouns&&Object.values(a.speakToAs.pronouns)[0]?.pronouns||""),[as,at]=(0,e.useState)(a?.calendarUri||""),[au,av]=(0,e.useState)(a?.schedulingUri||""),[aw,ax]=(0,e.useState)(a?.freeBusyUri||""),ay=(0,e.useMemo)(()=>{if(a?.addressBookIds){let b=Object.keys(a.addressBookIds).filter(b=>a.addressBookIds[b]);if(b.length>0)return b[0]}return g&&b?.some(a=>a.id===g)?g:""},[a,g,b]),[az,aA]=(0,e.useState)(ay),aL=(0,e.useMemo)(()=>{if(!a?.media)return null;for(let[b,c]of Object.entries(a.media))if("photo"===c.kind&&c.uri)return{key:b,uri:(0,G.yd)(c.uri,c.mediaType),mediaType:c.mediaType};return null},[a]),[aM,aN]=(0,e.useState)(aL?.uri),[aO,aP]=(0,e.useState)(aL?.mediaType),[aQ,aR]=(0,e.useState)(null),[aS,aT]=(0,e.useState)(!1),aU=(0,e.useRef)(null),[aV,aW]=(0,e.useState)(!1),[aX,aY]=(0,e.useState)(null),[aZ,a$]=(0,e.useState)({}),a_=async a=>{let b=a.target.files?.[0];if(a.target.value="",b){if(!b.type.startsWith("image/"))return void aR(k("photo_invalid"));if(b.size>0xa00000)return void aR(k("photo_too_large"));aR(null),aT(!0);try{let{uri:a,mediaType:c}=await aH(b);aN(a),aP(c)}catch{aR(k("photo_invalid"))}finally{aT(!1)}}},a0=async b=>{if(b.preventDefault(),aY(null),!s.trim()&&!z.trim())return void aY(k("name_required"));let c=K.filter(a=>a.address.trim());for(let a of c)if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a.address.trim()))return void aY(k("email_invalid"));let d={};c.forEach((a,b)=>{let c={address:a.address.trim()};a.context&&(c.contexts={[a.context]:!0}),d[`e${b}`]=c});let e=M.filter(a=>a.number.trim()),f={};e.forEach((a,b)=>{let c={number:a.number.trim()};a.context&&(c.contexts={[a.context]:!0}),a.feature&&(c.features={[a.feature]:!0}),f[`p${b}`]=c});let g=[];q.trim()&&g.push({kind:"title",value:q.trim()}),s.trim()&&g.push({kind:"given",value:s.trim()}),v.trim()&&g.push({kind:"given2",value:v.trim()}),z.trim()&&g.push({kind:"surname",value:z.trim()}),C.trim()&&g.push({kind:"generation",value:C.trim()});let h={};S.trim()&&(h.t0={name:S.trim(),kind:"title"}),U.trim()&&(h.t1={name:U.trim(),kind:"role"});let j=Q.trim()?[{name:Q.trim()}]:void 0,l={};W.filter(a=>a.street.trim()||a.locality.trim()||a.country.trim()).forEach((a,b)=>{let c=[];a.street.trim()&&c.push({kind:"name",value:a.street.trim()}),a.locality.trim()&&c.push({kind:"locality",value:a.locality.trim()}),a.region.trim()&&c.push({kind:"region",value:a.region.trim()}),a.postcode.trim()&&c.push({kind:"postcode",value:a.postcode.trim()}),a.country.trim()&&c.push({kind:"country",value:a.country.trim()});let d={components:c,isOrdered:!0,defaultSeparator:", "};a.context&&(d.contexts={[a.context]:!0}),l[`a${b}`]=d});let m={};Y.filter(a=>a.uri.trim()).forEach((a,b)=>{let c={uri:a.uri.trim()};a.service.trim()&&(c.service=a.service.trim()),a.label.trim()&&(c.label=a.label.trim()),m[`os${b}`]=c});let n={};$.filter(a=>a.date.trim()).forEach((a,b)=>{n[`an${b}`]={date:function(a){if(a.startsWith("--")){let b=a.substring(2).split("-"),c={month:parseInt(b[0],10)};return b[1]&&(c.day=parseInt(b[1],10)),c}let b=a.split("-"),c={};return b[0]&&(c.year=parseInt(b[0],10)),b[1]&&(c.month=parseInt(b[1],10)),b[2]&&(c.day=parseInt(b[2],10)),c}(a.date.trim()),kind:a.kind}});let o={};af.filter(a=>a.value.trim()).forEach((a,b)=>{let c={value:a.value.trim(),kind:a.kind};a.level&&(c.level=a.level),o[`pi${b}`]=c});let p={};ak.trim()&&ak.split(",").map(a=>a.trim()).filter(Boolean).forEach(a=>{p[a]=!0});let r={};if(a?.media)for(let[b,c]of Object.entries(a.media))"photo"!==c.kind&&(r[b]=c);aM&&(r[aL?.key||"photo"]={kind:"photo",uri:aM,mediaType:aO});let t=!!a?.media&&Object.keys(a.media).length>0,u=Object.keys(r).length>0?r:t?null:void 0,w={name:{components:g,isOrdered:!0},nicknames:I.trim()?{n0:{name:I.trim()}}:void 0,emails:Object.keys(d).length>0?d:void 0,phones:Object.keys(f).length>0?f:void 0,titles:Object.keys(h).length>0?h:void 0,organizations:O.trim()?{o0:{name:O.trim(),units:j}}:void 0,addresses:Object.keys(l).length>0?l:void 0,onlineServices:Object.keys(m).length>0?m:void 0,anniversaries:Object.keys(n).length>0?n:void 0,personalInfo:Object.keys(o).length>0?o:void 0,keywords:Object.keys(p).length>0?p:void 0,notes:am.trim()?{n0:{note:am.trim()}}:void 0,speakToAs:ao.trim()||aq.trim()?{grammaticalGender:ao.trim()||void 0,pronouns:aq.trim()?{p0:{pronouns:aq.trim()}}:void 0}:void 0,calendarUri:as.trim()||void 0,schedulingUri:au.trim()||void 0,freeBusyUri:aw.trim()||void 0,media:u,...az?{addressBookIds:{[az]:!0}}:{}};aW(!0);try{await i(w)}catch(a){aY(a instanceof Error?a.message:k("save_failed"))}finally{aW(!1)}},a1=[s,z].filter(Boolean).join(" ").trim(),a2=K.find(a=>a.address.trim())?.address.trim()||"";return(0,d.jsxs)("form",{onSubmit:a0,className:"flex flex-col h-full bg-background",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border flex-shrink-0",children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:m?k("edit_title"):k("create_title")}),(0,d.jsx)("button",{type:"button",onClick:j,className:"p-1.5 rounded-md hover:bg-muted transition-colors duration-150 text-muted-foreground hover:text-foreground",children:(0,d.jsx)(t.A,{className:"w-5 h-5"})})]}),(0,d.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,d.jsxs)("div",{className:"px-6 py-4 max-w-3xl",children:[aX&&(0,d.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:aX}),(0,d.jsxs)("div",{className:"flex items-center gap-4 pb-4",children:[(0,d.jsxs)("button",{type:"button",onClick:()=>aU.current?.click(),disabled:aS,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:k("upload_photo"),"aria-label":k("upload_photo"),children:[(0,d.jsx)(E.e,{name:a1||void 0,email:a2||void 0,contactPhotoUri:aM,size:"lg",className:"!w-20 !h-20 !text-xl"}),(0,d.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,d.jsx)(aB.A,{className:"w-5 h-5"}),(0,d.jsx)("span",{className:"text-[10px] font-medium leading-none",children:k("change_photo")})]}),(0,d.jsx)("input",{ref:aU,type:"file",accept:"image/*",className:"hidden",onChange:a_})]}),(0,d.jsxs)("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:k("photo_hint")}),aQ&&(0,d.jsx)("p",{className:"text-xs text-red-600 dark:text-red-400",children:aQ}),aM&&(0,d.jsxs)("button",{type:"button",onClick:()=>{aN(void 0),aP(void 0),aR(null)},className:"inline-flex items-center gap-1 self-start text-xs text-muted-foreground hover:text-destructive transition-colors",children:[(0,d.jsx)(A.A,{className:"w-3 h-3"}),k("remove_photo")]})]})]}),(0,d.jsxs)("div",{className:"divide-y divide-border/60",children:[b&&b.length>1&&(0,d.jsx)(aG,{icon:aC.A,title:k("section_address_book")||"Directory",children:(0,d.jsxs)("select",{value:az,onChange:a=>aA(a.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,d.jsx)("option",{value:"",children:k("select_address_book")||"Select a directory..."}),b.map(a=>(0,d.jsx)("option",{value:a.id,children:a.accountName?`${a.name} (${a.accountName})`:a.name},a.id))]})}),(0,d.jsxs)(aG,{icon:aD.A,title:k("section_identity"),children:[(0,d.jsxs)("div",{className:"grid grid-cols-[auto_1fr_1fr_auto] gap-2",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("prefix")}),(0,d.jsx)(D.p,{value:q,onChange:a=>r(a.target.value),placeholder:k("prefix_placeholder"),className:"w-20"})]}),(0,d.jsxs)("div",{children:[(0,d.jsxs)("label",{className:"text-xs text-muted-foreground mb-1 block",children:[k("given_name")," ",(0,d.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,d.jsx)(D.p,{value:s,onChange:a=>u(a.target.value),placeholder:k("given_name"),autoFocus:!0})]}),(0,d.jsxs)("div",{children:[(0,d.jsxs)("label",{className:"text-xs text-muted-foreground mb-1 block",children:[k("surname")," ",(0,d.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,d.jsx)(D.p,{value:z,onChange:a=>B(a.target.value),placeholder:k("surname")})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("suffix")}),(0,d.jsx)(D.p,{value:C,onChange:a=>H(a.target.value),placeholder:k("suffix_placeholder"),className:"w-20"})]})]}),(0,d.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("middle_name")}),(0,d.jsx)(D.p,{value:v,onChange:a=>y(a.target.value),placeholder:k("middle_name")})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("nickname")}),(0,d.jsx)(D.p,{value:I,onChange:a=>J(a.target.value),placeholder:k("nickname_placeholder")})]})]})]}),(0,d.jsx)(aG,{icon:w.A,title:k("email"),children:(0,d.jsxs)("div",{className:"space-y-2",children:[K.map((a,b)=>(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(D.p,{type:"email",inputMode:"email",value:a.address,onChange:a=>{let c=[...K];c[b]={...c[b],address:a.target.value},L(c),aZ[b]&&a$(a=>{let c={...a};return delete c[b],c})},onBlur:()=>((a,b)=>{b.trim()&&!(!b.trim()||/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(b.trim()))?a$(b=>({...b,[a]:k("email_error_inline")})):a$(b=>{let c={...b};return delete c[a],c})})(b,a.address),placeholder:k("email_placeholder"),className:(0,F.cn)("flex-1",aZ[b]&&"border-red-500 focus:ring-red-500")}),(0,d.jsxs)(aI,{value:a.context,onChange:a=>{let c=[...K];c[b]={...c[b],context:a.target.value},L(c)},children:[(0,d.jsx)("option",{value:"",children:"-"}),(0,d.jsx)("option",{value:"work",children:k("context_work")}),(0,d.jsx)("option",{value:"private",children:k("context_private")})]}),K.length>1&&(0,d.jsx)(l.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>L(K.filter((a,c)=>c!==b)),className:"h-8 w-8 shrink-0",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})})]}),aZ[b]&&(0,d.jsx)("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1 ms-1",children:aZ[b]})]},b)),(0,d.jsxs)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>L([...K,{address:"",context:""}]),className:"text-xs",children:[(0,d.jsx)(aE.A,{className:"w-3 h-3 me-1"}),k("add_email")]})]})}),(0,d.jsx)(aG,{icon:x.A,title:k("phone"),children:(0,d.jsxs)("div",{className:"space-y-2",children:[M.map((a,b)=>(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(D.p,{type:"tel",inputMode:"tel",value:a.number,onChange:a=>{let c=[...M];c[b]={...c[b],number:a.target.value},N(c)},placeholder:k("phone_placeholder"),className:"flex-1"}),(0,d.jsxs)(aI,{value:a.feature,onChange:a=>{let c=[...M];c[b]={...c[b],feature:a.target.value},N(c)},className:"w-[5.5rem]",children:[(0,d.jsx)("option",{value:"",children:k("phone_type")}),(0,d.jsx)("option",{value:"voice",children:k("phone_voice")}),(0,d.jsx)("option",{value:"cell",children:k("phone_cell")}),(0,d.jsx)("option",{value:"fax",children:k("phone_fax")}),(0,d.jsx)("option",{value:"pager",children:k("phone_pager")}),(0,d.jsx)("option",{value:"video",children:k("phone_video")}),(0,d.jsx)("option",{value:"text",children:k("phone_text")})]}),(0,d.jsxs)(aI,{value:a.context,onChange:a=>{let c=[...M];c[b]={...c[b],context:a.target.value},N(c)},children:[(0,d.jsx)("option",{value:"",children:"-"}),(0,d.jsx)("option",{value:"work",children:k("context_work")}),(0,d.jsx)("option",{value:"private",children:k("context_private")})]}),(0,d.jsx)(l.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>N(M.filter((a,c)=>c!==b)),className:"h-8 w-8 shrink-0",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})})]},b)),(0,d.jsxs)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>N([...M,{number:"",context:"",feature:""}]),className:"text-xs",children:[(0,d.jsx)(aE.A,{className:"w-3 h-3 me-1"}),k("add_phone")]})]})}),(0,d.jsx)(aG,{icon:ab.A,title:k("section_work"),collapsible:!0,defaultOpen:!!(O||Q||S||U),children:(0,d.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("organization")}),(0,d.jsx)(D.p,{value:O,onChange:a=>P(a.target.value),placeholder:k("organization_placeholder")})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("department")}),(0,d.jsx)(D.p,{value:Q,onChange:a=>R(a.target.value),placeholder:k("department_placeholder")})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("job_title")}),(0,d.jsx)(D.p,{value:S,onChange:a=>T(a.target.value),placeholder:k("job_title_placeholder")})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("role")}),(0,d.jsx)(D.p,{value:U,onChange:a=>V(a.target.value),placeholder:k("role_placeholder")})]})]})}),(0,d.jsx)(aG,{icon:_.A,title:k("addresses"),collapsible:!0,defaultOpen:W.length>0,children:(0,d.jsxs)("div",{className:"space-y-3",children:[W.map((a,b)=>(0,d.jsxs)("div",{className:"rounded-md border border-border/60 bg-muted/20 p-3 space-y-2 relative",children:[(0,d.jsx)(l.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>X(W.filter((a,c)=>c!==b)),className:"h-6 w-6 absolute top-2 right-2",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})}),(0,d.jsx)(D.p,{value:a.street,onChange:a=>{let c=[...W];c[b]={...c[b],street:a.target.value},X(c)},placeholder:k("street")}),(0,d.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,d.jsx)(D.p,{value:a.locality,onChange:a=>{let c=[...W];c[b]={...c[b],locality:a.target.value},X(c)},placeholder:k("city")}),(0,d.jsx)(D.p,{value:a.region,onChange:a=>{let c=[...W];c[b]={...c[b],region:a.target.value},X(c)},placeholder:k("region")})]}),(0,d.jsxs)("div",{className:"grid grid-cols-3 gap-2",children:[(0,d.jsx)(D.p,{value:a.postcode,onChange:a=>{let c=[...W];c[b]={...c[b],postcode:a.target.value},X(c)},placeholder:k("postcode")}),(0,d.jsx)(D.p,{value:a.country,onChange:a=>{let c=[...W];c[b]={...c[b],country:a.target.value},X(c)},placeholder:k("country")}),(0,d.jsxs)(aI,{value:a.context,onChange:a=>{let c=[...W];c[b]={...c[b],context:a.target.value},X(c)},children:[(0,d.jsx)("option",{value:"",children:"-"}),(0,d.jsx)("option",{value:"work",children:k("context_work")}),(0,d.jsx)("option",{value:"private",children:k("context_private")})]})]})]},b)),(0,d.jsxs)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>X([...W,{street:"",locality:"",region:"",postcode:"",country:"",context:""}]),className:"text-xs",children:[(0,d.jsx)(aE.A,{className:"w-3 h-3 me-1"}),k("add_address")]})]})}),(0,d.jsx)(aG,{icon:aa.A,title:k("online_services"),collapsible:!0,defaultOpen:Y.length>0,children:(0,d.jsxs)("div",{className:"space-y-2",children:[Y.map((a,b)=>(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(D.p,{value:a.uri,onChange:a=>{let c=[...Y];c[b]={...c[b],uri:a.target.value},Z(c)},placeholder:k("url_placeholder"),className:"flex-1"}),(0,d.jsx)(D.p,{value:a.service,onChange:a=>{let c=[...Y];c[b]={...c[b],service:a.target.value},Z(c)},placeholder:k("service_placeholder"),className:"w-24"}),(0,d.jsx)(l.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>Z(Y.filter((a,c)=>c!==b)),className:"h-8 w-8 shrink-0",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})})]},b)),(0,d.jsxs)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>Z([...Y,{uri:"",service:"",label:""}]),className:"text-xs",children:[(0,d.jsx)(aE.A,{className:"w-3 h-3 me-1"}),k("add_online_service")]})]})}),(0,d.jsx)(aG,{icon:ad.A,title:k("anniversaries"),collapsible:!0,defaultOpen:$.length>0,children:(0,d.jsxs)("div",{className:"space-y-2",children:[$.map((a,b)=>(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(D.p,{type:"date",value:a.date,onChange:a=>{let c=[...$];c[b]={...c[b],date:a.target.value},ac(c)},className:"flex-1"}),(0,d.jsxs)(aI,{value:a.kind,onChange:a=>{let c=[...$];c[b]={...c[b],kind:a.target.value},ac(c)},children:[(0,d.jsx)("option",{value:"birth",children:k("anniversary_birth")}),(0,d.jsx)("option",{value:"wedding",children:k("anniversary_wedding")}),(0,d.jsx)("option",{value:"death",children:k("anniversary_death")}),(0,d.jsx)("option",{value:"other",children:k("anniversary_other")})]}),(0,d.jsx)(l.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>ac($.filter((a,c)=>c!==b)),className:"h-8 w-8 shrink-0",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})})]},b)),(0,d.jsxs)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>ac([...$,{date:"",kind:"birth"}]),className:"text-xs",children:[(0,d.jsx)(aE.A,{className:"w-3 h-3 me-1"}),k("add_anniversary")]})]})}),(0,d.jsx)(aG,{icon:ag.A,title:k("personal_info"),collapsible:!0,defaultOpen:af.length>0,children:(0,d.jsxs)("div",{className:"space-y-2",children:[af.map((a,b)=>(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(D.p,{value:a.value,onChange:a=>{let c=[...af];c[b]={...c[b],value:a.target.value},ah(c)},placeholder:k("personal_info_placeholder"),className:"flex-1"}),(0,d.jsxs)(aI,{value:a.kind,onChange:a=>{let c=[...af];c[b]={...c[b],kind:a.target.value},ah(c)},children:[(0,d.jsx)("option",{value:"expertise",children:k("personal_expertise")}),(0,d.jsx)("option",{value:"hobby",children:k("personal_hobby")}),(0,d.jsx)("option",{value:"interest",children:k("personal_interest")}),(0,d.jsx)("option",{value:"other",children:k("personal_other")})]}),(0,d.jsxs)(aI,{value:a.level,onChange:a=>{let c=[...af];c[b]={...c[b],level:a.target.value},ah(c)},children:[(0,d.jsx)("option",{value:"",children:k("level")}),(0,d.jsx)("option",{value:"high",children:k("level_high")}),(0,d.jsx)("option",{value:"medium",children:k("level_medium")}),(0,d.jsx)("option",{value:"low",children:k("level_low")})]}),(0,d.jsx)(l.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>ah(af.filter((a,c)=>c!==b)),className:"h-8 w-8 shrink-0",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})})]},b)),(0,d.jsxs)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>ah([...af,{value:"",kind:"hobby",level:""}]),className:"text-xs",children:[(0,d.jsx)(aE.A,{className:"w-3 h-3 me-1"}),k("add_personal_info")]})]})}),(0,d.jsx)(aG,{icon:aF.A,title:k("categories"),collapsible:!0,defaultOpen:!!ak,children:(0,d.jsx)(aK,{keywordsStr:ak,onChange:al,allKeywords:c||[],placeholder:k("categories_placeholder"),hint:k("categories_hint"),addLabel:k("category_add")})}),(0,d.jsx)(aG,{icon:ae.A,title:k("gender"),collapsible:!0,defaultOpen:!!(ao||aq),children:(0,d.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("gender_sex")}),(0,d.jsxs)(aI,{value:ao,onChange:a=>ap(a.target.value),className:"w-full",children:[(0,d.jsx)("option",{value:"",children:"-"}),(0,d.jsx)("option",{value:"masculine",children:k("gender_male")}),(0,d.jsx)("option",{value:"feminine",children:k("gender_female")}),(0,d.jsx)("option",{value:"other",children:k("gender_other")}),(0,d.jsx)("option",{value:"none",children:k("gender_none")}),(0,d.jsx)("option",{value:"unknown",children:k("gender_unknown")})]})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("gender_identity")}),(0,d.jsx)(D.p,{value:aq,onChange:a=>ar(a.target.value),placeholder:k("gender_identity_placeholder")})]})]})}),(0,d.jsx)(aG,{icon:ai.A,title:k("calendar"),collapsible:!0,defaultOpen:!!(as||au||aw),children:(0,d.jsxs)("div",{className:"space-y-3",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("calendar_uri")}),(0,d.jsx)(D.p,{value:as,onChange:a=>at(a.target.value),placeholder:"https://..."})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("scheduling_uri")}),(0,d.jsx)(D.p,{value:au,onChange:a=>av(a.target.value),placeholder:"https://..."})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:k("freebusy_uri")}),(0,d.jsx)(D.p,{value:aw,onChange:a=>ax(a.target.value),placeholder:"https://..."})]})]})}),(0,d.jsx)(aG,{icon:aj.A,title:k("note"),collapsible:!0,defaultOpen:!!am,children:(0,d.jsx)("textarea",{value:am,onChange:a=>an(a.target.value),placeholder:k("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,d.jsxs)("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border flex-shrink-0",children:[(0,d.jsx)(l.$,{type:"button",variant:"outline",onClick:j,disabled:aV,children:k("cancel")}),(0,d.jsx)(l.$,{type:"submit",disabled:aV,children:aV?m?k("updating"):k("creating"):k("save")})]})]})}function aK({keywordsStr:a,onChange:b,allKeywords:c,placeholder:f,hint:g,addLabel:h}){let[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(""),m=(0,e.useRef)(null),n=(0,e.useMemo)(()=>a.split(",").map(a=>a.trim()).filter(Boolean),[a]),o=(0,e.useMemo)(()=>{let a=k.toLowerCase();return c.filter(b=>!n.includes(b)&&(!a||b.toLowerCase().includes(a)))},[c,n,k]),p=k.trim()&&!n.includes(k.trim())&&!c.some(a=>a.toLowerCase()===k.trim().toLowerCase()),q=(0,e.useCallback)(a=>{let c=a.trim();!c||n.includes(c)||(b([...n,c].join(", ")),l(""))},[n,b]),r=(0,e.useCallback)(a=>{b(n.filter(b=>b!==a).join(", "))},[n,b]);return(0,d.jsxs)("div",{className:"relative",children:[n.length>0&&(0,d.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2",children:n.map(a=>(0,d.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:[a,(0,d.jsx)("button",{type:"button",onClick:()=>r(a),className:"hover:text-destructive transition-colors",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})})]},a))}),(0,d.jsx)(D.p,{ref:m,value:k,onChange:a=>{l(a.target.value),j(!0)},onFocus:()=>j(!0),onBlur:()=>j(!1),onKeyDown:a=>{"Enter"===a.key?(a.preventDefault(),k.trim()&&q(k)):"Escape"===a.key&&j(!1)},placeholder:0===n.length?f:""}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground mt-1.5",children:g}),i&&(o.length>0||p)&&(0,d.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:a=>a.preventDefault(),children:[o.map(a=>(0,d.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:()=>{q(a),m.current?.focus()},children:[(0,d.jsx)(aF.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),a]},a)),p&&(0,d.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:()=>{q(k),m.current?.focus()},children:[(0,d.jsx)(aE.A,{className:"w-3.5 h-3.5 flex-shrink-0"}),h,': "',k.trim(),'"']})]})]})}var aL=c(42742);function aM({group:a,individuals:b,currentMemberIds:c=[],onSave:g,onCancel:h}){let i=(0,f.c)("contacts"),j=!!a,[k,m]=(0,e.useState)(a?(0,G.YM)(a):""),[n,o]=(0,e.useState)(new Set(c)),[p,q]=(0,e.useState)(""),[r,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(null),x=(0,e.useMemo)(()=>{if(!p)return b;let a=p.toLowerCase();return b.filter(b=>{let c=(0,G.YM)(b).toLowerCase(),d=(0,G.Bp)(b).toLowerCase();return c.includes(a)||d.includes(a)})},[b,p]),y=a=>{let b=new Set(n);b.has(a)?b.delete(a):b.add(a),o(b)},z=async a=>{if(a.preventDefault(),w(null),!k.trim())return void w(i("groups.name_required"));u(!0);try{await g(k.trim(),Array.from(n))}catch(a){w(a instanceof Error?a.message:i("groups.save_failed"))}finally{u(!1)}};return(0,d.jsxs)("form",{onSubmit:z,className:"flex flex-col h-full",children:[(0,d.jsx)("div",{className:"px-6 py-4 border-b border-border",children:(0,d.jsx)("h2",{className:"text-lg font-semibold",children:j?i("groups.edit"):i("groups.create")})}),(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[v&&(0,d.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:v}),(0,d.jsxs)("div",{children:[(0,d.jsx)("label",{className:"text-sm text-muted-foreground mb-1 block",children:i("groups.name_label")}),(0,d.jsx)(D.p,{value:k,onChange:a=>m(a.target.value),placeholder:i("groups.name_placeholder"),autoFocus:!0})]}),(0,d.jsxs)("div",{children:[(0,d.jsxs)("label",{className:"text-sm text-muted-foreground mb-2 block",children:[i("groups.members_label")," (",n.size,")"]}),(0,d.jsxs)("div",{className:"relative mb-2",children:[(0,d.jsx)(s.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),(0,d.jsx)(D.p,{placeholder:i("groups.search_members"),value:p,onChange:a=>q(a.target.value),className:"ps-9"})]}),(0,d.jsx)("div",{className:"border rounded-md max-h-64 overflow-y-auto divide-y divide-border",children:0===x.length?(0,d.jsx)("div",{className:"px-4 py-6 text-sm text-muted-foreground text-center",children:i("empty_search")}):x.map(a=>{let b=(0,G.YM)(a),c=(0,G.Bp)(a),e=n.has(a.id);return(0,d.jsxs)("button",{type:"button",onClick:()=>y(a.id),className:(0,F.cn)("w-full flex items-center gap-3 px-3 py-2.5 text-start transition-colors","hover:bg-muted",e&&"bg-primary/5"),children:[(0,d.jsx)("div",{className:(0,F.cn)("w-5 h-5 rounded border flex items-center justify-center flex-shrink-0 transition-colors",e?"bg-primary border-primary text-primary-foreground":"border-border"),children:e&&(0,d.jsx)(aL.A,{className:"w-3 h-3"})}),(0,d.jsx)(E.e,{name:b,email:c,size:"sm"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("div",{className:"text-sm font-medium truncate",children:b}),c&&(0,d.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:c})]})]},a.id)})})]}),n.size>0&&(0,d.jsx)("div",{className:"flex flex-wrap gap-1.5",children:Array.from(n).map(a=>{let c=b.find(b=>b.id===a);return c?(0,d.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-full bg-primary/10 text-primary",children:[(0,G.YM)(c),(0,d.jsx)("button",{type:"button",onClick:()=>y(a),className:"hover:text-red-600 dark:hover:text-red-400",children:(0,d.jsx)(t.A,{className:"w-3 h-3"})})]},a):null})})]}),(0,d.jsxs)("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border",children:[(0,d.jsx)(l.$,{type:"button",variant:"outline",onClick:h,disabled:r,children:i("form.cancel")}),(0,d.jsx)(l.$,{type:"submit",disabled:r,children:r?j?i("form.updating"):i("form.creating"):i("form.save")})]})]})}var aN=c(74302);function aO({group:a,members:b,onEdit:c,onDelete:e,onRemoveMember:g,onSelectMember:h,onComposeGroup:j,isMobile:k,className:m}){let n=(0,f.c)("contacts"),o=(0,G.YM)(a),p=b.some(a=>(0,G.Bp)(a).trim());return(0,d.jsxs)("div",{className:(0,F.cn)("flex flex-col h-full overflow-y-auto",m),children:[(0,d.jsxs)("div",{className:(0,F.cn)("border-b border-border",k?"px-4 py-4":"px-6 py-6"),children:[(0,d.jsxs)("div",{className:(0,F.cn)("flex gap-4",k?"flex-col":"items-start justify-between"),children:[(0,d.jsxs)("div",{className:"flex items-center gap-4",children:[(0,d.jsx)("div",{className:(0,F.cn)("rounded-full bg-primary/10 flex items-center justify-center",k?"w-12 h-12":"w-14 h-14"),children:(0,d.jsx)(i.A,{className:(0,F.cn)("text-primary",k?"w-6 h-6":"w-7 h-7")})}),(0,d.jsxs)("div",{children:[(0,d.jsx)("h2",{className:(0,F.cn)("font-semibold",k?"text-lg":"text-xl"),children:o}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground",children:n("groups.member_count",{count:b.length})})]})]}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsxs)(l.$,{variant:"outline",size:"sm",onClick:c,className:"touch-manipulation",children:[(0,d.jsx)(K.A,{className:"w-4 h-4 me-1"}),n("form.edit_title")]}),(0,d.jsx)(l.$,{variant:"outline",size:"sm",onClick:e,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,d.jsx)(A.A,{className:"w-4 h-4"})})]})]}),j&&p&&(0,d.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mt-4",children:[(0,d.jsx)(w.A,{className:"w-4 h-4 text-muted-foreground","aria-hidden":!0}),(0,d.jsx)("span",{className:"text-sm text-muted-foreground",children:n("groups.send_email")}),(0,d.jsx)("div",{className:"inline-flex gap-1",children:["to","cc","bcc"].map(a=>(0,d.jsx)(l.$,{variant:"outline",size:"sm",onClick:()=>j(a),className:"touch-manipulation",children:n(`groups.send_email_${a}`)},a))})]})]}),(0,d.jsxs)("div",{className:"px-6 py-4",children:[(0,d.jsx)("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:n("groups.members_label")}),0===b.length?(0,d.jsx)("p",{className:"text-sm text-muted-foreground py-4 text-center",children:n("groups.no_members")}):(0,d.jsx)("div",{className:"space-y-1",children:b.map(a=>{let b=(0,G.YM)(a),c=(0,G.Bp)(a);return(0,d.jsxs)("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md hover:bg-muted group transition-colors",children:[(0,d.jsxs)("button",{className:"flex items-center gap-3 flex-1 min-w-0 text-start",onClick:()=>h(a.id),children:[(0,d.jsx)(E.e,{name:b,email:c,size:"sm"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("div",{className:"text-sm font-medium truncate",children:b}),c&&(0,d.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:c})]})]}),(0,d.jsx)(l.$,{variant:"ghost",size:"icon",className:(0,F.cn)("h-8 w-8 transition-opacity",k?"opacity-100":"opacity-0 group-hover:opacity-100"),onClick:()=>g(a.id),children:(0,d.jsx)(aN.A,{className:"w-4 h-4 text-muted-foreground"})})]},a.id)})})]})]})}var aP=c(94019),aQ=c(50666),aR=c(80661),aS=c(61686),aT=c(95581),aU=c(93986);function aV(a){let b=[],c=new Map;for(let d of a)if(d.isShared){let a=d.accountId||d.accountName||d.id,b=c.get(a);b?b.books.push(d):c.set(a,{label:d.accountName||a,books:[d]})}else b.push(d);return{owned:b,sharedGroups:Array.from(c.values())}}let aW="contacts-sidebar-collapsed";function aX(){try{let a=localStorage.getItem(aW);return a?JSON.parse(a):{}}catch{return{}}}function aY({groups:a,individuals:b,addressBooks:c,activeCategory:h,onSelectCategory:j,onCreateGroup:k,onCreateContact:m,onCreateAddressBook:n,onImport:o,onEditGroup:p,onDeleteGroup:q,onComposeGroup:r,onDropContacts:s,onDropContactsToCategory:t,onRenameAddressBook:u,onShareAddressBook:v,onCreateContactInBook:x,onDeleteAddressBook:y,onRenameKeyword:z,className:D,multiAccountMode:E}){let H,J,L,M,N,O,P=(0,f.c)("contacts"),Q=(0,g.useRouter)(),{contextMenu:R,openContextMenu:S,closeContextMenu:U,menuRef:V}=(0,T.E)(),{contextMenu:W,openContextMenu:X,closeContextMenu:Y,menuRef:Z}=(0,T.E)(),{contextMenu:$,openContextMenu:_,closeContextMenu:aa,menuRef:ab}=(0,T.E)(),[ac,ad]=(0,e.useState)(aX),[ae,af]=(0,e.useState)(!1),ag=(0,e.useRef)(null),ah=(0,e.useRef)(null),ai=(0,e.useCallback)(a=>{ad(b=>{let c={...b,[a]:!b[a]};try{localStorage.setItem(aW,JSON.stringify(c))}catch{}return c})},[]),aj=(0,e.useMemo)(()=>[...a].sort((a,b)=>(0,G.YM)(a).localeCompare((0,G.YM)(b))),[a]),ak="all"===h,al=(0,e.useMemo)(()=>c.filter(a=>!a.isShared),[c]),am=(0,e.useMemo)(()=>{let a=new Map;for(let b of c){if(!b.isShared||!b.accountId)continue;let c=a.get(b.accountId);c?c.books.push(b):a.set(b.accountId,{accountId:b.accountId,accountName:b.accountName||b.accountId,books:[b]})}return Array.from(a.values())},[c]),an=(0,aU.E)(a=>a.accounts),ao=(0,aU.E)(a=>a.activeAccountId),ap=(0,e.useMemo)(()=>{if(!E)return[];let a=new Map;for(let b of c){let c=b.localAccountId||"__other__",d=a.get(c)??[];d.push(b),a.set(c,d)}let b=[];if(ao&&a.has(ao)){let c=an.find(a=>a.id===ao);b.push({key:ao,label:c?.label||c?.email||c?.username||ao,split:aV(a.get(ao))}),a.delete(ao)}for(let c of an)a.has(c.id)&&(b.push({key:c.id,label:c.label||c.email||c.username,split:aV(a.get(c.id))}),a.delete(c.id));for(let[c,d]of a.entries()){let a="__other__"===c?P("address_books.title"):d[0]?.accountName||c;b.push({key:c,label:a,split:aV(d)})}return b},[E,c,an,ao,P]),aq=(0,e.useMemo)(()=>{let a={};for(let c of b)if(c.addressBookIds)for(let b of Object.keys(c.addressBookIds))c.addressBookIds[b]&&(a[b]=(a[b]||0)+1);return a},[b]),ar=(0,e.useMemo)(()=>{let a={};for(let c of b)if(c.keywords)for(let[b,d]of Object.entries(c.keywords))d&&(a[b]=(a[b]||0)+1);return Object.entries(a).sort(([a],[b])=>a.localeCompare(b))},[b]),as=(0,e.useMemo)(()=>b.filter(a=>!a.keywords||0===Object.keys(a.keywords).filter(b=>a.keywords[b]).length).length,[b]),at=(0,e.useMemo)(()=>{let c={};for(let d of a){if(!d.members){c[d.id]=0;continue}let a=Object.keys(d.members).filter(a=>d.members[a]),e=a.map(a=>a.startsWith("urn:uuid:")?a.slice(9):a);c[d.id]=b.filter(b=>{if(a.includes(b.id)||e.includes(b.id))return!0;if(b.uid){let c=b.uid.startsWith("urn:uuid:")?b.uid.slice(9):b.uid;return a.includes(b.uid)||e.includes(c)}return!1}).length}return c},[a,b]);return(0,d.jsxs)("div",{className:(0,F.cn)("flex flex-col h-full bg-secondary",D),children:[(0,d.jsxs)("div",{className:"px-3 border-b border-border flex items-center justify-between",style:{paddingBlock:"var(--density-header-py)"},children:[(0,d.jsx)("span",{className:"text-sm font-semibold truncate",children:P("title")}),(0,d.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,d.jsx)(l.$,{ref:ah,size:"icon",variant:"ghost",onClick:()=>af(a=>!a),className:"h-7 w-7",children:(0,d.jsx)(aE.A,{className:"w-4 h-4"})}),ae&&(0,d.jsxs)("div",{ref:ag,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,d.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:()=>{af(!1),m()},children:[(0,d.jsx)(C.A,{className:"w-4 h-4"}),P("create_new")]}),(0,d.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:()=>{af(!1),k()},children:[(0,d.jsx)(aP.A,{className:"w-4 h-4"}),P("groups.create")]}),n&&(0,d.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:()=>{af(!1),n()},children:[(0,d.jsx)(aQ.A,{className:"w-4 h-4"}),P("address_books.create")]}),o&&(0,d.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:()=>{af(!1),o()},children:[(0,d.jsx)(aR.A,{className:"w-4 h-4"}),P("import.title")]})]})]})]}),(0,d.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[(0,d.jsxs)("button",{onClick:()=>j("all"),className:(0,F.cn)("w-full flex items-center gap-2 px-3 text-sm transition-colors",ak?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,d.jsx)(B.A,{className:"w-4 h-4 flex-shrink-0"}),(0,d.jsx)("span",{className:"truncate",children:P("tabs.all")}),(0,d.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:b.length})]}),E&&ap.length>0?ap.map(a=>{let b=`account-${a.key}`,c=!ac[b],{owned:e,sharedGroups:f}=a.split;return(0,d.jsxs)("div",{className:"mt-2",children:[(0,d.jsx)("div",{className:"flex items-center px-3 py-1 group",children:(0,d.jsxs)("button",{onClick:()=>ai(b),className:"flex items-center gap-1 flex-1 min-w-0 text-start",children:[c?(0,d.jsx)(az.A,{className:"w-3 h-3 text-muted-foreground"}):(0,d.jsx)(aA.A,{className:"w-3 h-3 text-muted-foreground"}),(0,d.jsx)(aD.A,{className:"w-3 h-3 text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs font-semibold text-foreground/90 uppercase tracking-wider truncate",children:a.label})]})}),c&&(0,d.jsxs)("div",{className:"ps-2",children:[e.length>0&&(0,d.jsxs)("div",{className:"mt-1",children:[(0,d.jsx)("div",{className:"px-3 py-0.5 text-[10px] font-medium text-muted-foreground/80 uppercase tracking-wider",children:P("address_books.title")}),e.map(a=>(0,d.jsx)(a$,{book:a,isActive:"object"==typeof h&&"addressBookId"in h&&h.addressBookId===a.id,contactCount:aq[a.id]||0,onSelect:()=>j({addressBookId:a.id}),onDropContacts:s,onContextMenu:u||v||x||y?b=>X(b,a):void 0},a.id))]}),f.map(b=>(0,d.jsxs)("div",{className:"mt-1",children:[(0,d.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,d.jsx)(aS.A,{className:"w-3 h-3"}),b.label]}),b.books.map(a=>(0,d.jsx)(a$,{book:a,isActive:"object"==typeof h&&"addressBookId"in h&&h.addressBookId===a.id,contactCount:aq[a.id]||0,onSelect:()=>j({addressBookId:a.id}),onDropContacts:s,onContextMenu:u||v||x||y?b=>X(b,a):void 0},a.id))]},`${a.key}-shared-${b.label}`))]})]},a.key)}):al.length>0&&(0,d.jsxs)("div",{className:"mt-2",children:[(0,d.jsxs)("div",{className:"flex items-center px-3 py-1 group",children:[(0,d.jsxs)("button",{onClick:()=>ai("addressBooks"),className:"flex items-center gap-1 flex-1 text-start",children:[ac.addressBooks?(0,d.jsx)(aA.A,{className:"w-3 h-3 text-muted-foreground"}):(0,d.jsx)(az.A,{className:"w-3 h-3 text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:P("address_books.title")})]}),(0,d.jsx)("button",{onClick:a=>{a.stopPropagation();try{localStorage.setItem("settings-active-tab","contacts")}catch{}Q.push("/settings")},className:"p-0.5 rounded opacity-0 group-hover:opacity-100 transition-opacity duration-150 hover:bg-muted",title:P("address_books.manage"),children:(0,d.jsx)(aT.A,{className:"w-3 h-3 text-muted-foreground"})})]}),!ac.addressBooks&&al.map(a=>(0,d.jsx)(a$,{book:a,isActive:"object"==typeof h&&"addressBookId"in h&&h.addressBookId===a.id,contactCount:aq[a.id]||0,onSelect:()=>j({addressBookId:a.id}),onDropContacts:s,onContextMenu:u||v||x||y?b=>X(b,a):void 0},a.id))]}),aj.length>0&&(0,d.jsxs)("div",{className:"mt-2",children:[(0,d.jsxs)("button",{onClick:()=>ai("groups"),className:"flex items-center gap-1 px-3 py-1 w-full text-start group",children:[ac.groups?(0,d.jsx)(aA.A,{className:"w-3 h-3 text-muted-foreground"}):(0,d.jsx)(az.A,{className:"w-3 h-3 text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:P("tabs.groups")})]}),!ac.groups&&aj.map(a=>{let b="object"==typeof h&&"groupId"in h&&h.groupId===a.id,c=at[a.id]||0;return(0,d.jsxs)("button",{onClick:()=>j({groupId:a.id}),onContextMenu:b=>S(b,a),className:(0,F.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors",b?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,d.jsx)(i.A,{className:"w-4 h-4 flex-shrink-0"}),(0,d.jsx)("span",{className:"truncate",children:(0,G.YM)(a)}),(0,d.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:c})]},a.id)})]}),(0,d.jsxs)("div",{className:"mt-2",children:[(0,d.jsxs)("button",{onClick:()=>ai("categories"),className:"flex items-center gap-1 px-3 py-1 w-full text-start group",children:[ac.categories?(0,d.jsx)(aA.A,{className:"w-3 h-3 text-muted-foreground"}):(0,d.jsx)(az.A,{className:"w-3 h-3 text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:P("detail.categories")})]}),!ac.categories&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("button",{onClick:()=>j("uncategorized"),className:(0,F.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors","uncategorized"===h?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,d.jsx)(aF.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-50"}),(0,d.jsx)("span",{className:"truncate italic",children:P("no_category")}),(0,d.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:as})]}),ar.map(([a,b])=>{let c="object"==typeof h&&"keyword"in h&&h.keyword===a;return(0,d.jsx)(aZ,{keyword:a,count:b,isActive:c,onSelect:()=>j({keyword:a}),onDropContacts:t,onContextMenu:z?b=>_(b,a):void 0},a)})]})]}),!E&&am.map(a=>(0,d.jsxs)("div",{className:"mt-2",children:[(0,d.jsxs)("div",{className:"flex items-center px-3 py-1 group",children:[(0,d.jsxs)("button",{onClick:()=>ai(`shared-${a.accountId}`),className:"flex items-center gap-1 flex-1 min-w-0 text-start",children:[ac[`shared-${a.accountId}`]?(0,d.jsx)(aA.A,{className:"w-3 h-3 text-muted-foreground"}):(0,d.jsx)(az.A,{className:"w-3 h-3 text-muted-foreground"}),(0,d.jsx)(aS.A,{className:"w-3 h-3 text-muted-foreground"}),(0,d.jsx)("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider truncate",children:P("address_books.shared_prefix",{name:a.accountName})})]}),(0,d.jsx)("button",{onClick:a=>{a.stopPropagation();try{localStorage.setItem("settings-active-tab","contacts")}catch{}Q.push("/settings")},className:"p-0.5 rounded opacity-0 group-hover:opacity-100 transition-opacity duration-150 hover:bg-muted",title:P("address_books.manage"),children:(0,d.jsx)(aT.A,{className:"w-3 h-3 text-muted-foreground"})})]}),!ac[`shared-${a.accountId}`]&&a.books.map(a=>(0,d.jsx)(a$,{book:a,isActive:"object"==typeof h&&"addressBookId"in h&&h.addressBookId===a.id,contactCount:aq[a.id]||0,onSelect:()=>j({addressBookId:a.id}),onDropContacts:s,onContextMenu:u||v||x||y?b=>X(b,a):void 0},a.id))]},a.accountId))]}),W.data&&(u||v||x||y)&&(H=W.data,J=x&&H.myRights?.mayWrite!==!1,L=u&&H.myRights?.mayWrite!==!1,M=v&&H.myRights?.mayShare&&!H.isShared,N=y&&!H.isDefault&&!H.isShared&&H.myRights?.mayDelete!==!1,O=(J||L||M)&&N,(0,d.jsxs)(I.tz,{ref:Z,isOpen:W.isOpen,position:W.position,onClose:Y,children:[J&&(0,d.jsx)(I.kt,{icon:C.A,label:P("address_books.new_contact_in_book"),onClick:()=>{Y(),x(H)}}),L&&(0,d.jsx)(I.kt,{icon:K.A,label:P("address_books.rename"),onClick:()=>{Y(),u(H)}}),M&&(0,d.jsx)(I.kt,{icon:i.A,label:P("address_books.share"),onClick:()=>{Y(),v(H)}}),O&&(0,d.jsx)(I.K5,{}),N&&(0,d.jsx)(I.kt,{icon:A.A,label:P("address_books.delete"),onClick:()=>{Y(),y(H)},destructive:!0})]})),$.data&&z&&(0,d.jsx)(I.tz,{ref:ab,isOpen:$.isOpen,position:$.position,onClose:aa,children:(0,d.jsx)(I.kt,{icon:K.A,label:P("rename_category"),onClick:()=>{let a=$.data;aa(),z(a)}})}),R.data&&(0,d.jsxs)(I.tz,{ref:V,isOpen:R.isOpen,position:R.position,onClose:U,children:[(0,d.jsx)(I.kt,{icon:K.A,label:P("groups.edit"),onClick:()=>{U(),p?.(R.data.id)}}),r&&(0,d.jsx)(I.qu,{icon:w.A,label:P("groups.send_email"),children:["to","cc","bcc"].map(a=>(0,d.jsx)(I.kt,{label:P(`groups.send_email_${a}`),onClick:()=>{let b=R.data.id;U(),r(b,a)}},a))}),(0,d.jsx)(I.K5,{}),(0,d.jsx)(I.kt,{icon:A.A,label:P("form.delete"),onClick:()=>{U(),q?.(R.data.id)},destructive:!0})]})]})}function aZ({keyword:a,count:b,isActive:c,onSelect:f,onDropContacts:g,onContextMenu:h}){let[i,j]=(0,e.useState)(!1),k=(0,e.useCallback)(a=>{a.dataTransfer.types.includes("application/x-contact-ids")&&(a.preventDefault(),a.dataTransfer.dropEffect="copy",j(!0))},[]),l=(0,e.useCallback)(()=>{j(!1)},[]),m=(0,e.useCallback)(b=>{b.preventDefault(),j(!1);let c=b.dataTransfer.getData("application/x-contact-ids");if(c&&g)try{let b=JSON.parse(c);b.length>0&&g(b,a)}catch{}},[a,g]);return(0,d.jsxs)("button",{onClick:f,onContextMenu:h,onDragOver:k,onDragLeave:l,onDrop:m,className:(0,F.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors",c?"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,d.jsx)(aF.A,{className:"w-3.5 h-3.5 flex-shrink-0"}),(0,d.jsx)("span",{className:"truncate",children:a}),(0,d.jsx)("span",{className:"ms-auto text-xs text-muted-foreground tabular-nums",children:b})]})}function a$({book:a,isActive:b,contactCount:c,onSelect:f,onDropContacts:g,onContextMenu:h}){let[j,k]=(0,e.useState)(!1),l=(0,e.useCallback)(a=>{a.dataTransfer.types.includes("application/x-contact-ids")&&(a.preventDefault(),a.dataTransfer.dropEffect="move",k(!0))},[]),m=(0,e.useCallback)(()=>{k(!1)},[]),n=(0,e.useCallback)(b=>{b.preventDefault(),k(!1);let c=b.dataTransfer.getData("application/x-contact-ids");if(c&&g)try{let b=JSON.parse(c);b.length>0&&g(b,a)}catch{}},[a,g]);return(0,d.jsxs)("button",{onClick:f,onContextMenu:h,onDragOver:l,onDragLeave:m,onDrop:n,className:(0,F.cn)("w-full flex items-center gap-2 ps-5 pe-3 text-sm transition-colors",b?"bg-accent text-accent-foreground font-medium":"text-foreground/80 hover:bg-muted",j&&"bg-primary/20 ring-2 ring-primary/50"),style:{paddingBlock:"var(--density-sidebar-py, 4px)",minHeight:"32px"},children:[(0,d.jsx)(aC.A,{className:"w-4 h-4 flex-shrink-0"}),(0,d.jsx)("span",{className:"truncate",children:a.name}),!a.isShared&&Object.keys(a.shareWith||{}).length>0&&(0,d.jsx)(i.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0 ms-auto"}),(0,d.jsx)("span",{className:(0,F.cn)("text-xs text-muted-foreground tabular-nums",!(!a.isShared&&Object.keys(a.shareWith||{}).length>0)&&"ms-auto"),children:c})]})}var a_=c(31900),a0=c(13786),a1=c(18203),a2=c(13355),a3=c(49913),a4=c(18707),a5=c(44833),a6=c(3905),a7=c(71935),a8=c(96188),a9=c(17018),ba=c(42917),bb=c(62802),bc=c(14174),bd=c(92368);function be(){let a,b,c,o,p,q,r=(0,f.c)("contacts"),s=(0,a4.V)(a=>a.isFeatureEnabled("contactsEnabled")),{client:t,isAuthenticated:u,logout:v,checkAuth:w,isLoading:x}=(0,am.useAuthStore)(),{showAppsModal:y,inlineApp:z,loadedApps:A,handleManageApps:B,handleInlineApp:C,closeInlineApp:D,closeAppsModal:E}=(0,a8.s)(),[H,I]=(0,e.useState)(()=>am.useAuthStore.getState().isAuthenticated&&!!am.useAuthStore.getState().client),{quota:J,isPushConnected:K}=(0,an.useEmailStore)(),{contacts:L,addressBooks:M,selectedContactId:N,searchQuery:P,supportsSync:Q,selectedContactIds:S,setSelectedContact:T,setSearchQuery:V,fetchContacts:W,createContact:X,updateContact:Y,deleteContact:$,addLocalContact:_,updateLocalContact:aa,deleteLocalContact:ab,getGroupMembers:ac,createGroup:ad,updateGroup:ae,addMembersToGroup:af,removeMembersFromGroup:ag,deleteGroup:ah,toggleContactSelection:ai,selectRangeContacts:aj,selectAllContacts:ak,clearSelection:al,bulkDeleteContacts:ao,bulkAddToGroup:ap,moveContactToAddressBook:aq,createAddressBook:ar,renameAddressBook:at,removeAddressBook:au,shareAddressBook:av,renameKeyword:aw,importContacts:ax}=(0,G.pc)(),[ay,az]=(0,e.useState)("list"),[aA,aB]=(0,e.useState)("all"),[aC,aD]=(0,e.useState)(!1),[aE,aF]=(0,e.useState)(null),[aG,aH]=(0,e.useState)(!1),[aI,aK]=(0,e.useState)(null),[aL,aN]=(0,e.useState)(void 0),[aP,aQ]=(0,e.useState)(void 0),[aR,aS]=(0,e.useState)(!1),[aT,aV]=(0,e.useState)(null),[aW,aX]=(0,e.useState)(null);(0,e.useRef)(!1);let{dialogProps:aZ,confirm:a$}=(0,n.G)(),be=(0,bb.al)(),bf=(0,bb.GM)(),bg=(0,a9.E)(),bh=(0,h.rd)();(0,g.useSearchParams)(),(0,e.useRef)(!1);let bi=!bf,[bj,bk]=(0,e.useState)(!1),[bl,bm]=(0,e.useState)(()=>{try{let a=localStorage.getItem("contacts-sidebar-width");return a?Number(a):256}catch{return 256}}),[bn,bo]=(0,e.useState)(!1),bp=(0,e.useRef)(256),[bq,br]=(0,e.useState)(()=>{try{let a=localStorage.getItem("contacts-list-width");return a?Number(a):384}catch{return 384}}),[bs,bt]=(0,e.useState)(!1),bu=(0,e.useRef)(384),{enabled:bv,accountClients:bw}=(a=(0,a9.E)(),b=(0,U.C$)(a=>a.proInterface),c=(0,aU.E)(a=>a.accounts),(0,am.useAuthStore)(a=>a.activeAccountId),(0,G.pc)(a=>a.fetchAllAccountsAddressBooks),(0,G.pc)(a=>a.fetchAllAccountsContacts),o=b||a,p=(0,e.useMemo)(()=>{if(!o)return[];let a=am.useAuthStore.getState().getClientForAccount,b=[];for(let d of c){if(!d.isConnected)continue;let c=a(d.id);c&&c.supportsContacts()&&b.push({localAccountId:d.id,client:c})}return b},[o,c]),{enabled:o,accountClients:p});(0,bc.A)({enabled:u&&!!t&&Q,onRefresh:async()=>{if(t){if(bv&&bw.length>0){let a=am.useAuthStore.getState().activeAccountId;if(a){let{fetchAllAccountsContacts:b,fetchAllAccountsAddressBooks:c}=G.pc.getState();await Promise.all([c(bw,a),b(bw,a)]);return}}await W(t)}}});let bx=(0,e.useMemo)(()=>L.filter(a=>"group"===a.kind),[L]),by=(0,e.useMemo)(()=>L.filter(a=>"group"!==a.kind),[L]),bz=L.find(a=>a.id===N)||null,bA=aW&&L.find(a=>a.id===aW)||null,bB=(0,e.useMemo)(()=>aW?ac(aW):[],[aW,ac]),bC=(0,e.useMemo)(()=>{let a=new Set;for(let b of by)if(b.keywords)for(let[c,d]of Object.entries(b.keywords))d&&a.add(c);return Array.from(a).sort((a,b)=>a.localeCompare(b))},[by]),bD=(0,e.useMemo)(()=>{if("all"===aA)return by;if("uncategorized"===aA)return by.filter(a=>!a.keywords||0===Object.keys(a.keywords).filter(b=>a.keywords[b]).length);if("addressBookId"in aA){let a=aA.addressBookId;return by.filter(b=>!!b.addressBookIds&&!0===b.addressBookIds[a])}return"keyword"in aA?by.filter(a=>a.keywords?.[aA.keyword]):ac(aA.groupId)},[aA,by,ac]),bE=(0,e.useCallback)(a=>{aB(a),al(),"object"==typeof a&&"groupId"in a?(aX(a.groupId),az("group-detail")):aX(null),bk(!1)},[al]),bF=(0,e.useCallback)(async(a,b)=>{if(t)try{await aq(t,a,b);let c=1===a.length?r("address_books.moved",{name:b.name}):r("address_books.moved_plural",{count:a.length,name:b.name});R.o.success(c)}catch(a){console.error("Failed to move contacts:",a),R.o.error(r("address_books.move_failed"))}},[t,aq,r]),bG=(0,e.useCallback)(async(a,b)=>{if(t||!Q)try{for(let c of a){let a=L.find(a=>a.id===c);if(!a)continue;let d=a.keywords||{};if(d[b])continue;let e={...d,[b]:!0};Q&&t?await Y(t,c,{keywords:e}):aa(c,{keywords:e})}let c=1===a.length?r("category_added",{name:b}):r("category_added_plural",{count:a.length,name:b});R.o.success(c)}catch(a){console.error("Failed to add contacts to category:",a),R.o.error(r("toast.error_update"))}},[t,Q,L,Y,aa,r]),bH=(0,e.useCallback)(async()=>{if(t){if(bv&&bw.length>0){let a=am.useAuthStore.getState().activeAccountId;if(a){let{fetchAllAccountsAddressBooks:b}=G.pc.getState();await b(bw,a);return}}await G.pc.getState().fetchAddressBooks(t)}},[t,bv,bw]),bI=(0,e.useCallback)(async a=>{if(t)try{await ar(t,a),await bH(),R.o.success(r("address_books.created")),aH(!1)}catch(a){console.error("Failed to create address book:",a),R.o.error(r("address_books.create_failed"))}},[t,ar,bH,r]),bJ=(0,e.useCallback)(async a=>ax(Q&&t?t:null,a),[Q,t,ax]),bK=()=>{T(null),az("create")},bL=()=>{az("edit")},bM=(0,e.useCallback)(async a=>{if(await a$({title:r("delete_confirm_title"),message:r("delete_confirm"),confirmText:r("form.delete"),variant:"destructive"}))try{Q&&t?await $(t,a):ab(a),R.o.success(r("toast.deleted")),N===a&&az("list")}catch(a){console.error("Failed to delete contact:",a),R.o.error(r("toast.error_delete"))}},[a$,r,Q,t,$,ab,N]),bN=async()=>{bz&&await bM(bz.id)},bO=(0,e.useCallback)(a=>{T(a),az("edit")},[T]),bP=(0,e.useCallback)(a=>{bM(a.id)},[bM]),bQ=(0,e.useCallback)(a=>{(al(),ai(a),0===bx.length)?az("group-create"):az("bulk-add-to-group")},[al,ai,bx.length]),bR=(0,e.useCallback)(async a=>{let{id:b,created:c,updated:d,...e}=a,f=JSON.parse(JSON.stringify(e));Q&&t?await X(t,f):_({id:`local-${(0,F.lk)()}`,addressBookIds:f.addressBookIds||{},...f}),R.o.success(r("toast.created"))},[Q,t,X,_,r]),bS=(0,e.useCallback)(async a=>{if(Q&&t?await X(t,a):_({id:`local-${(0,F.lk)()}`,addressBookIds:{},...a}),R.o.success(r("toast.created")),aN(void 0),aQ(void 0),aR){aS(!1),bh.back();return}az("list")},[Q,t,X,_,r,aR,bh]),bT=(0,e.useCallback)(async a=>{bz&&(Q&&t?await Y(t,bz.id,a):aa(bz.id,a),R.o.success(r("toast.updated")),az("detail"))},[Q,t,bz,Y,aa,r]),bU=()=>{if(aN(void 0),aR&&"create"===ay){aQ(void 0),aS(!1),bh.back();return}"create"===ay&&aQ(void 0),"group-create"===ay||"group-edit"===ay?az(bA?"group-detail":"list"):"bulk-add-to-group"===ay?az("list"):az(bz?"detail":"list")},bV=()=>{az("group-edit")},bW=(0,e.useCallback)(a=>{aX(a),aB({groupId:a}),az("group-edit")},[]),bX=(0,e.useCallback)((a,b)=>{(0,a2.B2)({to:"to"===b?a:[],cc:"cc"===b?a:[],bcc:"bcc"===b?a:[],subject:"",body:""}),bh.push("/")},[bh]),bY=(0,e.useCallback)((a,b)=>{let c=new Set,d=[];for(let b of ac(a)){let a=(0,G.Bp)(b).trim(),e=a.toLowerCase();if(!a||c.has(e))continue;c.add(e);let f=(0,G.YM)(b);d.push({name:f&&f!==a?f:void 0,email:a})}if(0===d.length)return void R.o.error(r("groups.no_member_emails"));let e=G.pc.getState().contacts.find(b=>b.id===a),f={name:e&&(0,G.YM)(e)||"Group",email:"",group:{members:d}};bX([(0,a3.Rx)(f)],b)},[ac,r,bX]),bZ=(0,e.useCallback)(a=>{let b=(0,G.Bp)(a).trim();b&&bX([(0,a3.jZ)((0,G.YM)(a),b)],"to")},[bX]),b$=(0,e.useCallback)(async a=>{if(await a$({title:r("groups.delete_confirm_title"),message:r("groups.delete_confirm"),confirmText:r("form.delete"),variant:"destructive"}))try{await ah(Q&&t?t:null,a),R.o.success(r("toast.deleted")),aW===a&&(aX(null),aB("all"),az("list"))}catch(a){console.error("Failed to delete group:",a),R.o.error(r("toast.error_delete"))}},[a$,ah,Q,t,aW,r]),b_=async()=>{if(bA&&await a$({title:r("groups.delete_confirm_title"),message:r("groups.delete_confirm"),confirmText:r("form.delete"),variant:"destructive"}))try{await ah(Q&&t?t:null,bA.id),R.o.success(r("toast.deleted")),aX(null),az("list")}catch(a){console.error("Failed to delete group:",a),R.o.error(r("toast.error_delete"))}},b0=(0,e.useCallback)(async(a,b)=>{let c=Q&&t?t:null;if("group-edit"===ay&&bA){await ae(c,bA.id,a);let d=bB.map(a=>a.id),e=b.filter(a=>!d.includes(a)),f=d.filter(a=>!b.includes(a));e.length>0&&await af(c,bA.id,e),f.length>0&&await ag(c,bA.id,f),R.o.success(r("toast.updated")),az("group-detail")}else await ad(c,a,b),R.o.success(r("toast.created")),az("list")},[ay,bA,bB,Q,t,ad,ae,af,ag,r]),b1=async a=>{if(bA)try{await ag(Q&&t?t:null,bA.id,[a]),R.o.success(r("toast.updated"))}catch(a){console.error("Failed to remove group member:",a),R.o.error(r("toast.error_update"))}},b2=async()=>{if(0!==S.size&&await a$({title:r("bulk.delete_confirm_title"),message:r("bulk.delete_confirm",{count:S.size}),confirmText:r("bulk.delete"),variant:"destructive"}))try{await ao(Q&&t?t:null,Array.from(S)),R.o.success(r("bulk.deleted",{count:S.size})),az("list")}catch(a){console.error("Failed to bulk delete contacts:",a),R.o.error(r("toast.error_delete"))}},b3=async a=>{try{await ap(Q&&t?t:null,a,Array.from(S)),R.o.success(r("bulk.added_to_group")),az("list")}catch(a){console.error("Failed to add contacts to group:",a),R.o.error(r("toast.error_update"))}};if(!u)return null;if(!s)return(0,d.jsx)("div",{className:"flex h-dvh items-center justify-center bg-background p-6",children:(0,d.jsxs)("div",{className:"max-w-lg text-center space-y-3",children:[(0,d.jsx)(j.A,{className:"w-10 h-10 text-yellow-500 mx-auto"}),(0,d.jsx)("p",{className:"text-sm font-medium",children:"Contacts feature is disabled by your administrator"}),(0,d.jsx)("p",{className:"text-xs text-muted-foreground",children:"Please contact your administrator if you need access."})]})});let b4=!be||"list"===ay,b5=!be||"list"!==ay;return(0,d.jsxs)("div",{className:(0,F.cn)("flex flex-col bg-background overflow-hidden pt-[env(safe-area-inset-top)]",bg?"h-full":"h-dvh"),children:[(0,d.jsx)(a1.T,{}),(0,d.jsxs)("div",{className:(0,F.cn)("flex flex-1 min-h-0 overflow-hidden",be&&"flex-col"),children:[!be&&!bg&&(0,d.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,d.jsx)(a5.t,{collapsed:!0,quota:J,isPushConnected:K,onLogout:v,onManageApps:B,onInlineApp:C,onCloseInlineApp:D,activeAppId:z?.id??null})}),(0,d.jsxs)("div",{className:"flex flex-col flex-1 min-w-0 min-h-0",children:[z&&(0,d.jsx)(a7.G,{apps:A,activeAppId:z.id,onClose:D}),(0,d.jsxs)("div",{className:(0,F.cn)("relative flex flex-1 min-h-0",z&&"hidden"),children:[bi&&bj&&(0,d.jsx)("div",{className:(0,F.cn)("inset-0 bg-black/50 z-40",bg?"absolute":"fixed"),onClick:()=>bk(!1)}),b4&&(0,d.jsxs)(d.Fragment,{children:[(!be||bi)&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:(0,F.cn)("border-e border-border flex flex-col flex-shrink-0 bg-background",!bn&&"transition-[width] duration-300",bi&&(0,F.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",!bj&&"-translate-x-full")),style:bi?void 0:{width:`${bl}px`},children:(0,d.jsx)(aY,{groups:bx,individuals:by,addressBooks:M,activeCategory:aA,onSelectCategory:bE,onCreateGroup:()=>{aX(null),az("group-create")},onCreateContact:bK,onCreateAddressBook:t?()=>aH(!0):void 0,onImport:()=>aD(!0),onEditGroup:bW,onDeleteGroup:b$,onComposeGroup:bY,onDropContacts:bF,onDropContactsToCategory:bG,onRenameAddressBook:t?a=>aF(a):void 0,onShareAddressBook:t?a=>aK(a.id):void 0,onCreateContactInBook:a=>{aN(a.id),bK()},onDeleteAddressBook:t?async a=>{if(await a$({title:r("address_books.delete"),message:r("address_books.confirm_delete",{name:a.name}),variant:"destructive",confirmText:r("address_books.delete")}))try{await au(t,a),R.o.success(r("address_books.deleted"))}catch{R.o.error(r("address_books.delete_failed"))}}:void 0,onRenameKeyword:a=>aV(a),multiAccountMode:bv&&bw.length>1})}),!bi&&(0,d.jsx)(ba.X,{onResizeStart:()=>{bp.current=bl,bo(!0)},onResize:a=>bm(Math.max(180,Math.min(400,bp.current+a))),onResizeEnd:()=>{bo(!1),localStorage.setItem("contacts-sidebar-width",String(bl))},onDoubleClick:()=>{bm(256),localStorage.setItem("contacts-sidebar-width","256")}})]}),(0,d.jsx)("div",{"data-tour":"contacts-list",className:(0,F.cn)("border-e border-border bg-background flex flex-col flex-shrink-0",be?"w-full":"",!bs&&!be&&"transition-[width] duration-300"),style:be?void 0:{width:`${bq}px`},children:(0,d.jsx)(Z,{contacts:bD,selectedContactId:N,searchQuery:P,onSearchChange:V,onSelectContact:a=>{T(a),al(),az("detail")},onCreateNew:bK,className:"flex-1",selectedContactIds:S,onToggleSelection:ai,onSelectRangeContacts:aj,onSelectAll:ak,onClearSelection:al,onBulkDelete:b2,onBulkAddToGroup:()=>{if(0!==S.size){if(0===bx.length)return void az("group-create");az("bulk-add-to-group")}},onBulkExport:()=>{let a=L.filter(a=>S.has(a.id));a.length>0&&((0,O.W)(a),R.o.success(r("export.success",{count:a.length})),al())},onEditContact:bO,onDeleteContact:bP,onAddContactToGroup:bQ,onMenuClick:bi?()=>bk(!0):void 0})}),!be&&(0,d.jsx)(ba.X,{onResizeStart:()=>{bu.current=bq,bt(!0)},onResize:a=>br(Math.max(220,Math.min(500,bu.current+a))),onResizeEnd:()=>{bt(!1),localStorage.setItem("contacts-list-width",String(bq))},onDoubleClick:()=>{br(384),localStorage.setItem("contacts-list-width","384")}})]}),b5&&(0,d.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[be&&(0,d.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,d.jsxs)(l.$,{variant:"ghost",size:"sm",onClick:()=>{if(aR){aS(!1),aQ(void 0),bh.back();return}az("list"),al()},className:"touch-manipulation",children:[(0,d.jsx)(k.A,{className:"w-4 h-4 me-2"}),aR?r("back_to_email"):r("back_to_contacts")]})}),(0,d.jsx)("div",{className:"flex-1 min-h-0",children:(()=>{switch(ay){case"create":return(0,d.jsx)(aJ,{addressBooks:M,allKeywords:bC,defaultAddressBookId:aL,prefill:aP,onSave:bS,onCancel:bU});case"edit":if(!bz)return null;return(0,d.jsx)(aJ,{contact:bz,addressBooks:M,allKeywords:bC,onSave:bT,onCancel:bU});case"group-detail":if(!bA)return null;return(0,d.jsx)(aO,{group:bA,members:bB,onEdit:bV,onDelete:b_,onRemoveMember:b1,onComposeGroup:a=>bY(bA.id,a),isMobile:be,onSelectMember:a=>{T(a),az("detail")}});case"group-create":return(0,d.jsx)(aM,{individuals:by,onSave:b0,onCancel:bU});case"group-edit":if(!bA)return null;return(0,d.jsx)(aM,{group:bA,individuals:by,currentMemberIds:bB.map(a=>a.id),onSave:b0,onCancel:bU});case"bulk-add-to-group":return(0,d.jsxs)("div",{className:"flex flex-col h-full",children:[(0,d.jsxs)("div",{className:"px-6 py-4 border-b border-border",children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:r("bulk.choose_group")}),(0,d.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:r("bulk.adding_contacts",{count:S.size})})]}),(0,d.jsx)("div",{className:"flex-1 overflow-y-auto divide-y divide-border",children:bx.map(a=>{let b=(0,G.YM)(a),c=a.members?Object.values(a.members).filter(Boolean).length:0;return(0,d.jsxs)("button",{onClick:()=>b3(a.id),className:"w-full flex items-center gap-3 px-6 py-3 text-start hover:bg-muted transition-colors",children:[(0,d.jsx)("div",{className:"w-9 h-9 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0",children:(0,d.jsx)(i.A,{className:"w-4 h-4 text-primary"})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("div",{className:"text-sm font-medium truncate",children:b}),(0,d.jsx)("div",{className:"text-xs text-muted-foreground",children:r("groups.member_count",{count:c})})]})]},a.id)})}),(0,d.jsx)("div",{className:"px-6 py-4 border-t border-border",children:(0,d.jsx)(l.$,{variant:"outline",onClick:bU,className:"w-full",children:r("form.cancel")})})]});default:return(0,d.jsx)(as,{contact:bz,onEdit:bL,onDelete:bN,onCompose:bz?()=>bZ(bz):void 0,onAddToGroup:bz?()=>bQ(bz.id):void 0,onDuplicate:bz?()=>void bR(bz):void 0,isMobile:be})}})()})]})]}),be&&!bg&&(0,d.jsx)(a5.t,{orientation:"horizontal",onManageApps:B,onInlineApp:C,onCloseInlineApp:D,activeAppId:z?.id??null})]}),(0,d.jsx)(a6.E,{isOpen:y,onClose:E}),(0,d.jsx)(m.T,{...aZ}),null!==aT&&(0,d.jsx)(a0.L,{currentName:aT,title:r("rename_category"),label:r("category_name_label"),onCancel:()=>aV(null),onConfirm:async a=>{try{await aw(Q&&t?t:null,aT,a),R.o.success(r("category_renamed")),"object"==typeof aA&&"keyword"in aA&&aA.keyword===aT&&aB({keyword:a.trim()}),aV(null)}catch(a){console.error("Failed to rename category:",a),R.o.error(r("category_rename_failed"))}}}),aG&&(0,d.jsx)(a0.L,{currentName:"",title:r("address_books.create"),label:r("address_books.name_label"),onCancel:()=>aH(!1),onConfirm:bI}),aE&&(0,d.jsx)(a0.L,{currentName:aE.name,title:r("address_books.rename"),label:r("address_books.name_label"),onCancel:()=>aF(null),onConfirm:async a=>{if(t)try{await at(t,aE,a),R.o.success(r("address_books.renamed")),aF(null)}catch(a){console.error("Failed to rename address book:",a),R.o.error(r("address_books.rename_failed"))}}}),aC&&(0,d.jsx)("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:(0,d.jsx)("div",{className:"bg-background rounded-lg border border-border shadow-xl w-full max-w-2xl max-h-[80vh] overflow-hidden",children:(0,d.jsx)(a_.m,{existingContacts:L,onImport:bJ,onClose:()=>aD(!1)})})}),aI&&t&&((q=M.find(a=>a.id===aI))?(0,d.jsx)(bd.S,{client:t,kind:"addressBook",collectionName:q.name,shareWith:q.shareWith,ownAccountId:t.getAccountId(),onShare:async(a,b)=>{await av(t,q,a,b)},onClose:()=>aK(null)}):null)]})]})}}};