PageSourceSearch

https://zapdata.co/_releases/legacy/assets/Settings-CCnuPf1H.js

js zapdata.co collected 2026-09-24 14:37:08 UTC 54,488 bytes, 6 lines download raw bytes

1import{r as o,j as e,L as ps,c as fs,f as gs}from"./react-vendor-BbKb1M84.js";import{H as bs,s as N,a as oe,ah as B,b5 as J,L as C,B as T,F as ye,b as Te,d as ze,e as Le,f as De,g as ee,aA as Me,al as X,I as U,aM as Fe,az as Xe,u as Ns,C as je,y as Oe,bI as Ye,z as Ee,aE as Ve,E as ve,aK as js,aL as vs,be as _s,ai as ys,bq as ws,br as ks,bs as Ss,bt as Cs,ao as Ke,U as Pe,m as Qe,aJ as As,n as Je,o as es,q as ss,b9 as Rs,v as ts,e5 as Is,a8 as _e,aS as as,bc as Ts,aT as is,aU as os,aV as ns,aW as rs,aX as ls,aY as cs,aZ as ds,aG as zs,w as S,r as Ls,bA as Ds,ay as Ie,c as Ne,bu as Os,ax as Es}from"./index-GVzhJuhV.js";import{S as Vs}from"./scroll-area-CxqxXcu6.js";import{C as Ps}from"./colored-switch-TTsjh76Q.js";import{A as Ms,a as Ge,b as Be,c as Ue}from"./accordion-BFGcHiXJ.js";import{P as Fs,a as qs,b as Gs}from"./popover-D0oX9fBv.js";import{P as ue}from"./plus-DdSIX70L.js";import{C as Bs,a as Us,b as Hs}from"./collapsible-CstqZJon.js";import{S as us}from"./search-aINhXfaY.js";import{E as $s}from"./eye-off-DgHcAQEZ.js";import{u as Zs,M as Ws,a as Xs,g as He,n as Ys,i as Ks,b as Qs}from"./useGlobalVariables-DyNMplte.js";import{P as Js}from"./pencil-D4lSFOtA.js";import{S as et}from"./shopping-bag-DhnEK_gj.js";import{P as st}from"./package-D9ZnWMHH.js";import{V as tt}from"./variable-e1Ib5q1h.js";import{C as at}from"./chevron-left-CXy3js90.js";import"./supabase-DuPJfW10.js";import"./index-CHCCHJ44.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const it=bs("AtSign",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]]);function ot(s){const[n,i]=o.useState(!1),[m,j]=o.useState(!0);return o.useEffect(()=>{let k=!1;return(async()=>{if(!s){i(!1),j(!1);return}j(!0);const{count:D,error:v}=await N.from("ads_ad_accounts").select("id",{count:"exact",head:!0}).eq("user_id",s).eq("is_selected",!0).eq("account_status",1);k||(v?(console.error("[useHasActiveAdAccounts] error:",v),i(!1)):i((D??0)>0),j(!1))})(),()=>{k=!0}},[s]),{hasActive:n,loading:m}}async function ms(s){const n=s==null?void 0:s.context;if(n&&typeof n.clone=="function")try{const i=await n.clone().json();if(i!=null&&i.error)return i.details?`${i.error} (${i.details})`:i.error;if(i!=null&&i.reason)return i.reason}catch{try{const i=await n.clone().text();if(i)return i.slice(0,300)}catch{}}return(s==null?void 0:s.message)||"Falha desconhecida ao enviar a notificação de teste."}async function nt(){const{data:s,error:n}=await N.functions.invoke("test-push-event");return n?{success:!1,reason:await ms(n)}:s}function rt({userId:s}){const{t:n}=oe(["settings","common"]),{toast:i}=Fe(),m={spend:n("adMetricRules.metrics.spend"),cpc:n("adMetricRules.metrics.cpc"),cpa:n("adMetricRules.metrics.cpa"),cost_per_message:n("adMetricRules.metrics.costPerMessage")},[j,k]=o.useState([]),[z,D]=o.useState([]),[v,R]=o.useState(!0),[L,l]=o.useState(!1);o.useEffect(()=>{(async()=>{R(!0);const[c,r]=await Promise.all([N.from("ads_metric_alert_rules").select("id, ad_account_ids, campaign_id, metric, operator, threshold, is_active").eq("user_id",s).order("created_at",{ascending:!0}),N.from("ads_ad_accounts").select("ad_account_id, name").eq("user_id",s).eq("is_selected",!0).eq("account_status",1)]);k(c.data||[]),D(r.data||[]),R(!1)})()},[s]);const b=async()=>{l(!0);try{const{data:h,error:c}=await N.from("ads_metric_alert_rules").insert({user_id:s,metric:"spend",operator:">",threshold:100,ad_account_ids:null,campaign_id:null,is_active:!0}).select("id, ad_account_ids, campaign_id, metric, operator, threshold, is_active").single();if(c)throw c;k(r=>[...r,h])}catch(h){i({variant:"destructive",title:n("adMetricRules.toasts.addError"),description:h.message})}finally{l(!1)}},y=async(h,c)=>{k(w=>w.map(_=>_.id===h?{..._,...c}:_));const{error:r}=await N.from("ads_metric_alert_rules").update(c).eq("id",h);r&&i({variant:"destructive",title:n("adMetricRules.toasts.updateError"),description:r.message})},G=async h=>{const{error:c}=await N.from("ads_metric_alert_rules").delete().eq("id",h);if(c){i({variant:"destructive",title:n("adMetricRules.toasts.removeError"),description:c.message});return}k(r=>r.filter(w=>w.id!==h))},O=(h,c)=>{const r=h.ad_account_ids||[],w=r.includes(c)?r.filter(_=>_!==c):[...r,c];y(h.id,{ad_account_ids:w.length===0?null:w})},P=h=>{const c=h.ad_account_ids||[];if(c.length===0)return n("adMetricRules.accountsLabel.all");
6if(c.length===1){const r=z.find(w=>w.ad_account_id===c[0]);return(r==null?void 0:r.name)||c[0]}return n("adMetricRules.accountsLabel.count",{count:c.length})};return v?e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(B,{className:"h-5 w-5 animate-spin text-accent"})}):e.jsxs("div",{className:"space-y-3 ml-6 pl-4 border-l-2 border-accent/30",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("adMetricRules.rulesInfo.pre")," ",e.jsx("strong",{children:n("adMetricRules.rulesInfo.today")}),". ",n("adMetricRules.rulesInfo.post")]}),j.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:n("adMetricRules.empty")}),j.map(h=>e.jsxs("div",{className:"rounded-md border border-border bg-secondary/20 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{checked:h.is_active,onCheckedChange:c=>y(h.id,{is_active:c})}),e.jsx(C,{className:"text-xs",children:h.is_active?n("adMetricRules.active"):n("adMetricRules.inactive")})]}),e.jsx(T,{size:"icon",variant:"ghost",className:"h-7 w-7 text-destructive hover:bg-destructive/10",onClick:()=>G(h.id),children:e.jsx(ye,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:n("adMetricRules.metric")}),e.jsxs(Te,{value:h.metric,onValueChange:c=>y(h.id,{metric:c}),children:[e.jsx(ze,{className:"h-8 text-xs",children:e.jsx(Le,{})}),e.jsx(De,{children:Object.keys(m).map(c=>e.jsx(ee,{value:c,className:"text-xs",children:m[c]},c))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:n("adMetricRules.adAccounts")}),e.jsxs(Fs,{children:[e.jsx(qs,{asChild:!0,children:e.jsxs(T,{variant:"outline",className:"h-8 w-full justify-between text-xs font-normal",children:[e.jsx("span",{className:"truncate",children:P(h)}),e.jsx(Me,{className:"h-3.5 w-3.5 opacity-50 shrink-0 ml-1"})]})}),e.jsx(Gs,{className:"w-[280px] p-2",align:"start",children:e.jsxs("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1",children:n("adMetricRules.leaveEmptyAllAccounts")}),z.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic px-2 py-2",children:n("adMetricRules.noActiveAccounts")}),z.map(c=>{const r=(h.ad_account_ids||[]).includes(c.ad_account_id);return e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 rounded hover:bg-accent/10 cursor-pointer",children:[e.jsx(X,{checked:r,onCheckedChange:()=>O(h,c.ad_account_id)}),e.jsx("span",{className:"text-xs truncate",children:c.name||c.ad_account_id})]},c.ad_account_id)})]})})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:n("adMetricRules.operator")}),e.jsxs(Te,{value:h.operator,onValueChange:c=>y(h.id,{operator:c}),children:[e.jsx(ze,{className:"h-8 text-xs",children:e.jsx(Le,{})}),e.jsxs(De,{children:[e.jsx(ee,{value:">",className:"text-xs",children:n("adMetricRules.operators.gt")}),e.jsx(ee,{value:">=",className:"text-xs",children:n("adMetricRules.operators.gte")}),e.jsx(ee,{value:"<",className:"text-xs",children:n("adMetricRules.operators.lt")}),e.jsx(ee,{value:"<=",className:"text-xs",children:n("adMetricRules.operators.lte")})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:n("common:fields.value")}),e.jsx(U,{type:"number",step:"0.01",min:0,value:h.threshold,onChange:c=>y(h.id,{threshold:parseFloat(c.target.value)||0}),className:"h-8 text-xs"})]})]})]},h.id)),e.jsxs(T,{onClick:b,disabled:L,size:"sm",variant:"outline",className:"border-accent text-accent hover:bg-accent/10",children:[e.jsx(ue,{className:"h-3.5 w-3.5 mr-1"}),n("adMetricRules.addRule")]})]})}function lt({userId:s,globalLimit:n}){const{t:i}=oe(["settings","common"]),{toast:m}
6=Fe(),[j,k]=o.useState(!1),[z,D]=o.useState(!1),[v,R]=o.useState(!1),[L,l]=o.useState([]),[b,y]=o.useState({}),[G,O]=o.useState(null),P=async()=>{R(!0);try{const{data:r,error:w}=await N.from("maturador_instances").select("id, instance_name, phone_number, label, lead_rotation_limit_override").eq("user_id",s).is("deletion_requested_at",null).order("created_at",{ascending:!0});if(w)throw w;const _=r||[];l(_);const V={};_.forEach(M=>{V[M.id]=M.lead_rotation_limit_override!=null?String(M.lead_rotation_limit_override):""}),y(V),D(!0)}catch(r){m({variant:"destructive",title:i("leadRotationOverrides.loadError"),description:r.message})}finally{R(!1)}},h=r=>{k(r),r&&!z&&P()},c=async r=>{var M;const w=(b[r]??"").trim(),_=w===""?null:parseInt(w,10),V=((M=L.find(F=>F.id===r))==null?void 0:M.lead_rotation_limit_override)??null;if(_!==null&&(isNaN(_)||_<1)){m({variant:"destructive",title:i("leadRotationOverrides.invalidValue"),description:i("leadRotationOverrides.invalidValueDescription")}),y(F=>({...F,[r]:V!=null?String(V):""}));return}if(_!==V){O(r);try{const{data:F,error:q}=await N.from("maturador_instances").update({lead_rotation_limit_override:_}).eq("id",r).select().single();if(q||!F)throw new Error((q==null?void 0:q.message)||i("leadRotationOverrides.noRowUpdatedError"));l(d=>d.map(A=>A.id===r?{...A,lead_rotation_limit_override:_}:A)),m({title:i(_===null?"leadRotationOverrides.overrideRemoved":"leadRotationOverrides.overrideSaved"),description:_===null?i("leadRotationOverrides.backToGlobalLimit"):i("leadRotationOverrides.nowUsesLimit",{limit:_})})}catch(F){y(q=>({...q,[r]:V!=null?String(V):""})),m({variant:"destructive",title:i("common:states.error"),description:F.message})}finally{O(null)}}};return e.jsxs(Bs,{open:j,onOpenChange:h,children:[e.jsx(Us,{asChild:!0,children:e.jsxs(T,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 -ml-2 text-xs text-muted-foreground hover:text-accent",children:[j?e.jsx(Xe,{className:"w-3 h-3 mr-1"}):e.jsx(Me,{className:"w-3 h-3 mr-1"}),i("leadRotationOverrides.customizePerInstance")]})}),e.jsx(Hs,{className:"mt-1.5 space-y-1.5",children:v?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground py-2",children:[e.jsx(B,{className:"w-3 h-3 animate-spin"})," ",i("leadRotationOverrides.loadingInstances")]}):L.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:i("leadRotationOverrides.noInstancesFound")}):L.map(r=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs truncate flex-1",title:r.instance_name,children:r.label||r.phone_number||r.instance_name}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(U,{type:"number",min:1,placeholder:String(n),value:b[r.id]??"",onChange:w=>y(_=>({..._,[r.id]:w.target.value})),onBlur:()=>c(r.id),onKeyDown:w=>{w.key==="Enter"&&w.target.blur()},disabled:G===r.id,className:"w-16 h-7 text-xs text-center"}),G===r.id&&e.jsx(B,{className:"w-3 h-3 animate-spin text-muted-foreground"})]})]},r.id))})]})}function $e(){const{t:s}=oe(["settings","common"]),n=[{id:"disabled",label:s("pushNotifications.adIssues.disabled.label"),description:s("pushNotifications.adIssues.disabled.description")},{id:"unsettled",label:s("pushNotifications.adIssues.unsettled.label"),description:s("pushNotifications.adIssues.unsettled.description")},{id:"risk_review",label:s("pushNotifications.adIssues.riskReview.label"),description:s("pushNotifications.adIssues.riskReview.description")},{id:"pending_settlement",label:s("pushNotifications.adIssues.pendingSettlement.label"),description:s("pushNotifications.adIssues.pendingSettlement.description")},{id:"grace_period",label:s("pushNotifications.adIssues.gracePeriod.label"),description:s("pushNotifications.adIssues.gracePeriod.description")},{id:"pending_closure",label:s("pushNotifications.adIssues.pendingClosure.label"),description:s("pushNotifications.adIssues.pendingClosure.description")},{id:"closed",label:s("pushNotifications.adIssues.closed.label"),description:s("pushNotifications.adIssues.closed.description")},{id:"balance_due",label:s("pushNotifications.adIssues.balanceDue.label"),description:s("pushNotifications.adIssues.balanceDue.description")}],{effectiveUserId:i}=Ns(),{toast:m}=Fe(),{hasActive:j,loading:k}
6=ot(i),[z,D]=o.useState(!1),[v,R]=o.useState([]),[L,l]=o.useState(""),[b,y]=o.useState(!1),[G,O]=o.useState(!1),[P,h]=o.useState(!1),[c,r]=o.useState(!1),[w,_]=o.useState(!1),[V,M]=o.useState(!1),[F,q]=o.useState(!1),[d,A]=o.useState(!1),[H,ne]=o.useState(!1),[Y,re]=o.useState(!1),[Q,se]=o.useState(n.map(t=>t.id)),[K,me]=o.useState(30),[te,he]=o.useState(30),[le,xe]=o.useState(!1),[ae,pe]=o.useState(!1),[fe,we]=o.useState(!0);o.useEffect(()=>{(async()=>{if(!i)return;const{data:u}=await N.from("profiles").select("push_webhook_enabled, push_subscription_ids, notify_on_sale, notify_on_disconnect, notify_on_lead_rotation, notify_on_logzz, lead_rotation_limit, notify_on_desktop, notify_on_ad_account_issue, notify_on_ad_metrics, ad_account_issue_notification_types").eq("id",i).single();if(u){D(u.push_webhook_enabled||!1),R(u.push_subscription_ids||[]),r(u.notify_on_sale||!1),_(u.notify_on_disconnect||!1),M(u.notify_on_lead_rotation||!1),q(u.notify_on_logzz||!1),A(u.notify_on_desktop||!1),ne(u.notify_on_ad_account_issue||!1),re(u.notify_on_ad_metrics||!1);const I=u.ad_account_issue_notification_types;se(I&&I.length>0?I:n.map(x=>x.id)),me(u.lead_rotation_limit||30),he(u.lead_rotation_limit||30)}we(!1)})()},[i]);const ke=async()=>{if(i){y(!0);try{const t=!z,{error:u}=await N.from("profiles").update({push_webhook_enabled:t}).eq("id",i);if(u)throw u;D(t),m({title:s(t?"pushNotifications.toasts.enabled":"pushNotifications.toasts.disabled"),description:s(t?"pushNotifications.toasts.willReceive":"pushNotifications.toasts.willNotReceive")})}catch(t){m({variant:"destructive",title:s("common:states.error"),description:t.message||s("pushNotifications.toasts.settingsChangeError")})}finally{y(!1)}}},Z=async(t,u,I)=>{if(i){y(!0);try{const{error:x}=await N.from("profiles").update({[t]:u}).eq("id",i);if(x)throw x;m({title:I})}catch(x){throw m({variant:"destructive",title:s("common:states.error"),description:x.message}),x}finally{y(!1)}}},ge=async t=>{try{await Z("notify_on_sale",t,s(t?"pushNotifications.toasts.saleOn":"pushNotifications.toasts.saleOff")),r(t)}catch{}},a=async t=>{try{await Z("notify_on_disconnect",t,s(t?"pushNotifications.toasts.disconnectOn":"pushNotifications.toasts.disconnectOff")),_(t)}catch{}},p=async t=>{try{await Z("notify_on_lead_rotation",t,s(t?"pushNotifications.toasts.leadRotationOn":"pushNotifications.toasts.leadRotationOff")),M(t)}catch{}},f=async t=>{try{await Z("notify_on_logzz",t,s(t?"pushNotifications.toasts.logzzOn":"pushNotifications.toasts.logzzOff")),q(t)}catch{}},g=async t=>{try{await Z("notify_on_desktop",t,s(t?"pushNotifications.toasts.desktopOn":"pushNotifications.toasts.desktopOff")),A(t)}catch{}},E=async t=>{try{await Z("notify_on_ad_account_issue",t,s(t?"pushNotifications.toasts.adAccountIssueOn":"pushNotifications.toasts.adAccountIssueOff")),ne(t)}catch{}},W=async t=>{try{await Z("notify_on_ad_metrics",t,s(t?"pushNotifications.toasts.adMetricsOn":"pushNotifications.toasts.adMetricsOff")),re(t)}catch{}},Se=async(t,u)=>{if(!i)return;const I=u?Array.from(new Set([...Q,t])):Q.filter(x=>x!==t);se(I);try{const{error:x}=await N.from("profiles").update({ad_account_issue_notification_types:I}).eq("id",i);if(x)throw x}catch(x){se(Q),m({variant:"destructive",title:s("common:states.error"),description:x.message})}},ie=async()=>{if(!(!i||K<1)){pe(!0);try{const{error:t}=await N.from("profiles").update({lead_rotation_limit:K}).eq("id",i);if(t)throw t;he(K),m({title:s("pushNotifications.toasts.limitUpdated"),description:s("pushNotifications.toasts.limitSetTo",{limit:K})})}catch(t){m({variant:"destructive",title:s("common:states.error"),description:t.message})}finally{pe(!1)}}},be=async()=>{if(i){xe(!0);try{const{data:t,error:u}=await N.functions.invoke("check-lead-rotation-manual",{body:{user_id:i}});if(u)throw u;m({title:t.notified>0?s("pushNotifications.toasts.notificationsSent"):s("pushNotifications.toasts.checkComplete"),description:t.message})}catch(t){m({variant:"destructive",title:s("pushNotifications.toasts.checkError"),description:t.message})}finally{xe(!1)}}},Ce=async()=>{if(!i||!L.trim())return;const t=L.trim();if(v.includes(t)){m({variant:"destructive",title:s("pushNotifications.toasts.tokenExists")});return}y(!0);try{const u=[...v,t],{error:I}=await N.from("profiles").update({push_subscription_ids:u}).eq("id",i);if(I)throw I;R(u),l(""),m({title:s("pushNotifications.toasts.tokenAdded")})}catch(u){m({variant:"destructive",title:s("common:states.error"),description:u.message})}finally{y(!1)}},Ae=async t=>{if(i){y(!0);try{const u=v.filter(x=>x!==t),{error:I}=await N.from("profiles").update({push_subscription_ids:u}).eq("id",i);if(I)throw I;R(u),m({title:s("pushNotifications.toasts.tokenRemoved")})}catch(u){m({variant:"destructive",title:s("common:states.error"),description:u.message})}finally{y(!1)}}},hs=async()=>{O(!0);try{const t=await nt();t.success?m({title:s("pushNotifications.toasts.testSent"),description:t.message||s("pushNotifications.toasts.testSentDescription",{count:t.devices_notified})}):m({variant:"destructive",title:s("pushNotifications.toasts.testFailed"),description:t.reason||s("pushNotifications.toasts.testFailedDescription")})}catch(t){m({variant:"destructive",title:s("pushNotifications.toasts.testError"),description:t.message})}finally{O(!1)}};if(fe)return e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx(B,{className:"h-8 w-8 animate-spin text-accent"})});const ce=!j||k,qe=({id:t,checked:u,onChange:I,label:x,description:Re})=>{const de=e.jsxs("div",{className:`flex items-start space-x-3 ${ce?"opacity-60":""}`,children:[e.jsx(X,{id:t,checked:u,onCheckedChange:$=>!ce&&I($),disabled:b||ce,className:"mt-0.5"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx(C,{htmlFor:t,className:`text-sm font-medium ${ce?"cursor-not-allowed":"cursor-pointer"}`,children:x}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Re})]})]});return ce?e.jsx(ws,{delayDuration:200,children:e.jsxs(ks,{children:[e.jsx(Ss,{asChild:!0,children:e.jsx("div",{children:de})}),e.jsx(Cs,{side:"top",className:"max-w-xs",children:e.jsxs("p",{className:"text-xs",children:[s("pushNotifications.facebookGate.pre")," ",e.jsx("strong",{children:s("pushNotifications.facebookGate.active")})," ",s("pushNotifications.facebookGate.mid")," ",e.jsx(ps,{to:"/ads/settings",className:"text-accent underline",children:s("pushNotifications.facebookGate.adsTab")})," ",s("pushNotifications.facebookGate.post")]})})]})}):de};return e.jsxs(je,{children:[e.jsxs(Oe,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ye,{className:"h-5 w-5 text-accent"}),e.jsx(Ee,{children:s("pushNotifications.title")})]}),e.jsx(Ps,{checked:z,onCheckedChange:ke,disabled:b})]}),e.jsx(Ve,{children:s("pushNotifications.subtitle")})]}),z&&e.jsxs(ve,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"subscription-id",className:"text-sm",children:s("pushNotifications.addDeviceToken")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{id:"subscription-id",placeholder:s("pushNotifications.tokenPlaceholder"),value:L,onChange:t=>l(t.target.value),disabled:b,className:"flex-1"}),e.jsx(T,{onClick:Ce,disabled:b||!L.trim(),size:"icon",variant:"outline",className:"border-accent text-accent hover:bg-accent/10",children:e.jsx(ue,{className:"w-4 h-4"})})]}),e.jsxs("a",{href:"https://push.zapdata.co",target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-1 text-xs",children:[s("pushNotifications.generateTokenHere")," ",e.jsx(js,{className:"w-3 h-3"})]})]}),v.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{className:"text-sm",children:s("pushNotifications.registeredDevices",{count:v.length})}),e.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:v.map((t,u)=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-secondary/30 rounded-md text-sm",children:[e.jsxs("span",{className:"font-mono text-xs truncate max-w-[200px]",title:t,children:[t.slice(0,20),"...",t.slice(-8)]}),e.jsx(T,{onClick:()=>Ae(t),disabled:b,size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(ye,{className:"w-3 h-3"})})]},u))})]}),e.jsxs("div",{className:"space-y-3 pt-4 border-t border-border",children:[e.jsx(C,{className:"text-sm font-medium",children:s("pushNotifications.notificationTypes")}),e.jsxs(Ms,{type:"multiple",className:"w-full",children:[e.jsxs(Ge,{value:"whatsapp",className:"border-border",children:[e.jsx(Be,{className:"text-sm hover:no-underline",children:e.jsxs("span",{className:"flex items-center gap-2",children:["📱 ",e.jsx("span",{children:s("pushNotifications.whatsapp.title")})]})}),e.jsxs(Ue,{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(X,{id:"notify-on-sale",checked:c,onCheckedChange:t=>ge(t),disabled:b,className:"mt-0.5"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsxs(C,{htmlFor:"notify-on-sale",className:"text-sm font-medium cursor-pointer",children:["🔥 ",s("pushNotifications.whatsapp.newSales.label")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("pushNotifications.whatsapp.newSales.description")})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(X,{id:"notify-on-disconnect",checked:w,onCheckedChange:t=>a(t),disabled:b,className:"mt-0.5"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsxs(C,{htmlFor:"notify-on-disconnect",className:"text-sm font-medium cursor-pointer",children:["🚨 ",s("pushNotifications.whatsapp.disconnect.label")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("pushNotifications.whatsapp.disconnect.description")})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(X,{id:"notify-on-lead-rotation",checked:V,onCheckedChange:t=>p(t),disabled:b,className:"mt-0.5"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsxs(C,{htmlFor:"notify-on-lead-rotation",className:"text-sm font-medium cursor-pointer",children:["🔄 ",s("pushNotifications.whatsapp.leadRotation.label")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("pushNotifications.whatsapp.leadRotation.description")})]})]}),V&&e.jsxs("div",{className:"ml-6 space-y-2 pl-4 border-l-2 border-accent/30",children:[e.jsx(C,{htmlFor:"lead-rotation-limit",className:"text-sm text-muted-foreground",children:s("pushNotifications.whatsapp.leadRotation.maxLimit")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(U,{id:"lead-rotation-limit",type:"number",min:1,value:K,onChange:t=>me(parseInt(t.target.value)||30),disabled:ae,className:"w-20"}),K!==te&&e.jsx(T,{onClick:ie,disabled:ae,size:"icon",variant:"ghost",className:"h-8 w-8 text-green-500 hover:text-green-400 hover:bg-green-500/10",children:ae?e.jsx(B,{className:"w-4 h-4 animate-spin"}):e.jsx(vs,{className:"w-4 h-4"})}),e.jsx(T,{onClick:be,disabled:le||v.length===0,size:"icon",variant:"ghost",className:"h-8 w-8 text-muted-foreground hover:text-accent hover:bg-accent/10",title:s("pushNotifications.checkNow"),children:le?e.jsx(B,{className:"w-4 h-4 animate-spin"}):e.jsx(us,{className:"w-4 h-4"})})]}),i&&e.jsx(lt,{userId:i,globalLimit:K})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(X,{id:"notify-on-logzz",checked:F,onCheckedChange:t=>f(t),disabled:b,className:"mt-0.5"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsxs(C,{htmlFor:"notify-on-logzz",className:"text-sm font-medium cursor-pointer",children:["📦 ",s("pushNotifications.whatsapp.logzz.label")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("pushNotifications.whatsapp.logzz.description")})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(X,{id:"notify-on-desktop",checked:d,onCheckedChange:t=>g(t),disabled:b,className:"mt-0.5"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsxs(C,{htmlFor:"notify-on-desktop",className:"text-sm font-medium cursor-pointer",children:["🖥️ ",s("pushNotifications.whatsapp.desktop.label")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("pushNotifications.whatsapp.desktop.description")})]})]})]})]}),e.jsxs(Ge,{value:"facebook",className:"border-border",children:[e.jsx(Be,{className:"text-sm hover:no-underline",children:e.jsxs("span",{className:"flex items-center gap-2",children:["📘 ",e.jsx("span",{children:s("pushNotifications.facebook.title")})]})}),e.jsxs(Ue,{className:"space-y-4 pt-2",children:[e.jsx(qe,{id:"notify-ad-account-issue",checked:H,onChange:E,label:`💳 ${s("pushNotifications.facebook.accountIssue.label")}`,description:s("pushNotifications.facebook.accountIssue.description")}),H&&j&&e.jsxs("div",{className:"ml-6 pl-4 border-l-2 border-accent/30 space-y-3",children:[e.jsxs("div",{children:[e.jsx(C,{className:"text-xs font-medium text-muted-foreground",children:s("pushNotifications.facebook.whichAlerts")}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:s("pushNotifications.facebook.whichAlertsDescription")})]}),e.jsx("div",{className:"space-y-2.5",children:n.map(t=>{const u=Q.includes(t.id);return e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(X,{id:`ad-issue-${t.id}`,checked:u,onCheckedChange:I=>Se(t.id,I),disabled:b,className:"mt-0.5"}),e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(C,{htmlFor:`ad-issue-${t.id}`,className:"text-sm font-medium cursor-pointer",children:t.label}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.description})]})]},t.id)})})]}),e.jsx(qe,{id:"notify-ad-metrics",checked:Y,onChange:W,label:`📊 ${s("pushNotifications.facebook.adMetrics.label")}`,description:s("pushNotifications.facebook.adMetrics.description")}),Y&&j&&i&&e.jsx(rt,{userId:i}),j&&(H||Y)&&e.jsx(T,{onClick:async()=>{h(!0);try{const[t,u]=await Promise.all([N.functions.invoke("monitor-ad-metrics"),N.functions.invoke("monitor-ad-accounts-status")]),I=t.error||u.error;if(I){const xs=await ms(I);m({variant:"destructive",title:s("pushNotifications.facebookTest.testError"),description:xs});return}const x=t.data||{},Re=u.data||{},de=(x.notifications_queued||0)+(Re.notifications_queued||0);if(de>0){m({title:s("pushNotifications.facebookTest.notificationsSent"),description:s("pushNotifications.facebookTest.notificationsQueued",{count:de})});return}const $=[];x.rules_evaluated===0?$.push(s("pushNotifications.facebookTest.noActiveRule")):x.accounts_checked===0&&x.missing_token_count>0?$.push(s("pushNotifications.facebookTest.missingToken",{count:x.missing_token_count})):x.fb_errors>0&&x.accounts_checked===0?$.push(s("pushNotifications.facebookTest.fbErrorAllAccounts",{count:x.fb_errors})):x.no_data_count>0&&x.above_threshold_count===0?$.push(s("pushNotifications.facebookTest.rulesEvaluatedNoSpend",{rules:x.rules_evaluated,accounts:x.accounts_checked,noData:x.no_data_count})):x.below_threshold_count>0&&x.above_threshold_count===0?$.push(s("pushNotifications.facebookTest.rulesEvaluatedBelowThreshold",{rules:x.rules_evaluated})):x.rules_evaluated>0&&$.push(s("pushNotifications.facebookTest.rulesAndAccountsChecked",{rules:x.rules_evaluated,accounts:x.accounts_checked})),$.push(s("pushNotifications.facebookTest.noProblematicAccount")),m({title:s("pushNotifications.facebookTest.checkCompleteNothing"),description:$.join(" • ")})}catch(t){m({variant:"destructive",title:s("pushNotifications.facebookTest.testError"),description:t.message})}finally{h(!1)}},disabled:P||v.length===0,variant:"outline",size:"sm",className:"w-full border-accent text-accent hover:bg-accent/10 mt-2",children:P?e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"w-4 h-4 mr-2 animate-spin"}),s("pushNotifications.facebookTest.checkingRules")]}):e.jsxs(e.Fragment,{children:[e.jsx(_s,{className:"w-4 h-4 mr-2"}),s("pushNotifications.facebookTest.testNow")]})})]})]})]})]}),e.jsx(T,{onClick:hs,disabled:G||v.length===0,variant:"outline",className:"w-full border-accent text-accent hover:bg-accent/10",children:G?e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"w-4 h-4 mr-2 animate-spin"}),s("pushNotifications.sendingTest")]}):e.jsxs(e.Fragment,{children:[e.jsx(ys,{className:"w-4 h-4 mr-2"}),s("pushNotifications.testNotification"
6)]})})]})]})}const Ze={automati_zap:!0,metricas:!0,organizador_numeros:!0,track_ofertas:!1,automati_zap_flows:!1,automati_zap_edit_flows:!1,automati_zap_delete_contacts:!1},ct=()=>{const{t:s}=oe(["settings","common"]),{user:n}=Ke(),i=[{key:"automati_zap",label:s("collaborators.systems.automatiZap.label"),description:s("collaborators.systems.automatiZap.description")},{key:"metricas",label:s("collaborators.systems.metricas.label"),description:s("collaborators.systems.metricas.description")},{key:"organizador_numeros",label:s("collaborators.systems.organizadorNumeros.label"),description:s("collaborators.systems.organizadorNumeros.description")}],m=[{key:"automati_zap_flows",label:s("collaborators.automatiZapDetails.flows.label"),description:s("collaborators.automatiZapDetails.flows.description")},{key:"automati_zap_edit_flows",label:s("collaborators.automatiZapDetails.editFlows.label"),description:s("collaborators.automatiZapDetails.editFlows.description")},{key:"automati_zap_delete_contacts",label:s("collaborators.automatiZapDetails.deleteContacts.label"),description:s("collaborators.automatiZapDetails.deleteContacts.description")}],[j,k]=o.useState([]),[z,D]=o.useState([]),[v,R]=o.useState(!0),[L,l]=o.useState(!1),[b,y]=o.useState(!1),[G,O]=o.useState(null),[P,h]=o.useState(null),[c,r]=o.useState(!1),[w,_]=o.useState(!1),[V,M]=o.useState(!1),[F,q]=o.useState(!1),[d,A]=o.useState(""),[H,ne]=o.useState(""),[Y,re]=o.useState(""),[Q,se]=o.useState(Ze),[K,me]=o.useState(null),te=async()=>{if(n){R(!0);try{const{data:a,error:p}=await N.functions.invoke("manage-collaborators",{body:{action:"list"}});if(p)throw p;k(a.collaborators||[])}catch(a){S.error(s("collaborators.toasts.loadError")),console.error(a)}finally{R(!1)}}},he=async()=>{if(!n)return;const{data:a}=await N.from("profiles").select("collab_hide_instances, collab_message_signing").eq("id",n.id).single();a&&(_(a.collab_hide_instances||!1),M(a.collab_message_signing||!1))},le=async(a,p)=>{if(n){q(!0);try{const{error:f}=await N.from("profiles").update({[a]:p}).eq("id",n.id);if(f)throw f;S.success(s("collaborators.toasts.settingSaved"))}catch{S.error(s("collaborators.toasts.settingSaveError"))}finally{q(!1)}}},xe=async()=>{if(!n)return;const{data:a}=await N.from("maturador_instances").select("id, instance_name, phone_number, status").eq("user_id",n.id).order("created_at",{ascending:!1});a&&D(a)};o.useEffect(()=>{te(),he(),xe()},[n]);const ae=()=>{A(""),ne(""),re(""),se(Ze),me(null),r(!1)},pe=async()=>{if(!d.trim()||!H.trim()||!Y.trim()){S.error(s("collaborators.toasts.fillAllFields"));return}if(Y.length<6){S.error(s("collaborators.toasts.passwordMinLength"));return}l(!0);try{const{data:a,error:p}=await N.functions.invoke("manage-collaborators",{body:{action:"create",name:d.trim(),email:H.trim().toLowerCase(),password:Y,permissions:Q}});if(p)throw p;if(a.error){S.error(a.error);return}S.success(s("collaborators.toasts.createSuccess")),y(!1),ae(),te()}catch(a){S.error(a.message||s("collaborators.toasts.createError"))}finally{l(!1)}},fe=async a=>{l(!0);try{const{data:p,error:f}=await N.functions.invoke("manage-collaborators",{body:{action:"update",collaborator_id:a.id,name:a.name,permissions:a.permissions,is_active:a.is_active,allowed_instance_ids:a.allowed_instance_ids}});if(f)throw f;if(p.error){S.error(p.error);return}S.success(s("collaborators.toasts.updateSuccess")),O(null),te()}catch(p){S.error(p.message||s("collaborators.toasts.updateError"))}finally{l(!1)}},we=async a=>{try{const{data:p,error:f}=await N.functions.invoke("manage-collaborators",{body:{action:"delete",collaborator_id:a}});if(f)throw f;if(p.error){S.error(p.error);return}S.success(s("collaborators.toasts.removeSuccess")),te()}catch(p){S.error(p.message||s("collaborators.toasts.removeError"))}},ke=async a=>{const p={...a,is_active:!a.is_active};k(f=>f.map(g=>g.id===a.id?p:g)),await fe(p)},Z=(a,p,f)=>{k(g=>g.map(E=>{if(E.id!==a)return E;const W={...E.permissions,[p]:f};return p==="automati_zap"&&!f&&(W.automati_zap_flows=!1,W.automati_zap_edit_flows=!1,W.automati_zap_delete_contacts=!1),p==="automati_zap_flows"&&!f&&(W.automati_zap_edit_flows=!1),{...E,permissions:W}}))},ge=({permissions:a,onChange:p,isForm:f=!1})=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-foreground mb-3",children:s("collaborators.systemsTitle")}),e.jsx("div",{className:"space-y-3",children:i.map(g=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:g.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.description})]}),e.jsx(J,{checked:a[g.key],onCheckedChange:E=>p(g.key,E)})]},g.key))})]}),a.automati_zap&&e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsx("h4",{className:"text-sm font-medium text-foreground mb-3",children:s("collaborators.automatiZap
6DetailsTitle")}),e.jsx("div",{className:"space-y-3 pl-2 border-l-2 border-accent/30",children:m.map(g=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:g.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.description})]}),e.jsx(J,{checked:a[g.key],onCheckedChange:E=>p(g.key,E),disabled:g.key==="automati_zap_edit_flows"&&!a.automati_zap_flows})]},g.key))})]})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(je,{children:[e.jsxs(Oe,{className:"pb-3",children:[e.jsx(Ee,{className:"text-sm",children:s("collaborators.globalSettings.title")}),e.jsx(Ve,{className:"text-xs",children:s("collaborators.globalSettings.description")})]}),e.jsxs(ve,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s("collaborators.globalSettings.hideInstances.label")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("collaborators.globalSettings.hideInstances.description")})]}),e.jsx(J,{checked:w,disabled:F,onCheckedChange:a=>{_(a),le("collab_hide_instances",a)}})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s("collaborators.globalSettings.messageSigning.label")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("collaborators.globalSettings.messageSigning.description")})]}),e.jsx(J,{checked:V,disabled:F,onCheckedChange:a=>{M(a),le("collab_message_signing",a)}})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"h-5 w-5 text-accent"}),s("collaborators.title")]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s("collaborators.subtitle")})]}),e.jsxs(Qe,{open:b,onOpenChange:a=>{y(a),a||ae()},children:[e.jsx(As,{asChild:!0,children:e.jsxs(T,{size:"sm",className:"gap-1.5",children:[e.jsx(ue,{className:"h-4 w-4"}),s("collaborators.newCollaborator")]})}),e.jsxs(Je,{className:"max-w-md max-h-[90vh] overflow-y-auto",children:[e.jsx(es,{children:e.jsx(ss,{children:s("collaborators.createDialog.title")})}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:s("common:fields.name")}),e.jsx(U,{value:d,onChange:a=>A(a.target.value),placeholder:s("collaborators.createDialog.namePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:s("collaborators.createDialog.emailLabel")}),e.jsx(U,{type:"email",value:H,onChange:a=>ne(a.target.value),placeholder:s("collaborators.createDialog.emailPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:s("common:fields.password")}),e.jsxs("div",{className:"relative",children:[e.jsx(U,{type:c?"text":"password",value:Y,onChange:a=>re(a.target.value),placeholder:s("collaborators.createDialog.passwordPlaceholder")}),e.jsx("button",{type:"button",onClick:()=>r(!c),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:c?e.jsx($s,{className:"h-4 w-4"}):e.jsx(Rs,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:s("collaborators.permissionsTitle")}),e.jsx(ge,{permissions:Q,onChange:(a,p)=>{se(f=>{const g={...f,[a]:p};return a==="automati_zap"&&!p&&(g.automati_zap_flows=!1,g.automati_zap_edit_flows=!1,g.automati_zap_delete_contacts=!1),a==="automati_zap_flows"&&!p&&(g.automati_zap_edit_flows=!1),g})},isForm:!0})]})]}),e.jsxs(ts,{children:[e.jsx(Is,{asChild:!0,children:e.jsx(T,{variant:"outline",children:s("common:actions.cancel")})}),e.jsxs(T,{onClick:pe,disabled:L,children:[L&&e.jsx(B,{className:"h-4 w-4 mr-2 animate-spin"}),s("common:actions.create")]})]})]})]})]}),v?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(B,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):j.length===0?e.jsx(je,{children:e.jsxs(ve,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(Pe,{className:"h-12 w-12 text-muted-foreground
6/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("collaborators.empty.title")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("collaborators.empty.description")})]})}):e.jsx("div",{className:"space-y-3",children:j.map(a=>{var p;return e.jsxs(je,{className:a.is_active?"":"opacity-60",children:[e.jsx(Oe,{className:"pb-2",children: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-9 h-9 rounded-full bg-accent/20 flex items-center justify-center",children:e.jsx("span",{className:"text-accent font-semibold text-sm",children:a.name.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx(Ee,{className:"text-sm",children:a.name}),e.jsx(Ve,{className:"text-xs",children:a.email})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{variant:a.is_active?"default":"secondary",className:"text-[10px]",children:a.is_active?s("collaborators.status.active"):s("collaborators.status.inactive")}),e.jsx(J,{checked:a.is_active,onCheckedChange:()=>ke(a)}),e.jsx("button",{onClick:()=>h(P===a.id?null:a.id),className:"p-1.5 rounded-md hover:bg-secondary text-muted-foreground",children:P===a.id?e.jsx(Xe,{className:"h-4 w-4"}):e.jsx(Me,{className:"h-4 w-4"})}),e.jsxs(as,{children:[e.jsx(Ts,{asChild:!0,children:e.jsx("button",{className:"p-1.5 rounded-md hover:bg-destructive/10 text-muted-foreground hover:text-destructive",children:e.jsx(ye,{className:"h-4 w-4"})})}),e.jsxs(is,{children:[e.jsxs(os,{children:[e.jsx(ns,{children:s("collaborators.deleteDialog.title")}),e.jsxs(rs,{children:[s("collaborators.deleteDialog.description.pre")," ",e.jsx("strong",{children:a.name})," (",a.email,")."]})]}),e.jsxs(ls,{children:[e.jsx(cs,{children:s("common:actions.cancel")}),e.jsx(ds,{onClick:()=>we(a.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:s("common:actions.delete")})]})]})]})]})]})}),P===a.id&&e.jsxs(ve,{className:"pt-2 space-y-4",children:[e.jsx(ge,{permissions:a.permissions,onChange:(f,g)=>Z(a.id,f,g)}),e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium text-foreground flex items-center gap-1.5",children:[e.jsx(zs,{className:"h-4 w-4 text-accent"}),s("collaborators.visibleInstances.title")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:s("collaborators.visibleInstances.description")})]}),e.jsx(J,{checked:a.allowed_instance_ids!==null,onCheckedChange:f=>{k(g=>g.map(E=>E.id===a.id?{...E,allowed_instance_ids:f?[]:null}:E))}})]}),a.allowed_instance_ids!==null?e.jsxs("div",{className:"space-y-2 pl-2 border-l-2 border-accent/30",children:[z.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("collaborators.visibleInstances.noInstancesFound")}):z.map(f=>{var E;const g=((E=a.allowed_instance_ids)==null?void 0:E.includes(f.id))||!1;return e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(X,{checked:g,onCheckedChange:W=>{k(Se=>Se.map(ie=>{if(ie.id!==a.id)return ie;const be=ie.allowed_instance_ids||[],Ce=W?[...be,f.id]:be.filter(Ae=>Ae!==f.id);return{...ie,allowed_instance_ids:Ce}}))}}),e.jsx("span",{className:"text-sm",children:f.instance_name}),f.phone_number&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",f.phone_number,")"]}),e.jsx(_e,{variant:f.status==="connected"?"default":"secondary",className:"text-[10px] ml-auto",children:f.status==="connected"?s("collaborators.visibleInstances.online"):f.status})]},f.id)}),((p=a.allowed_instance_ids)==null?void 0:p.length)===0&&z.length>0&&e.jsxs("p",{className:"text-xs text-amber-500",children:["⚠️ ",s("collaborators.visibleInstances.noneSelectedWarning")]})]}):e.jsx("p",{className:"text-xs text-muted-foreground ml-2",children:s("collaborators.visibleInstances.allVisible")})]}),e.jsx("div",{className:"flex justify-end mt-4 gap-2",children:e.jsxs(T,{size:"sm",onClick:()=>fe(a),disabled:L,children:[L&&e.jsx(B,{className:"h-4 w-4 mr-2 animate-spin"}),s("collaborators.savePermissions")]})})]})]},a.id)})})]})},We={nameRaw:"",description:"",type:"text",value:""},dt=()=>{const{t:s}=oe(["settings"]),{userId:n,variables:i,isLoading:m,invalidate:j}=Zs(),[k,z]=o.useState(""),[D,v]=o.useState(!1),[R,L]=o.useState(null),[l,b]=o.useState(We),[y,G]=o.useState(!1),[O,P]=o.useState(null),[h,c]=o.useState(!1),r=o.useMemo(()=>{const d=k.trim().toLowerCase();return d?i.filter(A=>A.name.toLowerCase().includes(d)||A.description.toLowerCase().includes(d)):i},[i,k]),w=()=>{L(null),b(We),v(!0)},_=d=>{L(d),b({nameRaw:d.name,description:d.description,type:d.type,value:d.value}),v(!0)},V=l.type==="number"&&l.value.trim()!==""?!Number.isFinite(Number(l.value.trim().replace(",","."))):!1,M=async()=>
6{if(!n||y)return;if(R){if(V){S.error(s("globalVariables.form.valueInvalidNumber"));return}G(!0);const{error:H}=await N.from("global_variables").update({description:l.description.trim(),type:l.type,value:l.value}).eq("id",R.id).eq("user_id",n);if(G(!1),H){S.error(s(He(H)));return}S.success(s("globalVariables.toasts.updated")),v(!1),j();return}const d=Ys(l.nameRaw);if(!Ks(d)){S.error(s("globalVariables.form.nameInvalid"));return}if(V){S.error(s("globalVariables.form.valueInvalidNumber"));return}if(i.length>=Qs){S.error(s("globalVariables.toasts.limitReached"));return}G(!0);const{error:A}=await N.from("global_variables").insert({user_id:n,name:d,description:l.description.trim(),type:l.type,value:l.value});if(G(!1),A){S.error(s(He(A)));return}S.success(s("globalVariables.toasts.created")),v(!1),j()},F=async()=>{if(!n||!O||h)return;c(!0);const{error:d}=await N.from("global_variables").delete().eq("id",O.id).eq("user_id",n);if(c(!1),d){S.error(s("globalVariables.toasts.error"));return}S.success(s("globalVariables.toasts.deleted")),P(null),j()},q=d=>d==="number"?e.jsx(_e,{variant:"secondary",className:"text-[10px]",children:s("globalVariables.typeNumber")}):e.jsx(_e,{variant:"outline",className:"text-[10px]",children:s("globalVariables.typeText")});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:s("globalVariables.title")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s("globalVariables.subtitle",{token:"{{g_nome}}"})})]}),e.jsxs(T,{onClick:w,className:"shrink-0",children:[e.jsx(ue,{className:"h-4 w-4 mr-1"}),s("globalVariables.newButton")]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(us,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(U,{value:k,onChange:d=>z(d.target.value),placeholder:s("globalVariables.searchPlaceholder"),className:"pl-9"})]}),m?e.jsx("div",{className:"rounded-lg border border-border p-10 text-center text-sm text-muted-foreground",children:s("globalVariables.loading")}):r.length===0?e.jsxs("div",{className:"rounded-lg border border-border p-10 text-center space-y-3",children:[e.jsx(it,{className:"h-10 w-10 mx-auto text-muted-foreground"}),i.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-medium",children:s("globalVariables.emptyTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("globalVariables.emptyDescription")}),e.jsxs(T,{variant:"secondary",onClick:w,className:"mt-2",children:[e.jsx(ue,{className:"h-4 w-4 mr-1"}),s("globalVariables.createButton")]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:s("globalVariables.noResults")})]}):e.jsx("div",{className:"rounded-lg border border-border divide-y divide-border overflow-hidden",children:r.map(d=>e.jsxs("div",{className:"flex items-center gap-3 p-3 hover:bg-secondary/40 transition-colors",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("code",{className:"text-sm font-mono text-primary",children:`{{${d.name}}}`}),q(d.type)]}),d.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:d.description})]}),e.jsx("div",{className:"text-sm text-muted-foreground max-w-[180px] truncate hidden sm:block",title:d.value,children:d.value||e.jsx("span",{className:"italic opacity-60",children:s("globalVariables.noValue")})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(T,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>_(d),children:e.jsx(Js,{className:"h-4 w-4"})}),e.jsx(T,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>P(d),children:e.jsx(ye,{className:"h-4 w-4"})})]})]},d.id))}),e.jsx(Qe,{open:D,onOpenChange:v,children:e.jsxs(Je,{className:"max-w-md",children:[e.jsxs(es,{children:[e.jsx(ss,{children:s(R?"globalVariables.form.editTitle":"globalVariables.form.createTitle")}),e.jsx(Ls,{children:s("globalVariables.form.description",{token:"{{g_exemplo}}"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"gv-name",children:s("globalVariables.form.nameLabel")}),e.jsx(U,{id:"gv-name",value:l.nameRaw,disabled:!!R,onChange:d=>b(A=>({...A,nameRaw:d.target.value})),placeholder:s("globalVariables.form.namePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"gv-description",children:s("globalVariables.form.descriptionLabel")}),e.jsx(U,{id:"gv-description",value:l.description,maxLength:Ws,onChange:d=>b(A=>({...A,description:d.target.value})),placeholder:s("globalVariables.form.descriptionPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:s("globalVariables.form.typeLabel")}),e.jsxs(Te,{value:l.type,onValueChange:d=>b(A=>({...A,type:d}
6)),children:[e.jsx(ze,{className:"w-full",children:e.jsx(Le,{})}),e.jsxs(De,{children:[e.jsx(ee,{value:"text",children:s("globalVariables.typeText")}),e.jsx(ee,{value:"number",children:s("globalVariables.typeNumber")})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("globalVariables.form.typeNote")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"gv-value",children:s("globalVariables.form.valueLabel")}),e.jsx(U,{id:"gv-value",value:l.value,maxLength:Xs,inputMode:l.type==="number"?"decimal":"text",onChange:d=>b(A=>({...A,value:d.target.value})),placeholder:l.type==="number"?"7.90":s("globalVariables.form.valuePlaceholder")})]})]}),e.jsxs(ts,{children:[e.jsx(T,{variant:"outline",onClick:()=>v(!1),children:s("globalVariables.form.cancel")}),e.jsx(T,{onClick:M,disabled:y,children:s(R?"globalVariables.form.save":"globalVariables.form.create")})]})]})}),e.jsx(as,{open:!!O,onOpenChange:d=>!d&&P(null),children:e.jsxs(is,{children:[e.jsxs(os,{children:[e.jsx(ns,{children:s("globalVariables.deleteDialog.title")}),e.jsx(rs,{children:s("globalVariables.deleteDialog.description",{name:(O==null?void 0:O.name)??"",token:O?`{{${O.name}}}`:""})})]}),e.jsxs(ls,{children:[e.jsx(cs,{children:s("globalVariables.form.cancel")}),e.jsx(ds,{onClick:d=>{d.preventDefault(),F()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:s("globalVariables.deleteDialog.confirm")})]})]})})]})},ut=["notifications","collaborators","global-variables"],mt=["integrations","pixel","logzz","elevenlabs","platform-ai"];function Tt(){const{t:s}=oe(["settings","common"]),{user:n}=Ke(),i=fs(),[m]=gs(),j=m.get("section"),k=j?mt.includes(j):!1,z=j,[D,v]=o.useState(z&&ut.includes(z)?z:"notifications");o.useState(!1),o.useEffect(()=>{n||i("/auth")},[n,i]),o.useEffect(()=>{if(!k)return;const l=m.get("tab")??(j==="integrations"?void 0:j);i(l?`/integrations?tab=${l}`:"/integrations",{replace:!0})},[k,j,m,i]);const R=[{id:"notifications",label:s("settingsPage.menu.notifications.label"),icon:Ye,description:s("settingsPage.menu.notifications.description"),submenu:[{label:s("settingsPage.menu.notifications.submenu.sales"),icon:et,onClick:()=>i("/settings/sale-notifications")},{label:s("settingsPage.menu.notifications.submenu.logzz"),icon:st,onClick:()=>i("/settings/logzz-notifications")}]},{id:"collaborators",label:s("collaborators.title"),icon:Pe,description:s("settingsPage.menu.collaborators.description"),badge:"Novo"},{id:"global-variables",label:s("settingsPage.menu.globalVariables.label"),icon:tt,description:s("settingsPage.menu.globalVariables.description")}],L=()=>{switch(D){case"notifications":return e.jsx($e,{});case"collaborators":return e.jsx(ct,{});case"global-variables":return e.jsx(dt,{});default:return e.jsx($e,{})}};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"fixed top-0 left-0 right-0 bg-background/95 backdrop-blur-sm border-b border-border z-50",children:e.jsx("div",{className:"container mx-auto px-4 h-14 md:h-16 flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{variant:"ghost",size:"icon",onClick:()=>i("/"),className:"shrink-0",children:e.jsx(at,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ds,{className:"h-5 w-5 text-accent"}),e.jsx("h1",{className:"text-lg font-semibold",children:s("settingsPage.title")})]})]})})}),e.jsxs("div",{className:"pt-16 flex",children:[e.jsx("aside",{className:"hidden md:flex w-64 min-h-[calc(100vh-4rem)] border-r border-border flex-col bg-card/50",children:e.jsx(Vs,{className:"flex-1 p-4",children:e.jsx("nav",{className:"space-y-2",children:R.map(l=>e.jsxs("div",{children:[e.jsxs(Ie.button,{onClick:()=>v(l.id),whileHover:{scale:1.02},whileTap:{scale:.98},className:Ne("w-full flex items-start gap-3 p-3 rounded-lg text-left transition-all",D===l.id?"bg-accent/10 border border-accent/50 text-accent":"hover:bg-secondary/50 border border-transparent"),children:[e.jsx(l.icon,{className:Ne("h-5 w-5 mt-0.5",D===l.id?"text-accent":"text-muted-foreground")}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:l.label}),l.badge&&e.jsx("span",{className:Ne("px-1.5 py-0.5 text-[10px] font-semibold rounded","bg-emerald-500/20 text-emerald-400"),children:s("integrationsSettings.badgeNew")})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:l.description})]})]}),D===l.id&&l.submenu&&e.jsx(Ie.div,{initial:{opacity:0,height:0}
6,animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"ml-8 mt-1 space-y-1",children:l.submenu.map((b,y)=>e.jsxs("button",{onClick:b.onClick,className:"w-full flex items-center gap-2 p-2 rounded-md text-left text-sm hover:bg-secondary/50 text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(b.icon,{className:"h-4 w-4"}),e.jsx("span",{children:b.label}),e.jsx(Os,{className:"h-3 w-3 ml-auto"})]},y))})]},l.id))})})}),e.jsx("div",{className:"md:hidden fixed top-14 left-0 right-0 z-30 bg-background/95 backdrop-blur-sm border-b border-border",children:e.jsx("div",{className:"flex overflow-x-auto scrollbar-none",children:R.map(l=>e.jsxs("button",{onClick:()=>v(l.id),className:Ne("flex items-center gap-2 px-4 py-3 text-xs font-medium whitespace-nowrap border-b-2 transition-colors shrink-0",D===l.id?"border-accent text-accent":"border-transparent text-muted-foreground"),children:[e.jsx(l.icon,{className:"h-4 w-4"}),e.jsx("span",{children:l.label})]},l.id))})}),e.jsx("main",{className:"flex-1 p-4 md:p-6 pt-16 md:pt-6 pb-24 md:pb-6",children:e.jsx(Es,{mode:"wait",children:e.jsx(Ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},className:"max-w-2xl mx-auto",children:L()},D)})})]})]})}export{Tt 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.