PageSourceSearch

https://socialloop.ai/_next/static/chunks/8008.321260d89bcbcbca.js

js socialloop.ai collected 2026-10-05 12:47:20 UTC 66,659 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8008],{13676:(e,t,a)=>{"use strict";function s(){let e=(7-new Date().getDay())%7||7;return 1===e?"Resets tomorrow":e<=2?"Resets in ".concat(e," days"):"Resets Sunday"}function l(e){return"You have ".concat(e," contact list").concat(1!==e?"s":""," — the maximum on your current plan. Remove one to make room.")}a.d(t,{Rh:()=>l,yf:()=>s})},32383:()=>{},46177:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>V});var s=a(95155),l=a(12115),n=a(92546);let r=(0,l.lazy)(()=>Promise.all([a.e(320),a.e(4156),a.e(8780),a.e(9542),a.e(2477),a.e(9085)]).then(a.bind(a,54156)));function i(e){let{onBack:t}=e,[a,i]=(0,l.useState)(null);return(0,s.jsxs)("section",{className:"space-y-5",children:[(0,s.jsx)("button",{className:"text-sm underline",onClick:t,children:"Back to Network lists"}),(0,s.jsx)(n.A,{kind:"segment",onUse:i,onOpen:()=>void 0}),a&&(0,s.jsx)(l.Suspense,{fallback:(0,s.jsx)("p",{children:"Opening editor…"}),children:(0,s.jsx)(r,{campaignId:null,libraryId:a,context:{},onClose:()=>i(null)})})]})}var c=a(52931),o=a(82994),d=a(4246),u=a(39390),m=a(76849),h=a(14585),p=a(29213),x=a(4912),g=a(37401),f=a(3131),b=a(18619),v=a(30770),j=a(13038),y=a(8683),N=a(12180),w=a(13676),k=a(63846),C=a(12711);function S(e){let{listId:t,listName:a,duplicateCount:n,totalContacts:r,onClose:i,onMerged:c}=e,[o,d]=(0,l.useState)(!1),[u,p]=(0,l.useState)(null),x=(0,l.useCallback)(async()=>{d(!0);try{let e=(0,m.httpsCallable)(h.functions,"mergeDuplicateContacts"),a=await e({listId:t});p(a.data),c()}catch(e){}finally{d(!1)}},[t,c]);return(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:(0,s.jsxs)("div",{className:"bg-card border border-card rounded-xl w-full max-w-md p-6 space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"studio-subtitle",children:"Merge Duplicates"}),(0,s.jsx)("button",{onClick:i,className:"p-1 rounded-lg hover:bg-white/[0.06] text-t2 hover:text-t1 transition",children:(0,s.jsx)(y.fK,{className:"w-5 h-5"})})]}),u?(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"p-4 rounded-lg bg-green-500/10 border border-green-500/20",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-positive-ink",children:"Merge complete"}),(0,s.jsxs)("p",{className:"text-xs text-positive-ink/70 mt-1",children:[u.merged," duplicate",1!==u.merged?"s":""," removed,"," ",u.remaining," contacts remaining"]})]}),(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:i,children:"Done"})})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"p-4 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[(0,s.jsxs)("p",{className:"text-sm text-amber-200",children:[(0,s.jsx)("strong",{children:n})," duplicate contact",1!==n?"s":""," detected in “",a,"”"]}),(0,s.jsx)("p",{className:"text-xs text-amber-200/60 mt-1.5",children:"Contacts sharing the same email or phone number will be merged. The most complete record is kept for each group."})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-white/[0.03] rounded-lg",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"studio-caption",children:"Before"}),(0,s.jsxs)("p",{className:"studio-body-strong",children:[r," contacts"]})]}),(0,s.jsx)("svg",{className:"w-5 h-5 text-t2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3"})}),(0,s.jsxs)("div",{className:"text-right",children:[(0,s.jsx)("p",{className:"studio-caption",children:"After"}),(0,s.jsxs)("p",{className:"text-sm font-medium text-positive-ink",children:["~",r-n," contacts"]})]})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)(C.$n,{variant:"secondary",size:"md",onClick:i,children:"Cancel"}),(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:x,disabled:o,children:o?"Merging...":"Merge ".concat(n," Duplicates")})]})]})]})})}let A=/^[^\s@]+@[^\s@]+\.[^\s@]+$/u;function I(e){return!!e&&A.test(e.trim())}function L(e){let{headers:t,dataRows:a,mapping:n,maxRows:r=8}=e,i=(0,l.useMemo)(()=>{let e=[],t=a.slice(0,r);for(let a of t){var s,l;let t="",r="",i="",c="",o="",d=[];for(let[e,l]of Object.entries(n.coreFields)){let n=(null!=(s=a[parseInt(e)])?s:"").trim();n&&("name"===l?t=n:"firstName"===l?r=n:"lastName"===l?i=n:"email"===l?c=n:"phone"===l&&(o=n))}for(let[e,t]of Object.entries(n.metadataFields)){let s=(null!=(l=a[parseInt(e)])?l:"").trim();s&&d.push("".concat(t,": ").concat(s.length>30?s.slice(0,30)+"…":s))}!t&&(r||i)&&(t="".concat(r," ").concat(i).trim());let u=I(c)||function(e){if(!e)return!1;let t=0;for(let a of e){let e=a.codePointAt(0);void 0!==e&&(e>=48&&e<=57||e>=65296&&e<=65305||e>=1632&&e<=1641||e>=1776&&e<=1785||e>=2406&&e<=2415||e>=2534&&e<=2543||e>=2662&&e<=2671||e>=2790&&e<=2799||e>=2918&&e<=2927||e>=3046&&e<=3055||e>=3174&&e<=3183||e>=3302&&e<=3311||e>=3430&&e<=3439||e>=3664&&e<=3673||e>=3792&&e<=3801||e>=3872&&e<=3881||e>=4160&&e<=4169)&&t++}return t>=7&&t<=20}(o);e.push({name:t,email:c,phone:o,metadataPreview:d.slice(0,2).join(", "),isReachable:u})}let i=t.length,c=e.filter(e=>e.isReachable).length;return{rows:e,totalSampled:i,reachableCount:c}},[a,n,r]),c=(0,l.useMemo)(()=>Object.values(n.coreFields).includes("phone"),[n.coreFields]);return(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("p",{className:"studio-label",children:"Preview"}),(0,s.jsx)("div",{className:"overflow-x-auto rounded-lg border border-white/[0.06]",children:(0,s.jsxs)("table",{className:"w-full text-[11px]",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,s.jsx)("th",{className:"px-2.5 py-1.5 text-left text-t3 font-medium",children:"Name"}),(0,s.jsx)("th",{className:"px-2.5 py-1.5 text-left text-t3 font-medium",children:"Email"}),c&&(0,s.jsx)("th",{className:"px-2.5 py-1.5 text-left text-t3 font-medium",children:"Phone"}),(0,s.jsx)("th",{className:"px-2.5 py-1.5 text-left text-t3 font-medium",children:"Metadata"}),(0,s.jsx)("th",{className:"px-2.5 py-1.5 text-center text-t3 font-medium w-8",title:"Reachable (has valid email or phone)",children:"✓"})]})}),(0,s.jsx)("tbody",{children:i.rows.map((e,t)=>(0,s.jsxs)("tr",{className:"border-b border-white/[0.03] ".concat(e.isReachable?"":"bg-red-500/[0.04]"),children:[(0,s.jsx)("td",{className:"px-2.5 py-1.5 text-t1 truncate max-w-[140px]",title:e.name,children:e.name||(0,s.jsx)("span",{className:"text-t4 italic",children:"empty"})}),(0,s.jsx)("td",{className:"px-2.5 py-1.5 truncate max-w-[180px]",title:e.email,children:e.email?(0,s.jsx)("span",{className:I(e.email)?"text-t1":"text-negative-ink/70",children:e.email}):(0,s.jsx)("span",{className:"text-t4 italic",children:"empty"})}),c&&(0,s.jsx)("td",{className:"px-2.5 py-1.5 text-t1 truncate max-w-[120px]",title:e.phone,children:e.phone||(0,s.jsx)("span",{className:"text-t4 italic",children:"empty"})}),(0,s.jsx)("td",{className:"px-2.5 py-1.5 text-t3 truncate max-w-[180px]",title:e.metadataPreview,children:e.metadataPreview||(0,s.jsx)("span",{className:"text-t4",children:"—"})}),(0,s.jsx)("td",{className:"px-2.5 py-1.5 text-center",children:e.isReachable?(0,s.jsx)("span",{className:"text-positive-ink",children:"✓"}):(0,s.jsx)("span",{className:"text-negative-ink/70",title:"No valid email or phone — will be skipped",children:"✗"})})]},t))})]})}),(0,s.jsxs)("div",{className:"flex items-center justify-between text-[10px]",children:[(0,s.jsxs)("span",{className:"text-t3",children:["Showing ",i.totalSampled," of ",a.length.toLocaleStr
1ing()," rows"]}),(0,s.jsxs)("span",{className:i.reachableCount===i.totalSampled?"text-positive-ink/70":"text-attention-ink/70",children:[i.reachableCount,"/",i.totalSampled," reachable in sample"]})]})]})}function E(e){let{progress:t,error:a,busy:l,listName:n,onConfirm:r,onCancel:i,onRetry:c}=e;if(!t)return null;let o="awaiting_review"===t.status,d=[["New contacts",t.newContacts],["Already in this list",t.existingDuplicates],["Repeated in this file",t.fileDuplicates],["Invalid rows",t.invalid]];return(0,s.jsxs)("section",{"aria-label":"Contact import review",className:"rounded-xl border border-card bg-card p-5 space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"studio-subtitle",children:o?"Review your import":t.phase}),(0,s.jsx)("p",{className:"studio-body break-words",children:n}),(0,s.jsx)("p",{className:"text-sm text-t2 mt-1",children:o?"Your contacts are ready to review. Nothing has been added yet.":"You can leave this view. Your import continues in the background."})]}),o?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("dl",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:d.map(e=>{let[t,a]=e;return(0,s.jsxs)("div",{className:"rounded-lg border border-card p-3",children:[(0,s.jsx)("dt",{className:"text-sm text-t2",children:t}),(0,s.jsx)("dd",{className:"text-xl text-t1 mt-1",children:(a||0).toLocaleString()})]},t)})}),(0,s.jsxs)("p",{className:"text-sm text-t2",children:["Checked ",t.analyzedAtMs?new Date(t.analyzedAtMs).toLocaleString():"just now",". Matching email addresses or phone numbers are skipped; existing contacts are never overwritten. If the list changes, the final count can be lower. This analysis expires after 24 hours."]}),(0,s.jsx)("p",{className:"studio-body",children:"Importing does not subscribe anyone to emails or texts. Messaging still requires their permission."})]}):(0,s.jsxs)("div",{role:"status",className:"text-sm text-t2",children:[t.added.toLocaleString()," added \xb7 ",t.skipped.toLocaleString()," skipped"]}),a&&(0,s.jsx)("p",{role:"alert",className:"text-sm text-danger-ink",children:a}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-3",children:[o&&(0,s.jsx)("button",{onClick:r,disabled:l,className:"rounded-lg bg-t1 text-page px-4 py-2 text-sm disabled:opacity-40",children:l?"Saving…":t.newContacts?"Import ".concat(t.newContacts.toLocaleString()," new contacts"):"Finish — no new contacts"}),a&&(0,s.jsx)("button",{onClick:c,disabled:l,className:"rounded-lg border border-card px-4 py-2 text-sm disabled:opacity-40",children:"Resume analysis"}),(0,s.jsx)("button",{onClick:i,disabled:l,className:"rounded-lg border border-card px-4 py-2 text-sm disabled:opacity-40",children:"importing"===t.status?"Stop remaining import":"Cancel import"})]})]})}let F={vip:{label:"VIP",color:"bg-[var(--state-attention-bg)] text-[color:var(--state-attention-fg)]"},active:{label:"Active",color:"bg-[var(--state-positive-bg)] text-[color:var(--state-positive-fg)]"},casual:{label:"Casual",color:"bg-[var(--state-info-bg)] text-[color:var(--state-info-fg)]"},new:{label:"New",color:"bg-[rgb(var(--accent-purple)/0.13)] text-[color:rgb(var(--accent-purple))]"},unknown:{label:"Unknown",color:"bg-[var(--button-ghost-bg)] text-t2"}},M={event:"Event",csv:"CSV",manual:"Manual",smart_import:"Smart Import"};function _(e){let{isAppUser:t,hasFcmToken:a,engagementTier:l,source:n,eventName:r}=e,i=l&&F[l];return(0,s.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[t&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[9px] font-medium bg-green-500/15 text-positive-ink",children:[(0,s.jsx)("span",{className:"w-1 h-1 rounded-full bg-green-400"}),"App User"]}),a&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[9px] font-medium bg-blue-500/15 text-info-ink",children:[(0,s.jsx)("svg",{className:"w-2.5 h-2.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"})}),"Push"]}),i&&(0,s.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-medium ".concat(i.color),children:i.label}),n&&(0,s.jsx)("span",{title:"event"===n&&r?r:void 0,className:"inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-medium bg-white/[0.06] text-t2",children:M[n]||n})]})}function D(e){let{data:t,width:a=64,height:l=24}=e;if(!t||t.length<2)return null;let n=t.map(e=>e.count),r=Math.min(...n),i=Math.max(...n)-r||1,c=n.map((e,t)=>{let s=t/(n.length-1)*a,c=l-(e-r)/i*(l-2)-1;return"".concat(s,",").concat(c)}).join(" "),o=n[n.length-1]>n[0],d=n[n.length-1]<n[0];return(0,s.jsx)("svg",{width:a,height:l,viewBox:"0 0 ".concat(a," ").concat(l),className:"shrink-0",children:(0,s.jsx)("polyline",{points:c,fill:"none",style:{stroke:o?"rgb(var(--color-green))":d?"rgb(var(--color-red))":"rgb(var(--text-secondary))"},strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function z(e){let{selectedCount:t,onDelete:a,onExport:l,onClearSelection:n}=e;return 0===t?null:(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 bg-indigo-950/60 border border-indigo-500/20 rounded-lg",children:[(0,s.jsxs)("span",{className:"text-xs font-medium text-indigo-300",children:[t," selected"]}),(0,s.jsx)("div",{className:"w-px h-4 bg-indigo-500/20"}),(0,s.jsx)(C.$n,{variant:"ghost",size:"sm",onClick:l,children:"Export Selected"}),(0,s.jsx)(C.$n,{variant:"danger",size:"sm",onClick:a,icon:(0,s.jsx)(y.uc,{className:"w-3 h-3"}),children:"Delete"}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:n,className:"p-1 rounded hover:bg-white/[0.06] text-t2 hover:text-t1 transition",children:(0,s.jsx)(y.fK,{className:"w-3.5 h-3.5"})})]})}var P=a(12160),T=a(24318),R=a(79996);let U=e=>"socialloop:reviewed-import:".concat(e),B=["completed","failed","partial_failure","canceled"];var $=a(8012);let O=/^[^\s@]+@[^\s@]+\.[^\s@]+$/u;function q(e){try{(0,m.httpsCallable)(h.functions,"logClientImportError")({...e,userAgent:"undefined"!=typeof navigator?navigator.userAgent:""}).catch(()=>{})}catch(e){}}function V(){var e,t,a,n,r,A,I;let F=(0,o.S)(),[M,V]=(0,l.useState)(!1),{user:W,userProfile:K,notify:H}=(0,g.Y)(),Y=(null==K?void 0:K.plan)||"free",J=f.B2[Y].maxLists,[Q,G]=(0,l.useState)(null),[X,Z]=(0,l.useState)(!1),[ee,et]=(0,l.useState)(""),[ea,es]=(0,l.useState)("people"),[el,en]=(0,l.useState)(null),[er,ei]=(0,l.useState)(""),[ec,eo]=(0,l.useState)(!1),[ed,eu]=(0,l.useState)(!1),[em,eh]=(0,l.useState)(!1),[ep,ex]=(0,l.useState)(!1),[eg,ef]=(0,l.useState)(""),[eb,ev]=(0,l.useState)(""),[ej,ey]=(0,l.useState)(""),[eN,ew]=(0,l.useState)(!1),[ek,eC]=(0,l.useState)(""),[eS,eA]=(0,l.useState)(!1),[eI,eL]=(0,l.useState)([]),[eE,eF]=(0,l.useState)(null),[eM,e_]=(0,l.useState)([]),[eD,ez]=(0,l.useState)(!1),[eP,eT]=(0,l.useState)(!1),[eR,eU]=(0,l.useState)(""),[eB,e$]=(0,l.useState)(null),[eO,eq]=(0,l.useState)(null),[eV,eW]=(0,l.useState)(!1),[eK,eH]=(0,l.useState)(null),[eY,eJ]=(0,l.useState)(new Set),[eQ,eG]=(0,l.useState)(!1),[eX,eZ]=(0,l.useState)(0),[e0,e1]=(0,l.useState)({missingCount:0,eventsCount:0,totalParticipants:0});(0,v.x)("create-list",e=>{let t=null==e?void 0:e.name;t&&et(t),Z(!0)},{});let e2=W?"users/".concat(W.uid,"/distribution_lists"):null,{data:e5,loading:e3}=(0,j.$)(e2,[(0,u.orderBy)("createdAt","desc"),(0,u.limit)(200)],(e,t)=>{var a,s,l;return t.deletedAt?null:{id:e,name:null!=(a=t.name)?a:"",type:null!=(s=t.type)?s:"people",createdAt:(0,$.E)(t.createdAt),updatedAt:(0,$.E)(t.updatedAt),contactCount:null!=(l=t.contactCount)?l:0,countMode:t.countMode,countUpdatedAtMs:t.countUpdatedAtMs,health:t.health}}),e4=(0,l.useMemo)(()=>
1e5.filter(Boolean),[e5]),e6=W&&Q?"users/".concat(W.uid,"/distribution_lists/").concat(Q,"/contacts"):null,e8=null!=(a=e4.find(e=>e.id===Q))?a:null,e7=function(e,t,a,s,n){let[r,i]=(0,l.useState)([]),[c,o]=(0,l.useState)(0),[d,m]=(0,l.useState)(!0),[p,x]=(0,l.useState)(!1),g=(0,l.useRef)([]),f=(0,l.useRef)(s);f.current=s;let b=(0,l.useRef)(t);b.current=t;let v=Math.max(1,Math.ceil(n/100)),j=c>0,y=(0,l.useCallback)(async(t,s)=>{if(!e){i([]),m(!1);return}m(!0);try{let l=(0,u.collection)(h.db,e),n=[...b.current,(0,u.limit)(100)];s&&n.push((0,u.startAfter)(s));let r=(0,u.query)(l,...n),c=await (0,u.getDocs)(r),d=c.docs.map(e=>f.current(e.id,e.data()));c.docs.length>0&&(g.current[t]=c.docs[c.docs.length-1]),i(d),o(t),x(c.docs.length===a)}catch(e){i([]),x(!1)}finally{m(!1)}},[e,a]);(0,l.useEffect)(()=>{g.current=[],o(0),y(0,null)},[y]);let N=(0,l.useCallback)(()=>{var e;if(!p||d)return;let t=null!=(e=g.current[c])?e:null;y(c+1,t)},[p,d,c,y]),w=(0,l.useCallback)(()=>{if(!(c<=0)&&!d)if(1===c)y(0,null);else{var e;let t=null!=(e=g.current[c-2])?e:null;y(c-1,t)}},[c,d,y]),k=(0,l.useCallback)(()=>{d||(g.current=[],y(0,null))},[d,y]);return{data:r,page:c,totalPages:v,loading:d,hasNext:p,hasPrev:j,nextPage:N,prevPage:w,firstPage:k,refresh:(0,l.useCallback)(()=>{g.current=[],o(0),y(0,null)},[y])}}(e6,[(0,u.orderBy)("addedAt","desc")],100,(e,t)=>{var a,s,l,n,r,i,c,o,d;return{id:e,name:null!=(a=t.name)?a:"",email:null!=(s=t.email)?s:"",phone:null!=(l=t.phone)?l:"",source:null!=(n=t.source)?n:"manual",eventId:t.eventId,eventName:t.eventName,addedAt:(0,$.E)(t.addedAt),appUserId:t.appUserId,isAppUser:null!=(r=t.isAppUser)&&r,hasFcmToken:null!=(i=t.hasFcmToken)&&i,lastActiveAt:t.lastActiveAt?(0,$.E)(t.lastActiveAt):void 0,eventsAttended:null!=(c=t.eventsAttended)?c:0,engagementTier:null!=(o=t.engagementTier)?o:"unknown",tags:null!=(d=t.tags)?d:[]}},null!=(n=null==e8?void 0:e8.contactCount)?n:0),e9=e7.data,te=e7.loading;(0,l.useEffect)(()=>{e3||e4.length>0||eV||!W||(async()=>{eW(!0);try{let e=(0,m.httpsCallable)(h.functions,"initializeDefaultDistributionList"),t=await e({});if(t.data.listId&&(G(t.data.listId),t.data.contactCount>0))try{let e=(0,m.httpsCallable)(h.functions,"analyzeDistributionList"),a=await e({listId:t.data.listId});a.data.health&&eH(a.data.health)}catch(e){}}catch(e){}finally{eW(!1)}})()},[e3,e4.length,eV,W]),(0,l.useEffect)(()=>{if(!e8)return void eH(null);if(e8.health){eH(e8.health);let e=e8.health.lastEnrichedAt;e&&Date.now()-("number"==typeof e?e:new Date(e).getTime())>18e5&&tt()}else e8.contactCount>0&&tt()},[Q,eX]);let tt=(0,l.useCallback)(async()=>{if(Q)try{let e=(0,m.httpsCallable)(h.functions,"analyzeDistributionList"),t=await e({listId:Q});t.data.health&&eH(t.data.health)}catch(e){}},[Q]),ta=(0,l.useMemo)(()=>{let e=e9;if(eO&&(e=e.filter(e=>e.engagementTier===eO)),eR.trim()){let t=eR.toLowerCase().trim(),a=RegExp("\\b".concat(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),"i");e=e.map(e=>{let s=e.name.toLowerCase(),l=0;return s===t?l=100:s.startsWith(t)?l=80:a.test(e.name)?l=60:s.includes(t)?l=40:e.email.toLowerCase().includes(t)?l=20:e.phone.includes(t)?l=10:(e.tags||[]).some(e=>e.toLowerCase().includes(t))&&(l=5),{item:e,score:l}}).filter(e=>e.score>0).sort((e,t)=>t.score-e.score).map(e=>e.item)}return e},[e9,eR,eO]),ts=null!=(r=null==e8?void 0:e8.contactCount)?r:0,tl=(0,l.useCallback)(async()=>{if(W&&ee.trim()){if(J!==1/0&&e4.length>=J)return void(0,N.WL)("ListLimit",H,{tab:"LISTS",action:"create-list",meter:"lists",payload:{name:ee.trim()}})({code:"functions/resource-exhausted",message:(0,w.Rh)(J)});try{let e=(0,m.httpsCallable)(h.functions,"checkListCreationLimit"),t=await e({listName:ee.trim(),listType:ea});G(t.data.listId),et(""),es("people"),Z(!1),H({type:"success",message:"List created"})}catch(e){(0,N.WL)("ListLimit",H,{tab:"LISTS",action:"create-list",meter:"lists",payload:{name:ee.trim()}})(e)}}},[W,ee,J,e4.length,ea,H]),tn=(0,l.useCallback)(async e=>{if(W&&er.trim())try{await (0,u.updateDoc)((0,u.doc)(h.db,"users/".concat(W.uid,"/distribution_lists"),e),{name:er.trim(),updatedAt:u.Timestamp.now()}),en(null),H({type:"success",message:"List renamed"})}catch(e){H({type:"error",message:"Failed to rename list"})}},[W,er,H]),tr=(0,l.useCallback)(async e=>{if(W&&window.confirm("Delete this list and all its contacts?"))try{await (0,u.updateDoc)((0,u.doc)(h.db,"users/".concat(W.uid,"/distribution_lists"),e),{deletedAt:u.Timestamp.now(),updatedAt:u.Timestamp.now()}),Q===e&&G(null),H({type:"success",message:"List deleted"})}catch(e){H({type:"error",message:"Failed to delete list"})}},[W,Q,H]);(0,l.useCallback)(async e=>{var t;if(!W||!Q)return;let a="users/".concat(W.uid,"/distribution_lists/").concat(Q),s={addedAt:u.Timestamp.now()};for(let[t,a]of Object.entries(e))void 0!==a&&(s[t]=a);await (0,u.addDoc)((0,u.collection)(h.db,"".concat(a,"/contacts")),s);let l=e4.find(e=>e.id===Q);await (0,u.updateDoc)((0,u.doc)(h.db,a),{contactCount:(null!=(t=null==l?void 0:l.contactCount)?t:0)+1,updatedAt:u.Timestamp.now()})},[W,Q,e4]);let ti=(0,l.useCallback)(async()=>
1{if(Q&&(eg.trim()||eb.trim()||ej.trim())){ew(!0);try{let e=(0,m.httpsCallable)(h.functions,"bulkAddContactsToList");await e({listId:Q,contacts:[{name:eg.trim(),email:eb.toLowerCase().trim(),phone:ej.replace(/\D/g,""),source:"manual"}]}),ef(""),ev(""),ey(""),eo(!1),e7.refresh(),H({type:"success",message:"Contact added"})}catch(e){(0,N.WL)("AddContact",H,{tab:"LISTS",action:"add-contact",meter:"contactsStored"})(e)}finally{ew(!1)}}},[Q,eg,eb,ej,H,e7.refresh]),[tc,to]=(0,l.useState)([]),[td,tu]=(0,l.useState)(""),[tm,th]=(0,l.useState)(null),[tp,tx]=(0,l.useState)(null),[tg,tf]=(0,l.useState)(null),[tb,tv]=(0,l.useState)(""),[tj,ty]=(0,l.useState)([]),[tN,tw]=(0,l.useState)(!1),[tk,tC]=(0,l.useState)(!1),tS=(0,l.useCallback)(e=>new Promise((t,a)=>{let s=new FileReader;s.onload=e=>{try{var s;let a=new Uint8Array(null==(s=e.target)?void 0:s.result),l=d.LF(a,{type:"array"}),n=l.Sheets[l.SheetNames[0]],r=d.Wp.sheet_to_json(n,{header:1,defval:""});t(r.map(e=>e.map(e=>String(null!=e?e:"").trim())))}catch(e){a(Error("Could not parse this file. Try exporting as CSV first."))}},s.onerror=()=>a(Error("Failed to read file")),s.readAsArrayBuffer(e)}),[]),tA=(0,l.useCallback)(async()=>{if(0===tc.length)return;if(tc.length<2)return void H({type:"error",message:"File needs at least a header row and one contact."});let e=tc[0]||[];if(e.length<2)return void H({type:"error",message:"File needs at least 2 columns (e.g., name and email)."});let t=tc.slice(1).filter(e=>e.some(e=>e)),a=(0,p.k)();tv(a),tf(null),th(null),tx(null),tw(!0);try{let s=(0,m.httpsCallable)(h.functions,"parseCSVWithAI"),l=(await s({headers:e,sampleRows:t.slice(0,10),sessionId:a})).data;th(l),ty(t),l.rejected?(tf(l.rejected),tx(null),q({sessionId:a,stage:"classifier_rejected",rejectionCode:l.rejected.code,message:l.rejected.userMessage,context:JSON.stringify({classification:l.classification,confidence:l.confidence})})):l.mapping?tx(l.mapping):(tf({code:"classification_unclear",userMessage:"We couldn't work out how to map this file's columns. Try a different export."}),q({sessionId:a,stage:"classifier_accepted_but_no_mapping",message:"Server returned accepted response with null mapping"}))}catch(t){var s;let e="string"==typeof(null==t?void 0:t.code)?t.code:"unknown";q({sessionId:a,stage:"classifier_call_failed",rejectionCode:e,message:"string"==typeof(null==t?void 0:t.message)?t.message:String(t),context:JSON.stringify({details:null!=(s=null==t?void 0:t.details)?s:null})}),"functions/resource-exhausted"===e||"resource-exhausted"===e?H({type:"error",message:"You're analyzing files too quickly. Try again in a minute."}):"functions/unauthenticated"===e||"unauthenticated"===e?H({type:"error",message:"Sign in required to analyze files."}):H({type:"error",message:"Something went wrong analyzing this file. Please try again in a moment."}),th(null),tx(null)}finally{tw(!1)}},[tc,H]),tI=function(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0],t=function(){var e;let t=(0,P.m)(),a=(0,T.kq)(t)?t.user.uid:null,[s,n]=(0,l.useState)(null),[r,i]=(0,l.useState)(null),[c,o]=(0,l.useState)(null),[d,x]=(0,l.useState)(!1),[g,f]=(0,l.useState)(!1),b=(0,l.useRef)(null),v=(0,l.useRef)(null),j=(0,l.useRef)(0),y=(0,l.useCallback)(e=>{var t;null==(t=v.current)||t.call(v),b.current=e,n(e.jobId);let a=++j.current;v.current=(0,u.onSnapshot)((0,u.doc)(h.db,"contact_import_jobs/".concat(e.jobId,"/progress/current")),t=>{var s,l;if(j.current!==a||(null==(s=h.auth.currentUser)?void 0:s.uid)!==e.uid||!t.exists())return;let n=t.data();if(i(n),n.error&&o(n.error),B.includes(n.status)){try{sessionStorage.removeItem(U(e.uid))}catch(e){}null==(l=v.current)||l.call(v),v.current=null}},e=>{j.current===a&&o(e.message)})},[]),N=(0,l.useCallback)(async()=>{var e,t;let a=b.current;if(!a||(null==(e=h.auth.currentUser)?void 0:e.uid)!==a.uid)return;let s=j.current;x(!0),o(null);try{await (0,m.httpsCallable)(h.functions,"initiateContactImport")({...a,reviewBeforeImport:!0}),j.current===s&&(null==(t=h.auth.currentUser)?void 0:t.uid)===a.uid&&y(a)}catch(e){j.current===s&&o(e instanceof Error?e.message:"Could not resume the import analysis.")}finally{x(!1)}},[y]);(0,l.useEffect)(()=>{var e;if(t.authReady){if(j.current++,null==(e=v.current)||e.call(v),v.current=null,b.current=null,n(null),i(null),o(null),a)try{let e=JSON.parse(sessionStorage.getItem(U(a))||"null");(null==e?void 0:e.uid)===a&&e.jobId==="".concat(a,"_").concat(e.requestId)&&(y(e),N())}catch(e){}return()=>{var e;j.current++,null==(e=v.current)||e.call(v)}}},[t.authReady,a,y,N]);let w=(0,l.useCallback)(async(e,t,a)=>{var s,l;let n=null==(s=h.auth.currentUser)?void 0:s.uid;if(!n)throw Error("Sign in before analyzing an import.");if(b.current)throw Error("Finish or cancel the current import first.");x(!0),o(null);let r=j.current;try{let s=new Blob(t.map(e=>
1"".concat(JSON.stringify(e),"\n")),{type:"application/x-ndjson"});if(s.size>=0x6400000)throw Error("Use a contact file smaller than 100 MB.");let c=(0,p.k)(),o="contact-imports/".concat(n,"/").concat(c,".ndjson");if(i({status:"uploading",phase:"Uploading for analysis…",totalContacts:t.length,added:0,skipped:0,failed:0,progress:0}),await new Promise((e,t)=>{(0,R.bp)((0,R.KR)(h.privateStorage,o),s,{contentType:"application/x-ndjson"}).on("state_changed",e=>{j.current===r&&i(t=>t&&{...t,progress:Math.round(e.bytesTransferred/e.totalBytes*100)})},t,e)}),(null==(l=h.auth.currentUser)?void 0:l.uid)!==n||j.current!==r)return;let d={uid:n,requestId:c,jobId:"".concat(n,"_").concat(c),listId:e,storagePath:o,totalContacts:t.length,...a};b.current=d;try{sessionStorage.setItem(U(d.uid),JSON.stringify(d))}catch(e){}y(d),await (0,m.httpsCallable)(h.functions,"initiateContactImport")({...d,reviewBeforeImport:!0})}catch(e){throw o(e instanceof Error?e.message:"Could not analyze this file."),e}finally{x(!1)}},[y]),k=(0,l.useCallback)(async e=>{var t,a;if(b.current&&(null==(t=h.auth.currentUser)?void 0:t.uid)===b.current.uid){f(!0),o(null);try{await (0,m.httpsCallable)(h.functions,"reviewContactImport")({action:e,jobId:b.current.jobId,reviewHash:null==r?void 0:r.reviewHash})}catch(t){if("cancel"===e&&"functions/not-found"===t.code){let e=b.current;if(e)try{sessionStorage.removeItem(U(e.uid))}catch(e){}j.current++,null==(a=v.current)||a.call(v),b.current=null,n(null),i(null)}else o(t instanceof Error?t.message:"Could not save this import decision.")}finally{f(!1)}}},[null==r?void 0:r.reviewHash]),C=(0,l.useCallback)(()=>{var e;if(b.current)try{sessionStorage.removeItem(U(b.current.uid))}catch(e){}j.current++,null==(e=v.current)||e.call(v),v.current=null,b.current=null,n(null),i(null),o(null)},[]);return{reviewEnabled:!0,startImport:w,retryInitiation:N,review:k,jobId:s,listId:null==(e=b.current)?void 0:e.listId,progress:r,isActive:!!s&&!B.includes((null==r?void 0:r.status)||""),isInitiating:d,isReviewing:g,error:c,reset:C}}(),a=function(){let[e,t]=(0,l.useState)(null),[a,s]=(0,l.useState)(null),[n,r]=(0,l.useState)(null),[i,c]=(0,l.useState)(!1),o=(0,l.useRef)(null);(0,l.useEffect)(()=>()=>{var e;null==(e=o.current)||e.call(o)},[]);let d=!!e&&!!a&&"completed"!==a.status&&"failed"!==a.status&&"partial_failure"!==a.status;return{startImport:(0,l.useCallback)(async(e,a,l)=>{var n,i;let d=null==(n=h.auth.currentUser)?void 0:n.uid;if(!d)return void r("Authentication required");c(!0),r(null);try{s({status:"uploading",phase:"Uploading contacts...",totalContacts:a.length,added:0,skipped:0,failed:0,progress:0});let n=(0,p.k)(),c="contact-imports/".concat(d,"/").concat(n,".ndjson"),x=(0,R.KR)(h.privateStorage,c),g=Array(a.length);for(let e=0;e<a.length;e++)g[e]=JSON.stringify(a[e]);let f=new Blob([g.join("\n")],{type:"application/x-ndjson"});await new Promise((e,t)=>{(0,R.bp)(x,f,{contentType:"application/x-ndjson"}).on("state_changed",e=>{let t=Math.round(e.bytesTransferred/e.totalBytes*100);s(e=>e?{...e,phase:"Uploading contacts... ".concat(t,"%"),progress:Math.round(.1*t)}:e)},e=>t(e),()=>e())}),s(e=>e?{...e,phase:"Starting import...",progress:10}:e);let b=(0,p.k)(),v=(0,m.httpsCallable)(h.functions,"initiateContactImport"),j=(await v({requestId:b,listId:e,storagePath:c,privateUpload:!0,totalContacts:a.length,...(null==l?void 0:l.classification)&&{classification:l.classification},...(null==l?void 0:l.importedFrom)&&{importedFrom:l.importedFrom}})).data.jobId;t(j),null==(i=o.current)||i.call(o);let y=(0,u.doc)(h.db,"contact_import_jobs/".concat(j,"/progress/current"));o.current=(0,u.onSnapshot)(y,e=>{var t,a,l,n,i,c,d,u;if(!e.exists())return;let m=e.data();s({status:null!=(t=m.status)?t:"pending",phase:null!=(a=m.phase)?a:"Queued",totalContacts:null!=(l=m.totalContacts)?l:0,added:null!=(n=m.added)?n:0,skipped:null!=(i=m.skipped)?i:0,failed:null!=(c=m.failed)?c:0,progress:null!=(d=m.progress)?d:0,updatedAt:m.updatedAt,completedAt:m.completedAt,error:m.error}),["completed","failed","partial_failure"].includes(m.status)&&(m.error&&r(m.error),null==(u=o.current)||u.call(o),o.current=null)},e=>{r(e.message)})}catch(e){r(e instanceof Error?e.message:"Failed to start contact import")}finally{c(!1)}},[]),jobId:e,progress:a,isActive:d,isInitiating:i,error:n,reset:(0,l.useCallback)(()=>{var e;null==(e=o.current)||e.call(o),o.current=null,t(null),s(null),r(null)},[])}}();return e||t.jobId?t:{...a,reviewEnabled:!1,listId:void 0,isReviewing:!1,review:async e=>{},retryInitiation:async()=>{}}}(F);(0,l.useEffect)(()=>
1{if(!tI.progress)return;let{status:e}=tI.progress;if(!["completed","failed","partial_failure","canceled"].includes(e))return;let{added:t,skipped:a,failed:s}=tI.progress,l=[];t>0&&l.push("".concat(t.toLocaleString()," imported")),a>0&&l.push("".concat(a.toLocaleString()," skipped")),s>0&&l.push("".concat(s.toLocaleString()," failed")),H({type:"failed"===e?"error":"success",message:l.join(", ")||("failed"===e?"Import failed":"canceled"===e?"Import canceled":"No new contacts to import")}),(t>0||a>0)&&(eC(""),tx(null),ty([]),eu(!1),e7.refresh()),tC(!1),tI.reset()},[null==(e=tI.progress)?void 0:e.status]);let tL=(0,l.useCallback)(async()=>{var e,t,a,s,l;if(!tp||!Q||0===tj.length)return;tC(!0);let n=[],r=0;for(let a of tj){let s="",i="",c="",o="",d="",u={};for(let[t,l]of Object.entries(tp.coreFields)){let n=(null!=(e=a[parseInt(t)])?e:"").trim();n&&("name"===l?s=n:"firstName"===l?i=n:"lastName"===l?c=n:"email"===l?o=n:"phone"===l&&(d=n))}for(let[e,s]of Object.entries(tp.metadataFields)){let l=(null!=(t=a[parseInt(e)])?t:"").trim();l&&(u[s]=l)}if(!s&&(i||c)&&(s="".concat(i," ").concat(c).trim()),!((l=o)&&O.test(l.trim())||function(e){if(!e)return!1;let t=0;for(let a of e){let e=a.codePointAt(0);void 0!==e&&(e>=48&&e<=57||e>=65296&&e<=65305||e>=1632&&e<=1641||e>=1776&&e<=1785||e>=2406&&e<=2415||e>=2534&&e<=2543||e>=2662&&e<=2671||e>=2790&&e<=2799||e>=2918&&e<=2927||e>=3046&&e<=3055||e>=3174&&e<=3183||e>=3302&&e<=3311||e>=3430&&e<=3439||e>=3664&&e<=3673||e>=3792&&e<=3801||e>=3872&&e<=3881||e>=4160&&e<=4169)&&t++}return t>=7&&t<=20}(d))){r++;continue}n.push({name:s,email:o,phone:d,source:"csv",...Object.keys(u).length>0&&{metadata:u}})}let i=tj.length,c=i>0?n.length/i:0;if(0===n.length){H({type:"error",message:"None of the rows had a usable email or phone. Please check your column mapping and try again."}),q({sessionId:tb,stage:"import_gate_all_unreachable",message:"All ".concat(i.toLocaleString()," rows failed the reachability gate")}),tC(!1);return}if(c<.5){let e=Math.round(100*c);H({type:"error",message:"Only ".concat(e,"% of rows had a usable email or phone. Check your column mapping — this file may not be set up as a contact list.")}),q({sessionId:tb,stage:"import_gate_low_usable_ratio",message:"Usable ratio ".concat(e,"% (").concat(n.length,"/").concat(i,")")}),tC(!1);return}if(r>0&&H({type:"info",message:"Dropping ".concat(r.toLocaleString()," rows with no reachable email or phone.")}),!tI.reviewEnabled&&n.length>=1e3&&!window.confirm("Import ".concat(n.length.toLocaleString(),' contacts to "').concat(null!=(s=null==(a=e4.find(e=>e.id===Q))?void 0:a.name)?s:"this list",'"?\n\n').concat(r>0?"".concat(r.toLocaleString()," rows will be skipped (no valid email or phone)."):"All rows have a usable email or phone.")))return void tC(!1);try{await tI.startImport(Q,n,{classification:null==tm?void 0:tm.classification}),tI.reviewEnabled&&(eu(!1),tC(!1))}catch(e){q({sessionId:tb,stage:"start_import_failed",rejectionCode:"string"==typeof(null==e?void 0:e.code)?e.code:"unknown",message:"string"==typeof(null==e?void 0:e.message)?e.message:String(e)}),H({type:"error",message:"Couldn't start the import. Please try again."}),tC(!1)}},[tp,tj,Q,H,tI,tb,tm]),tE=(0,l.useCallback)((e,t)=>{tx(a=>{if(!a)return a;let s={...a.coreFields},l={...a.metadataFields};if(delete s[e],delete l[e],"metadata"===t){var n,r;let t=(null!=(r=null==(n=tc[0])?void 0:n[parseInt(e)])?r:"column_".concat(e)).toLocaleLowerCase("en-US").replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")||"column_".concat(e);l[e]=t}else"ignore"===t||(s[e]=t);return{...a,coreFields:s,metadataFields:l,splitName:Object.values(s).includes("firstName")&&Object.values(s).includes("lastName")}})},[tc]),tF=(0,l.useCallback)(()=>{to([]),tu(""),th(null),tx(null),tf(null),tv(""),ty([]),eC(""),tw(!1),tC(!1)},[]),tM=(0,l.useCallback)(async e=>{if(W&&Q&&window.confirm("Remove this contact from the list?"))try{var t;let a="users/".concat(W.uid,"/distribution_lists/").concat(Q);await (0,u.deleteDoc)((0,u.doc)(h.db,"".concat(a,"/contacts"),e));let s=e4.find(e=>e.id===Q);await (0,u.updateDoc)((0,u.doc)(h.db,a),{contactCount:Math.max((null!=(t=null==s?void 0:s.contactCount)?t:1)-1,0),updatedAt:u.Timestamp.now()}),e7.refresh(),H({type:"success",message:"Contact removed"})}catch(e){H({type:"error",message:"Failed to remove contact"})}},[W,Q,e4,H]),t_=(0,l.useCallback)(e=>{var t;let a=new Blob(["Name,Email,Phone,Source,Event\n"+(e||ta).map(e=>{let t='"'.concat(e.name.replace(/"/g,'""'),'"'),a=e.eventName?'"'.concat(e.eventName.replace(/"/g,'""'),'"'):"";return"".concat(t,",").concat(e.email,",").concat(e.phone,",").concat(e.source,",").concat(a)}).join("\n")],{type:"text/csv"}),s=URL.createObjectURL(a),l=document.createElement("a");l.href=s,l.download="".concat(null!=(t=null==e8?void 0:e8.name)?t:"contacts","-").concat(new Date().toISOString().slice(0,10),".csv"),l.click(),URL.revokeObjectURL(s)},[ta,e8]),tD=((0,l.useCallback)(async(e,t)=>{try{let a=(0,m.httpsCallable)(h.functions,"bulkAddContactsToList"),s=await a({listId:e,contacts:t.contacts.map(e=>({...e,source:"smart_import",eventId:t.eventId,eventName:t.eventName}))});
1H({type:"success",message:"".concat(s.data.added," contacts added").concat(s.data.skipped>0?", ".concat(s.data.skipped," already existed"):"")}),e===Q&&eZ(e=>e+1)}catch(e){H({type:"error",message:"Failed to import contacts"})}},[Q,H]),(0,l.useCallback)(e=>{eJ(t=>{let a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})},[])),tz=(0,l.useCallback)(()=>{let e=ta.map(e=>e.id);e.every(e=>eY.has(e))?eJ(t=>{let a=new Set(t);return e.forEach(e=>a.delete(e)),a}):eJ(t=>new Set([...t,...e]))},[eY,ta]),tP=(0,l.useCallback)(async()=>{if(W&&Q&&0!==eY.size&&window.confirm("Delete ".concat(eY.size," selected contacts?")))try{var e;let t="users/".concat(W.uid,"/distribution_lists/").concat(Q);await Promise.all(Array.from(eY).map(e=>(0,u.deleteDoc)((0,u.doc)(h.db,"".concat(t,"/contacts"),e)))),await (0,u.updateDoc)((0,u.doc)(h.db,t),{contactCount:Math.max((null!=(e=null==e8?void 0:e8.contactCount)?e:0)-eY.size,0),updatedAt:u.Timestamp.now()}),eJ(new Set),e7.refresh(),H({type:"success",message:"".concat(eY.size," contacts deleted")})}catch(e){H({type:"error",message:"Failed to delete contacts"})}},[W,Q,e8,eY,H,e7.refresh]),tT=(0,l.useCallback)(()=>{t_(ta.filter(e=>eY.has(e.id)))},[ta,eY,t_]),tR=(0,l.useCallback)(async()=>{if(W){eh(!0),ex(!1),eA(!0),eF(null),e_([]);try{let e=(0,u.collection)(h.db,"events"),t=(0,u.query)(e,(0,u.where)("hosts","array-contains",W.uid),(0,u.orderBy)("eventDate","desc")),a=await (0,u.getDocs)(t);eL(a.docs.filter(e=>"cancelled"!==e.data().status).map(e=>{var t,a,s,l;let n=e.data();return{id:e.id,name:null!=(l=n.eventName)?l:"Untitled",date:(null==(a=n.eventDate)||null==(t=a.toDate)?void 0:t.call(a))||void 0,locationAddress:n.locationAddress||void 0,city:(null==(s=n.venue)?void 0:s.city)||void 0,attendeeCount:n.participantCount||0}}))}catch(e){H({type:"error",message:"Failed to load events"})}finally{eA(!1)}}},[W,H]),tU=(0,l.useCallback)(async e=>{eF(e),ez(!0),e_([]);try{let s=(0,u.collection)(h.db,"events/".concat(e,"/participants")),l=await (0,x.w)((0,u.getDocs)((0,u.query)(s,(0,u.limit)(5e3))),15e3),n=[],r=new Set;for(let e of l.docs){var t,a;let s=e.data(),l=null!=(t=s.userID)?t:e.id,i=s.name||s.displayName||s.userName||"",c=(null!=(a=s.email)?a:"").toLowerCase().trim(),o=(s.phone||s.phoneNumber||"").replace(/\D/g,"");n.push({uid:l,name:i,email:c,phone:o}),i&&c||r.add(l)}let i=new Map,c=Array.from(r),o=[];for(let e=0;e<c.length;e+=30)o.push(c.slice(e,e+30));for(let e of(await Promise.allSettled(o.map(e=>{let t=(0,u.query)((0,u.collection)(h.db,"publicProfiles"),(0,u.where)((0,u.documentId)(),"in",e));return(0,x.w)((0,u.getDocs)(t),1e4)}))))"fulfilled"===e.status&&e.value.docs.forEach(e=>i.set(e.id,e.data()));let d=n.map(e=>{var t,a;let s=i.get(e.uid),l=e.name||(null==s?void 0:s.displayName)||(null==s?void 0:s.name)||((null==s?void 0:s.firstName)?"".concat(s.firstName," ").concat(null!=(t=s.lastName)?t:"").trim():"")||"",n=e.email||(null!=(a=null==s?void 0:s.email)?a:"").toLowerCase().trim(),r=e.phone||((null==s?void 0:s.phone)||(null==s?void 0:s.phoneNumber)||"").replace(/\D/g,"");return{uid:e.uid,name:l,email:n,phone:r,checked:!0}});e_(d)}catch(e){H({type:"error",message:"Failed to load participants"})}finally{ez(!1)}},[H]),tB=(0,l.useCallback)(async()=>{var e,t;if(!eE||!Q)return;eT(!0);let a=null!=(t=null==(e=eI.find(e=>e.id===eE))?void 0:e.name)?t:"",s=eM.filter(e=>e.checked);try{let e=(0,m.httpsCallable)(h.functions,"bulkAddContactsToList"),t=await e({listId:Q,contacts:s.map(e=>({name:e.name,email:e.email,phone:e.phone,source:"event",eventId:eE,eventName:a}))});H({type:"success",message:"".concat(t.data.added," contact").concat(1!==t.data.added?"s":""," added").concat(t.data.skipped>0?", ".concat(t.data.skipped," already existed"):"")})}catch(e){H({type:"error",message:"Failed to add contacts"})}finally{eh(!1),eT(!1),e7.refresh()}},[eE,Q,eI,eM,H,e7.refresh]);return M&&F?(0,s.jsx)(i,{onBack:()=>V(!1)}):e3?(0,s.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,s.jsx)("div",{className:"studio-spinner",style:{width:32,height:32}})}):(0,s.jsxs)("div",{className:"space-y-4",children:[F&&(0,s.jsx)("button",{className:"rounded-lg border border-white/15 px-4 py-2 text-sm",onClick:()=>V(!0),children:"Saved audiences & relationship views"}),tI.reviewEnabled&&tI.jobId&&tI.isActive&&(0,s.jsx)(E,{progress:tI.progress,error:tI.error,busy:tI.isInitiating||tI.isReviewing,listName:(null==(t=e4.find(e=>e.id===tI.listId))?void 0:t.name)||"Selected list",onConfirm:()=>void tI.review("confirm"),onCancel:()=>void tI.review("cancel"),onRetry:()=>void tI.retryInitiation()}),!1,(0,s.jsxs)("div",{className:"flex flex-col lg:flex-row gap-4",children:[(0,s.jsxs)("div",{className:"w-full lg:w-72 shrink-0 space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"studio-body-strong",children:"Your Lists"}),J===1/0||e4.length<J?(0,s.jsxs)("button",{onClick:()=>Z(!0),className:"flex items-center gap-1 text-xs text-t2 hover:text-t1 transition",children:[(0,s.jsx)(y.c1,{className:"w-3.5 h-3.5"}),"New List"]}):(0,s.jsxs)("span",{className:"studio-micro",children:[e4.length,"/",J]})]}),J!==1/0&&(0,s.jsxs)("div",{className:"rounded-xl border p-3 ".concat(e4.length>=J?"bg-amber-500/[0.06] border-amber-500/20":"bg-surface-raised border-white/[0.04]"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("p",{className:"studio-caption",children:[e4.length," of ",J," list",1!==J?"s":""," used"]}),e4.length>=J&&(0,s.jsx)("button",{onClick:()=>(0,b.k)({intent:{tab:"LISTS",action:"create-list",meter:"lists"}}),className:"text-[10px] font-semibold text-indigo-400 hover:text-indigo-300 transition",children:"Upgrade"})]}),(0,s.jsx)("div",{className:"h-1 rounded-full bg-white/[0.06] overflow-hidden",children:(0,s.jsx)("div",{className:"h-full rounded-full transition-all duration-500 ".concat(e4.length>=J?"bg-amber-500":"bg-indigo-500"),style:{width:"".concat(Math.min(100,e4.length/J*100),"%")}})})]}),X&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex rounded-lg border border-white/10 overflow-hidden w-fit",children:[(0,s.jsx)("button",{onClick:()=>es("people"),className:"px-3 py-1.5 text-xs font-medium transition ".concat("people"===ea?"bg-white/10 text-white":"bg-white/[0.02] text-t2 hover:text-t2"),children:"People"}),(0,s.jsx)("button",{onClick:()=>es("affiliates"),className:"px-3 py-1.5 text-xs font-medium transition ".concat("affiliates"===ea?"bg-[rgb(var(--accent-purple)/0.2)] text-[color:rgb(var(--accent-purple))]":"bg-white/[0.02] text-t2 hover:text-t2"),children:"Affiliates"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("input",{autoFocus:!0,value:ee,onChange:e=>et(e.target.value),onKeyDown:e=>{"Enter"===e.key&&tl(),"Escape"===e.key&&(Z(!1),et(""),es("people"))},placeholder:"List name...",className:"flex-1 min-w-0 px-3 py-2 bg-card border border-card rounded-lg text-sm text-t1 placeholder-t3 focus:outline-none focus:border-white/20"}),(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:tl,disabled:!ee.trim(),children:"Create"})]})]}),0!==e4.length||X?(0,s.jsx)("div",{className:"space-y-2.5",children:e4.map(e=>{let t=e.health;return(0,s.jsx)("div",{onClick:()=>{G(e.id),eJ(new Set),eq(null)},className:"group relative cursor-pointer rounded-xl border p-4 transition ".concat(Q===e.id?"bg-white/[0.08] border-white/[0.15] shadow-[0_0_12px_rgba(139,92,246,0.06)]":"bg-white/[0.025] border-white/[0.06] hover:bg-white/[0.05] hover:border-white/[0.1]"),children:el===e.id?(0,s.jsxs)("div",{className:"flex gap-2",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("input",{autoFocus:!0,value:er,onCh
1ange:e=>ei(e.target.value),onKeyDown:t=>{"Enter"===t.key&&tn(e.id),"Escape"===t.key&&en(null)},className:"flex-1 min-w-0 px-2 py-1 bg-card border border-card rounded text-sm text-t1 focus:outline-none focus:border-white/20"}),(0,s.jsx)("button",{onClick:()=>tn(e.id),className:"p-1 text-positive-ink hover:text-positive-ink transition",children:(0,s.jsx)(y.Sr,{className:"w-4 h-4"})}),(0,s.jsx)("button",{onClick:()=>en(null),className:"p-1 text-t2 hover:text-t1 transition",children:(0,s.jsx)(y.fK,{className:"w-4 h-4"})})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-start justify-between",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("p",{className:"studio-body-strong truncate",children:e.name}),"affiliates"===e.type&&(0,s.jsx)("span",{className:"shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium bg-violet-500/15 text-[rgb(var(--accent-purple)/0.80)]",children:"Affiliates"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[(0,s.jsxs)("p",{className:"studio-caption",children:["subscriber_shards"===e.countMode?"≈ ":"",Math.max(0,e.contactCount)," contact",1!==e.contactCount?"s":""]}),(null==t?void 0:t.growthHistory)&&t.growthHistory.length>=2&&(0,s.jsx)(D,{data:t.growthHistory,width:48,height:16})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-0.5 sm:opacity-0 sm:group-hover:opacity-100 transition",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("button",{onClick:()=>{en(e.id),ei(e.name)},className:"p-1 rounded text-t2 hover:text-t1 hover:bg-white/[0.06] transition",children:(0,s.jsx)(y.R2,{className:"w-3.5 h-3.5"})}),(0,s.jsx)("button",{onClick:()=>tr(e.id),className:"p-1 rounded text-t2 hover:text-negative-ink hover:bg-red-500/10 transition",children:(0,s.jsx)(y.uc,{className:"w-3.5 h-3.5"})})]})]}),(0,s.jsxs)("p",{className:"studio-micro mt-2",children:["Created ",e.createdAt.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]})]})},e.id)})}):eV?(0,s.jsxs)("div",{className:"bg-card border border-card rounded-xl p-8 text-center space-y-3",children:[(0,s.jsx)("div",{className:"w-8 h-8 border-2 border-white/10 border-t-white rounded-full animate-spin mx-auto"}),(0,s.jsx)("p",{className:"studio-body-strong",children:"Setting up your audience"}),(0,s.jsx)("p",{className:"studio-caption",children:"Importing participants from your events..."})]}):(0,s.jsxs)("div",{className:"bg-card border border-card rounded-xl p-8 text-center",children:[(0,s.jsx)("p",{className:"studio-body",children:"No lists yet"}),(0,s.jsx)("p",{className:"text-xs text-t3 mt-1",children:"Create a list to start organizing contacts"})]})]}),(0,s.jsx)("div",{className:"flex-1 min-w-0",children:e8?(0,s.jsxs)("div",{className:"space-y-4",children:[!1,!1,(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"studio-subtitle",children:e8.name}),(0,s.jsxs)("p",{className:"studio-caption mt-0.5",children:[ts.toLocaleString()," contact",1!==ts?"s":"","subscriber_shards"===e8.countMode&&" \xb7 approximate"]}),"subscriber_shards"===e8.countMode&&(0,s.jsxs)("p",{className:"studio-caption mt-1",children:[e8.countUpdatedAtMs?"Count refreshed ".concat(new Date(e8.countUpdatedAtMs).toLocaleString(),"."):"Count is being prepared."," Campaign review checks the current eligible audience."]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:()=>ex(e=>!e),icon:(0,s.jsx)(y.c1,{className:"w-4 h-4"}),children:"Add Contacts"}),ep&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>ex(!1)}),(0,s.jsxs)("div",{className:"absolute right-0 mt-1 z-50 w-48 bg-modal-glass backdrop-blur-xl border border-card rounded-lg shadow-xl overflow-hidden",children:[(0,s.jsx)("button",{onClick:tR,className:"w-full text-left px-4 py-2.5 text-sm text-t1 hover:bg-white/[0.06] transition",children:"From Event"}),(0,s.jsx)("button",{onClick:()=>{eo(!0),ex(!1)},className:"w-full text-left px-4 py-2.5 text-sm text-t1 hover:bg-white/[0.06] transition",children:"Manual Entry"}),(0,s.jsx)("button",{onClick:()=>{eu(!0),ex(!1)},className:"w-full text-left px-4 py-2.5 text-sm text-t1 hover:bg-white/[0.06] transition",children:"Import CSV"})]})]})]}),(0,s.jsx)(C.$n,{variant:"secondary",size:"md",onClick:()=>
1t_(),disabled:0===e9.length,children:"Export"})]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[eO&&(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"studio-caption",children:"Filtered by:"}),(0,s.jsxs)("button",{onClick:()=>eq(null),className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] font-medium bg-white/[0.08] text-t1 hover:bg-white/[0.12] transition",children:[eO.charAt(0).toUpperCase()+eO.slice(1),(0,s.jsx)(y.fK,{className:"w-3 h-3"})]})]}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(y.WI,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-t2"}),(0,s.jsx)("input",{type:"text",placeholder:"Search contacts...",value:eR,onChange:e=>eU(e.target.value),className:"w-full pl-10 pr-4 py-2.5 bg-card border border-card rounded-lg text-sm text-t1 placeholder-t3 focus:outline-none focus:border-white/20"})]})]}),(0,s.jsx)(z,{selectedCount:eY.size,onDelete:tP,onExport:tT,onClearSelection:()=>eJ(new Set)}),(0,s.jsxs)("div",{className:"bg-card border border-card rounded-xl overflow-hidden",children:[te?(0,s.jsx)("div",{className:"flex items-center justify-center h-32",children:(0,s.jsx)("div",{className:"w-6 h-6 border-2 border-white/10 border-t-white rounded-full animate-spin"})}):(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"w-full min-w-[640px]",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,s.jsx)("th",{className:"px-3 py-3 text-left w-10",children:(0,s.jsx)("input",{type:"checkbox",checked:ta.length>0&&ta.every(e=>eY.has(e.id)),onChange:tz,className:"w-3.5 h-3.5 rounded border-white/20 bg-surface-raised accent-white"})}),(0,s.jsx)("th",{className:"px-4 py-3 text-left studio-label",children:"Name"}),(0,s.jsx)("th",{className:"px-4 py-3 text-left studio-label",children:"Email"}),(0,s.jsx)("th",{className:"px-4 py-3 text-left studio-label",children:"Phone"}),(0,s.jsx)("th",{className:"px-4 py-3 text-left studio-label",children:"Status"}),(0,s.jsx)("th",{className:"px-4 py-3 text-right studio-label w-16"})]})}),(0,s.jsx)("tbody",{children:0===ta.length?(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:6,className:"px-4 py-12 text-center studio-body",children:eR?"No contacts match your search":"No contacts in this list yet"})}):ta.map(e=>(0,s.jsxs)("tr",{className:"border-b border-white/[0.03] hover:bg-white/[0.02] transition group",children:[(0,s.jsx)("td",{className:"px-3 py-3",children:(0,s.jsx)("input",{type:"checkbox",checked:eY.has(e.id),onChange:()=>tD(e.id),className:"w-3.5 h-3.5 rounded border-white/20 bg-surface-raised accent-white"})}),(0,s.jsx)("td",{className:"px-4 py-3 studio-body-strong",children:(0,s.jsx)("button",{disabled:!F,className:"text-left enabled:hover:underline",onClick:()=>Q&&e$({listId:Q,contactId:e.id}),children:e.name||(0,s.jsx)("span",{className:"text-t2 italic",children:"No name"})})}),(0,s.jsx)("td",{className:"px-4 py-3 studio-body",children:e.email||(0,s.jsx)("span",{className:"text-t2",children:"—"})}),(0,s.jsx)("td",{className:"px-4 py-3 studio-body",children:e.phone||(0,s.jsx)("span",{className:"text-t2",children:"—"})}),(0,s.jsx)("td",{className:"px-4 py-3",children:(0,s.jsx)(_,{isAppUser:e.isAppUser,hasFcmToken:e.hasFcmToken,engagementTier:e.engagementTier,source:e.source,eventName:e.eventName})}),(0,s.jsx)("td",{className:"px-4 py-3 text-right",children:(0,s.jsx)("button",{onClick:()=>tM(e.id),className:"p-1 rounded text-t3 sm:text-white/0 sm:group-hover:text-t2 hover:!text-negative-ink hover:bg-red-500/10 transition",children:(0,s.jsx)(y.uc,{className:"w-4 h-4"})})})]},e.id))})]})}),(ta.length>0||e7.hasPrev)&&(0,s.jsxs)("div",{className:"px-4 py-3 border-t border-white/[0.06] flex flex-col sm:flex-row sm:items-center justify-between gap-2",children:[(0,s.jsx)("span",{className:"studio-caption",children:ts>0?"Showing ".concat((100*e7.page+1).toLocaleString(),"–").concat(Math.min((e7.page+1)*100,ts).toLocaleString()," of ").concat(ts.toLocaleString()," contacts"):"".concat(ta.length," contacts")}
1),e7.totalPages>1&&(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[e7.page>1&&(0,s.jsx)("button",{onClick:e7.firstPage,disabled:e7.loading,className:"px-2 py-1 text-xs text-t2 hover:text-t1 disabled:text-t4 transition",children:"← First"}),(0,s.jsx)("button",{onClick:e7.prevPage,disabled:!e7.hasPrev||e7.loading,className:"px-2 py-1 text-xs text-t2 hover:text-t1 disabled:text-t4 transition",children:"Prev"}),(0,s.jsxs)("span",{className:"studio-caption px-2",children:[(e7.page+1).toLocaleString()," / ",e7.totalPages.toLocaleString()]}),(0,s.jsx)("button",{onClick:e7.nextPage,disabled:!e7.hasNext||e7.loading,className:"px-2 py-1 text-xs text-t2 hover:text-t1 disabled:text-t4 transition",children:"Next →"})]})]})]})]}):(0,s.jsx)("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:(0,s.jsx)("p",{className:"studio-body",children:eV?"Setting up your audience...":0===e4.length?"Your audience will appear here shortly":"Select a list to view contacts"})})})]}),ec&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:(0,s.jsxs)("div",{className:"bg-card border border-card rounded-xl w-full max-w-md p-6 space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"studio-subtitle",children:"Add Contact"}),(0,s.jsx)("button",{onClick:()=>eo(!1),className:"p-1 rounded-lg hover:bg-white/[0.06] text-t2 hover:text-t1 transition",children:(0,s.jsx)(y.fK,{className:"w-5 h-5"})})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)("input",{type:"text",placeholder:"Name",value:eg,onChange:e=>ef(e.target.value),className:"w-full px-3 py-2.5 bg-card border border-card rounded-lg text-sm text-t1 placeholder-t3 focus:outline-none focus:border-white/20"}),(0,s.jsx)("input",{type:"email",placeholder:"Email",value:eb,onChange:e=>ev(e.target.value),className:"w-full px-3 py-2.5 bg-card border border-card rounded-lg text-sm text-t1 placeholder-t3 focus:outline-none focus:border-white/20"}),(0,s.jsx)("input",{type:"tel",placeholder:"Phone",value:ej,onChange:e=>ey(e.target.value),className:"w-full px-3 py-2.5 bg-card border border-card rounded-lg text-sm text-t1 placeholder-t3 focus:outline-none focus:border-white/20"})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)(C.$n,{variant:"secondary",size:"md",onClick:()=>eo(!1),children:"Cancel"}),(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:ti,disabled:eN,children:eN?"Adding...":"Add Contact"})]})]})}),ed&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:(0,s.jsxs)("div",{className:"bg-card border border-card rounded-xl w-full max-w-lg p-6 space-y-4 max-h-[calc(100dvh-2rem)] overflow-y-auto",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"studio-subtitle",children:"Import CSV"}),(0,s.jsx)("button",{onClick:()=>{eu(!1),tF()},className:"p-1 rounded-lg hover:bg-white/[0.06] text-t2 hover:text-t1 transition",children:(0,s.jsx)(y.fK,{className:"w-5 h-5"})})]}),tg?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"bg-amber-500/[0.08] border border-amber-500/20 rounded-lg p-4 space-y-2",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)("div",{className:"w-6 h-6 rounded-full bg-amber-500/20 flex items-center justify-center flex-shrink-0 mt-0.5",children:(0,s.jsx)("span",{className:"text-attention-ink text-sm",children:"!"})}),(0,s.jsxs)("div",{className:"flex-1 space-y-1",children:[(0,s.jsx)("p",{className:"studio-body-strong",children:"This file isn’t ready to import"}),(0,s.jsx)("p",{className:"studio-caption leading-relaxed",children:tg.userMessage}),tg.detail&&(0,s.jsx)("p",{className:"studio-caption leading-relaxed pt-1",children:tg.detail})]})]})}),td&&(0,s.jsxs)("p",{className:"studio-caption truncate",children:["File: ",td]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)(C.$n,{variant:"secondary",size:"md",onClick:()=>{eu(!1),tF()},children:"Cancel"}),(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:()=>{tf(null),th(null),tx(null),to([]),tu(""),eC("")},children:"Try a different file"})]})]}):tp?(0,s.jsxs)(s.Fragment,{children:[tm&&(0,s.jsxs)("div",{className:"bg-emerald-500/[0.06] border border-emerald-500/15 rounded-lg p-3 space-y-1",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("p",{className:"studio-label",children:"Detected"}),(0,s.jsxs)("span",{className:"text-[10px] text-positive-ink/70",children:[Math.round(100*tm.confidence),"% confident"]})]}),(0,s.jsx)("p",{className:"studio-body",children:tp.summary})]}),tm&&(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("p",{className:"studio-label",children:"Sample Quality"}),(0,s.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[["Emails",tm.quality.validEmailPct],["Names",tm.quality.namePresencePct],["Phones",tm.quality.validPhonePct]].map(e=>
1{let[t,a]=e;return(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsxs)("div",{className:"flex justify-between text-[10px]",children:[(0,s.jsx)("span",{className:"text-t2",children:t}),(0,s.jsxs)("span",{className:"text-t3",children:[a,"%"]})]}),(0,s.jsx)("div",{className:"h-1 rounded-full bg-white/[0.06] overflow-hidden",children:(0,s.jsx)("div",{className:"h-full rounded-full transition-all duration-500 ".concat(a>=80?"bg-emerald-400":a>=40?"bg-amber-400":"bg-red-400/60"),style:{width:"".concat(a,"%")}})})]},t)})})]}),tm&&tm.concerns.length>0&&(0,s.jsxs)("div",{className:"bg-amber-500/[0.06] border border-amber-500/15 rounded-lg p-2.5",children:[(0,s.jsx)("p",{className:"text-[10px] text-attention-ink/80 uppercase tracking-wider font-medium mb-1",children:"Things to know"}),(0,s.jsx)("ul",{className:"space-y-0.5",children:tm.concerns.map((e,t)=>(0,s.jsxs)("li",{className:"studio-caption leading-relaxed",children:["\xb7 ",e]},t))})]}),(0,s.jsx)(L,{headers:null!=(A=tc[0])?A:[],dataRows:tj,mapping:tp,maxRows:8}),(0,s.jsxs)("details",{open:!tm||tm.confidence<.8,children:[(0,s.jsx)("summary",{className:"studio-label cursor-pointer hover:text-t2 transition select-none",children:tm&&tm.confidence>=.8?"Edit column mapping ▸":"Column Mapping"}),(0,s.jsx)("div",{className:"space-y-1 max-h-[240px] overflow-y-auto pr-1 mt-1.5",children:(null!=(I=tc[0])?I:[]).map((e,t)=>{let a=String(t),l=tp.coreFields[a],n=tp.metadataFields[a];return(0,s.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 bg-white/[0.03] rounded-lg",children:[(0,s.jsx)("span",{className:"studio-caption truncate flex-1 min-w-0",title:e||"(column ".concat(a,")"),children:e||"Column ".concat(a)}),(0,s.jsxs)("select",{value:null!=l?l:n?"metadata":"ignore",onChange:e=>tE(a,e.target.value),disabled:tk,className:"text-[11px] bg-white/[0.05] border border-white/[0.08] rounded px-1.5 py-0.5 text-t1 focus:outline-none focus:border-white/20 disabled:opacity-40",children:[(0,s.jsx)("option",{value:"name",children:"Name"}),(0,s.jsx)("option",{value:"firstName",children:"First name"}),(0,s.jsx)("option",{value:"lastName",children:"Last name"}),(0,s.jsx)("option",{value:"email",children:"Email"}),(0,s.jsx)("option",{value:"phone",children:"Phone"}),(0,s.jsx)("option",{value:"metadata",children:"Metadata"}),(0,s.jsx)("option",{value:"ignore",children:"Ignore"})]})]},a)})})]}),(0,s.jsxs)("p",{className:"studio-caption",children:[tj.length.toLocaleString()," rows ready to import"]}),tI.progress&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"text-t2",children:tI.progress.phase}),(0,s.jsxs)("span",{className:"text-t3",children:[tI.progress.added>0&&"".concat(tI.progress.added.toLocaleString()," added"),tI.progress.skipped>0&&", ".concat(tI.progress.skipped.toLocaleString()," skipped")]})]}),(0,s.jsx)("div",{className:"h-1.5 rounded-full bg-white/[0.06] overflow-hidden",children:(0,s.jsx)("div",{className:"h-full rounded-full bg-white transition-all duration-500",style:{width:"".concat(tI.progress.progress,"%")}})})]}),(0,s.jsxs)("div",{className:"flex justify-between items-center pt-2",children:[(0,s.jsx)("button",{onClick:()=>{tx(null),th(null),ty([]),tf(null)},disabled:tk,className:"px-3 py-1.5 text-xs text-t2 hover:text-t1 transition disabled:opacity-20",children:"← Re-analyze"}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(C.$n,{variant:"secondary",size:"md",onClick:()=>{eu(!1),tF()},disabled:tk,children:"Cancel"}),(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:tL,disabled:tk,className:"flex items-center gap-2",children:tk?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-3.5 h-3.5 border-2 border-black/20 border-t-black rounded-full animate-spin"})," Importing..."]}):"".concat(tI.reviewEnabled?"Check":"Import"," ").concat(tj.length.toLocaleString()," contacts")})]})]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{onDragOver:e=>{e.preventDefault(),e.currentTarget.classList.add("border-white/30")},onDragLeave:e=>{e.preventDefault(),e.currentTarget.classList.remove("border-white/30")},onDrop:e=>{e.preventDefault(),e.currentTarget.classList.remove("border-white/30");let t=e.dataTransfer.files[0];if(t){if(t.size>5e7)return void H({type:"error",message:"File is too large. Maximum 50MB."});tu(t.name),tS(t).then(e=>{to(e),eC("".concat(e.length," rows loaded"))}).catch(e=>H({type:"error",message:e.message}))}},className:"relative border-2 border-dashed border-white/[0.08] rounded-xl p-8 text-center transition-colors hover:border-white/15 cursor-pointer",onClick:()=>{var e;
1return null==(e=document.getElementById("csv-file-input"))?void 0:e.click()},children:[(0,s.jsx)("input",{id:"csv-file-input",type:"file",accept:".csv,.tsv,.txt,.xls,.xlsx,.xlsm,.xlsb,.numbers",className:"hidden",onChange:e=>{var t;let a=null==(t=e.target.files)?void 0:t[0];if(a){if(a.size>5e7)return void H({type:"error",message:"File is too large. Maximum 50MB."});tu(a.name),tS(a).then(e=>{to(e),eC("".concat(e.length," rows loaded"))}).catch(e=>H({type:"error",message:e.message}))}}}),tc.length>0?(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"studio-body-strong",children:td||"File loaded"}),(0,s.jsxs)("p",{className:"studio-caption mt-1",children:[(tc.length-1).toLocaleString()," contacts detected"]}),(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),eC(""),to([]),tu("")},className:"mt-2 text-xs text-negative-ink/60 hover:text-negative-ink transition",children:"Clear"})]}):(0,s.jsxs)("div",{children:[(0,s.jsx)("svg",{className:"w-8 h-8 text-t4 mx-auto mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5"})}),(0,s.jsx)("p",{className:"studio-body",children:"Drop a file here or click to browse"}),(0,s.jsx)("p",{className:"text-[11px] text-t4 mt-1",children:"CSV, Excel, Google Sheets exports — from Luma, Eventbrite, or any platform"})]})]}),!ek&&(0,s.jsxs)("details",{className:"group",children:[(0,s.jsx)("summary",{className:"text-[11px] text-t4 cursor-pointer hover:text-t2 transition",children:"Or paste CSV text manually"}),(0,s.jsx)("textarea",{value:ek,onChange:e=>eC(e.target.value),placeholder:"Paste CSV data here...",rows:5,className:"mt-2 w-full px-3 py-2.5 bg-card border border-card rounded-lg text-sm text-t1 placeholder-t3 focus:outline-none focus:border-white/20 font-mono resize-none"})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)(C.$n,{variant:"secondary",size:"md",onClick:()=>eu(!1),children:"Cancel"}),(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:tA,disabled:tN||0===tc.length,className:"flex items-center gap-2",children:tN?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-3.5 h-3.5 border-2 border-black/20 border-t-black rounded-full animate-spin"})," Analyzing..."]}):(0,s.jsx)(s.Fragment,{children:"✨ Analyze"})})]})]})]})}),em&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:(0,s.jsxs)("div",{className:"bg-card border border-card rounded-xl w-full max-w-lg p-6 space-y-4 max-h-[calc(100dvh-2rem)] flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between shrink-0",children:[(0,s.jsx)("h3",{className:"studio-subtitle",children:"Add From Event"}),(0,s.jsx)("button",{onClick:()=>eh(!1),className:"p-1 rounded-lg hover:bg-white/[0.06] text-t2 hover:text-t1 transition",children:(0,s.jsx)(y.fK,{className:"w-5 h-5"})})]}),(0,s.jsx)("div",{className:"shrink-0",children:(0,s.jsx)(k.A,{events:eI,selectedEventId:null!=eE?eE:"",onSelect:e=>{e&&tU(e)},loading:eS,placeholder:"Select an event..."})}),eE&&(0,s.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0 space-y-1",children:eD?(0,s.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,s.jsx)("div",{className:"studio-spinner-sm",style:{width:20,height:20}})}):0===eM.length?(0,s.jsx)("p",{className:"studio-body text-center py-8",children:"No participants found"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-1 py-1",children:[(0,s.jsxs)("p",{className:"studio-caption",children:[eM.filter(e=>e.checked).length," of"," ",eM.length," selected"]}),(0,s.jsx)("button",{onClick:()=>e_(e=>{let t=e.every(e=>e.checked);return e.map(e=>({...e,checked:!t}))}),className:"text-xs text-t2 hover:text-t1 transition",children:eM.every(e=>e.checked)?"Deselect All":"Select All"})]}),eM.map((e,t)=>(0,s.jsxs)("label",{className:"flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-white/[0.03] cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:e.checked,onChange:()=>e_(e=>e.map((e,a)=>a===t?{...e,checked:!e.checked}:e)),className:"w-4 h-4 rounded border-white/20 bg-surface-raised text-t1 accent-white"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("p",{className:"studio-body-strong truncate",children:e.name||(0,s.jsx)("span",{className:"text-t2 italic",children:"No name"})}),(0,s.jsx)("p",{className:"studio-caption truncate",children:[e.email,e.phone].filter(
1Boolean).join(" \xb7 ")||"No contact info"})]})]},e.uid))]})}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2 shrink-0",children:[(0,s.jsx)(C.$n,{variant:"secondary",size:"md",onClick:()=>eh(!1),children:"Cancel"}),(0,s.jsx)(C.$n,{variant:"primary",size:"md",onClick:tB,disabled:eP||!eE||0===eM.filter(e=>e.checked).length,children:eP?"Adding...":"Add ".concat(eM.filter(e=>e.checked).length," Contact").concat(1!==eM.filter(e=>e.checked).length?"s":"")})]})]})}),eQ&&Q&&e8&&eK&&(0,s.jsx)(S,{listId:Q,listName:e8.name,duplicateCount:eK.duplicateCount,totalContacts:Math.max(0,e8.contactCount),onClose:()=>eG(!1),onMerged:()=>eZ(e=>e+1)}),eB&&(0,s.jsx)(c.default,{...eB,onClose:()=>e$(null)})]})}},83686:()=>{}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.