PageSourceSearch

https://app.beeplace.ai/assets/Settings-DkSxnlHh.js

js beeplace.ai collected 2026-10-05 14:39:12 UTC 86,875 bytes, 6 lines download raw bytes

1import{Y as $s,P as ms,w as H,g as o,j as e,v as Ee,bL as Bs,b as X,b1 as Ks,z as Qs,aa as we,ab as Ce,ac as Se,ad as ke,ae as Ie,t as se,aX as Vs,U as h,K as W,aH as ze,ar as De,bM as Hs,B as v,as as Le,at as Re,au as _e,av as us,an as je,bN as xs,aJ as Ue,I as R,R as Js,A as Fe,D as Te,F as Z,G as A,H as Pe,J as M,k as Ve,V as Ys,i as Gs,am as Ws,cr as gs,e as ys,c as He,Q as te,l as de,af as bs,aI as ws,bj as Xs,b6 as Cs,a8 as rs,d1 as Zs,aG as re,a3 as et,aE as st,aK as Ss,aP as tt,ak as ks,al as Is,aL as L,W as Fs,d2 as at,u as nt,E as it,cc as rt,cy as lt,c$ as ot}from"./index--HPZSr6_.js";import{T as ct,a as dt,b as Ne,c as ye}from"./tabs-CfSqkchZ.js";import{b as mt,g as ut}from"./DatagridFilters-CfeiM_1G.js";import{E as xt}from"./ellipsis-Ut6gAC67.js";import{p as Be,e as Je,f as be}from"./pt-BR-D9D5SaqL.js";import{S as xe,a as he,b as pe,c as ge,d as ee}from"./select-CGEqyPDB.js";import{P as ht,a as pt,b as gt}from"./popover-pwyEPOCM.js";import{C as jt}from"./calendar-BZ9IhgeT.js";import{F as ls}from"./filter-C6UUYBOY.js";import{P as fe}from"./plus-TqaS31sx.js";import{C as os}from"./calendar-CvanVCF4.js";import{A as Ts}from"./AutocompleteSearch-BVq_Qknp.js";import{F as Ye}from"./FormSubmitButton-DRyq27R3.js";import{u as ft}from"./useRcsTemplates-BDmIjjuE.js";import{I as vt,a as Nt,b as Oe}from"./input-otp-CPdV0Yed.js";import{e as Ps}from"./uploadService-BGAFA3uS.js";import{T as yt}from"./TwoFactorNotConfigured-BaW7vy8_.js";import{I as $e}from"./image-IlnWQlZ-.js";import{M as Es}from"./mouse-pointer-click-CgIfLdG5.js";import{C as bt}from"./clock-uGz1D6IW.js";import{S as cs}from"./SaveTwoFactorDialog-BbTwW-34.js";import{P as Ge}from"./pencil-DgZyCAJv.js";import{T as wt}from"./type-D5LUtWFc.js";import{I as Ct}from"./ImageUploadDialog-Bv_BS7YI.js";import{S as St}from"./shield-BsqvMGy7.js";import{S as kt}from"./switch-BPSRNGrC.js";import{T as hs}from"./TwoFactorForm-B-Ix0zGo.js";import{S as It}from"./save-NFugsJBQ.js";import{T as js}from"./tag-Ck6HQ7yq.js";import{D as Ds,a as Ls}from"./DatagridActionsBar-BgB9A1RY.js";import{u as Rs}from"./useDatagrid-Du9X9CK7.js";import{F as _s}from"./file-spreadsheet-D-ZuxRaF.js";import"./index-CruLLK-Z.js";import"./subDays-CB4gPp4A.js";import"./endOfMonth-CHhJm54O.js";import"./shield-alert-CIcJxkwK.js";import"./arrow-left-Dep2T0Bt.js";import"./bug-OiFWbrU5.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 fs=$s("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]);function Ft({page:s=1,activeFilters:t=[],filterFields:n=[]}={}){return ms({queryKey:["audit-logs",s,t],queryFn:async()=>{const a=`/admin/logs?${mt(s)}`,i=Tt(t,n);return console.log("Audit logs request URL:",a),i&&console.log("Audit logs request body:",JSON.stringify(i,null,2)),await H.get(a,{body:i})}})}function Tt(s,t){if(s.length===0)return;const n={},l={},a=i=>t.find(c=>c.id===i);if(s.forEach(i=>{var j;const c=a(i.fieldId);if(!c||i.value===void 0||i.value===null||i.value==="")return;const g=c.id;if(c.type==="date_interval"&&((j=i.dateRange)!=null&&j.from)){const y=i.dateRange.from.getFullYear(),u=String(i.dateRange.from.getMonth()+1).padStart(2,"0"),k=String(i.dateRange.from.getDate()).padStart(2,"0"),w=`${y}-${u}-${k}`;let b=w;if(i.dateRange.to){const I=i.dateRange.to.getFullYear(),S=String(i.dateRange.to.getMonth()+1).padStart(2,"0"),F=String(i.dateRange.to.getDate()).padStart(2,"0");b=`${I}-${S}-${F}`}n[g]={from:w,to:b}}else n[g]=i.value;l[g]=i.queryType}),Object.keys(n).length!==0)return{params:n,filters:l}}function Pt(s){return ms({queryKey:["audit-log-detail",s],queryFn:async()=>s?(await H.get(`/admin/logs/${s}`)).list:null,enabled:!!s})}const As=({className:s,...t})=>e.jsx("nav",{role:"navigation","aria-label":"pagination",className:Ee("mx-auto flex w-full justify-center",s),...t});As.displayName="Pagination";const qs=o.forwardRef(({className:s,...t},n)=>e.jsx("ul",{ref:n,className:Ee("flex flex-row items-center gap-1",s),...t}));qs.displayName="PaginationContent";const ue=o.forwardRef(({className:s,...t},n)=>e.jsx("li",{ref:n,className:Ee("",s),...t}));ue.displayName="PaginationItem";const Me=({className:s,isActive:t,size:n="icon",...l})=>e.jsx("a",{"aria-current":t?"page":void 0,className:Ee(Bs({variant:t?"outline":"ghost",size:n}),s),...l});Me.displayName="PaginationLink";const Os=({className:s,...t})=>{const{t:n}=X();return e.jsxs(Me,{"aria-label":n("orders.goToPrevious"),size:"default",className:Ee("gap-1 pl-2.5",s),...t,children:[e.jsx(Ks,{className:"h-4 w-4"}),e.jsx("span",{children:n("orders.previous")})]})};Os.displayName="PaginationPrevious";const zs=({className:s,...t})=>{const{t:n}=X();return e.jsxs(Me,{"aria-label":n("orders.goToNext"),size:"default",className:Ee("gap-1 pr-2.5",s),...t,children:[e.jsx("span",{children:n("orders.next")}),e.jsx(Qs,{className:"h-4 w-4"})]})};zs.displayName="PaginationNext";const ds=({className:s,...t})=>{const{t:n}=X();
6return e.jsxs("span",{"aria-hidden":!0,className:Ee("flex h-9 w-9 items-center justify-center",s),...t,children:[e.jsx(xt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("orders.morePages")})]})};ds.displayName="PaginationEllipsis";function Et(s){switch(s.toUpperCase()){case"GET":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400";case"POST":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400";case"PUT":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400";case"DELETE":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400";case"PATCH":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400";default:return"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400"}}function Dt(s){try{return JSON.parse(s)}catch{return s}}function as(s){if(typeof s=="string"){const t=Dt(s);return typeof t=="object"?JSON.stringify(t,null,2):s}return JSON.stringify(s,null,2)}function Lt({logId:s,open:t,onOpenChange:n}){var y,u,k;const{t:l,i18n:a}=X(),{data:i,isLoading:c}=Pt(s),g=a.language==="pt-BR"?Be:Je,j=w=>{try{return be(new Date(w),"dd/MM/yyyy HH:mm:ss",{locale:g})}catch{return"-"}};return e.jsx(we,{open:t,onOpenChange:n,children:e.jsxs(Ce,{className:"max-w-3xl max-h-[90vh]",children:[e.jsxs(Se,{children:[e.jsx(ke,{children:l("audit.logDetail")}),e.jsx(Ie,{children:l("audit.logDetailDescription")})]}),c?e.jsxs("div",{className:"space-y-4",children:[e.jsx(se,{className:"h-6 w-48"}),e.jsx(se,{className:"h-24 w-full"}),e.jsx(se,{className:"h-48 w-full"})]}):i?e.jsx(Vs,{className:"max-h-[60vh] pr-4",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.date")}),e.jsx("p",{className:"font-medium",children:j(i.created_at)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.method")}),e.jsx(W,{className:Et(i.method),children:i.method})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.endpoint")}),e.jsx("p",{className:"font-mono text-sm break-all",children:i.url})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.ip")}),e.jsx("p",{className:"font-mono text-sm",children:i.ip})]})]}),e.jsx(ze,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold",children:l("audit.userInfo")}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.userName")}),e.jsx("p",{className:"font-medium",children:((y=i.user)==null?void 0:y.name)||"-"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.userId")}),e.jsx("p",{className:"font-mono text-sm",children:((u=i.user)==null?void 0:u.id)||"-"})]}),e.jsxs("div",{className:"space-y-1 col-span-2",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.userEmail")}),e.jsx("p",{className:"font-medium",children:((k=i.user)==null?void 0:k.email)||"-"})]})]})]}),e.jsx(ze,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold",children:l("audit.requestBody")}),e.jsx("pre",{className:"bg-muted/50 rounded-lg p-4 text-xs overflow-x-auto max-h-48",children:as(i.body)})]}),i.params&&i.params!=="[]"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold",children:l("audit.requestParams")}),e.jsx("pre",{className:"bg-muted/50 rounded-lg p-4 text-xs overflow-x-auto max-h-48",children:as(i.params)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold",children:l("audit.headers")}),e.jsx("pre",{className:"bg-muted/50 rounded-lg p-4 text-xs overflow-x-auto max-h-48",children:as(i.headers)})]})]})}):e.jsx("p",{className:"text-center text-muted-foreground py-8",children:l("audit.logNotFound")})]})})}function Rt({filterFields:s,onApplyFilters:t,activeFiltersCount:n=0}){const{t:l,i18n:a}=X(),[i,c]=o.useState(!1),[g,j]=o.useState([]),[y,u]=o.useState(""),k=a.language==="pt-BR"?Be:Je,w=s.filter(d=>!g.some(f=>f.fieldId===d.id)),b=d=>s.find(f=>f.id===d),I=()=>
6{if(!y)return;const d=b(y);if(!d)return;const f={id:`${y}-${Date.now()}`,fieldId:y,value:"",queryType:ut(d)};j(r=>[...r,f]),u("")},S=d=>{j(f=>f.filter(r=>r.id!==d))},F=(d,f)=>{j(r=>r.map(P=>P.id===d?{...P,value:f}:P))},m=(d,f)=>{j(r=>r.map(P=>P.id===d?{...P,queryType:f}:P))},z=(d,f)=>{j(r=>r.map(P=>P.id===d?{...P,dateRange:f,value:f}:P))},N=()=>{const d=g.filter(f=>!(f.value===void 0||f.value===null||f.value===""));t(d,s),c(!1)},T=()=>{j([]),t([],s),c(!1)},V=d=>{var r,P;const f=b(d.fieldId);return f?f.type==="date_interval"?e.jsxs(ht,{children:[e.jsx(pt,{asChild:!0,children:e.jsxs(v,{variant:"outline",className:"w-full justify-start text-left font-normal",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),(r=d.dateRange)!=null&&r.from?d.dateRange.to?e.jsxs(e.Fragment,{children:[be(d.dateRange.from,"dd/MM/yyyy",{locale:k})," -"," ",be(d.dateRange.to,"dd/MM/yyyy",{locale:k})]}):be(d.dateRange.from,"dd/MM/yyyy",{locale:k}):e.jsx("span",{className:"text-muted-foreground",children:l("common.selectPeriod")})]})}),e.jsx(gt,{className:"w-auto p-0",align:"start",children:e.jsx(jt,{initialFocus:!0,mode:"range",defaultMonth:(P=d.dateRange)==null?void 0:P.from,selected:d.dateRange,onSelect:C=>z(d.id,C),numberOfMonths:2,locale:k})})]}):f.type==="autocomplete"&&f.options_default?e.jsxs(xe,{value:d.value||"",onValueChange:C=>F(d.id,C),children:[e.jsx(he,{children:e.jsx(pe,{placeholder:l("audit.selectValue")})}),e.jsx(ge,{children:f.options_default.map(C=>e.jsx(ee,{value:C.id,children:C.name},C.id))})]}):e.jsx(R,{placeholder:l("audit.enterValue"),value:d.value||"",onChange:C=>F(d.id,C.target.value)}):null};return e.jsxs(De,{open:i,onOpenChange:c,children:[e.jsx(Hs,{asChild:!0,children:e.jsxs(v,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ls,{className:"h-4 w-4"}),l("common.filters"),n>0&&e.jsx("span",{className:"bg-primary text-primary-foreground rounded-full px-2 py-0.5 text-xs",children:n})]})}),e.jsxs(Le,{side:"right",className:"w-full sm:max-w-md flex flex-col",children:[e.jsxs(Re,{children:[e.jsx(_e,{children:l("common.filters")}),e.jsx(us,{children:l("audit.filtersDescription")})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-6 px-1 space-y-4",children:[g.map(d=>{const f=b(d.fieldId);return f?e.jsxs("div",{className:"space-y-3 p-4 border rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{className:"font-medium",children:f.label}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>S(d.id),children:e.jsx(je,{className:"h-4 w-4"})})]}),f.query_types.length>1&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(h,{className:"text-xs text-muted-foreground whitespace-nowrap",children:[l("audit.queryType"),":"]}),e.jsxs(xe,{value:d.queryType,onValueChange:r=>m(d.id,r),children:[e.jsx(he,{className:"h-8 text-xs",children:e.jsx(pe,{})}),e.jsx(ge,{children:f.query_types.map(r=>e.jsx(ee,{value:r,className:"text-xs",children:r},r))})]})]}),f.query_types.length===1&&e.jsx(W,{variant:"secondary",className:"text-xs",children:d.queryType}),V(d)]},d.id):null}),w.length>0&&e.jsxs(e.Fragment,{children:[g.length>0&&e.jsx(ze,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"text-muted-foreground",children:l("audit.addFilter")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(xe,{value:y,onValueChange:u,children:[e.jsx(he,{className:"flex-1",children:e.jsx(pe,{placeholder:l("audit.selectField")})}),e.jsx(ge,{children:w.map(d=>e.jsx(ee,{value:d.id,children:d.label},d.id))})]}),e.jsx(v,{variant:"outline",size:"icon",onClick:I,disabled:!y,children:e.jsx(fe,{className:"h-4 w-4"})})]})]})]}),g.length===0&&e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ls,{className:"h-12 w-12 mx-auto mb-4 opacity-20"}),e.jsx("p",{children:l("audit.noFiltersAdded")}),e.jsx("p",{className:"text-sm",children:l("audit.addFilterHint")})]})]}),e.jsxs(xs,{className:"flex flex-col gap-2 border-t pt-4 mt-auto",children:[e.jsx(v,{onClick:N,className:"w-full",disabled:g.length===0,children:l("common.applyFilters")}),g.length>0&&e.jsxs(v,{variant:"outline",onClick:T,className:"w-full",children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"}),l("common.clearAll")]})]})]})]})}function _t(s){switch(s.toUpperCase()){case"GET":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400";case"POST":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400";case"PUT":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400";case"DELETE":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400";case"PATCH":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400";default:return"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400"}}function At(){var f,r,P;const{t:s,i18n:t}=X(),[n,l]=o.useState(1),[a,i]=o.useState(null),[c,g]=o.useState([]),[j,y]=o.useState([]),{data:u,isLoading:k,refetch:w,isFetching:b}=Ft({page:n,activeFilters:c,filterFields:j}),I=t.language==="pt-BR"?Be:Je;(f=u==null?void 0:u.data)!=null&&f.filter_fields&&j.length===0&&y(u.data.filter_fields);const S=((r=u==null?void 0:u.data)==null?void 0:r.list)||[],F=(P=u==null?void 0:u.data)==null?void 0:P.pagination,m=(F==null?void 0:F.pages)||[],z=C=>{try{return be(new Date(C),"dd/MM/yyyy HH:mm:ss",{locale:I})}catch{return"-"}},N=(C,p)=>{g(C),y(p),l(1)},T=()=>{g([]),l(1)},V=c.length>0,d=()=>
6{if(!m.length)return null;const C=5,p=Math.max(1,n-Math.floor(C/2)),q=Math.min(m[m.length-1],p+C-1),Y=m.filter(x=>x>=p&&x<=q);return e.jsx(As,{children:e.jsxs(qs,{children:[e.jsx(ue,{children:e.jsx(Os,{onClick:()=>l(x=>Math.max(1,x-1)),className:n===1?"pointer-events-none opacity-50":"cursor-pointer"})}),p>1&&e.jsxs(e.Fragment,{children:[e.jsx(ue,{children:e.jsx(Me,{onClick:()=>l(1),className:"cursor-pointer",children:"1"})}),p>2&&e.jsx(ue,{children:e.jsx(ds,{})})]}),Y.map(x=>e.jsx(ue,{children:e.jsx(Me,{onClick:()=>l(x),isActive:n===x,className:"cursor-pointer",children:x})},x)),q<m[m.length-1]&&e.jsxs(e.Fragment,{children:[q<m[m.length-1]-1&&e.jsx(ue,{children:e.jsx(ds,{})}),e.jsx(ue,{children:e.jsx(Me,{onClick:()=>l(m[m.length-1]),className:"cursor-pointer",children:m[m.length-1]})})]}),e.jsx(ue,{children:e.jsx(zs,{onClick:()=>l(x=>Math.min(m[m.length-1],x+1)),className:n===m[m.length-1]?"pointer-events-none opacity-50":"cursor-pointer"})})]})})};return k?e.jsxs("div",{className:"space-y-4",children:[e.jsx(se,{className:"h-10 w-full"}),e.jsx(se,{className:"h-64 w-full"})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Rt,{filterFields:j,onApplyFilters:N,activeFiltersCount:c.length}),V&&e.jsxs(v,{variant:"ghost",size:"sm",onClick:T,className:"text-muted-foreground hover:text-destructive",children:[e.jsx(Ue,{className:"h-4 w-4 mr-1"}),s("common.clearAll")]})]}),e.jsx(v,{variant:"outline",size:"icon",onClick:()=>w(),disabled:b,children:e.jsx(Js,{className:`h-4 w-4 ${b?"animate-spin":""}`})})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(Fe,{children:[e.jsx(Te,{children:e.jsxs(Z,{children:[e.jsx(A,{className:"w-16",children:s("audit.actions")}),e.jsx(A,{children:s("audit.date")}),e.jsx(A,{children:s("audit.user")}),e.jsx(A,{children:s("audit.userId")}),e.jsx(A,{children:s("audit.method")}),e.jsx(A,{children:s("audit.endpoint")})]})}),e.jsx(Pe,{children:S.length===0?e.jsx(Z,{children:e.jsx(M,{colSpan:6,className:"text-center py-8 text-muted-foreground",children:s("audit.noLogs")})}):S.map(C=>{var p,q;return e.jsxs(Z,{children:[e.jsx(M,{children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>i(C.id),title:s("common.view"),children:e.jsx(Ve,{className:"h-4 w-4"})})}),e.jsx(M,{className:"whitespace-nowrap",children:z(C.created_at)}),e.jsx(M,{children:((p=C.user)==null?void 0:p.name)||"-"}),e.jsx(M,{className:"font-mono text-xs",children:((q=C.user)==null?void 0:q.id)||"-"}),e.jsx(M,{children:e.jsx(W,{className:_t(C.method),children:C.method})}),e.jsx(M,{className:"font-mono text-xs max-w-xs truncate",title:C.url,children:C.url})]},C.id)})})]})}),F&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:F.title}),d()]}),e.jsx(Lt,{logId:a,open:!!a,onOpenChange:C=>!C&&i(null)})]})}function qt({open:s,onOpenChange:t,channel:n}){var I,S;const{t:l}=X(),[a,i]=o.useState(null),[c,g]=o.useState(null),[j,y]=o.useState(!1);o.useEffect(()=>{if(s&&n){const F=n.automations_scenarios?{id:n.automations_scenarios.id,name:n.automations_scenarios.name}:null;g(F),i(F)}},[s,n]);const u=(a==null?void 0:a.id)!==(c==null?void 0:c.id),k=async()=>{if(!(!u||!n)){y(!0);try{await H.put(`/admin/action/automations/scenarios/${n.id}`,{automations_scenarios:a?{id:a.id,name:a.name}:null}),g(a),gs({title:l("common.success","Sucesso"),description:l("settings.scenarioSaved","Cenário vinculado com sucesso.")})}catch(F){gs({title:l("common.error","Erro"),description:F.message,variant:"destructive"})}finally{y(!1)}}};if(!n)return null;const w=!!((I=n.linked_channel)!=null&&I.id),b=(a==null?void 0:a.id)??((S=n.automations_scenarios)==null?void 0:S.id)??null;return e.jsx(De,{open:s,onOpenChange:t,children:e.jsxs(Le,{className:"sm:max-w-[540px] flex flex-col gap-0 p-0",children:[e.jsx(Re,{className:"px-6 py-4 border-b pr-12",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_e,{className:"text-lg font-semibold",children:l("settings.whatsappConfig","Configuração WhatsApp")}),e.jsx(W,{variant:n.status.id==="active"?"default":"secondary",className:n.status.id==="active"?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400":"",children:n.status.name})]}),e.jsx(Ye,{isDirty:u,isSubmitting:j,label:l("common.save","Salvar"),onClick:k})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-6 space-y-6",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:l("settings.channelId","ID do Canal")}),e.jsx(Ys,{value:n.id,readOnly:!0,className:"font-mono text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:l("settings.name")}
6),e.jsx(R,{value:n.name,readOnly:!0,className:"border-0 border-b rounded-none px-0 focus-visible:ring-0 focus-visible:border-primary"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:l("settings.type")}),e.jsx(R,{value:n.type.name,readOnly:!0,className:"border-0 border-b rounded-none px-0 focus-visible:ring-0 focus-visible:border-primary"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:l("settings.templates")}),e.jsx(R,{value:String(n.templates_quantity),readOnly:!0,className:"border-0 border-b rounded-none px-0 focus-visible:ring-0 focus-visible:border-primary"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[b?e.jsxs(Gs,{to:`/automation/scenarios/${b}`,onClick:()=>t(!1),className:"inline-flex items-center gap-1 text-xs uppercase tracking-wider text-primary font-medium hover:underline",children:[l("settings.automationScenario","Cenário de Automação"),e.jsx(Ws,{className:"h-3 w-3 opacity-70","aria-hidden":!0})]}):e.jsx(h,{className:"text-xs uppercase tracking-wider text-muted-foreground",children:l("settings.automationScenario","Cenário de Automação")}),e.jsx(Ts,{endpoint:"/admin/list/automations/scenarios",queryParam:"q",minChars:0,placeholder:l("settings.searchScenario","Buscar cenário..."),value:a,onSelect:i,hideDocument:!0,disabled:w}),w&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.linkedChannelScenarioBlocked","Este canal é vinculado a outro cliente. O cenário de automação é controlado pelo canal de origem.")})]})]})]})})}function Ot({open:s,onOpenChange:t,channelId:n,onSuccess:l}){var Qe;const{t:a}=X(),{toast:i}=ys(),{user:c}=He(),g=te(),j=o.useRef(null),y=((Qe=c==null?void 0:c.two_factor_secret)==null?void 0:Qe.is_enabled)??!1,[u,k]=o.useState(""),[w,b]=o.useState("default"),[I,S]=o.useState(""),[F,m]=o.useState(""),[z,N]=o.useState(""),[T,V]=o.useState(!1),[d,f]=o.useState(!1),[r,P]=o.useState([]),[C,p]=o.useState(!1),[q,Y]=o.useState(""),[x,$]=o.useState(120),le=o.useRef(null),ce=u.trim().length>0||I.trim().length>0,ve=()=>{k(""),b("default"),S(""),m(""),N(""),P([]),p(!1),Y(""),$(120)},Ae=D=>{D||ve(),t(D)},Ke=async D=>{var ae,E,_;const J=(ae=D.target.files)==null?void 0:ae[0];if(!J)return;if(!["image/png","image/jpeg","image/jpg","image/webp"].includes(J.type)){i({title:a("settings.invalidImageType","Tipo de imagem inválido"),description:a("settings.useImageFormats","Use PNG, JPG ou WebP"),variant:"destructive"});return}V(!0);try{const U=Cs();if(!U)throw new Error("Não autenticado");const K=localStorage.getItem("user"),O=K?(E=JSON.parse(K))==null?void 0:E.teams_id:void 0,B=new FormData;B.append("file",J),B.append("public","true"),O&&B.append("teams_id",O);const{data:Q,error:oe}=await Ps.functions.invoke("upload-do-spaces",{body:B,headers:{Authorization:`Bearer ${U}`}});if(oe)throw new Error(oe.message||"Falha no upload");if(Q!=null&&Q.success&&((_=Q.data)!=null&&_.url))m(Q.data.url),N(URL.createObjectURL(J));else throw new Error((Q==null?void 0:Q.error)||"Erro no upload")}catch(U){i({title:a("settings.uploadError","Erro no upload"),description:U instanceof Error?U.message:"Erro desconhecido",variant:"destructive"})}finally{V(!1),j.current&&(j.current.value="")}},Xe=()=>({name:u.trim(),type:{id:w,name:w==="default"?"Somente Texto":"Mídia e Interativo"},status:{id:"active",name:"Ativo"},category:{id:"UTILITY",name:"Utilitário"},components:{params:[],header:{format:{id:"image",name:"Imagem"},example:w==="interactive"?F:null},body:I.trim(),buttons:w==="interactive"?r:[],carousel:{cards:[]}},channel:{id:n}}),Ze=()=>u.trim()?I.trim()?w==="interactive"&&!F?(i({title:a("settings.imageRequired","Imagem é obrigatória para o tipo interativo"),variant:"destructive"}),!1):!0:(i({title:a("settings.messageRequired","Mensagem é obrigatória"),variant:"destructive"}),!1):(i({title:a("settings.nameRequired","Nome é obrigatório"),variant:"destructive"}),!1),es=()=>{Ze()&&(Y(""),$(120),p(!0))};o.useEffect(()=>{if(!C)return;if(x<=0){p(!1);return}const D=setInterval(()=>$(J=>J-1),1e3);return()=>clearInterval(D)},[C,x]),o.useEffect(()=>{if(C){const D=setTimeout(()=>{var J,G;(G=(J=le.current)==null?void 0:J.querySelector("input"))==null||G.focus()},100);return()=>clearTimeout(D)}},[C]);const ss=D=>`${Math.floor(D/60)}:${(D%60).toString().padStart(2,"0")}`,ts=async()=>
6{if(q.length===6){f(!0);try{const D=Xe();console.log("📦 RCS Template Payload:",JSON.stringify(D,null,2)),await H.post("/communication-templates/rcs",D,{twoFactorCode:q}),i({title:a("settings.templateCreated","Modelo criado com sucesso")}),g.invalidateQueries({queryKey:["rcs-templates",n]}),l==null||l(),p(!1),Ae(!1)}catch(D){i({title:a("settings.templateCreateError","Erro ao criar modelo"),description:D instanceof Error?D.message:"Erro desconhecido",variant:"destructive"})}finally{f(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx(De,{open:s,onOpenChange:Ae,children:e.jsxs(Le,{className:"sm:max-w-[540px] flex flex-col gap-0 p-0",children:[e.jsx(Re,{className:"px-6 py-4 border-b pr-12",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(_e,{className:"text-lg font-semibold",children:a("settings.newRcsTemplate","Novo modelo RCS")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:"outline",size:"sm",onClick:()=>Ae(!1),disabled:d,children:a("common.cancel","Cancelar")}
6),e.jsx(Ye,{isDirty:ce,isSubmitting:d||T,onClick:es})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"tpl-name",children:a("settings.name")}),e.jsx(R,{id:"tpl-name",value:u,onChange:D=>k(D.target.value),placeholder:a("settings.templateNamePlaceholder","Nome do modelo"),maxLength:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:a("settings.templateType","Tipo")}),e.jsxs(xe,{value:w,onValueChange:D=>b(D),children:[e.jsx(he,{children:e.jsx(pe,{})}),e.jsxs(ge,{children:[e.jsx(ee,{value:"default",children:a("settings.typeDefault","Somente Texto")}),e.jsx(ee,{value:"interactive",children:a("settings.typeInteractive","Mídia e Interativo")})]})]})]}),w==="interactive"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:a("settings.headerImage","Imagem do cabeçalho")}),z?e.jsxs("div",{className:"relative rounded-md border overflow-hidden",children:[e.jsx("img",{src:z,alt:"Preview",className:"w-full h-40 object-cover"}),e.jsx(v,{type:"button",variant:"destructive",size:"icon",className:"absolute top-2 right-2 h-7 w-7",onClick:()=>{m(""),N("")},children:e.jsx(Ue,{className:"h-4 w-4"})})]}):e.jsxs("button",{type:"button",onClick:()=>{var D;return(D=j.current)==null?void 0:D.click()},disabled:T,className:"w-full h-32 border-2 border-dashed border-muted-foreground/30 rounded-md flex flex-col items-center justify-center gap-2 text-muted-foreground hover:border-primary/50 hover:text-primary transition-colors cursor-pointer disabled:opacity-50",children:[T?e.jsx(de,{className:"h-6 w-6 animate-spin"}):e.jsx($e,{className:"h-6 w-6"}),e.jsx("span",{className:"text-sm",children:T?a("settings.uploading","Enviando..."):a("settings.clickToUpload","Clique para enviar imagem")})]}),e.jsx("input",{ref:j,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:Ke})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{htmlFor:"tpl-body",children:a("settings.message","Mensagem")}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[I.length,"/1024"]})]}),e.jsx(bs,{id:"tpl-body",value:I,onChange:D=>S(D.target.value.slice(0,1024)),placeholder:a("settings.templateBodyPlaceholder","Digite a mensagem do modelo..."),maxLength:1024,rows:5})]}),w==="interactive"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{children:a("settings.buttons","Botões")}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.length,"/3"]})]}),r.map((D,J)=>e.jsxs("div",{className:"rounded-md border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:[a("settings.button","Botão")," ",J+1]}),e.jsx(v,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive",onClick:()=>P(G=>G.filter((ae,E)=>E!==J)),children:e.jsx(je,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-xs",children:a("settings.buttonType","Tipo do botão")}),e.jsxs(xe,{value:D.type.id,onValueChange:G=>{P(ae=>ae.map((E,_)=>_===J?{...E,type:{id:G,name:G==="QUICK_REPLY"?"Click to Action":"Endereço de site"},content:G==="QUICK_REPLY"?E.text:E.content}:E))},children:[e.jsx(he,{className:"h-9",children:e.jsx(pe,{})}),e.jsxs(ge,{children:[e.jsx(ee,{value:"QUICK_REPLY",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),"Click to Action"]})}),e.jsx(ee,{value:"URL",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ws,{className:"h-3.5 w-3.5"}),a("settings.websiteUrl","Endereço de site")]})})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-xs",children:a("settings.buttonText","Texto do botão")}),e.jsx(R,{value:D.text,onChange:G=>{const ae=G.target.value;P(E=>E.map((_,U)=>U===J?{..._,text:ae,..._.type.id==="QUICK_REPLY"?{content:ae}:{}}:_))},placeholder:a("settings.buttonTextPlaceholder","Ex: Eu quero"),maxLength:50,className:"h-9"})]}),D.type.id==="URL"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-xs",children:"URL"}),e.jsx(R,{value:D.content,onChange:G=>{P(ae=>ae.map((E,_)=>_===J?{...E,content:G.target.value}:E))},placeholder:"https://...",className:"h-9"})]})]},D.id)),r.length<3&&e.jsxs(v,{type:"button",variant:"outline",size:"sm",className:"w-full gap-1.5",onClick:()=>{P(D=>[...D,{id:Date.now(),type:{id:"QUICK_REPLY",name:"Click to Action"},text:"",example:[],content:"",sales_campaign:[]}])},children:[e.jsx(fe,{className:"h-4 w-4"}),a("settings.addButton","Adicionar botão")]})]})]})]})}),e.jsx(we,{open:C,onOpenChange:p,children:e.jsx(Ce,{className:"sm:max-w-md",children:y?e.jsxs(e.Fragment,{children:[e.jsxs(Se,{children:[e.jsx("div",{className:"mx-auto w-14 h-14 roun
6ded-full bg-primary/10 flex items-center justify-center mb-2",children:e.jsx(Xs,{className:"h-7 w-7 text-primary"})}),e.jsx(ke,{className:"text-center",children:a("auth.twoFactorTitle","Verificação em duas etapas")}),e.jsx(Ie,{className:"text-center",children:a("auth.twoFactorDescription","Digite o código de 6 dígitos do seu aplicativo autenticador")}),e.jsxs("div",{className:`flex items-center justify-center gap-2 mt-2 text-sm ${x<=30?"text-destructive":"text-muted-foreground"}`,children:[e.jsx(bt,{className:"h-4 w-4"}),e.jsxs("span",{children:[a("auth.timeRemaining","Tempo restante"),": ",ss(x)]})]})]}),e.jsx("div",{ref:le,className:"flex justify-center py-4",children:e.jsx(vt,{maxLength:6,value:q,onChange:Y,disabled:d,children:e.jsxs(Nt,{children:[e.jsx(Oe,{index:0}),e.jsx(Oe,{index:1}),e.jsx(Oe,{index:2}),e.jsx(Oe,{index:3}),e.jsx(Oe,{index:4}),e.jsx(Oe,{index:5})]})})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(v,{variant:"outline",className:"flex-1",onClick:()=>p(!1),disabled:d,children:a("common.cancel","Cancelar")}
6),e.jsxs(v,{className:"flex-1",onClick:ts,disabled:d||q.length!==6,children:[d?e.jsx(de,{className:"h-4 w-4 mr-2 animate-spin"}):null,a("auth.verify","Verificar")]})]})]}):e.jsx(yt,{onCancel:()=>p(!1)})})})]})}const zt={active:"Ativo",disabled:"Desativado",draft:"Rascunho"};function Mt({open:s,onOpenChange:t,idTemplate:n,channelId:l,onSuccess:a}){var D,J,G,ae;const{toast:i}=ys(),c=te(),g=o.useRef(null),[j,y]=o.useState(!1),[u,k]=o.useState(!1),[w,b]=o.useState(!1),[I,S]=o.useState(!1),[F,m]=o.useState(!1),[z,N]=o.useState(!1),[T,V]=o.useState(null),[d,f]=o.useState(""),[r,P]=o.useState("default"),[C,p]=o.useState(""),[q,Y]=o.useState(""),[x,$]=o.useState(""),[le,ce]=o.useState([]),[ve,Ae]=o.useState("active"),Ke=E=>E==="inactive"?"disabled":E,Xe=T&&(d!==T.name||C!==(((D=T.components)==null?void 0:D.body)||"")||q!==(((G=(J=T.components)==null?void 0:J.header)==null?void 0:G.example)||"")||JSON.stringify(le)!==JSON.stringify(T._parsedButtons||[])||ve!==Ke(((ae=T.status)==null?void 0:ae.id)||"active"));o.useEffect(()=>{if(!s||!n)return;(async()=>{var _,U,K,O,B,Q,oe;y(!0);try{const me=await H.get(`/communication-templates/rcs/${n}`),ne=((_=me.data)==null?void 0:_.list)??me.data??me.list;if(ne){const ie=(((U=ne.components)==null?void 0:U.buttons)||[]).map((Ms,Us)=>({id:Us,...Ms}));V({...ne,_parsedButtons:ie}),f(ne.name||""),P(((K=ne.type)==null?void 0:K.id)||"default"),p(((O=ne.components)==null?void 0:O.body)||""),Ae(Ke(((B=ne.status)==null?void 0:B.id)||"active"));const qe=(oe=(Q=ne.components)==null?void 0:Q.header)==null?void 0:oe.example;qe&&(Y(qe),$(qe)),ce(ie)}}catch(me){console.error("Erro ao buscar template:",me),i({title:"Erro ao carregar modelo",variant:"destructive"})}finally{y(!1)}})()},[s,n]),o.useEffect(()=>{s||(f(""),p(""),Y(""),$(""),ce([]),V(null))},[s]);const Ze=async E=>{var K,O,B;const _=(K=E.target.files)==null?void 0:K[0];if(!_)return;if(!["image/png","image/jpeg","image/jpg","image/webp"].includes(_.type)){i({title:"Tipo de imagem inválido. Use PNG, JPG ou WebP",variant:"destructive"});return}S(!0);try{const Q=Cs();if(!Q)throw new Error("Não autenticado");const oe=localStorage.getItem("user"),me=oe?(O=JSON.parse(oe))==null?void 0:O.teams_id:void 0,ne=new FormData;ne.append("file",_),ne.append("public","true"),me&&ne.append("teams_id",me);const{data:ie,error:qe}=await Ps.functions.invoke("upload-do-spaces",{body:ne,headers:{Authorization:`Bearer ${Q}`}});if(qe)throw new Error(qe.message||"Falha no upload");if(ie!=null&&ie.success&&((B=ie.data)!=null&&B.url))Y(ie.data.url),$(ie.data.url);else throw new Error((ie==null?void 0:ie.error)||"Erro no upload")}catch(Q){i({title:"Erro no upload",description:Q instanceof Error?Q.message:"Erro desconhecido",variant:"destructive"})}finally{S(!1),g.current&&(g.current.value="")}},es=()=>
6{if(!d.trim()||!C.trim()){i({title:"Preencha os campos obrigatórios",variant:"destructive"});return}m(!0)},ss=async E=>{var _,U;k(!0);try{const K=r==="interactive",O={...T,name:d.trim(),type:{id:r,name:K?"Mídia e Interativo":"Somente Texto"},status:{id:ve,name:zt[ve]||ve},components:{...T==null?void 0:T.components,header:K?{format:{id:"image",name:"Imagem"},example:q}:{format:{id:"text",name:"Texto"},example:null},body:C.trim(),buttons:K?le.map(({type:B,text:Q,content:oe})=>({type:B,text:Q.trim(),content:B.id==="QUICK_REPLY"?Q.trim():oe.trim()})):[]}};delete O.created_at,delete O.updated_at,delete O.owner,delete O.companies,await H.put(`/communication-templates/rcs/${n}`,O,{twoFactorCode:E}),i({title:"Modelo atualizado!"}),await new Promise(B=>setTimeout(B,1500)),c.invalidateQueries({queryKey:["rcs-templates"]}),a==null||a(),t(!1)}catch(K){i({title:"Erro ao salvar",description:((U=(_=K.response)==null?void 0:_.data)==null?void 0:U.message)||"Verifique os dados",variant:"destructive"})}finally{k(!1),m(!1)}},ts=()=>{N(!0)},Qe=async E=>{b(!0);try{await H.delete(`/communication-templates/rcs/${n}`,{twoFactorCode:E}),i({title:"Modelo excluído com sucesso!"}),await new Promise(_=>setTimeout(_,1500)),c.invalidateQueries({queryKey:["rcs-templates"]}),a==null||a(),t(!1)}catch(_){i({title:"Erro ao excluir",description:_.message||"Verifique os dados",variant:"destructive"})}finally{b(!1),N(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(De,{open:s,onOpenChange:t,children:e.jsxs(Le,{className:"sm:max-w-[700px] flex flex-col gap-0 p-0",children:[e.jsx(Re,{className:"px-6 py-4 border-b",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(_e,{children:"Editar Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10",onClick:ts,disabled:j,children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx(Ye,{isDirty:Xe,isSubmitting:u,onClick:es})]})]})}),j?e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx(se,{className:"h-10 w-full"}),e.jsx(se,{className:"h-32 w-full"})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Nome do Template"}),e.jsx(R,{value:d,onChange:E=>f(E.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Tipo"}),e.jsxs(xe,{value:r,disabled:!0,children:[e.jsx(he,{children:e.jsx(pe,{})}),e.jsxs(ge,{children:[e.jsx(ee,{value:"default",children:"Texto"}),e.jsx(ee,{value:"interactive",children:"Interativo"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Situação"}),e.jsxs(xe,{value:ve,onValueChange:Ae,children:[e.jsx(he,{children:e.jsx(pe,{})}),e.jsxs(ge,{children:[e.jsx(ee,{value:"active",children:"Ativo"}),e.jsx(ee,{value:"disabled",children:"Inativo"}),e.jsx(ee,{value:"draft",children:"Rascunho"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Conteúdo da Mensagem"}),e.jsx(bs,{value:C,onChange:E=>p(E.target.value),className:"min-h-[120px]"})]}),r==="interactive"&&e.jsxs("div",{className:"pt-4 border-t space-y-4",children:[e.jsx(h,{className:"text-primary",children:"Configurações Interativas"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Imagem do cabeçalho"}),x?e.jsxs("div",{className:"relative rounded-md border overflow-hidden",children:[e.jsx("img",{src:x,alt:"Preview",className:"w-full h-40 object-cover"}),e.jsx(v,{type:"button",variant:"destructive",size:"icon",className:"absolute top-2 right-2 h-7 w-7",onClick:()=>{Y(""),$("")},children:e.jsx(Ue,{className:"h-4 w-4"})})]}):e.jsxs("button",{type:"button",onClick:()=>{var E;return(E=g.current)==null?void 0:E.click()},disabled:I,className:"w-full h-32 border-2 border-dashed border-muted-foreground/30 rounded-md flex flex-col items-center justify-center gap-2 text-muted-foreground hover:border-primary/50 hover:text-primary transition-colors cursor-pointer disabled:opacity-50",children:[I?e.jsx(de,{className:"h-6 w-6 animate-spin"}):e.jsx($e,{className:"h-6 w-6"}),e.jsx("span",{className:"text-sm",children:I?"Enviando...":"Clique para enviar imagem"})]}),e.jsx("input",{ref:g,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:Ze})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{children:"Botões"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[le.length,"/3"]})]}),le.map((E,_)=>e.jsxs("div",{className:"rounded-md border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:["Botão ",_+1]}),e.jsx(v,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive",onClick:()=>ce(U=>U.filter((K,O)=>O!==_)),children:e.jsx(je,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-xs",children:"Tipo do botão"}),e.jsxs(xe,{value:E.type.id,onValueChange:U=>{ce(K=>K.map((O,B)=>B===_?{...O,type:{id:U,name:U==="QUICK_REPLY"?"Click to Action":"Endereço de site"},content:U==="QUICK_REPLY"?O.text:O.content}:O))},children:[e.jsx(he,{className:"h-9",children:e.jsx(pe,{})}),e.jsxs(ge,{children:[e.jsx(ee,{value:"QUICK_REPLY",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),"Click to Action"]})}),e.jsx(ee,{value:"URL",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ws,{className:"h-3.5 w-3.5"}),"Endereço de site"]})})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-xs",children:"Texto do botão"}),e.jsx(R,{value:E.text,onChange:U=>{const K=U.target.value;ce(O=>O.map((B,Q)=>Q===_?{...B,text:K,...B.type.id==="QUICK_REPLY"?{content:K}:{}}:B))},placeholder:"Ex: Eu quero",maxLength:50,className:"h-9"})]}),E.type.id==="URL"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-xs",children:"URL"}),e.jsx(R,{value:E.content,onChange:U=>{ce(K=>K.map((O,B)=>B===_?{...O,content:U.target.value}:O))},placeholder:"https://...",className:"h-9"})]})]},E.id)),le.length<3&&e.jsxs(v,{type:"button",variant:"outline",size:"sm",className:"w-full gap-1.5",onClick:()=>{ce(E=>[...E,{id:Date.now(),type:{id:"QUICK_REPLY",name:"Click to Action"},text:"",content:""}])},children:[e.jsx(fe,{className:"h-4 w-4"}),"Adicionar botão"]})]})]})]})]})}),e.jsx(cs,{open:F,onOpenChange:m,onConfirm:ss,isLoading:u}),e.jsx(cs,{open:z,onOpenChange:N,onConfirm:Qe,isLoading:w})]})}function Ut(s){if(!s)return"-";try{const t=Zs.language==="pt-BR"?Be:Je;return be(new Date(s),"dd/MM/yyyy HH:mm",{locale:t})}catch{return"-"}}function $t({open:s,onOpenChange:t,channel:n}){X();const{data:l,isLoading:a,refetch:i}=ft(s&&(n!=null&&n.id)?n.id:void 0),[c,g]=o.useState(!1),[j,y]=o.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(De,{open:s,onOpenChange:t,children:e.jsxs(Le,{className:"sm:max-w-[700px] flex flex-col gap-0 p-0",children:[e.jsx(Re,{className:"px-6 py-4 border-b pr-12",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_e,{className:"text-lg font-semibold",children:"Modelos RCS"}),n&&e.jsx(W,{variant:"outline",children:n.name})]}),e.jsxs(v,{size:"sm",className:"gap-1.5",onClick:()=>g(!0),children:[e.jsx(fe,{className:"h-4 w-4"})," Novo modelo"]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:a?e.jsx("div",{className:"p-6 space-y-3",children:[1,2,3,4].map(u=>e.jsx(se,{className:"h-12 w-full"},u))}):l&&l.length>0?e.jsxs(Fe,{children:[e.jsx(Te,{children:e.jsxs(Z,{children:[e.jsx(A,{className:"w-10"}),e.jsx(A,{children:"Nome"}),e.jsx(A,{children:"Tipo"}),e.jsx(A,{children:"Status"}),e.jsx(A,{className:"text-right",children:"Criado em"})]})}),e.jsx(Pe,{children:l.map(u=>{var k,w,b,I,S;return e.jsxs(Z,{children:[e.jsx(M,{children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>y(u.id),children:e.jsx(Ge,{className:"h-4 w-4"})})}),e.jsx(M,{className:"font-medium text-sm",children:u.name}),e.jsx(M,{children:e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[((k=u.type)==null?void 0:k.id)==="interactive"?e.jsx($e,{className:"h-3.5 w-3.5"}):e.jsx(wt,{className:"h-3.5 w-3.5"}),(w=u.type)==null?void 0:w.name]})}),e.jsx(M,{children:e.jsx(W,{variant:((b=u.status)==null?void 0:b.id)==="active"?"default":"secondary",className:((I=u.status)==null?void 0:I.id)==="active"?"bg-green-100 text-green-800":"",children:((S=u.status)==null?void 0:S.name)||"Inativo"})}),e.jsx(M,{className:"text-xs text-muted-foreground text-right",children:Ut(u.created_at)})]},u.id)})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground gap-3",children:[e.jsx(rs,{className:"h-10 w-10 opacity-40"}),e.jsx("p",{className:"text-sm",children:"Nenhum modelo RCS encontrado"})]})})]})}),n&&e.jsx(Ot,{open:c,onOpenChange:g,channelId:n.id,onSuccess:i}),n&&e.jsx(Mt,{open:!!j,onOpenChange:u=>!u&&y(null),idTemplate:j,channelId:n.id,onSuccess:i})]})}function ns(s){if(!s)return"-";try{return be(new Date(s),"dd/MM/yyyy 'às' HH:mm",{locale:Be})}catch{return"-"}}function vs(s){if(!s)return"-";const t=s.replace(/\D/g,"");return t.length===11?t.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/,"$1.$2.$3-$4"):t.length===14?t.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/,"$1.$2.$3/$4-$5"):s}function Bt(s){return s?s.replace(/\D/g,""):""}function Kt(s){return s?s.replace(/\D/g,""):""}function Qt({label:s,value:t}){const[n,l]=o.useState(!1),a=async()=>{await navigator.clipboard.writeText(t),l(!0),L.success("Copiado para a área de transferência"),setTimeout(()=>l(!1),2e3)};return e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:s}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{value:t,readOnly:!0,className:"font-mono text-sm"}),e.jsx(v,{variant:"outline",size:"icon",onClick:a,className:"shrink-0",children:n?e.jsx(ks,{className:"h-4 w-4 text-green-500"}):e.jsx(Is,{className:"h-4 w-4"})})]})]})}function Vt({label:s,value:t}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:s}),e.jsx(R,{value:t||"-",readOnly:!0})]})}function Ht({icon:s,title:t,description:n,action:l}){return e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(s,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:t}),n&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n})]})]}),l]})}function is(s){var t,n,l,a,i,c,g,j;return{name:(s==null?void 0:s.name)||"",contact_name:(s==null?void 0:s.contact_name)||"",email:(s==null?void 0:s.email)||"",phone:Bt(s==null?void 0:s.phone),logo_url:(s==null?void 0:s.logo_url)||"",zip_code:Kt((t=s==null?void 0:s.address)==null?void 0:t.zip_code),address:((n=s==null?void 0:s.address)==null?void 0:n.address)||"",address_number:(l=s==null?void 0:s.address)==null?void 0:l.address_number,complement:((a=s==null?void 0:s.address)==null?void 0:a.complement)||"",neighborhood:(i=s==null?void 0:s.address)==null?void 0:i.neighborhood,city:((c=s==null?void 0:s.address)==null?void 0:c.city)||"",state:((g=s==null?void 0:s.address)==null?void 0:g.state)||"",country:((j=s==null?void 0:s.address)==null?void 0:j.country)||""}}function Jt({customer:s}){var V,d,f;const{t}=X(),n=te(),{refreshUser:l}=He(),[a,i]=o.useState(()=>is(s)),[c,g]=o.useState(()=>is(s)),[j,y]=o.useState(!1),[u,k]=o.useState(!1),[w,b]=o.useState(!1),[I,S]=o.useState(!1);o.useEffect(()=>{const r=is(s);i(r),g(r)},[s]);const F=JSON.stringify(a)!==JSON.stringify(c),m=o.useCallback((r,P)=>{i(C=>({...C,[r]:P})),r==="address_number"&&b(!1)},[]),z=async r=>{const P=r.replace(/\D/g,"");if(m("zip_code",P),P.length===8){k(!0);try{const p=await(await fetch(`https://viacep.com.br/ws/${P}/json/`)).json();p.erro||i(q=>({...q,address:p.logradouro||q.address,neighborhood:p.bairro||q.neighborhood,city:p.localidade||q.city,state:p.uf||q.state,country:"Brasil"}))}catch{}finally{k(!1)}}},N=()=>
6{if(!a.address_number.trim()){b(!0),L.error("O campo Número é obrigatório.");return}y(!0)},T=re({mutationFn:async r=>{const P={name:a.name,contact_name:a.contact_name,email:a.email,phone:a.phone,logo_url:a.logo_url||null,address:{country:a.country,address:a.address,city:a.city,neighborhood:a.neighborhood,state:a.state,complement:a.complement,zip_code:a.zip_code,address_number:a.address_number}};return H.post("/admin/customers",P,{twoFactorCode:r})},onSuccess:async()=>{L.success(t("common.success")),y(!1),await Promise.all([n.invalidateQueries({queryKey:["customer-config"]}),l()])},onError:r=>{L.error(r.message||t("common.error"))}});return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-6",children:[e.jsx(Ht,{icon:et,title:t("settings.registrationData"),description:t("settings.registrationDescription"),action:e.jsx(Ye,{isDirty:F,isSubmitting:T.isPending,label:t("common.save"),onClick:N})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground",children:[e.jsx(st,{className:"h-4 w-4"}),t("settings.identification")]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(Qt,{label:t("settings.customerCode"),value:(s==null?void 0:s.id)||""}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.companyName")}),e.jsx(R,{value:a.name,onChange:r=>m("name",r.target.value)})]}),e.jsx(Vt,{label:t("settings.document"),value:vs(s==null?void 0:s.federal_document)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.contactName")}),e.jsx(R,{value:a.contact_name,onChange:r=>m("contact_name",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.mainEmail")}),e.jsx(R,{value:a.email,onChange:r=>m("email",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.phone")}
6),e.jsx(R,{value:a.phone,onChange:r=>m("phone",r.target.value.replace(/\D/g,""))})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-6 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t("settings.status"),":"]}),e.jsx(W,{variant:((V=s==null?void 0:s.status)==null?void 0:V.id)==="active"?"default":"secondary",className:((d=s==null?void 0:s.status)==null?void 0:d.id)==="active"?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400":"",children:((f=s==null?void 0:s.status)==null?void 0:f.name)||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(os,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t("settings.registration"),":"]}),e.jsx("span",{className:"text-sm font-medium",children:ns(s==null?void 0:s.created_at)})]}),(s==null?void 0:s.active_at)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(os,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t("settings.activeSince"),":"]}),e.jsx("span",{className:"text-sm font-medium",children:ns(s==null?void 0:s.active_at)})]})]})]}),e.jsx(ze,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground",children:[e.jsx($e,{className:"h-4 w-4"}),t("settings.logo","Logo")]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsx("div",{className:"flex h-24 w-24 shrink-0 items-center justify-center rounded-lg border border-dashed bg-muted/30 overflow-hidden",children:a.logo_url?e.jsx("img",{src:a.logo_url,alt:"Logo",className:"h-full w-full object-contain p-2",onError:r=>{r.currentTarget.style.display="none"}}):e.jsx($e,{className:"h-8 w-8 text-muted-foreground/40"})}),e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settings.logoDescription","Faça upload da logo da sua empresa (PNG ou JPEG, até 5 MB).")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(v,{type:"button",variant:"outline",size:"sm",onClick:()=>S(!0),className:"gap-2",children:[e.jsx(Ss,{className:"h-4 w-4"}),a.logo_url?t("settings.replaceLogo","Substituir logo"):t("settings.uploadLogo","Enviar logo")]}),a.logo_url&&e.jsxs(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>m("logo_url",""),className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(je,{className:"h-4 w-4"}),t("settings.removeLogo","Remover")]})]})]})]})]}),e.jsx(ze,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground",children:[e.jsx(tt,{className:"h-4 w-4"}),t("settings.address")]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.zipCode")}),e.jsxs("div",{className:"relative",children:[e.jsx(R,{value:a.zip_code,onChange:r=>z(r.target.value),maxLength:8,placeholder:"00000000"}),u&&e.jsx(de,{className:"absolute right-3 top-3 h-4 w-4 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"md:col-span-2 space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.street")}),e.jsx(R,{value:a.address,onChange:r=>m("address",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(h,{className:w?"text-destructive":"text-muted-foreground",children:[t("settings.number")," *"]}),e.jsx(R,{value:a.address_number,onChange:r=>m("address_number",r.target.value),className:w?"border-destructive":""}),w&&e.jsx("p",{className:"text-xs text-destructive",children:"Campo obrigatório"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.complement")}),e.jsx(R,{value:a.complement,onChange:r=>m("complement",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.neighborhood")}),e.jsx(R,{value:a.neighborhood,onChange:r=>m("neighborhood",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.city")}),e.jsx(R,{value:a.city,onChange:r=>m("city",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.state")}),e.jsx(R,{value:a.state,onChange:r=>m("state",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"text-muted-foreground",children:t("settings.country")}),e.jsx(R,{value:a.country,onChange:r=>m("country",r.target.value)})]})]})]}),e.jsx(ze,{}),(s==null?void 0:s.terms)&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground",children:[e.jsx(St,{className:"h-4 w-4"}),t("settings.terms")]}),e.jsx(W,{variant:s.terms.accepted?"default":"destructive",className:s.terms.accepted?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400":"",children:s.terms.accepted?t("settings.termsAccepted"):t("settings.termsNotAccepted")})]}),e.jsx("div",{className:"bg-muted/30 rounded-lg p-4",children:e.jsxs("div",{className:"flex flex-wrap gap-x-8 gap-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("settings.responsible"),": "]}),e.jsx("span",{className:"font-medium",children:s.terms.name||"-"})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("settings.document"),": "]}),e.jsx("span",{className:"font-medium",children:vs(s.terms.federal_document)||"-"})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("settings.date"),": "]}),e.jsx("span",{className:"font-medium",children:ns(s.terms.date)})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("settings.ip"),": "]}),e.jsx("span",{className:"font-mono text-xs",children:s.terms.ip||"-"})]})]})})]})]}),e.jsx(Ct,{open:I,onOpenChange:S,title:t("settings.uploadLogo","Enviar logo"),description:t("settings.logoDescription","Faça upload da logo da sua empresa (PNG ou JPEG, até 5 MB)."),onUploaded:r=>m("logo_url",r)}),e.jsx(cs,{open:j,onOpenChange:y,onConfirm:async r=>{await T.mutateAsync(r)},isLoading:T.isPending})]})}function Yt(){const{user:s,setBeeOneVisualNotifications:t}=He(),[n,l]=o.useState(!1),a=(s==null?void 0:s.beeone_visual_notifications)!==!1;async function i(c){l(!0);
6try{if(!(await H.put("/profile/beeone-settings",{visual_notifications:c})).success)throw new Error("save failed");t(c),L.success("Configuração salva.")}catch{L.error("Não foi possível salvar. Tente novamente.")}finally{l(!1)}}return e.jsxs("section",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:"BeeOne"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Personalize suas notificações do BeeOne."})]}),e.jsxs("div",{className:"flex items-center justify-between gap-6 rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{htmlFor:"beeone-visual-notifications",children:"Notificações visuais de novas mensagens"}),e.jsx("p",{id:"beeone-visual-description",className:"text-sm text-muted-foreground",children:"Exibir um pop-up na tela quando chegar uma nova mensagem de um contato. Esta configuração vale somente para o seu usuário."}),e.jsx("p",{className:"text-sm text-muted-foreground","aria-live":"polite",children:n?"Salvando…":a?"Ligado":"Desligado"})]}),e.jsx(kt,{id:"beeone-visual-notifications","aria-describedby":"beeone-visual-description",checked:a,disabled:n,onCheckedChange:i})]})]})}function Gt(){return ms({queryKey:["beemedia-filters-alerts"],queryFn:async()=>{const t=(await H.get("/admin/bemedia-filters-alerts")).data;return Array.isArray(t)?t:t.list??[]}})}function Wt(){const s=te();return re({mutationFn:async t=>H.post("/admin/bemedia-filters-alerts",t),onSuccess:()=>{setTimeout(()=>{s.invalidateQueries({queryKey:["beemedia-filters-alerts"]})},1500)}})}function Xt(){const s=te();return re({mutationFn:async({id:t,payload:n})=>H.put(`/admin/bemedia-filters-alerts/${t}`,n),onSuccess:()=>{setTimeout(()=>{s.invalidateQueries({queryKey:["beemedia-filters-alerts"]})},1500)}})}function Zt(){const s=te();return re({mutationFn:async({id:t,twoFactorCode:n})=>H.delete(`/admin/bemedia-filters-alerts/${t}`,{twoFactorCode:n}),onSuccess:()=>{setTimeout(()=>{s.invalidateQueries({queryKey:["beemedia-filters-alerts"]})},1500)}})}function ea(){const{t:s}=X(),{data:t,isLoading:n}=Gt(),l=Wt(),a=Xt(),i=Zt(),[c,g]=o.useState(!1),[j,y]=o.useState(null),[u,k]=o.useState(null),[w,b]=o.useState(""),[I,S]=o.useState([]),[F,m]=o.useState(null),[z,N]=o.useState(!1),T=()=>{k(null),b(""),S([]),y(null),g(!1)},V=()=>{T(),g(!0)},d=x=>{y(x),k({id:x.category,name:x.category}),S([...x.keywords]),b(""),g(!0)},f=()=>{const x=w.trim().toLowerCase();x&&!I.includes(x)&&S($=>[...$,x]),b("")},r=x=>{S($=>$.filter(le=>le!==x))},P=x=>{x.key==="Enter"&&(x.preventDefault(),f())},C=()=>{if(!u){L.error(s("settings.beemediaFilters.categoryRequired"));return}if(I.length===0){L.error(s("settings.beemediaFilters.keywordsRequired"));return}const x={category:u.name.trim().toLowerCase(),keywords:I};j?a.mutate({id:j.id,payload:x},{onSuccess:()=>{L.success(s("settings.beemediaFilters.updatedSuccess")),T()},onError:$=>L.error($.message||s("settings.beemediaFilters.updateError"))}):l.mutate(x,{onSuccess:()=>{L.success(s("settings.beemediaFilters.createdSuccess")),T()},onError:$=>L.error($.message||s("settings.beemediaFilters.createError"))})},p=x=>{m(x),N(!0)},q=async x=>{F&&i.mutate({id:F.id,twoFactorCode:x},{onSuccess:()=>{L.success(s("settings.beemediaFilters.deletedSuccess")),N(!1),m(null)},onError:$=>{L.error($.message||s("settings.beemediaFilters.deleteError"))}})},Y=l.isPending||a.isPending;return n?e.jsx("div",{className:"space-y-4",children:Array.from({length:3}).map((x,$)=>e.jsx(se,{className:"h-20 w-full"},$))}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ls,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:s("settings.beemediaFilters.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settings.beemediaFilters.description")})]})]}),e.jsxs(v,{onClick:V,size:"sm",className:"gap-1.5",children:[e.jsx(fe,{className:"h-4 w-4"}),s("settings.beemediaFilters.addFilter")]})]}),c&&e.jsxs("div",{className:"border rounded-lg p-5 space-y-4 bg-muted/30 animate-in fade-in-0 slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium text-sm",children:s(j?"settings.beemediaFilters.editTitle":"settings.beemediaFilters.createTitle")}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:T,children:e.jsx(Ue,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:s("settings.beemediaFilters.categoryLabel")}),e.jsx(Ts,{endpoint:"/beemedia/categories",placeholder:s("settings.beemediaFilters.categoryPlaceholder"),value:u,onSelect:k,minChars:1,hideDocument:!0,className:"max-w-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:s("settings.beemediaFilters.keywordsLabel")}),e.jsxs("div",{className:"flex gap-2 max-w-sm",children:[e.jsx(R,{placeholder:s("settings.beemediaFilters.keywordPlaceholder"),value:w,onChange:x=>b(x.target.value),onKeyDown:P}),e.jsx(v,{variant:"outline",size:"icon",onClick:f,className:"shrink-0",children:e.jsx(fe,{className:"h-4 w-4"})})]}),I.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:I.map(x=>e.jsxs(W,{variant:"secondary",className:"gap-1 pr-1 cursor-pointer hover:bg-destructive/10 transition-colors",onClick:()=>r(x),children:[x,e.jsx(Ue,{className:"h-3 w-3"})]},x))})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(v,{variant:"outline",size:"sm",onClick:T,children:s("common.cancel")}),e.jsxs(v,{size:"sm",onClick:C,disabled:Y,className:"gap-1.5",children:[Y?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(It,{className:"h-3.5 w-3.5"}),s(j?"common.save":"settings.beemediaFilters.addFilter")]})]})]}),t!=null&&t.length?e.jsx("div",{className:"space-y-3",children:t.map(x=>e.jsxs("div",{className:"group border rounded-lg p-4 flex items-start gap-4 hover:border-primary/30 transition-colors",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-primary/5 mt-0.5",children:e.jsx(js,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm capitalize",children:x.category}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:x.keywords.map($=>e.jsx(W,{variant:"outline",className:"text-xs font-normal",children:$},$))})]}),e.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>d(x),children:e.jsx(Ge,{className:"h-3.5 w-3.5"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>p(x),children:e.jsx(je,{className:"h-3.5 w-3.5"})})]})]},x.id))}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(js,{className:"h-8 w-8 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:s("settings.beemediaFilters.noFilters")})]}),e.jsx(we,{open:z,onOpenChange:x=>{x||(N(!1),m(null))},children:e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsxs(Se,{children:[e.jsx(ke,{children:s("settings.beemediaFilters.deleteTitle")}),e.jsx(Ie,{children:s("settings.beemediaFilters.deleteDescription",{category:F==null?void 0:F.category})})]}),e.jsx(hs,{onSubmit:q,onCancel:()=>{N(!1),m(null)},isLoading:i.isPending})]})})]})}function sa({items:s,isLoading:t,onView:n,onEdit:l,onDelete:a}){const{t:i}=X();return t?e.jsx("div",{className:"rounded-md border",children:e.jsxs(Fe,{children:[e.jsx(Te,{children:e.jsxs(Z,{children:[e.jsx(A,{className:"w-[120px]",children:i("common.actions")}),e.jsx(A,{className:"w-[140px]",children:i("settings.salesImportCfop.cfop")}),e.jsx(A,{children:i("settings.salesImportCfop.name")}
6)]})}),e.jsx(Pe,{children:Array.from({length:5}).map((c,g)=>e.jsx(Z,{children:Array.from({length:3}).map((j,y)=>e.jsx(M,{children:e.jsx(se,{className:"h-4 w-full"})},y))},g))})]})}):s.length===0?e.jsxs("div",{className:"rounded-md border p-10 text-center",children:[e.jsx(_s,{className:"h-10 w-10 mx-auto mb-3 text-muted-foreground opacity-40"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i("settings.salesImportCfop.noItems")})]}):e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(Fe,{children:[e.jsx(Te,{children:e.jsxs(Z,{children:[e.jsx(A,{className:"w-[120px] whitespace-nowrap",children:i("common.actions")}),e.jsx(A,{className:"w-[140px] whitespace-nowrap",children:i("settings.salesImportCfop.cfop")}),e.jsx(A,{children:i("settings.salesImportCfop.name")})]})}),e.jsx(Pe,{children:s.map(c=>e.jsxs(Z,{children:[e.jsx(M,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>n(c),title:i("common.view"),children:e.jsx(Ve,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>l(c),title:i("common.edit"),children:e.jsx(Ge,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>a(c),title:i("common.delete"),children:e.jsx(je,{className:"h-4 w-4"})})]})}),e.jsx(M,{className:"whitespace-nowrap",children:e.jsx(W,{variant:"secondary",className:"font-mono",children:c.cfop||"-"})}),e.jsx(M,{className:"font-medium",children:c.name||"-"})]},c.id))})]})})}const ps="/admin/beeplace/sales-import-cfop";function ta(){const s=te();return re({mutationFn:async t=>H.post(ps,t),onSuccess:()=>{s.invalidateQueries({queryKey:["sales-import-cfop"]})}})}function aa(){const s=te();return re({mutationFn:async({id:t,payload:n})=>H.put(`${ps}/${t}`,n),onSuccess:()=>{s.invalidateQueries({queryKey:["sales-import-cfop"]})}})}function na(){const s=te();return re({mutationFn:async({id:t,twoFactorCode:n})=>H.delete(`${ps}/${t}`,{twoFactorCode:n}),onSuccess:()=>{s.invalidateQueries({queryKey:["sales-import-cfop"]})}})}const ia="/admin/beeplace/sales-import-cfop";function ra(){const{t:s}=X(),t=Rs({endpoint:ia}),n=ta(),l=aa(),a=na(),[i,c]=o.useState(!1),[g,j]=o.useState(null),[y,u]=o.useState(""),[k,w]=o.useState(""),[b,I]=o.useState(null),[S,F]=o.useState(null),m=n.isPending||l.isPending,z=()=>{t.handlePageChange(t.currentPage)},N=()=>{j(null),u(""),w(""),c(!0)},T=r=>{j(r),u(r.name??""),w(r.cfop??""),c(!0)},V=()=>{c(!1),j(null),u(""),w("")},d=()=>{if(!y.trim()){L.error(s("settings.salesImportCfop.nameRequired"));return}if(!g&&!k.trim()){L.error(s("settings.salesImportCfop.cfopRequired"));return}g?l.mutate({id:g.id,payload:{name:y.trim(),cfop:k.trim()||void 0}},{onSuccess:()=>{L.success(s("settings.salesImportCfop.updatedSuccess")),V(),z()},onError:r=>L.error(r.message||s("settings.salesImportCfop.saveError"))}):n.mutate({name:y.trim(),cfop:k.trim()},{onSuccess:()=>{L.success(s("settings.salesImportCfop.createdSuccess")),V(),z()},onError:r=>L.error(r.message||s("settings.salesImportCfop.saveError"))})},f=async r=>{S&&a.mutate({id:S.id,twoFactorCode:r},{onSuccess:()=>{L.success(s("settings.salesImportCfop.deletedSuccess")),F(null),z()},onError:P=>L.error(P.message||s("settings.salesImportCfop.deleteError"))})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(_s,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:s("settings.salesImportCfop.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settings.salesImportCfop.description")})]})]}),e.jsxs(v,{onClick:N,size:"sm",className:"gap-1.5 shrink-0",children:[e.jsx(fe,{className:"h-4 w-4"}),s("settings.salesImportCfop.addItem")]})]}),e.jsx(Ds,{searchQuery:t.searchQuery,onSearchChange:t.setSearchQuery,searchPlaceholder:s("settings.salesImportCfop.searchPlaceholder"),filterFields:t.filterFields,onApplyFilters:t.handleApplyFilters,activeFiltersCount:t.activeFilters.length,isLoading:t.isLoading,rawResponse:t.rawResponse,refresh:!0,onRefresh:z}),e.jsx(sa,{items:t.items,isLoading:t.isLoading,onView:I,onEdit:T,onDelete:F}),e.jsx(Ls,{pagination:t.pagination,onPageChange:t.handlePageChange,onPageSizeChange:t.handlePageSizeChange,pageSize:t.pageSize,isLoading:t.isLoading}),e.jsx(De,{open:i,onOpenChange:r=>{r||V()},children:e.jsxs(Le,{className:"sm:max-w-md",children:[e.jsxs(Re,{children:[e.jsx(_e,{children:s(g?"settings.salesImportCfop.editTitle":"settings.salesImportCfop.createTitle")}),e.jsx(us,{children:s(g?"settings.salesImportCfop.editDescription":"settings.salesImportCfop.createDescription")})]}),e.jsxs("div",{className:"space-y-5 py-6",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{htmlFor:"cfop-code",children:s("settings.salesImportCfop.cfop")}),e.jsx(R,{id:"cfop-code",placeholder:s("settings.salesImportCfop.cfopPlaceholder"),value:k,onChange:r=>w(r.target.value),className:"font-mono"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{htmlFor:"cfop-name",children:s("settings.salesImportCfop.name")}
6),e.jsx(R,{id:"cfop-name",placeholder:s("settings.salesImportCfop.namePlaceholder"),value:y,onChange:r=>u(r.target.value)})]})]}),e.jsxs(xs,{children:[e.jsx(v,{variant:"outline",onClick:V,disabled:m,children:s("common.cancel")}),e.jsxs(v,{onClick:d,disabled:m,className:"gap-1.5",children:[m&&e.jsx(de,{className:"h-4 w-4 animate-spin"}),s("common.save")]})]})]})}),e.jsx(we,{open:!!b,onOpenChange:r=>{r||I(null)},children:e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsxs(Se,{children:[e.jsx(ke,{children:s("settings.salesImportCfop.viewTitle")}),e.jsx(Ie,{children:s("settings.salesImportCfop.viewDescription")})]}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:s("settings.salesImportCfop.cfop")}),e.jsx("div",{children:e.jsx(W,{variant:"secondary",className:"font-mono text-sm",children:(b==null?void 0:b.cfop)||"-"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:s("settings.salesImportCfop.name")}),e.jsx("p",{className:"text-sm font-medium",children:(b==null?void 0:b.name)||"-"})]})]})]})}),e.jsx(we,{open:!!S,onOpenChange:r=>{r||F(null)},children:e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsxs(Se,{children:[e.jsx(ke,{children:s("settings.salesImportCfop.deleteTitle")}),e.jsx(Ie,{children:s("settings.salesImportCfop.deleteDescription",{name:S==null?void 0:S.name})})]}),e.jsx(hs,{onSubmit:f,onCancel:()=>F(null),isLoading:a.isPending})]})})]})}function la({items:s,isLoading:t,onView:n,onEdit:l,onDelete:a}){const{t:i}=X();return t?e.jsx("div",{className:"rounded-md border",children:e.jsxs(Fe,{children:[e.jsx(Te,{children:e.jsxs(Z,{children:[e.jsx(A,{className:"w-[120px]",children:i("common.actions")}),e.jsx(A,{className:"w-[220px]",children:i("settings.salesImportSku.sku")}),e.jsx(A,{children:i("settings.salesImportSku.name")})]})}),e.jsx(Pe,{children:Array.from({length:5}).map((c,g)=>e.jsx(Z,{children:Array.from({length:3}).map((j,y)=>e.jsx(M,{children:e.jsx(se,{className:"h-4 w-full"})},y))},g))})]})}):s.length===0?e.jsxs("div",{className:"rounded-md border p-10 text-center",children:[e.jsx(Fs,{className:"h-10 w-10 mx-auto mb-3 text-muted-foreground opacity-40"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i("settings.salesImportSku.noItems")})]}):e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(Fe,{children:[e.jsx(Te,{children:e.jsxs(Z,{children:[e.jsx(A,{className:"w-[120px] whitespace-nowrap",children:i("common.actions")}),e.jsx(A,{className:"w-[220px] whitespace-nowrap",children:i("settings.salesImportSku.sku")}),e.jsx(A,{children:i("settings.salesImportSku.name")})]})}),e.jsx(Pe,{children:s.map(c=>e.jsxs(Z,{children:[e.jsx(M,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>n(c),title:i("common.view"),children:e.jsx(Ve,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>l(c),title:i("common.edit"),children:e.jsx(Ge,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>a(c),title:i("common.delete"),children:e.jsx(je,{className:"h-4 w-4"})})]})}),e.jsx(M,{className:"whitespace-nowrap",children:e.jsx(W,{variant:"secondary",className:"font-mono",children:c.sku||"-"})}),e.jsx(M,{className:"font-medium",children:c.name||"-"})]},c.id))})]})})}const We="/admin/beeplace/sales-import-sku";function oa(){const s=te();return re({mutationFn:async t=>H.post(We,t),onSuccess:()=>{s.invalidateQueries({queryKey:["sales-import-sku"]})}})}function ca(){const s=te();return re({mutationFn:async({id:t,payload:n})=>H.put(`${We}/${t}`,n),onSuccess:()=>{s.invalidateQueries({queryKey:["sales-import-sku"]})}})}function da(){const s=te();return re({mutationFn:async({id:t,twoFactorCode:n})=>H.delete(`${We}/${t}`,{twoFactorCode:n}),onSuccess:()=>{s.invalidateQueries({queryKey:["sales-import-sku"]})}})}function ma(){const s=te();return re({mutationFn:async t=>{const n=new FormData;return n.append("file",t),H.uploadFormData(`${We}/import`,n)},onSuccess:()=>{s.invalidateQueries({queryKey:["sales-import-sku"]})}})}const ua="/admin/beeplace/sales-import-sku";function xa(){const{t:s}=X(),t=Rs({endpoint:ua}),n=o.useRef(null),l=oa(),a=ca(),i=da(),c=ma(),[g,j]=o.useState(!1),[y,u]=o.useState(null),[k,w]=o.useState(""),[b,I]=o.use
6State(""),[S,F]=o.useState(null),[m,z]=o.useState(null),N=l.isPending||a.isPending,T=()=>{t.handlePageChange(t.currentPage)},V=()=>{u(null),w(""),I(""),j(!0)},d=p=>{u(p),w(p.name??""),I(p.sku??""),j(!0)},f=()=>{j(!1),u(null),w(""),I("")},r=()=>{if(!b.trim()){L.error(s("settings.salesImportSku.skuRequired"));return}if(y){a.mutate({id:y.id,payload:{name:k.trim()||b.trim(),sku:b.trim()}},{onSuccess:()=>{L.success(s("settings.salesImportSku.updatedSuccess")),f(),T()},onError:p=>L.error(p.message||s("settings.salesImportSku.saveError"))});return}l.mutate({name:k.trim()||b.trim(),sku:b.trim()},{onSuccess:()=>{L.success(s("settings.salesImportSku.createdSuccess")),f(),T()},onError:p=>L.error(p.message||s("settings.salesImportSku.saveError"))})},P=async p=>{m&&i.mutate({id:m.id,twoFactorCode:p},{onSuccess:()=>{L.success(s("settings.salesImportSku.deletedSuccess")),z(null),T()},onError:q=>L.error(q.message||s("settings.salesImportSku.deleteError"))})},C=p=>{var Y;const q=(Y=p.target.files)==null?void 0:Y[0];p.target.value="",q&&c.mutate(q,{onSuccess:x=>{L.success(x.message||s("settings.salesImportSku.importSuccess")),T()},onError:x=>L.error(x.message||s("settings.salesImportSku.importError"))})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Fs,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:s("settings.salesImportSku.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settings.salesImportSku.description")})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("input",{ref:n,type:"file",accept:".xlsx,.xls,.csv,.xml,.txt",className:"hidden",onChange:C}),e.jsxs(v,{variant:"outline",size:"sm",className:"gap-1.5",disabled:c.isPending,onClick:()=>{var p;return(p=n.current)==null?void 0:p.click()},children:[c.isPending?e.jsx(de,{className:"h-4 w-4 animate-spin"}):e.jsx(Ss,{className:"h-4 w-4"}),s("settings.salesImportSku.importFile")]}),e.jsxs(v,{onClick:V,size:"sm",className:"gap-1.5",children:[e.jsx(fe,{className:"h-4 w-4"}),s("settings.salesImportSku.addItem")]})]})]}),e.jsx(Ds,{searchQuery:t.searchQuery,onSearchChange:t.setSearchQuery,searchPlaceholder:s("settings.salesImportSku.searchPlaceholder"),filterFields:t.filterFields,onApplyFilters:t.handleApplyFilters,activeFiltersCount:t.activeFilters.length,isLoading:t.isLoading,rawResponse:t.rawResponse,refresh:!0,onRefresh:T}),e.jsx(la,{items:t.items,isLoading:t.isLoading,onView:F,onEdit:d,onDelete:z}),e.jsx(Ls,{pagination:t.pagination,onPageChange:t.handlePageChange,onPageSizeChange:t.handlePageSizeChange,pageSize:t.pageSize,isLoading:t.isLoading}),e.jsx(De,{open:g,onOpenChange:p=>{p||f()},children:e.jsxs(Le,{className:"sm:max-w-md",children:[e.jsxs(Re,{children:[e.jsx(_e,{children:s(y?"settings.salesImportSku.editTitle":"settings.salesImportSku.createTitle")}),e.jsx(us,{children:s(y?"settings.salesImportSku.editDescription":"settings.salesImportSku.createDescription")})]}),e.jsxs("div",{className:"space-y-5 py-6",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{htmlFor:"sku-code",children:s("settings.salesImportSku.sku")}),e.jsx(R,{id:"sku-code",placeholder:s("settings.salesImportSku.skuPlaceholder"),value:b,onChange:p=>I(p.target.value),className:"font-mono"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{htmlFor:"sku-name",children:s("settings.salesImportSku.name")}),e.jsx(R,{id:"sku-name",placeholder:s("settings.salesImportSku.namePlaceholder"),value:k,onChange:p=>w(p.target.value)})]})]}),e.jsxs(xs,{children:[e.jsx(v,{variant:"outline",onClick:f,disabled:N,children:s("common.cancel")}),e.jsxs(v,{onClick:r,disabled:N,className:"gap-1.5",children:[N&&e.jsx(de,{className:"h-4 w-4 animate-spin"}),s("common.save")]})]})]})}),e.jsx(we,{open:!!S,onOpenChange:p=>{p||F(null)},children:e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsxs(Se,{children:[e.jsx(ke,{children:s("settings.salesImportSku.viewTitle")}),e.jsx(Ie,{children:s("settings.salesImportSku.viewDescription")})]}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:s("settings.salesImportSku.sku")}),e.jsx("div",{children:e.jsx(W,{variant:"secondary",className:"font-mono text-sm",children:(S==null?void 0:S.sku)||"-"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:s("settings.salesImportSku.name")}),e.jsx("p",{className:"text-sm font-medium",children:(S==null?void 0:S.name)||"-"})]})]})]})}),e.jsx(we,{open:!!m,onOpenChange:p=>{p||z(null)},children:e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsxs(Se,{children:[e.jsx(ke,{children:s("settings.salesImportSku.deleteTitle")}),e.jsx(Ie,{children:s("settings.salesImportSku.deleteDescription",{name:(m==null?void 0:m.sku)||(m==null?void 0:m.name)})})]}),e.jsx(hs,{onSubmit:P,onCancel:()=>z(null),isLoading:i.isPending})]})})]})}function Ns({icon:s,title:t,description:n}){return e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(s,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:t}),n&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n})]})]})}function ha(s){switch(s.toLowerCase()){case"whatsapp":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400";case"sms":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400";case"rcs":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400";case"portal":return"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-400";default:return"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400"}}function pa(){return e.jsx("div",{className:"space-y-8",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(se,{className:"h-8 w-48"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((s,t)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(se,{className:"h-4 w-24"}),e.jsx(se,{className:"h-10 w-full"})]},t))})]})})}function en(){var z;const{t:s}=X(),{data:t,isLoading:n}=at(),{hasPrivilege:l}=He(),a=nt(),i=te(),[c,g]=o.useState(!1),[j,y]=o.useState(!1),[u,k]=o.useState(null),[w,b]=o.useState(null),I=re({mutationFn:async()=>H.post("/admin/action/customers/config/token-create"),onSuccess:()=>{L.success(s("settings.tokenCreatedSuccess")),i.invalidateQueries({queryKey:["customer-config"]})},onError:N=>{L.error(N.message||s("settings.tokenCreatedError"))}}),S=async()=>{var T;const N=(T=t==null?void 0:t.config)==null?void 0:T.token;N&&(await navigator.clipboard.writeText(N),g(!0),L.success(s("settings.tokenCopied")),setTimeout(()=>g(!1),2e3))},F=(z=t==null?void 0:t.config)==null?void 0:z.token,m=F?"•".repeat(Math.min(F.length,40)):"";return n?e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:s("settings.title")}),e.jsx("p",{className:"text-muted-foreground",children:s("settings.subtitle")})]}),e.jsx(pa,{})]}):e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:s("settings.title")}),e.jsx("p",{className:"text-muted-foreground",children:s("settings.subtitle")})]}),e.jsxs("div",{className:"mb-6 space-y-2",children:[e.jsxs(h,{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(fs,{className:"h-4 w-4"}),s("settings.integrationToken")]}),F?e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{value:j?F:m,readOnly:!0,className:"font-mono text-sm w-full"}),e.jsx(v,{variant:"outline",size:"icon",onClick:()=>y(!j),className:"shrink-0",title:s(j?"settings.hideToken":"settings.showToken"),children:j?e.jsx(it,{className:"h-4 w-4"}):e.jsx(Ve,{className:"h-4 w-4"})}),e.jsx(v,{variant:"outline",size:"icon",onClick:S,className:"shrink-0",children:c?e.jsx(ks,{className:"h-4 w-4 text-green-500"}):e.jsx(Is,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{value:s("settings.noTokenConfigured"),readOnly:!0,disabled:!0,className:"w-full text-muted-foreground"}),e.jsxs(v,{onClick:()=>I.mutate(),disabled:I.isPending,className:"shrink-0",children:[I.isPending?e.jsx(de,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(fs,{className:"h-4 w-4 mr-2"}),s("settings.createToken")]})]})]}),e.jsxs(ct,{defaultValue:"geral",className:"w-full",children:[e.jsxs(dt,{className:"w-full justify-start border-b roun
6ded-none h-auto p-0 bg-transparent",children:[e.jsx(Ne,{value:"geral",className:"data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none px-4 py-3",children:s("settings.generalTab")}),e.jsx(Ne,{value:"canais",className:"data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none px-4 py-3",children:s("settings.channelsTab")}),l("beeone")&&e.jsx(Ne,{value:"beeone",className:"data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none px-4 py-3",children:"BeeOne"}),l("beemedia")&&e.jsx(Ne,{value:"beemedia",className:"data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none px-4 py-3",children:"BeeMedia"}),e.jsx(Ne,{value:"import-cfop",className:"data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none px-4 py-3",children:s("settings.salesImportCfop.tab")}),e.jsx(Ne,{value:"import-sku",className:"data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none px-4 py-3",children:s("settings.salesImportSku.tab")}),e.jsx(Ne,{value:"auditoria",className:"data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none px-4 py-3",children:s("settings.auditTab")})]}),e.jsx(ye,{value:"geral",className:"mt-8",children:e.jsx(Jt,{customer:t})}),e.jsx(ye,{value:"canais",className:"mt-8 space-y-8",children:e.jsxs("section",{className:"space-y-6",children:[e.jsx(Ns,{icon:rt,title:s("settings.channels"),description:s("settings.channelsDescription")}),t!=null&&t.channels&&t.channels.length>0?e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(Fe,{children:[e.jsx(Te,{children:e.jsxs(Z,{children:[e.jsx(A,{className:"w-16",children:s("settings.actions")}),e.jsx(A,{children:s("settings.name")}),e.jsx(A,{children:s("settings.type")}),e.jsx(A,{children:s("settings.status")}),e.jsx(A,{className:"text-right",children:s("settings.templates")})]})}),e.jsx(Pe,{children:t.channels.map(N=>e.jsxs(Z,{children:[e.jsx(M,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[N.type.id==="sms"&&e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>a(`/settings/sms-templates/${N.id}?name=${encodeURIComponent(N.name)}`),title:s("smsTemplates.title"),children:e.jsx(rs,{className:"h-4 w-4"})}),N.type.id==="whatsapp"&&e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>k(N),title:s("settings.whatsappConfig","Configuração WhatsApp"),children:e.jsx(lt,{className:"h-4 w-4"})}),N.type.id==="rcs"&&e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>b(N),title:s("settings.rcsTemplates","Modelos RCS"),children:e.jsx(rs,{className:"h-4 w-4"})})]})}),e.jsx(M,{className:"font-medium",children:N.name}),e.jsx(M,{children:e.jsx(W,{className:ha(N.type.id),children:N.type.name})}),e.jsx(M,{children:e.jsx(W,{variant:N.status.id==="active"?"default":"secondary",className:N.status.id==="active"?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400":"",children:N.status.name})}),e.jsx(M,{className:"text-right",children:N.templates_quantity})]},N.id))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:s("settings.noChannels")})]})}),l("beeone")&&e.jsx(ye,{value:"beeone",className:"mt-8",children:e.jsx(Yt,{})}),l("beemedia")&&e.jsx(ye,{value:"beemedia",className:"mt-8",children:e.jsx(ea,{})}),e.jsx(ye,{value:"import-cfop",className:"mt-8",children:e.jsx(ra,{})}),e.jsx(ye,{value:"import-sku",className:"mt-8",children:e.jsx(xa,{})}),e.jsx(ye,{value:"auditoria",className:"mt-8 space-y-8",children:e.jsxs("section",{className:"space-y-6",children:[e.jsx(Ns,{icon:ot,title:s("audit.title"),description:s("audit.description")}),e.jsx(At,{})]})})]}),e.jsx(qt,{open:!!u,onOpenChange:N=>{N||k(null)},channel:u}),e.jsx($t,{open:!!w,onOpenChange:N=>{N||b(null)},channel:w})]})}export{en 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.