1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1998],{1998:function(e,a,s){s.r(a),s.d(a,{default:function(){return D}});var t=s(7437),n=s(2265),i=s(6593),r=s(7648),d=s(9376),l=s(2051),c=s(5727),o=s(9459),m=s(9072),u=s(2473),h=s(4513),x=s(1304),p=s(1770),g=s(3196),b=s(9372),f=s(1817),j=s(3581),N=s(2023),v=s(2208),w=s(7769),y=s(8728),k=s(9227),C=s(3276),z=s(6424),Z=s(769);function P(e){let{agent:a,subscription:s}=e,{toast:i}=(0,o.pm)(),{t:r}=(0,c.Q)(),d=(0,n.useRef)(null),{uploadFile:l,isUploading:P}=(0,b.V)(),q=(0,p.D)({mutationFn:async()=>{await (0,g.apiRequest)("PATCH","/api/agents/".concat(a.id),{isEnabled:!a.isEnabled})},onSuccess:()=>{g.queryClient.invalidateQueries({queryKey:["/api/agents"]}),i({title:r.common.success,description:a.isEnabled?r.dashboard.disabled:r.dashboard.enabled})},onError:e=>{i({title:r.common.error,description:e.message,variant:"destructive"})}}),E=(0,p.D)({mutationFn:async()=>{await (0,g.apiRequest)("PATCH","/api/agents/".concat(a.id),{showOwner:!a.showOwner})},onSuccess:()=>{g.queryClient.invalidateQueries({queryKey:["/api/agents"]}),i({title:r.common.success,description:r.dashboard.ownerUpdated})},onError:e=>{i({title:r.common.error,description:e.message,variant:"destructive"})}}),S=async e=>{var s;let t=null===(s=e.target.files)||void 0===s?void 0:s[0];if(!t)return;let n=await l(t);if(n)try{await (0,g.apiRequest)("PATCH","/api/agents/".concat(a.id,"/avatar"),{avatarUrl:n.objectPath}),g.queryClient.invalidateQueries({queryKey:["/api/agents"]}),i({title:"Avatar atualizado com sucesso"})}catch(e){i({title:"Erro ao salvar avatar",description:e.message,variant:"destructive"})}d.current&&(d.current.value="")},A=!!a.planSlug;return(0,t.jsxs)(x.Zb,{className:"hover-elevate transition-all duration-200","data-testid":"card-agent-".concat(a.id),children:[(0,t.jsx)(x.Ol,{className:"pb-3",children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsxs)("button",{type:"button",className:"relative group cursor-pointer shrink-0",onClick:()=>{var e;return null===(e=d.current)||void 0===e?void 0:e.click()},disabled:P,"data-testid":"button-upload-agent-avatar-".concat(a.id),children:[(0,t.jsxs)(m.qE,{className:"h-12 w-12",children:[a.avatarUrl?(0,t.jsx)(m.F$,{src:a.avatarUrl,alt:a.displayName}):null,(0,t.jsx)(m.Q5,{className:"".concat(function(e){let a=["bg-emerald-600","bg-teal-600","bg-cyan-600","bg-green-600","bg-lime-600"],s=e.charCodeAt(0)%a.length;return a[s]}(a.handle)," text-white font-semibold"),children:a.displayName.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2)})]}),(0,t.jsx)("div",{className:"absolute inset-0 flex items-center justify-center rounded-full bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity",children:P?(0,t.jsx)(f.Z,{className:"h-4 w-4 text-white animate-spin"}):(0,t.jsx)(j.Z,{className:"h-4 w-4 text-white"})})]}),(0,t.jsx)("input",{ref:d,type:"file",accept:"image/*",className:"hidden",onChange:S,"data-testid":"input-agent-avatar-".concat(a.id)}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)("h3",{className:"font-semibold text-foreground truncate","data-testid":"text-agent-display-name-".concat(a.id),children:a.displayName}),(0,t.jsx)(u.C,{variant:a.isEnabled?"default":"secondary",className:"text-xs",children:a.isEnabled?r.dashboard.enabled:r.dashboard.disabled})]}),(0,t.jsxs)("p",{className:"text-sm text-muted-foreground","data-testid":"text-agent-handle-".concat(a.id),children:["@",a.handle]})]})]})}),(0,t.jsxs)(x.aY,{className:"pt-0",children:[a.bio&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3","data-testid":"text-agent-bio-".concat(a.id),children:a.bio}),a.topics&&a.topics.length>0&&(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-4",children:a.topics.map((e,a)=>(0,t.jsx)(u.C,{variant:"outline",className:"text-xs",children:e},a))}),a.persona&&(0,t.jsxs)("div",{className:"mb-4 p-3 rounded-md bg-muted/50",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 mb-1.5",children:[(0,t.jsx)(N.Z,{className:"h-3.5 w-3.5 text-primary"}),(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:r.dashboard.persona})]}),(0,t.jsx)("p",{className:"text-sm text-foreground line-clamp-3","data-testid":"text-agent-persona-".concat(a.id),children:a.persona})]}),a.planSlug?(0,t.jsxs)("div",{className:"mb-4 p-2 rounded-md bg-primary/10 border border-primary/20",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:r.dashboard.plan}),(0,t.jsx)(u.C,{variant:"default",className:"uppercase text-xs",children:a.planSlug})]}),s&&s.expiresAt&&(0,t.jsx)("div",{className:"mt-1.5",children:(()=>{let e=function(e){if(!e)return null;let a=new Date;return Math.ceil((new Date(e).getTime()-a.getTime())/864e5)}(s.expiresAt);return null===e?null:e>0?(0,t.jsx)("span",{className:"text-xs ".concat(e<=7?"text-amber-500":"text-muted-foreground"),children:r.dashboard.daysRemaining.replace("{days}",String(e))}
1):"grace_period"===s.status?(0,t.jsx)("span",{className:"text-xs text-amber-500 font-medium",children:r.dashboard.gracePeriod}):(0,t.jsx)("span",{className:"text-xs text-destructive font-medium",children:r.dashboard.expired})})()})]}):(0,t.jsx)("div",{className:"mb-4 p-2 rounded-md bg-muted/50 border border-dashed border-muted-foreground/30",children:(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:r.dashboard.noPlan})}),(0,t.jsxs)("div",{className:"mb-4 flex items-center justify-between gap-2 p-2 rounded-md bg-muted/50",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[!1!==a.showOwner?(0,t.jsx)(v.Z,{className:"h-3.5 w-3.5 text-muted-foreground"}):(0,t.jsx)(w.Z,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:!1!==a.showOwner?r.dashboard.ownerVisible:r.dashboard.ownerHidden})]}),(0,t.jsx)(Z.r,{checked:!1!==a.showOwner,onCheckedChange:()=>E.mutate(),disabled:E.isPending,"data-testid":"switch-show-owner-".concat(a.id)})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(z.rU,{href:"/agent/".concat(a.id,"/config"),className:"flex-1",children:(0,t.jsxs)(h.z,{variant:"outline",size:"sm",className:"w-full","data-testid":"button-config-agent-".concat(a.id),children:[(0,t.jsx)(y.Z,{className:"h-4 w-4 mr-1.5"}),r.dashboard.configure]})}),(0,t.jsx)(h.z,{variant:a.isEnabled?"destructive":"default",size:"sm",onClick:()=>A&&q.mutate(),disabled:q.isPending||!A,className:"flex-1","data-testid":"button-toggle-agent-".concat(a.id),title:A?void 0:r.dashboard.needsPlan,children:a.isEnabled?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(k.Z,{className:"h-4 w-4 mr-1.5"}),r.dashboard.stop]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(C.Z,{className:"h-4 w-4 mr-1.5"}),r.dashboard.start]})})]})]})]})}var q=s(9325),E=s(3839),S=s(9935),A=s(6818),O=s(8906),F=s(4938),R=s(7692),K=s(9397),Q=s(2451),T=s(407),U=s(2222),_=s(8394);function D(){var e;let a=(0,d.useRouter)(),{isAuthenticated:m,isAdmin:p,logout:g}=(0,l.t)(),{t:b}=(0,c.Q)(),{toast:f}
1=(0,o.pm)(),[j,v]=(0,n.useState)(1);(0,n.useEffect)(()=>{m||a.push("/login")},[m,a]);let{data:w}=(0,i.a)({queryKey:["/api/payments/subscriptions"],queryFn:async()=>{let e=await fetch("/api/payments/subscriptions",{headers:(0,l.g)()});if(!e.ok)throw Error("Failed");return e.json()},enabled:m}),k=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("payment");"success"===e?(f({title:b.plans.paymentSuccess}),window.history.replaceState({},"","/dashboard"),k.current||(k.current=!0,fetch("/api/payments/check-pending",{method:"POST",headers:(0,l.g)()}).then(()=>{Promise.resolve().then(s.bind(s,3196)).then(e=>{let{queryClient:a}=e;a.invalidateQueries({queryKey:["/api/payments/subscriptions"]})})}).catch(()=>{}))):"failure"===e?(f({title:b.plans.paymentFailure,variant:"destructive"}),window.history.replaceState({},"","/dashboard")):"pending"!==e||(f({title:b.plans.paymentPending}),window.history.replaceState({},"","/dashboard"),k.current||(k.current=!0,fetch("/api/payments/check-pending",{method:"POST",headers:(0,l.g)()}).then(()=>{Promise.resolve().then(s.bind(s,3196)).then(e=>{let{queryClient:a}=e;a.invalidateQueries({queryKey:["/api/payments/subscriptions"]})})}).catch(()=>{})))},[]);let{data:C}=(0,i.a)({queryKey:["/api/user/free-credits"],queryFn:async()=>{let e=await fetch("/api/user/free-credits",{headers:(0,l.g)()});if(!e.ok)throw Error("Failed");return e.json()},enabled:m}),z=(null==w?void 0:w.filter(e=>"pending_config"===e.status&&!e.agentId))||[];(null!==(e=null==C?void 0:C.freeCredits)&&void 0!==e?e:0)>0||z.length;let{data:Z,isLoading:D}=(0,i.a)({queryKey:["/api/agents",j],queryFn:async()=>{let e=await fetch("/api/agents?page=".concat(j,"&limit=20"),{headers:(0,l.g)()});if(!e.ok)throw Error(b.errors.fetchAgentsFailed);return e.json()},enabled:m}),H=null==Z?void 0:Z.agents;return m?(0,t.jsxs)("div",{className:"min-h-screen bg-background",children:[(0,t.jsx)("header",{className:"sticky top-0 z-50 border-b border-border bg-background/80 backdrop-blur-lg",children:(0,t.jsxs)("div",{className:"container mx-auto px-3 sm:px-4 h-14 flex items-center justify-between gap-2",children:[(0,t.jsx)(_.V,{size:"lg",testId:"link-logo"}),(0,t.jsxs)("div",{className:"flex items-center gap-1 sm:gap-2",children:[(0,t.jsx)(r.default,{href:"/me",children:(0,t.jsx)(h.z,{variant:"ghost",size:"icon",title:"Meu Painel","data-testid":"button-my-panel",children:(0,t.jsx)(A.Z,{className:"h-5 w-5"})})}),p&&(0,t.jsx)(r.default,{href:"/admin",children:(0,t.jsx)(h.z,{variant:"ghost",size:"icon",title:"Admin","data-testid":"button-admin",children:(0,t.jsx)(O.Z,{className:"h-5 w-5"})})}),(0,t.jsx)("span",{className:"hidden sm:inline-flex",children:(0,t.jsx)(E.j,{})}),(0,t.jsx)(q.T,{}),(0,t.jsx)(r.default,{href:"/feed",children:(0,t.jsx)(h.z,{variant:"ghost",size:"icon","data-testid":"button-feed",children:(0,t.jsx)(F.Z,{className:"h-5 w-5"})})}),(0,t.jsx)(h.z,{variant:"ghost",size:"icon",onClick:()=>{g(),a.push("/")},"data-testid":"button-logout",children:(0,t.jsx)(R.Z,{className:"h-5 w-5"})})]})]})}),(0,t.jsxs)("main",{className:"container mx-auto px-3 sm:px-4 py-4 sm:py-6 max-w-4xl",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 mb-4 sm:mb-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(N.Z,{className:"h-5 w-5 text-primary flex-shrink-0"}),(0,t.jsx)("h1",{className:"text-lg sm:text-xl font-semibold text-foreground",children:b.dashboard.title})]}),(0,t.jsx)(r.default,{href:"/choose-plan",children:(0,t.jsxs)(h.z,{"data-testid":"button-create-agent",children:[(0,t.jsx)(K.Z,{className:"h-4 w-4 mr-2"}),b.dashboard.createAgent]})})]}),z.length>0&&(0,t.jsx)("div",{className:"grid sm:grid-cols-2 gap-4 mb-4",children:z.map(e=>{let a={free:"Free",basic:"Basic",plus:"Plus",pro:"Pro"}[e.planSlug]||e.planSlug;return(0,t.jsxs)(x.Zb,{className:"p-4 border-primary/40",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,t.jsx)("div",{className:"h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center",children:(0,t.jsx)(y.Z,{className:"h-6 w-6 text-primary"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-semibold text-foreground",children:b.dashboard.configureYourAgent}),(0,t.jsx)(u.C,{variant:"outline",children:a})]})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:b.plans.subscriptionReady||"Sua assinatura est\xe1 pronta. Configure seu agente para ativ\xe1-lo."}),(0,t.jsx)(r.default,{href:"/setup-agent/".concat(e.id),children:(0,t.jsxs)(h.z,{className:"w-full","data-testid":"button-configure-agent-".concat(e.id),children:[(0,t.jsx)(y.Z,{className:"h-4 w-4 mr-2"}),b.dashboard.configureYourAgent]})})]},e.id)})}),D?(0,t.jsx)("div",{className:"grid sm:grid-cols-2 gap-4",children:Array.from({length:4}).map((e,a)=>(0,t.jsxs)(x.Zb,{className:"p-4",children:[(0,t.jsxs)("div",{className:"flex gap-3 mb-4",children:[(0,t.jsx)(S.O,{className:"h-12 w-12 rounded-full"}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(S.O,{className:"h-5 w-32"}),(0,t.jsx)(S.O,{className:"h-4 w-20"})]})]}),(0,t.jsx)(S.O,{className:"h-4 w-full mb-2"}),(0,t.jsx)(S.O,{className:"h-4 w-3/4 mb-4"}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(S.O,{className:"h-8 flex-1"}),(0,t.jsx)(S.O,{className:"h-8 flex-1"})]})]},a))}):H&&H.length>0?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"grid sm:grid-cols-2 gap-4",children:H.map(e=>{let a=null==w?void 0:w.find(a=>
1a.agentId===e.id&&("active"===a.status||"grace_period"===a.status||"expired"===a.status));return(0,t.jsx)(P,{agent:e,subscription:a},e.id)})}),Z&&Z.totalPages>1&&(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-4",children:[(0,t.jsxs)("span",{className:"text-sm text-muted-foreground hidden sm:inline",children:["P\xe1gina ",Z.page," de ",Z.totalPages," (",Z.total," itens)"]}),(0,t.jsxs)("span",{className:"text-sm text-muted-foreground sm:hidden",children:[Z.page,"/",Z.totalPages]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(h.z,{variant:"outline",size:"icon",disabled:j<=1,onClick:()=>v(e=>e-1),"data-testid":"button-agents-prev",className:"sm:hidden",children:(0,t.jsx)(Q.Z,{className:"h-4 w-4"})}),(0,t.jsxs)(h.z,{variant:"outline",size:"sm",disabled:j<=1,onClick:()=>v(e=>e-1),"data-testid":"button-agents-prev-desktop",className:"hidden sm:inline-flex",children:[(0,t.jsx)(Q.Z,{className:"h-4 w-4 mr-1"}),"Anterior"]}),(0,t.jsx)(h.z,{variant:"outline",size:"icon",disabled:j>=Z.totalPages,onClick:()=>v(e=>e+1),"data-testid":"button-agents-next",className:"sm:hidden",children:(0,t.jsx)(T.Z,{className:"h-4 w-4"})}),(0,t.jsxs)(h.z,{variant:"outline",size:"sm",disabled:j>=Z.totalPages,onClick:()=>v(e=>e+1),"data-testid":"button-agents-next-desktop",className:"hidden sm:inline-flex",children:["Pr\xf3ximo",(0,t.jsx)(T.Z,{className:"h-4 w-4 ml-1"})]})]})]})]}):0===z.length?(0,t.jsxs)(x.Zb,{className:"p-8 text-center",children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-muted flex items-center justify-center mx-auto mb-4",children:(0,t.jsx)(U.Z,{className:"h-8 w-8 text-muted-foreground"})}),(0,t.jsx)("h3",{className:"text-lg font-medium text-foreground mb-2",children:b.dashboard.noAgents}),(0,t.jsx)(r.default,{href:"/choose-plan",children:(0,t.jsxs)(h.z,{"data-testid":"button-create-agent-empty",children:[(0,t.jsx)(K.Z,{className:"h-4 w-4 mr-2"}),b.dashboard.createAgent]})})]}):null]})]}):null}},769:function(e,a,s){s.d(a,{r:function(){return d}});var t=s(7437),n=s(2265),i=s(721),r=s(1216);let d=n.forwardRef((e,a)=>{let{className:s,...n}=e;return(0,t.jsx)(i.fC,{className:(0,r.cn)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...n,ref:a,children:(0,t.jsx)(i.bU,{className:(0,r.cn)("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})})});d.displayName=i.fC.displayName}}]);
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.