import{o as e}from"./rolldown-runtime-iuO8RvI4.js";import{Bi as s,bi as t}from"./shared-0-C4kdVF7Y.js";import{Mi as r}from"./vendor-frame-CwiylG4Y.js";import{Mh as a}from"./shared-1-3-6x7RKF.js";import{rn as i}from"./vendor-all-2-BJdkbLSj.js";var n=e(r()),o=["email","email address","email_address","e-mail"],l=["role"],u=["seat_tier","seat tier","seat","tier"];function c(e){const s=[];let t="",r=!1;for(let a=0;a<e.length;a++){const i=e[a];'"'===i?r&&'"'===e[a+1]?(t+='"',a++):r=!r:","!==i||r?t+=i:(s.push(t),t="")}return s.push(t),s.map(e=>e.trim())}function d(e,s){return e.findIndex(e=>s.includes(e))}function f({source:e,onParsed:r}){const f=i(),{addError:m}=a(),{track:p}=t(),h=(0,n.useRef)(null),v=(0,n.useRef)(!0),_=(0,n.useRef)(r);(0,n.useEffect)(()=>{_.current=r},[r]),(0,n.useEffect)(()=>(v.current=!0,()=>{v.current=!1}),[]);const g=(0,n.useCallback)(async t=>{if(!/\.csv$/i.test(t.name)&&"text/csv"!==t.type)return void m(f.formatMessage({defaultMessage:"Please choose a .csv file.",id:"fiUP5zDImT"}));const r=await t.text();if(!v.current)return;const{rows:a,skipped:i}=function(e){const t=e.replace(/^\ufeff/,"").split(/\r\n|\r|\n/).filter(e=>e.trim().length>0);if(0===t.length)return{emails:[],rows:[],skipped:[]};const r=c(t[0]).map(e=>e.toLowerCase()),a=d(r,o),i=-1!==a,n=i?a:0,f=i?d(r,l):-1,m=i?d(r,u):-1,p=i?t.slice(1):t,h=[],v=[],_=new Set;return p.forEach((e,t)=>{const r=t+(i?2:1),a=c(e),o=a[n]??"";if(0===o.length)return void v.push({row:r,value:o,reason:"empty"});const l=o.toLowerCase();if(!s(o))return void v.push({row:r,value:o,reason:"invalid_email"});if(_.has(l))return void v.push({row:r,value:o,reason:"duplicate_in_file"});_.add(l);const u=-1!==f&&a[f]||void 0,d=-1!==m&&a[m]||void 0;h.push({email:o,role:u,seatTier:d})}),{emails:h.map(e=>e.email),rows:h,skipped:v}}(r);if(0===a.length)return m(f.formatMessage({defaultMessage:"No valid email addresses were found in that CSV file.",id:"M/hk1LFpsi"})),void p({event_key:"claudeai.csv_invite.file_uploaded",source:e,email_count:0,skipped_count:i.length});const n=a.length>500,h=n?a.slice(0,500):a;n&&m(f.formatMessage({defaultMessage:"Only the first {max} rows were imported.",id:"AB2EVdRKmB"},{max:500})),p({event_key:"claudeai.csv_invite.file_uploaded",source:e,email_count:h.length,skipped_count:i.length,capped:n,has_role_column:h.some(e=>void 0!==e.role),has_seat_tier_column:h.some(e=>void 0!==e.seatTier)}),_.current({rows:h,emails:h.map(e=>e.email),fileName:t.name})},[m,f,e,p]),k=(0,n.useCallback)(e=>{const s=e.dataTransfer?.files?.[0];s&&g(s)},[g]),w=(0,n.useCallback)(e=>{const s=e.target.files?.[0];s&&g(s),e.target.value=""},[g]);return{fileInputRef:h,openFilePicker:(0,n.useCallback)(()=>{h.current?.click()},[]),handleDrop:k,handleInputChange:w}}export{f as t};