1import{g as Se,u as Ce,o as ke,r as a,k as i,j as e,L as c,bW as re,c7 as Ee,c8 as Te,aT as oe,aR as R,a1 as Ae,bj as L,aW as le,A as Pe,S as $e,N as De}from"./index-DNBzpCbc.js";import{o as Re,g as Le}from"./outlook-icon-B0a8UILX.js";const Ge={gmail:{provider:"google",nameKey:"integrations.gmail.name",icon:Le},outlook:{provider:"microsoft",nameKey:"integrations.outlook.name",icon:Re}};function Oe({appId:G}){const{user:Ie}=Se(),{t:s}=Ce();ke();const r=Ge[G],[f,w]=a.useState("compose"),[d,S]=a.useState({connected:!1}),[ie,ce]=a.useState(!0),[C,I]=a.useState(!1),[k,U]=a.useState(!1),[E,K]=a.useState(""),[O,h]=a.useState([]),[de,z]=a.useState(!1),[o,q]=a.useState(null),[g,T]=a.useState(""),[u,A]=a.useState(""),[x,P]=a.useState(""),[b,me]=a.useState(""),[y,F]=a.useState(!1),[j,Q]=a.useState(!1),[ue,$]=a.useState(!1),[m,W]=a.useState(["Definite","Closed"]),[p,X]=a.useState(!1),[xe,_]=a.useState(""),[B,D]=a.useState([]),[pe,M]=a.useState(!1),[H,J]=a.useState(null),[fe,V]=a.useState(null),[N,Y]=a.useState(!1),[Z,ee]=a.useState(null),[te,he]=a.useState(!1),ge=["Prospective","Tentative","Definite","Closed"];a.useEffect(()=>{r&&(async()=>{try{const l=(await(await i("GET","/api/integrations/sync-preferences")).json())[r.provider];l&&(W(l.statuses||["Definite","Closed"]),X(!!l.autoSync))}catch{}finally{he(!0)}})()},[]);const se=a.useCallback(async(t,n)=>{if(!(!te||!r))try{await i("PUT","/api/integrations/sync-preferences",{provider:r.provider,statuses:t,autoSync:n})}catch{}},[te,r]),be=async()=>{if(!(N||m.length===0)){Y(!0),ee(null);try{const n=await(await i("POST","/api/integrations/sync-all",{provider:r.provider,statuses:m})).json();ee({synced:n.synced||0,errors:n.errors||0})}catch{}finally{Y(!1)}}};a.useEffect(()=>{(async()=>{try{const n=await(await i("GET","/api/integrations/connection-status")).json();S(n.connections?.[r?.provider]||{connected:!1})}catch{}finally{ce(!1)}})()},[]),a.useEffect(()=>{const t=window.location.search||"",n=window.location.hash.includes("?")&&window.location.hash.split("?")[1]||"";new URLSearchParams(t||n).get("connected")==="true"&&(window.history.replaceState(null,"",`/#/apps/${G}`),(async()=>{try{const we=await(await i("GET","/api/integrations/connection-status")).json();S(we.connections?.[r?.provider]||{connected:!1})}catch{}})())},[]);const ye=async()=>{if(!C){I(!0);try{const n=await(await i("GET",`/api/integrations/${r.provider}/auth-url`)).json();n.url&&(window.location.href=n.url)}catch{I(!1)}}},je=async()=>{if(!k){U(!0);try{await i("DELETE",`/api/integrations/disconnect?provider=${r.provider}`),S({connected:!1})}catch{}finally{U(!1)}}},ae=a.useCallback(async t=>{if(t.length<2){h([]);return}z(!0);try{const l=await(await i("GET",`/api/events/search?q=${encodeURIComponent(t)}`)).json();h(Array.isArray(l)?l.filter(v=>v.resultType==="event").slice(0,8):[])}catch{h([])}finally{z(!1)}},[]);a.useEffect(()=>{const t=setTimeout(()=>ae(E),300);return()=>clearTimeout(t)},[E,ae]);const Ne=t=>{q(t),T(t.contactEmail||""),K(""),h([])},ne=async()=>{if(!(!o||!b.trim()||y)){F(!0),$(!1);try{const n=await(await i("POST","/api/integrations/compose-email",{eventData:{partyName:o.partyName,date:o.date,venue:o.venue||"",guests:o.guests||"",client:o.client||"",contactEmail:o.contactEmail||"",eventNumber:o.eventNumber||""},prompt:b.trim()})).json();A(n.subject||""),P(n.body||"")}catch{}finally{F(!1)}}},ve=async()=>{if(!(!g||!u||!x||j)){Q(!0);try{await i("POST","/api/integrations/send-email",{provider:r.provider,to:g,subject:u,body:x}),$(!0)}catch{}finally{Q(!1)}}};return r?ie?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(c,{className:"w-6 h-6 animate-spin text-primary"})}):e.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-6 py-8",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-muted/50 flex items-center justify-center p-2",children:e.jsx("img",{src:r.icon,alt:s(r.nameKey),className:"w-full h-full object-contain"})}),e.jsx("h1",{className:"text-xl font-semibold text-foreground",children:s(r.nameKey)})]})}),e.jsxs("div",{className:"flex items-center gap-1 bg-muted/30 rounded-full p-1 mb-6 w-fit",children:[e.jsx("button",{onClick:()=>w("compose"),className:`px-4 py-2 rounded-full text-sm font-medium transition-colors ${f==="compose"?"bg-primary text-white shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(re,{className:"w-3.5 h-3.5"}),s("email.composer")]})}),e.jsx("button",{onClick:()=>w("settings"),className:`px-4 py-2 rounded-full text-sm font-medium transition-colors ${f==="settings"?"bg-primary text-white shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ee,{className:"w-3.5 h-3.5"}),s("app.settings")]})})]}),f==="settings"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6",children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground mb-4",children:s("app.yourAccount")}
1),d.connected?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-emerald-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s("integrations.connected")}),d.email&&e.jsx("p",{className:"text-xs text-muted-foreground",children:d.email})]})]}),e.jsxs("button",{onClick:je,disabled:k,className:"inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-medium bg-destructive/10 text-destructive hover:bg-destructive/20 transition-all disabled:opacity-50",children:[k?e.jsx(c,{className:"w-4 h-4 animate-spin"}):e.jsx(Te,{className:"w-4 h-4"}),s("integrations.disconnect")]})]}):e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-amber-400"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("integrations.notConnected")})]}),e.jsxs("button",{onClick:ye,disabled:C,className:"inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 transition-all shadow-sm disabled:opacity-50",children:[C?e.jsx(c,{className:"w-4 h-4 animate-spin"}):e.jsx(oe,{className:"w-4 h-4"}),s("integrations.connect")]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(R,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:s("app.calendarSync")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("app.calendarSyncDesc")})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:s("app.syncStatuses")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ge.map(t=>{const n=m.includes(t);return e.jsxs("button",{onClick:()=>{const l=n?m.filter(v=>v!==t):[...m,t];W(l),se(l,p)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-all ${n?"border-primary bg-primary/10 text-primary":"border-border bg-card text-muted-foreground hover:border-primary/60"}`,children:[n&&e.jsx(Ae,{className:"w-3 h-3"}),t]},t)})})]}),d.connected&&e.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-border/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s("app.autoSync")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("app.autoSyncDesc")})]}),e.jsx("button",{onClick:()=>{const t=!p;X(t),se(m,t)},className:`relative w-11 h-6 rounded-full transition-colors ${p?"bg-primary":"bg-muted"}`,children:e.jsx("div",{className:`absolute top-0.5 w-5 h-5 rounded-full bg-white shadow transition-transform ${p?"translate-x-5.5 left-0":"left-0.5"}`,style:{transform:p?"translateX(22px)":"translateX(0)"}})})]}),d.connected&&e.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-border/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s("app.syncNow")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("app.syncNowDesc")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Z&&e.jsxs("span",{className:"text-xs font-medium text-emerald-600 dark:text-emerald-400 flex items-center gap-1",children:[e.jsx(L,{className:"w-3.5 h-3.5"}),s("app.syncComplete").replace("{synced}",String(Z.synced))]}),e.jsxs("button",{onClick:be,disabled:N||m.length===0,className:"inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-all shadow-sm",children:[N?e.jsx(c,{className:"w-4 h-4 animate-spin"}):e.jsx(R,{className:"w-4 h-4"}),s(N?"app.syncingAll":"app.syncNow")]})]})]}),d.connected&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:s("app.syncEvent")}),e.jsxs("div",{className:"relative",children:[e.jsx(le,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground pointer-events-none"}),e.jsx("input",{type:"text",value:xe,onChange:t=>{_(t.target.value),V(null),t.target.value.length>=2?(M(!0),i("GET",`/api/events/search?q=${encodeURIComponent(t.target.value)}`).then(n=>n.json()).then(n=>D(Array.isArray(n)?n.filter(l=>l.resultType==="event").slice(0,6):[])).finally(()=>M(!1))):D([])},placeholder:s("app.syncSearch"),className:"w-full pl-9 pr-4 py-2.5 rounded-xl bg-background border border-border text-sm focus:outline-none focus:ring-2 focus:ring-primary/30"}),pe&&e.jsx(c,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 animate-spin text-muted-foreground"}),B.length>0&&e.jsx("div",{className:"absolute z-10 left-0 right-0 mt-1 rounded-xl border border-border bg-card shadow-lg max-h-48 overflow-auto",children:B.map(t=>e.jsxs("button",{disabled:H===t.evtNum,onClick:async()=>{J(t.evtNum);try{await i("POST","/api/integrations/sync-calendar",{provider:r.provider,evtNum:t.evtNum}),V(t.evtNum),D([]),_(t.partyName)}catch{}finally{J(null)}},className:"w-full text-left px-4 py-3 hover:bg-muted/50 transition-colors border-b border-border/50 last:border-0 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:t.partyName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.eventNumber," · ",t.date," ",t.client&&`· ${t.client}`]})]}),H===t.evtNum?e.jsx(c,{className:"w-4 h-4 animate-spin text-primary shrink-0"}):e.jsx(R,{className:"w-4 h-4 text-muted-foreground shrink-0"})]},t.evtNum))})]}),fe&&e.jsxs("div",{className:"flex items-center gap-2 mt-2 text-xs font-medium text-emerald-600 dark:text-emerald-400",children:[e.jsx(L,{className:"w-3.5 h-3.5"}),s("app.synced")]})]})]})]}),f==="compose"&&e.jsx(e.Fragment,{children:d.connected?e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsx("label",{className:"text-sm font-medium text-foreground mb-2 block",children:s("email.selectEvent")}),o?e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-primary/5 border border-primary/60",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pe,{className:"w-4 h-4 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:o.partyName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[o.eventNumber," · ",o.date,o.client&&` · ${o.client}`]})]})]}),e.jsx("button",{onClick:()=>{q(null),T(""),A(""),P(""),$(!1)},className:"text-xs text-muted-foreground hover:text-foreground",children:"Change"})]}):e.jsxs("div",{className:"relative",children:[e.jsx(le,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground pointer-events-none"}),e.jsx("input",{type:"text",value:E,onChange:t=>K(t.target.value),placeholder:s("email.searchEvents"),className:"w-full pl-9 pr-4 py-2.5 rounded-xl bg-background border border-border text-sm focus:outline-none focus:ring-2 focus:ring-primary/30"}),de&&e.jsx(c,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 animate-spin text-muted-foreground"}),O.length>0&&e.jsx("div",{className:"absolute z-10 left-0 right-0 mt-1 rounded-xl border border-border bg-card shadow-lg max-h-60 overflow-auto",children:O.map(t=>e.jsxs("button",{onClick:()=>Ne(t),className:"w-full text-left px-4 py-3 hover:bg-muted/50 transition-colors border-b border-border/50 last:border-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:t.partyName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.eventNumber," · ",t.date," ",t.client&&`· ${t.client}`]})]},t.evtNum))})]})]}),o&&e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsx("label",{className:"text-sm font-medium text-foreground mb-2 block",children:s("email.prompt")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:b,onChange:t=>me(t.target.value),onKeyDown:t=>t.key==="Enter"&&ne(),placeholder:s("email.promptPlaceholder"),className:"flex-1 px-4 py-2.5 rounded-xl bg-background border border-border text-sm focus:outline-none focus:ring-2 focus:ring-primary/30"}),e.jsxs("button",{onClick:ne,disabled:y||!b.trim(),className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-all shadow-sm",children:[y?e.jsx(c,{className:"w-4 h-4 animate-spin"}):e.jsx($e,{className:"w-4 h-4"}),s(y?"email.composing":"email.compose")]})]})]}),(u||x)&&e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:s("email.to")}),e.jsx("input",{type:"email",value:g,onChange:t=>T(t.target.value),className:"w-full px-4 py-2.5 rounded-xl bg-background border border-border text-sm focus:outline-none focus:ring-2 focus:ring-primary/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:s("email.subject")}),e.jsx("input",{type:"text",value:u,onChange:t=>A(t.target.value),className:"w-full px-4 py-2.5 rounded-xl bg-background border border-border text-sm focus:outline-none focus:ring-2 focus:ring-primary/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:s("email.body")}),e.jsx("textarea",{value:x,onChange:t=>P(t.target.value),rows:10,className:"w-full px-4 py-3 rounded-xl bg-background border border-border text-sm focus:outline-none focus:ring-2 focus:ring-primary/30 resize-y"})]}),e.jsx("div",{className:"flex items-center justify-end pt-2",children:ue?e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-medium text-emerald-600 dark:text-emerald-400",children:[e.jsx(L,{className:"w-4 h-4"}),s("email.sent")]}):e.jsxs("button",{onClick:ve,disabled:j||!g||!u||!x,className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-all shadow-sm",children:[j?e.jsx(c,{className:"w-4 h-4 animate-spin"}):e.jsx(De,{className:"w-4 h-4"}),s(j?"email.sending":"email.send")]})})]})]}):e.jsxs("div",{className:"rounded-2xl border border-dashed border-border bg-muted/20 p-8 text-center",children:[e.jsx(re,{className:"w-10 h-10 text-muted-foreground mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:s("email.noConnection")}),e.jsxs("button",{onClick:()=>w("settings"),className:"inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 transition-all shadow-sm",children:[e.jsx(oe,{className:"w-4 h-4"}),s("integrations.connect")]})]})})]}):e.jsx("div",{className:"p-8 text-muted-foreground",children:"App not found."})}export{Oe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.