1import{j as s}from"./vendor-ui-CJswEVbh.js";import{r as x}from"./vendor-react-CXRu5Dj1.js";import{u as D,p as M,m as L,Q as P,C as v,f as V,g as H,B as d,R as I,a as R,K as O,s as u,h as l}from"./index-D7ZrIOpR.js";import{B as F}from"./badge-Ci7ft87c.js";import{T as $,a as K,b as f,c as n,d as Q,e as r}from"./table-Cs9hCfNc.js";import{R as W}from"./rotate-ccw-B4kk0kJc.js";import"./vendor-query-DGJZ7wa4.js";import"./vendor-helmet--SzguAe_.js";import"./vendor-recharts-_i_RtjiL.js";import"./vendor-supabase-DiBj512E.js";import"./vendor-markdown-BLahVorR.js";const Z={synced:"bg-emerald-100 text-emerald-800",pending:"bg-sky-100 text-sky-800",processing:"bg-sky-100 text-sky-800",retry:"bg-amber-100 text-amber-800",failed:"bg-red-100 text-red-800"},j={hubspot:"crm-sync-worker",google_sheets:"sheets-sync-worker"},q=["all","hubspot","google_sheets"],oe=()=>{const{l:t,dir:N}=D(),{user:h,loading:w}=M(),[k,y]=x.useState(!1),[C,_]=x.useState(!1),[o,T]=x.useState("all"),i=L((h==null?void 0:h.id)??null,!w,async e=>O(await u.from("crm_sync_jobs").select("id, provider, submission_type, submission_id, source, status, attempt_count, last_error_message_safe, hubspot_contact_id, hubspot_company_id, hubspot_deal_id, hubspot_ticket_id, created_at, synced_at").order("created_at",{ascending:!1}).limit(300).abortSignal(e.signal))??[],[]),c=i.data,S=i.initialLoading,b=()=>i.refresh(!1,!0),g=x.useMemo(()=>o==="all"?c:c.filter(e=>e.provider===o),[c,o]),E=g.reduce((e,a)=>(e[a.status]=(e[a.status]??0)+1,e),{}),G=c.reduce((e,a)=>(e[a.provider]=(e[a.provider]??0)+1,e),{}),z=async e=>{const{error:a}=await u.from("crm_sync_jobs").update({status:"pending",attempt_count:0,next_attempt_at:new Date().toISOString(),last_error_message_safe:null}).eq("id",e.id);if(a){l.error(a.message);return}await u.functions.invoke(j[e.provider]??"crm-sync-worker",{body:{trigger:"admin"}}),l.success(t("تÙ
ت إعادة جدÙÙØ© اÙÙ
زاÙ
ÙØ©","Sync re-queued","已鿰æé","Synchronisation relancée","Synchronisierung erneut eingeplant","Sincronización reencolada")),b()},A=async()=>{y(!0);const e=o==="all"?["crm-sync-worker","sheets-sync-worker"]:[j[o]],a=await Promise.all(e.map(p=>u.functions.invoke(p,{body:{trigger:"admin"}})));y(!1);const m=a.find(p=>p.error);m!=null&&m.error?l.error(m.error.message):l.success(t("تÙ
تشغÙ٠اÙÙ
زاÙ
ÙØ©","Sync run started","忥已å¯å¨","Synchronisation lancée","Synchronisierung gestartet","Sincronización iniciada")),b()},B=async()=>{_(!0);const{error:e}=await u.functions.invoke("sheets-sync-worker",{body:{ensure_tabs:!0}});_(!1),e?l.error(e.message):l.success(t("تÙ
Ø§ÙØªØÙÙ Ù
٠تبÙÙØ¨Ø§Øª Ø¬ÙØ¬Ù Ø´ÙØª","Google Sheets tabs verified","å·²éªè¯ Google Sheets æ ç¾","Onglets Google Sheets vérifiés","Google-Sheets-Tabs geprüft","Pestañas de Google Sheets verificadas"))};return s.jsxs("div",{className:"space-y-6",dir:N,children:[s.jsx(P,{state:i}),s.jsxs(v,{children:[s.jsxs(V,{className:"flex-row items-center justify-between gap-3",children:[s.jsx(H,{className:"text-base",children:t("Ù
زاÙ
ÙØ© CRM ÙØ¬ÙØ¬Ù Ø´ÙØª","CRM & Google Sheets delivery","CRM ä¸ Google Sheets 忥","Livraison CRM et Google Sheets","CRM- und Google-Sheets-Zustellung","Entrega CRM y Google Sheets")}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsxs(d,{variant:"outline",size:"sm",onClick:()=>void i.refresh(!0,!0),disabled:S||i.manualRefreshing,children:[s.jsx(I,{className:`h-4 w-4 me-1 ${i.manualRefreshing?"animate-spin":""}`}),t("ØªØØ¯ÙØ«","Refresh","å·æ°","Actualiser","Aktualisieren","Actualizar")]}),s.jsx(d,{variant:"outline",size:"sm",onClick:()=>void B(),disabled:C,children:t("تÙÙØ¦Ø© تبÙÙØ¨Ø§Øª Ø¬ÙØ¬Ù Ø´ÙØª","Verify Sheets tabs","éªè¯è¡¨æ ¼æ ç¾","Vérifier les onglets","Tabs prüfen","Verificar pestañas")}),s.jsx(d,{size:"sm",onClick:()=>void A(),disabled:k,children:t("تشغÙ٠اÙÙ
زاÙ
ÙØ©","Run sync","è¿è¡åæ¥","Lancer la synchro","Sync starten","Ejecutar sincronización")})]})]}),s.jsxs(R,{className:"space-y-3",children:[s.jsx("div",{className:"flex flex-wrap gap-2",children:q.map(e=>s.jsxs(d,{size:"sm",variant:o===e?"default":"outline",onClick:()=>T(e),children:[e==="all"?t("اÙÙÙ","All","å
¨é¨","Tout","Alle","Todos"):e==="hubspot"?"HubSpot":"Google Sheets",e!=="all"?` (${G[e]??0})`:` (${c.length})`]},e))}),s.jsx("div",{className:"flex flex-wrap gap-2",children:["synced","pending","retry","processing","failed"].map(e=>s.jsxs(F,{variant:"outline",className:"text-xs",children:[e,": ",E[e]??0]},e))})]})]}),s.jsx(v,{children:s.jsx(R,{className:"p-0 overflow-x-auto",children:s.jsxs($,{children:[s.jsx(K,{children:s.jsxs(f,{children:[s.jsx(n,{className:"text-start",children:t("اÙÙÙØ§Ø©","Destination","æ¸ é","Destination","Ziel","Destino")}),s.jsx(n,{className:"text-start",children:t("اÙÙÙØ¹","Type","ç±»å","Type","Typ","Tipo")}),s.jsx(n,{className:"text-start",children:t("اÙÙ
عرÙÙ","Submission","æäº¤","Soumission","Eingang","EnvÃo")}),s.jsx(n,{className:"text-start",children:t("Ø§ÙØØ§ÙØ©","Status","ç¶æ","Statut","Status","Estado")}),s.jsx(n,{className:"text-start",children:t("اÙÙ
ØØ§ÙÙØ§Øª","Attempts","å°è¯","Tentatives","Versuche","Intentos")}),s.jsx(n,{className:"text-start",children:t("Ù
راجع","References","å¼ç¨","Références","Referenzen","Referencias")}),s.jsx(n,{className:"text-start",children:t("Ø§ÙØªØ§Ø±ÙØ®","Created","å建","Créé","Erstellt","Creado")}),s.jsx(n,{className:"text-start"})]})}),s.jsxs(Q,{children:[g.map(e=>s.jsxs(f,{children:[s.jsx(r,{className:"text-start text-xs",children:e.provider==="google_sheets"?"Google Sheets":"HubSpot"}),s.jsx(r,{className:"text-start",children:e.submission_type}),s.jsx(r,{className:"text-left font-mono text-xs",children:e.submission_id}),s.jsxs(r,{className:"text-start",children:[s.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs ${Z[e.status]??""}`,children:e.status}),e.last_error_message_safe?s.jsx("p",{className:"text-xs text-muted-foreground mt-1 max-w-xs truncate",title:e.last_error_message_safe,children:e.last_error_message_safe}):null]}),s.jsx(r,{className:"text-start",children:e.attempt_count}),s.jsx(r,{className:"text-left font-mono text-xs",children:e.provider==="google_sheets"?e.synced_at?t("تÙ
Ø§ÙØ¥Ø¶Ø§ÙØ©","Row appended","已追å ","Ligne ajoutée","Zeile ergänzt","Fila añadida"):"â":[e.hubspot_contact_id,e.hubspot_company_id,e.hubspot_deal_id,e.hubspot_ticket_id].filter(
1Boolean).join(" / ")||"â"}),s.jsx(r,{className:"text-left text-xs",children:new Date(e.created_at).toLocaleString()}),s.jsx(r,{className:"text-start",children:e.status!=="synced"?s.jsxs(d,{variant:"ghost",size:"sm",onClick:()=>void z(e),children:[s.jsx(W,{className:"h-4 w-4 me-1"}),t("إعادة","Retry","éè¯","Réessayer","Wiederholen","Reintentar")]}):null})]},e.id)),!g.length&&!S?s.jsx(f,{children:s.jsx(r,{colSpan:8,className:"text-center text-sm text-muted-foreground py-8",children:t("ÙØ§ ØªÙØ¬Ø¯ Ø³Ø¬ÙØ§Øª Ù
زاÙ
ÙØ© بعد","No sync records yet","ææ åæ¥è®°å½","Aucun enregistrement","Keine Einträge","Sin registros")})}):null]})]})})})]})};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.