import{r as a,j as e}from"./vendor-react-wBh_31cN.js";import{C as S,a as A,b as I,c as H}from"./card-BeQtvmcJ.js";import{G as z,r as G,aw as F}from"./index-dNe6i2rS.js";import{I as O}from"./input-DFI7JniT.js";import{C as P}from"./checkbox-BlA4MwH9.js";import{I as h}from"./icon-button-BZeFL7T7.js";import{T as j}from"./tooltip-DFFgUYh6.js";import{C as R}from"./confirmation-dialog-C7dws5K4.js";import{T as V,a as X,b,c as r,d as _,e as l}from"./table-a0YeQrHM.js";import{N as w}from"./NoData-BtM2pAIA.js";import{u as Q}from"./useTitle-DQo_L6Ox.js";import{t as U}from"./titles-CzjGGAB3.js";import{a as Y,b as q,c as J}from"./index-yk_nV5MH.js";import{u as K}from"./vendor-router-D1GqFWiT.js";import{Y as W,a6 as Z,ah as $,ai as ee}from"./vendor-icons-BUUmD6ht.js";import"./vendor-redux-CJZrIb6x.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./label-gPWmc6ow.js";import"./useCopyToClipboard-DfzwgDFE.js";import"./useNotifier-BGMn6HaH.js";import"./notifications-5miqOdlG.js";import"./toast-wiGcevcF.js";const T=255,ye=()=>{Q(U.Banners);const y=K(),{data:i,isLoading:k}=Y(),[g,{isLoading:B}]=q(),[C,{isLoading:v}]=J(),[o,u]=a.useState(-1),[c,N]=a.useState(!1),[n,d]=a.useState(""),[m,f]=a.useState(!1),[t,p]=a.useState(null),E=a.useCallback(async s=>{m||((s.active!==c||s.message!==n)&&await g({id:s.id,data:{message:n,active:c}}),u(-1),d(""),f(!1))},[c,n,g,m]),D=a.useCallback(()=>{u(-1),d(""),f(!1)},[]),L=a.useCallback(async()=>{t&&(await C({id:t.id}),p(null))},[t,C]),M=a.useCallback(s=>{u(s.id),d(s.message),N(s.active)},[]);return e.jsxs(S,{children:[e.jsxs(A,{className:"flex flex-row items-center justify-between",children:[e.jsx(I,{children:"Banners"}),e.jsx(z,{onClick:()=>y(G.settings.banner.create),children:"New banner"})]}),e.jsx(H,{className:"max-h-[calc(100vh-215px)] overflow-auto",children:k?e.jsx("div",{className:"my-10 flex justify-center",children:e.jsx(w,{mainText:"Loading..."})}):i!=null&&i.count&&i.count>0?e.jsxs(V,{children:[e.jsx(X,{children:e.jsxs(b,{children:[e.jsx(r,{children:"Id"}),e.jsx(r,{children:"message"}),e.jsx(r,{children:"created on"}),e.jsx(r,{children:"active"}),e.jsx(r,{className:"w-24",children:"actions"})]})}),e.jsx(_,{children:i.items.map(s=>e.jsxs(b,{children:[e.jsx(l,{children:e.jsx("span",{className:"text-xs font-bold",children:s.id})}),e.jsx(l,{children:o===s.id?e.jsxs("div",{className:"w-full",children:[e.jsx(O,{className:m?"border-destructive":void 0,placeholder:"Banner message",value:n,onChange:x=>{f(x.target.value.length>T),d(x.target.value)}}),m&&e.jsxs("span",{className:"text-xs text-destructive",children:["Message can not be longer than ",T," ","characters"]})]}):e.jsx("span",{className:"text-xs font-bold whitespace-normal break-words",children:s.message})}),e.jsx(l,{children:e.jsx("span",{className:"whitespace-nowrap text-xs font-bold",children:F(new Date(s.createdOn),"yyyy-MM-dd HH:mm")})}),e.jsx(l,{children:e.jsx(P,{checked:o===s.id?c:s.active,disabled:o!==s.id,onCheckedChange:()=>N(x=>!x)})}),e.jsx(l,{children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[o===s.id?e.jsxs(e.Fragment,{children:[e.jsx(j,{content:"Cancel",children:e.jsx(h,{onClick:()=>D(),children:e.jsx(W,{className:"size-4"})})}),e.jsx(j,{content:"Save",children:e.jsx(h,{onClick:()=>E(s),disabled:n==="",children:e.jsx(Z,{className:"size-4"})})})]}):e.jsx(j,{content:"Edit banner",children:e.jsx(h,{disabled:B,onClick:()=>M(s),children:e.jsx($,{className:"size-4"})})}),e.jsx(j,{content:"Delete banner",children:e.jsx(h,{disabled:v,onClick:()=>p(s),children:e.jsx(ee,{className:"size-4"})})})]})})]},s.id))})]}):e.jsx("div",{className:"my-10 flex justify-center",children:e.jsx(w,{mainText:"No banners found"})})}),e.jsx(R,{open:!!t,onOpenChange:s=>!s&&p(null),title:"Delete banner",description:t&&e.jsxs(e.Fragment,{children:["Permanently removes banner"," ",e.jsxs("code",{className:"font-mono",children:["#",t.id]}),". Active users will stop seeing it on their next refresh."]}),confirmLabel:"Delete",confirmVariant:"destructive",isLoading:v,onConfirm:L})]})};export{ye as default};
