PageSourceSearch

https://skyfree.io/assets/instance-settings-JTEXCL0N.js

js skyfree.io collected 2026-10-10 02:45:13 UTC 92,563 bytes, 1 lines download raw bytes

1import{c as M,u as Q,j as e,b as E,f as Ee,r as F,a as B,q as ce,i as Ve,o as Ze}from"./index-CyVA1wZG.js";import{S as Xe,a as es}from"./settings-page-7eLG4i49.js";import{T as Ie,a as ss,b as _,c as $}from"./tabs-BSv5s0B5.js";import{b3 as b,b4 as y,bh as D,bi as A,bk as L,ak as fe,b1 as Z,C as te,A as ae,l as Ne,b as re,b5 as G,e as C,aK as ie,aI as ts,D as as,o as ns,p as is,q as rs,r as ls,s as f,t as w,f as K,G as os,ay as cs,I as ds,E as ms,X as xs}from"./impersonation-banner-D_-on_xF.js";import"./textarea-BAAzCWx0.js";import"./command-CGbqgb5N.js";import{d as Pe,h as X,S as Ue,m as Le}from"./App-CWO1MySO.js";import{a as ps}from"./date-time-picker-Cq4LNC5d.js";import"./checkbox-Bz5Ppm-b.js";import{S as de}from"./secret-input-0MvpVn2Y.js";import"./table-vgAu5oIo.js";import"./ReportSettings-DDBs1N34.js";import{A as Y,a as V,b as be}from"./alert-3B0XQEPe.js";import"./whatsapp-pricing-markets-l_y2XGrE.js";import{P as me}from"./progress-BV93x1kq.js";import{C as W}from"./clock-UctaHBkk.js";import{C as _e}from"./cpu-BBaEK5ws.js";import{C as xe,a as us}from"./index-Cyws3dvY.js";import{H as $e}from"./hard-drive-DI9nkgX0.js";import{D as qe}from"./database-DFVn6Xwf.js";import{T as Me}from"./timer-DDyXHuQ-.js";import{R as ee}from"./refresh-cw-bmXc0t69.js";import{P as je}from"./play-C4unFlt-.js";import{S as H}from"./save-BToXywlw.js";import{M as hs}from"./mail-BRwUCvof.js";import{C as gs}from"./coins-B_3Apj-E.js";import{L as js}from"./loading-DfhTHglN.js";import{A as ye,a as we,b as Ce,c as Se,d as ke,g as Te,e as Re,f as Fe}from"./alert-dialog-BdVAm21o.js";import{E as vs}from"./eye-nDwGkKxV.js";import"./radio-group-CJiUcfGQ.js";import{S as fs}from"./shield-tne_7Bqb.js";import{S as Ns}from"./square-pen-DRDG8PZg.js";import{S as bs}from"./shield-alert-S4pHxDJ6.js";import{E as ys}from"./external-link-BrFw_46Q.js";import"./UserMigrationSettings-DFgokOVE.js";import{N as ws}from"./nova-resource-page-tJJ4o3y3.js";import{N as Cs,a as J}from"./nova-tabs-4Yum497P.js";import"./page-shell-Dh0kFaWJ.js";import"./useDocForPage-BGLLPY-H.js";import"./calendar-DeeSB-aS.js";import"./format-cwji8z7Q.js";import"./subDays-DPIRz014.js";import"./calendar-UomhDNlY.js";import"./eye-off-BGDLimLG.js";import"./zod-Dw4DNUzk.js";import"./types-BZPsxhkr.js";import"./nova-page-loading-skeleton-BazY73MQ.js";import"./skeleton-B2sPiNj4.js";import"./pencil-DNJ5mpuN.js";import"./message-circle-CRCJmKJC.js";import"./share-2-ygOmOU9v.js";import"./send-3NBqOeP2.js";import"./text-A0nlxLOL.js";import"./archive-restore-FM2dPnwr.js";import"./archive-BOfBzNnP.js";import"./file-video-DJBatoBj.js";import"./rotate-cw-mjWMKm7s.js";import"./utensils-crossed-Bl5lnZV1.js";import"./arrow-left-DYJneMpH.js";import"./arrow-right-D0Mq4PqU.js";import"./arrow-up-down-BIb00ASA.js";import"./arrow-up-from-line-BGm87DDc.js";import"./arrow-up-right-C19qRLDz.js";import"./arrow-up-BobGifBN.js";import"./badge-check-DVjyf89D.js";import"./circle-dollar-sign-5lL0cZiK.js";import"./ban-BuVd_gnz.js";import"./banknote-Ct2QbcgU.js";import"./palette-CjKcYu_q.js";import"./route-CPnOlaSn.js";import"./bell-ring-DrQ0OoSE.js";import"./underline-CKuHzKmt.js";import"./package-plus-CfpHUjT-.js";import"./brain-BcC2H6sU.js";import"./building-2-D1R3xnPL.js";import"./building-Ba1fne-K.js";import"./calculator-DDuh47ww.js";import"./table-2-TaSZEwWe.js";import"./calendar-clock-CH6LyeLZ.js";import"./calendar-days-DgPqoNWk.js";import"./calendar-plus-CxthDDkr.js";import"./clipboard-list-CuTbWCOr.js";import"./ticket-check-Bb2Ft2WC.js";import"./check-check-ClQgMzxB.js";import"./chrome-ZGCtSbGF.js";import"./circle-arrow-up-C5x3LCsB.js";import"./circle-dot-C9zeTmWq.js";import"./circle-help-CYlyU9fn.js";import"./circle-pause-DArF6UMB.js";import"./circle-play-DDMI03lE.js";import"./circle-plus-BfyCn4vP.js";import"./circle-slash-d5uGid4F.js";import"./zoom-out-BIzTvE93.js";import"./clock-3-BBZ1OSPv.js";import"./wallet-cards-C3olmktY.js";import"./grip-vertical-B70wR535.js";import"./cloud-CXL4walE.js";import"./shuffle-yCKdQr6X.js";import"./columns-3-boGl6_Ii.js";import"./contact-Cuf0wffl.js";import"./copy-DJefu7dN.js";import"./flask-conical-DHUyoCAV.js";import"./dollar-sign-DmOk-lMY.js";import"./download-BgrmGuYP.js";import"./earth-DpB8vzG6.js";import"./ellipsis-vertical-Dn1i_GeF.js";import"./ellipsis-Dquka5Nr.js";import"./file-audio-DVEm3v9K.js";import"./file-json-Cng9zown.js";import"./file-spreadsheet-D_0u7NNL.js";import"./file-CdycwSAs.js";import"./filter-CenHxjh1.js";import"./gauge-BRGcZKOM.js";import"./git-merge-Cn73itjx.js";import"./smile-Diw3Qtw1.js";import"./hash--gk5oonj.js";import"./heart-handshake-BbrkjCeY.js";import"./heart-Bs4dGrzQ.js";import"./history-B-9ktNtG.js";import"./image-plus-DZ8Nbz7q.js";import"./inbox-C6g67XRK.js";import"./key-round-DfxXSENE.js";import"./key-kuU8HuVy.js";import"./link-2-CblmVkID.js";import"./list-checks-CAdK6_YX.js";import"./list-ordered-C_ubEwva.js";import"./list-tree-BljQWPPB.js";import"./list-BsOG-rLk.js";import"./loader-CGo49SQy.js";import"./log-in-BSpq3owE.js";import"./mail-check-B7zhYkCm.js";import"./map-pin-BAUvPgHL.js";import"./minimize-2-N7svW4OO.js";import"./mic-off-CP4j7kVD.js";import"./volume-2-DnBxHc1z.js";import"./minus-DwvTtZqv.js";import"./mouse-pointer-click-FN5PNFvr.js";import"./navigation-Bvx5gCTI.js";import"./notebook-text-e3AGSGqz.js";import"./package-2-C1oNaY3y.js";import"./package-search-Dok6ea23.js";import"./package-DRq5kk1w.js";import"./paperclip-C8Q31JHW.js";import"./pause-Wl5Cw2rQ.js";import"./pen-line-BBFuH1dX.js";import"./pen-tool-BVhYfnOb.js";import"./pen-DEHGjG5p.js";import"./pencil-line-B0TKZ51M.js";import"./percent-JigkGWO_.js";import"./phone-call-C8QqagXp.js";import"./phone-incoming-BhT6Hefm.js";import"./phone-missed-6nKbsgDr.js";import"./phone-off-CPluY9O4.js";import"./phone-outgoing-J-BfANgW.js";import"./piggy-bank-BdlhXSTp.js";import"./send-horizontal-C1L7gmNH.js";import"./plug-zap-DlAOmwtM.js";import"./plug-DvJhBop0.js";import"./power-off-C_cmm9ho.js";import"./power-CdgTt_c-.js";import"./printer-DbWENF4H.js";import"./repeat-gzhWY2XU.js";import"./reply-al6uMhks.js";import"./rocket-Dhyo7yC0.js";import"./rotate-ccw-Dj_yWHYP.js";import"./scan-eye-Dw8KBJJ3.js";import"./shield-off-v_LwRlIv.js";import"./shopping-cart-O_AqCqmR.js";import"./signal-2REJKlPN.js";import"./sliders-horizontal-C3IxzjAB.js";import"./sparkles-jkgtCYTV.js";import"./square-BCyPLuPo.js";import"./star-DJZNhvge.js";import"./thumbs-up-DGdeWsMQ.js";import"./tablet-CHCs3etf.js";import"./target-Cws70lMw.js";import"./terminal-ifww_Mmp.js";import"./toggle-left-Cnfe4whY.js";
1import"./trash-C0cniiE4.js";import"./trending-up-DInhCtGt.js";import"./truck-CaJBneIv.js";import"./type-Chw98N9F.js";import"./undo-2-D2TDCoRr.js";import"./unplug-CcqWJvMR.js";import"./upload-B8ptddDD.js";import"./user-check-C4RT6qND.js";import"./user-cog-DJSooon4.js";import"./user-minus-ZOrXXr6f.js";import"./user-plus-DzcVh8rd.js";import"./user-round-BO7U1oah.js";import"./user-x-WAraSCgS.js";import"./wand-sparkles-i4QVfNUf.js";import"./webhook-CyPLGtD_.js";import"./wrench-BRjI98mr.js";import"./separator-DX9XCSTk.js";function Ss({borderless:t=!1}){const{t:s}=M(),{data:a,isLoading:o,error:j}=Q({queryKey:["/api/server-stats"],queryFn:async()=>{try{return await(await E("GET","/api/server-stats")).json()}catch(h){throw h}},refetchInterval:5e3,retry:1});try{if(o)return e.jsx("div",{className:"space-y-3",children:e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0 pt-0":"pt-6",children:e.jsx("p",{className:"text-center text-muted-foreground",children:s("common.loadingServerStats")})})})});if(j)return e.jsx("div",{className:"space-y-3",children:e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0 pt-0":"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-red-500 font-medium mb-2",children:s("common.failedToLoadServerStats")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?.message||"Please ensure you have owner access"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Check browser console for details"})]})})})});if(!a)return e.jsx("div",{className:"space-y-3",children:e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0 pt-0":"pt-6",children:e.jsx("p",{className:"text-center text-muted-foreground",children:s("common.noData")})})})});if(!a.server||!a.cpu||!a.memory||!a.worker||!a.queue)return e.jsx("div",{className:"space-y-3",children:e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0 pt-0":"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-red-500 font-medium mb-2",children:s("common.invalidServerData")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Server returned incomplete information"}),e.jsx("pre",{className:"text-xs mt-2 text-left bg-muted p-2 rounded",children:JSON.stringify(a,null,2)})]})})})});const h=a.memory?.usagePercent||0,x=h>80?"bg-red-500":h>60?"bg-yellow-500":"bg-green-500",k=a.cpu?.loadAverage?.[0]||0,l=a.cpu?.cores||1,i=Math.min(k/l*100,100),N=i>80?"bg-red-500":i>60?"bg-yellow-500":"bg-green-500";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsxs(D,{className:t?"px-0 py-0":void 0,children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2",children:[!t&&e.jsx(Pe,{className:"w-5 h-5"}),"Server Information"]}),e.jsx(L,{children:s("common.basicServerDetails")})]}),e.jsxs(y,{className:`space-y-3 ${t?"px-0 pb-0 pt-4":""}`,children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.hostname")}
1),e.jsx("span",{className:"text-sm font-mono",children:a.server.hostname})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("admin.platform")}),e.jsx("span",{className:"text-sm font-mono",children:a.server.platform})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.architecture")}),e.jsx("span",{className:"text-sm font-mono",children:a.server.architecture})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(W,{className:"w-4 h-4"}),"Uptime"]}),e.jsx("span",{className:"text-sm font-mono",children:a.server.uptime.formatted})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsxs(D,{className:t?"px-0 py-0":void 0,children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2",children:[!t&&e.jsx(_e,{className:"w-5 h-5"}),"CPU"]}),e.jsx(L,{children:s("common.processorInformation")})]}),e.jsxs(y,{className:`space-y-3 ${t?"px-0 pb-0 pt-4":""}`,children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.coresAllocated")}),e.jsxs("span",{className:"text-sm font-semibold",children:[a.cpu.cores," cores"]})]}),a.cpu.physicalCores&&a.cpu.physicalCores!==a.cpu.cores&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.physicalCores")}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[a.cpu.physicalCores," cores (host)"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.model")}),e.jsxs("span",{className:"text-sm font-mono text-xs",children:[a.cpu.model.substring(0,30),"..."]})]}),a.server.containerLimits&&e.jsx("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950 p-3 mt-2",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs text-blue-700 dark:text-blue-300",children:[e.jsx(xe,{className:"w-3.5 h-3.5 shrink-0"}),"Container: ",a.server.containerLimits.allocatedCPU," vCPU allocated (from ",a.server.containerLimits.physicalCPU," physical cores)"]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.loadAverage1m")}),e.jsx("span",{className:"text-sm font-mono",children:k.toFixed(2)})]}),e.jsx(me,{value:i,className:`h-2 ${N}`}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.toFixed(0),"% utilization"]})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsxs(D,{className:t?"px-0 py-0":void 0,children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2",children:[!t&&e.jsx($e,{className:"w-5 h-5"}),"Memory"]}),e.jsx(L,{children:s("common.ramUsage")})]}),e.jsxs(y,{className:`space-y-3 ${t?"px-0 pb-0 pt-4":""}`,children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a.memory.physicalTotal&&a.memory.total!==a.memory.physicalTotal?"Total RAM (Allocated)":"Total RAM"}),e.jsxs("span",{className:"text-sm font-semibold",children:[a.memory.total," GB"]})]}),a.memory.physicalTotal&&a.memory.total!==a.memory.physicalTotal&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.physicalRam")}),e.jsxs("span",{className:"text-sm text-content-tertiary",children:[a.memory.physicalTotal," GB (host)"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.used")}),e.jsxs("span",{className:"text-sm",children:[a.memory.used," GB"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.free")}),e.jsxs("span",{className:"text-sm",children:[a.memory.free," GB"]})]}),a.server.containerLimits?.allocatedRAM&&e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-tint-info px-3 py-2 text-sm text-tint-info-fg",children:[e.jsx(xe,{className:"w-4 h-4 shrink-0"}),"Container: ",a.server.containerLimits.allocatedRAM," GB allocated (from ",a.server.containerLimits.physicalRAM," GB physical)"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(me,{value:a.memory.usagePercent,className:`h-2 ${x}`}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a.memory.usagePercent,"% used"]})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsxs(D,{className:t?"px-0 py-0":void 0,children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2",children:[!t&&e.jsx(fe,{className:"w-5 h-5"}),"Campaign Worker"]}),e.jsx(L,{children:s("common.backgroundJobProcessor")})]}),e.jsxs(y,{className:`space-y-3 ${t?"px-0 pb-0 pt-4":""}`,children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.status")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${a.worker.isRunning?"bg-green-500 animate-pulse":"bg-red-500"}`}),e.jsx("span",{className:`text-sm font-semibold ${a.worker.isRunning?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:a.worker.status==="running"?"Running":"Stopped"})]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.activeWorkers")}),e.jsxs("span",{className:"text-sm font-semibold",children:[a.worker.activeWorkers," worker",a.worker.activeWorkers!==1?"s":""]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.concurrency")}),e.jsxs("span",{className:"text-sm font-semibold",children:[a.worker.concurrency," jobs at once"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.rateLimit")}),e.jsxs("span",{className:"text-sm",children:[a.worker.rateLimit," messages/sec"]})]}),a.worker.error?e.jsx("div",{className:"rounded-md bg-yellow-50 dark:bg-yellow-950 p-3 mt-2",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs text-yellow-700 dark:text-yellow-300",children:[e.jsx(Z,{className:"w-3.5 h-3.5 shrink-0"}),a.worker.error]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md bg-muted p-3 mt-2",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Auto-detected: ",a.worker.description]})}),e.jsx("div",{className:`rounded-md p-3 mt-2 ${a.worker.isRunning?"bg-green-50 dark:bg-green-950":"bg-red-50 dark:bg-red-950"}`,children:e.jsxs("p",{className:`flex items-center gap-1 text-xs ${a.worker.isRunning?"text-green-700 dark:text-green-300":"text-red-700 dark:text-red-300"}`,children:[a.worker.isRunning?e.jsx(te,{className:"w-3.5 h-3.5 shrink-0"}):e.jsx(Z,{className:"w-3.5 h-3.5 shrink-0"}),a.worker.isRunning?"Worker is active and processing campaigns":"No workers detected - campaigns will not process"]})})]})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsxs(D,{className:t?"px-0 py-0":void 0,children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2",children:[!t&&e.jsx(qe,{className:"w-5 h-5"}),"Campaign Queue Status"]}),e.jsx(L,{children:s("common.realTimeMessageQueueStatistics")})]}),e.jsx(y,{className:t?"px-0 pb-0 pt-4":void 0,children:a.queue.error?e.jsx("div",{className:"p-4 rounded-lg bg-yellow-50 dark:bg-yellow-950",children:e.jsxs("p",{className:"flex items-center gap-1.5 text-sm text-yellow-700 dark:text-yellow-300",children:[e.jsx(Z,{className:"w-4 h-4 shrink-0"}),a.queue.error]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 ga
1p-4",children:[e.jsxs("div",{className:"text-center p-4 rounded-lg bg-surface-muted border border-line",children:[e.jsx(ae,{className:"w-6 h-6 mx-auto mb-2 text-blue-500"}),e.jsx("p",{className:"text-2xl font-bold",children:a.queue.active}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("common.active")})]}),e.jsxs("div",{className:"text-center p-4 rounded-lg bg-surface-muted border border-line",children:[e.jsx(W,{className:"w-6 h-6 mx-auto mb-2 text-yellow-500"}),e.jsx("p",{className:"text-2xl font-bold",children:a.queue.waiting}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("common.waiting")})]}),e.jsxs("div",{className:"text-center p-4 rounded-lg bg-surface-muted border border-line",children:[e.jsx(W,{className:"w-6 h-6 mx-auto mb-2 text-orange-500"}),e.jsx("p",{className:"text-2xl font-bold",children:a.queue.delayed}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("common.scheduled")})]}),e.jsxs("div",{className:"text-center p-4 rounded-lg bg-surface-muted border border-line",children:[e.jsx(te,{className:"w-6 h-6 mx-auto mb-2 text-green-500"}),e.jsx("p",{className:"text-2xl font-bold",children:a.queue.completed}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("admin.completed")})]}),e.jsxs("div",{className:"text-center p-4 rounded-lg bg-surface-muted border border-line",children:[e.jsx(Ne,{className:"w-6 h-6 mx-auto mb-2 text-red-500"}),e.jsx("p",{className:"text-2xl font-bold",children:a.queue.failed}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("inbox.failed")})]})]}),a.queue.waiting>0&&e.jsxs("div",{className:"mt-4 p-4 rounded-lg bg-blue-50 dark:bg-blue-950",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-sm font-medium text-blue-700 dark:text-blue-300",children:[e.jsx(Me,{className:"w-4 h-4 shrink-0"}),"Estimated processing time: ",Math.ceil(a.queue.waiting/a.worker.rateLimit)," seconds"]}),e.jsxs("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-1",children:["At ",a.worker.rateLimit," messages/second with ",a.worker.concurrency," concurrent workers"]})]})]})})]}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[e.jsx(ae,{className:"w-3 h-3 animate-pulse"}),e.jsx("span",{children:s("common.autoRefreshingEvery5Seconds")})]})]})}catch(h){return console.error("Render error:",h),e.jsx("div",{className:"space-y-3",children:e.jsx(b,{children:e.jsx(y,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-red-500 font-medium mb-2",children:s("common.errorRenderingStats")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:h?.message||"Unknown error"})]})})})})}}function De(t){const s=Math.max(1,Math.round(Number(t)||0)),a=(o,j)=>`${o} ${j}${o===1?"":"s"}`;return s%86400===0?a(s/86400,"day"):s%3600===0?a(s/3600,"hour"):s%60===0?a(s/60,"minute"):a(s,"second")}function ks({data:t}){const{t:s}=M();return e.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--nova-border)] bg-[var(--nova-hover-bg)] p-3 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-[var(--nova-text-muted)]",children:s("settings.cronRunsIn")}),e.jsx("span",{className:"font-medium text-[var(--nova-text-secondary)]",children:s("settings.cronRunsInWorker")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-[var(--nova-text-muted)]",children:s("settings.cronScheduleUtc")}),e.jsx("span",{className:"font-mono text-[var(--nova-text-secondary)]",children:t.effectiveSchedule||s("settings.cronNotSchedulable")})]}),t.includes?.length?e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-[var(--nova-text-muted)]",children:s("settings.cronProcessorsOnSchedule")}),e.jsx("span",{className:"text-right text-[var(--nova-text-secondary)]",children:t.includes.join(", ")})]}):null]})}const ze={ok:"success",running:"info",failing:"danger",overdue:"warning",never:"neutral",disabled:"neutral"},ve={ok:"settings.cronHealthOk",running:"settings.cronHealthRunning",failing:"settings.cronHealthFailing",overdue:"settings.cronHealthOverdue",never:"settings.cronHealthNever",disabled:"settings.cronHealthDisabled"};function pe(t){if(!t)return null;const s=new Date(t);
1return Number.isNaN(s.getTime())?null:s.toLocaleString()}function Be(t){return t==null?null:t<1e3?`${t} ms`:`${(t/1e3).toFixed(t<1e4?1:0)} s`}function Ts({monitor:t}){const{t:s}=M(),a=pe(t?.lastStartedAt),o=Be(t?.lastDurationMs);return e.jsxs("span",{className:"mt-1 block text-xs text-[var(--nova-text-muted)]",children:[s("settings.cronLastRun"),": ",a??s("settings.cronNeverRun"),a&&o?` · ${o}`:"",t?.runRequestedAt?` · ${s("settings.cronRunPending")}`:""]})}function Rs({monitor:t}){const{t:s}=M();if(!t)return null;const a=[[s("settings.cronLastRun"),pe(t.lastStartedAt)??s("settings.cronNeverRun")],[s("settings.cronLastSuccess"),pe(t.lastSuccessAt)],[s("settings.cronDuration"),Be(t.lastDurationMs)],[s("settings.cronRunCount"),String(t.runCount)],[s("settings.cronFailureCount"),String(t.failureCount)]];return e.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--nova-border)] bg-[var(--nova-hover-bg)] p-3 text-xs",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsx(ie,{tone:ze[t.health],children:s(ve[t.health])})}),a.map(([o,j])=>j?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-[var(--nova-text-muted)]",children:o}),e.jsx("span",{className:"text-[var(--nova-text-secondary)]",children:j})]},o):null),t.lastError&&t.health==="failing"?e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-[var(--nova-text-muted)]",children:s("settings.cronLastError")}),e.jsx("span",{className:"break-words text-right text-[var(--nova-text-secondary)]",children:t.lastError})]}):null]})}function Oe({borderless:t=!1}){const{t:s}=M(),{toast:a}=re(),o=Ee(),[j,h]=F.useState({}),[x,k]=F.useState(null),{data:l,isLoading:i,isFetching:N,error:T}=Q({queryKey:["/api/system-settings/cron"],queryFn:async()=>{const r=await fetch("/api/system-settings/cron");if(!r.ok)throw new Error("Failed to fetch cron settings");return await r.json()},refetchInterval:15e3}),m=B({mutationFn:async r=>{const c=await fetch(`/api/system-settings/cron/${encodeURIComponent(r)}/run`,{method:"POST"});if(!c.ok)throw new Error("Failed to request run");return c.json()},onSuccess:()=>{a({title:s("settings.cronRunRequested")}),setTimeout(()=>o.invalidateQueries({queryKey:["/api/system-settings/cron"]}),15e3),o.invalidateQueries({queryKey:["/api/system-settings/cron"]})},onError:()=>{a({title:s("settings.cronRunRequestFailed"),variant:"destructive"})}}),p=B({mutationFn:async({key:r,value:c})=>{const n=await fetch(`/api/system-settings/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!n.ok)throw new Error("Failed to update setting");return n.json()},onSuccess:(r,c)=>{o.invalidateQueries({queryKey:["/api/system-settings/cron"]});const n=l?.[c.key]?.name||c.key;a({title:s("common.settingsUpdated2"),description:`${n} settings have been updated. Server will apply changes on next run.`}),h(u=>{const R={...u};return delete R[c.key],R})},onError:r=>{a({title:s("common.error"),description:r.message,variant:"destructive"})}}),S=(r,c,n)=>{h(u=>({...u,[r]:{...l?.[r]||{},...u[r]||{},[c]:n}}))},I=r=>{const c=j[r]||l?.[r];if(c){const n=c.schedule?{...c,timezone:"UTC"}:c;p.mutate({key:r,value:n})}},q=r=>r in j,d=r=>j[r]||l?.[r]||{enabled:!0},v=(r,c)=>{const n=d(r),u=q(r);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(f,{className:"text-sm font-medium",children:s("common.enabled")}),c.critical?e.jsxs("p",{className:"mt-0.5 flex items-center gap-1 text-xs text-[var(--nova-text-muted)]",children:[e.jsx(G,{className:"h-3 w-3"}),"This job cannot be disabled as it's required for system operation"]}):null]}),e.jsx(X,{checked:n.enabled,onCheckedChange:R=>S(r,"enabled",R),disabled:c.critical})]}),c.usesInterval&&!c.critical&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:`${r}-interval`,children:"Interval (seconds) - Higher = Less server load"}),e.jsx(w,{id:`${r}-interval`,type:"number",min:"10",max:"3600",value:n.intervalSeconds||300,onChange:R=>S(r,"intervalSeconds",parseInt(R.target.value)),disabled:!n.enabled}),e.jsxs("p",{className:"text-xs text-[var(--nova-text-muted)]",children:["Current: Every ",n.intervalSeconds||300," seconds (",Math.round((n.intervalSeconds||300)/60)," minutes)"]})]}),c.usesInterval&&c.critical&&e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-hover-bg)] p-3",children:[e.jsxs("p",{className:"text-sm text-[var(--nova-text-secondary)]",children:[e.jsx("strong",{children:"Interval:"})," Every ",De(n.intervalSeconds||86400)]}),e.jsx("p",{className:"mt-1 text-xs text-[var(--nova-text-muted)]",children:"This is a system-managed setting and cannot be modified."})]}),!c.usesInterval&&n.schedule&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:`${r}-schedule`,children:s("common.cronSchedule")}),e.jsx(w,{id:`${r}-schedule`,value:n.schedule,onChange:R=>S(r,"schedule",R.target.value),disabled:!n.enabled,className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-[var(--nova-text-muted)]",children:'UTC only — format: minute hour day month weekday (e.g. "0 0 * * *" = daily at 00:00 UTC)'})]}),n.batchSize!==void 0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:`${r}-batch`,children:s("common.batchSize")}),e.jsx(w,{id:`${r}-batch`,type:"number",min:"10",max:"500",value:n.batchSize,onChange:R=>S(r,"batchSize",parseInt(R.target.value)),disabled:!n.enabled}),e.jsxs("p",{className:"text-xs text-[var(--nova-text-muted)]",children:["Process ",n.batchSize," items per run"]})]}),u&&e.jsxs(ps,{onClick:()=>I(r),disabled:p.isPending,className:"w-full justify-center",children:[e.jsx(H,{className:"h-4 w-4"}),"Save Changes"]})]})};return i?e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0":"p-6",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(ee,{className:"w-6 h-6 animate-spin text-content-muted"}),e.jsx("span",{className:"ml-2 text-content-secondary",children:s("common.loadingSettings")})]})})}):T?e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0":"p-6",children:e.jsxs("div",{className:"flex items-center justify-center text-red-600",children:[e.jsx(G,{className:"w-6 h-6 mr-2"}),e.jsxs("span",{children:["Error loading settings: ",T.message]})]})})}):!l||Object.keys(l).length===0?e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0":"p-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx(G,{className:"w-12 h-12 mx-auto text-yellow-500 mb-4"}),e.jsx("p",{className:"text-content-secondary mb-4",children:s("common.noCronJobsConfiguredYetTheSystemWillAuto0a2fd1")}),e.jsxs(C,{onClick:()=>o.invalidateQueries({queryKey:["/api/system-settings/cron"]}),disabled:N,children:[e.jsx(ee,{className:`w-4 h-4 mr-2 ${N?"animate-spin":""}`}),"Refresh"]})]})})}):t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-[var(--nova-text-primary)]",children:"System Cron Jobs Configuration"}),e.jsx("p",{className:"mt-0.5 text-xs text-[var(--nova-text-muted)]",children:"Configure automated background tasks. Changes require server restart to take full effect."})]}),e.jsx("div",{className:"mt-4 divide-y divide-[var(--nova-border)]",children:Object.entries(l).map(([r,c])=>{const n=d(r);return e.jsxs("button",{type:"button",onClick:()=>k(r),className:"flex w-full items-center gap-4 py-4 text-left transition-colors hover:bg-[var(--nova-hover-bg)]",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-bg)]",children:e.jsx(W,{className:"h-4 w-4 text-[var(--nova-text-secondary)]"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium text-[var(--nova-text-primary)]",children:c.name}),c.critical&&e.jsx(ie,{tone:"danger",children:s("common.critical")})]}),e.jsx("span",{className:"mt-0.5 block text-xs text-[var(--nova-text-muted)]",children:c.description}),e.jsxs("span",{className:"mt-1 block font-mono text-xs text-[var(--nova-text-secondary)]",children:[c.effectiveSchedule||s("settings.cronNotSchedulable")," · UTC"]}),e.jsx(Ts,{monitor:c.monitor})]}),c.monitor&&c.monitor.health!=="ok"&&c.monitor.health!=="disabled"?e.jsx(ie,{tone:ze[c.monitor.health],children:s(ve[c.monitor.health])}):null,e.jsx(ie,{tone:n.enabled?"success":"neutral",children:n.enabled?s("common.enabled"):s("common.disabled")}),e.jsx(ts,{className:"h-4 w-4 shrink-0 text-[var(--nova-text-muted)]"})]},r)})}),e.jsx(as,{open:!!x,onOpenChange:r=>{r||k(null)},children:e.jsxs(ns,{className:"bg-[var(--nova-panel-bg)] sm:max-w-lg",children:[e.jsxs(is,{children:[e.jsx(rs,{children:x?l[x]?.name:""}),e.jsx(ls,{children:x?l[x]?.description:""})]}),e.jsxs("div",{className:"space-y-5 pt-4",children:[x&&l[x]?e.jsx(ks,{data:l[x]}):null,x&&l[x]?e.jsxs(e.Fragment,{children:[e.jsx(Rs,{monitor:l[x].monitor}),e.jsxs(C,{type:"button",variant:"outline",className:"w-full",onClick:()=>m.mutate(x),disabled:m.isPending||!d(x).enabled||!!l[x].monitor?.runRequestedAt,children:[e.jsx(je,{className:"mr-2 h-4 w-4"}),s("settings.cronRunNow")]})]}):null,x&&l[x]?v(x,l[x]):null]})]})})]}):e.jsx("div",{className:"space-y-3",children:e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsxs(D,{className:t?"px-0 pt-0":void 0,children:[e.jsxs(A,{className:"flex items-center gap-2",children:[e.jsx(W,{className:"w-5 h-5"}),"System Cron Jobs Configuration"]}),e.jsx(L,{children:"Configure automated background tasks. Changes require server restart to take full effect."})]}),e.jsx(y,{className:t?"px-0 pb-0":void 0,children:e.jsx("div",{className:"space-y-3",children:l&&Object.entries(l).map(([r,c])=>{const n=d(r),u=q(r);return e.jsxs(b,{className:u?"border-tint-warning-border bg-tint-warning":"",children:[e.jsx(D,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{className:"text-lg",children:c.name}),c.critical&&e.jsx("span",{className:"text-xs bg-tint-danger-strong text-tint-danger-fg-muted px-2 py-0.5 rounded-full font-medium",children:"Critical"})]}),e.jsx(L,{children:c.description}),e.jsxs("p",{className:"text-xs text-content-tertiary mt-1",children:[s("settings.cronRunsIn"),": ",s("settings.cronRunsInWorker")," · ",s("settings.cronScheduleUtc"),":"," ",e.jsx("span",{className:"font-mono",children:c.effectiveSchedule||s("settings.cronNotSchedulable")}),c.includes?.length?` · ${c.includes.join(", ")}`:""]}),e.jsxs("p",{className:"text-xs text-content-tertiary mt-1",children:[s("settings.cronLastRu
1n"),":"," ",pe(c.monitor?.lastStartedAt)??s("settings.cronNeverRun"),c.monitor&&c.monitor.health!=="ok"?` · ${s(ve[c.monitor.health])}`:""]}),c.critical&&e.jsxs("p",{className:"text-xs text-red-600 mt-1 flex items-center gap-1",children:[e.jsx(G,{className:"w-3 h-3"}),"This job cannot be disabled as it's required for system operation"]})]}),e.jsx(X,{checked:n.enabled,onCheckedChange:R=>S(r,"enabled",R),disabled:c.critical})]})}),e.jsxs(y,{className:"space-y-4",children:[c.usesInterval&&!c.critical&&e.jsxs("div",{children:[e.jsx(f,{htmlFor:`${r}-interval`,children:"Interval (seconds) - Higher = Less server load"}),e.jsx(w,{id:`${r}-interval`,type:"number",min:"10",max:"3600",value:n.intervalSeconds||300,onChange:R=>S(r,"intervalSeconds",parseInt(R.target.value)),disabled:!n.enabled,className:"mt-1"}),e.jsxs("p",{className:"text-xs text-content-tertiary mt-1",children:["Current: Every ",n.intervalSeconds||300," seconds (",Math.round((n.intervalSeconds||300)/60)," minutes)"]})]}),c.usesInterval&&c.critical&&e.jsxs("div",{className:"p-3 bg-surface-muted border border-line rounded-md",children:[e.jsxs("p",{className:"text-sm text-content-secondary",children:[e.jsx("strong",{children:"Interval:"})," Every ",De(n.intervalSeconds||86400)]}),e.jsx("p",{className:"text-xs text-content-tertiary mt-1",children:"This is a system-managed setting and cannot be modified."})]}),!c.usesInterval&&n.schedule&&e.jsxs("div",{children:[e.jsx(f,{htmlFor:`${r}-schedule`,children:s("common.cronSchedule")}),e.jsx(w,{id:`${r}-schedule`,value:n.schedule,onChange:R=>S(r,"schedule",R.target.value),disabled:!n.enabled,className:"mt-1 font-mono text-sm"}),e.jsx("p",{className:"text-xs text-content-tertiary mt-1",children:'UTC only — format: minute hour day month weekday (e.g. "0 0 * * *" = daily at 00:00 UTC)'})]}),n.batchSize!==void 0&&e.jsxs("div",{children:[e.jsx(f,{htmlFor:`${r}-batch`,children:s("common.batchSize")}),e.jsx(w,{id:`${r}-batch`,type:"number",min:"10",max:"500",value:n.batchSize,onChange:R=>S(r,"batchSize",parseInt(R.target.value)),disabled:!n.enabled,className:"mt-1"}),e.jsxs("p",{className:"text-xs text-content-tertiary mt-1",children:["Process ",n.batchSize," items per run"]})]}),e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:()=>m.mutate(r),disabled:m.isPending||!n.enabled||!!c.monitor?.runRequestedAt,children:[e.jsx(je,{className:"w-4 h-4 mr-2"}),s("settings.cronRunNow")]}),u&&e.jsxs(C,{onClick:()=>I(r),disabled:p.isPending,className:"w-full",children:[e.jsx(H,{className:"w-4 h-4 mr-2"}),"Save Changes"]})]})]},r)})})})]})})}const Ae=["/api/system-settings/instance-config"];async function Fs(t){const s=await fetch("/api/system-settings/instance-config",{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!s.ok){const a=await s.json().catch(()=>({}));throw new Error(a?.error||"Failed to update instance config")}return s.json()}function Ke({borderless:t=!1}){const{t:s}=M(),{toast:a}=re(),o=Ee(),[j,h]=F.useState({region:"",accessKeyId:"",secretAccessKey:"",fromEmail:"",replyToEmail:""}),[x,k]=F.useState({apiBaseUrl:"",apiKey:""}),[l,i]=F.useState({storedMessageUnits:1,statusUpdateUnits:0,billableStatusUpdates:"sent, delivered, read, failed",estimatedStatusUpdateCount:0}),{data:N,isLoading:T,error:m}=Q({queryKey:Ae,queryFn:async()=>{const d=await fetch("/api/system-settings/instance-config",{credentials:"include"});if(!d.ok)throw new Error("Failed to fetch instance config");return(await d.json()).data}});F.useEffect(()=>{if(!N)return;const d=N.aws_ses_fallback||{};h({region:String(d.region||""),accessKeyId:String(d.accessKeyId||""),secretAccessKey:String(d.secretAccessKey||""),fromEmail:String(d.fromEmail||""),replyToEmail:String(d.replyToEmail||"")});const v=N.fx_rate_api||{};k({apiBaseUrl:String(v.apiBaseUrl||""),apiKey:String(v.apiKey||"")});const r=N.message_credit_billing||{};i({storedMessageUnits:Number(r.storedMessageUnits??1),statusUpdateUnits:Number(r.statusUpdateUnits??0),billableStatusUpdates:Array.isArray(r.billableStatusUpdates)?r.billableStatusUpdates.join(", "):"sent, delivered, read, failed",estimatedStatusUpdateCount:Number(r.estimatedStatusUpdateCount??0)})},[N]);const p=B({mutationFn:Fs,onSuccess:d=>{o.invalidateQueries({queryKey:Ae}),a({title:s("common.settingsUpdated2"),description:`${s("settings.instanceConfig.title")}: ${(d?.updated||[]).join(", ")}`})},onError:d=>{a({title:s("common.error"),description:d.message,variant:"destructive"})}}),S=N?.readonly?.health_worker_heartbeat,I=N?.readonly?.platform_capacity_records,q=S?.updatedAt?Date.now()-new Date(S.updatedAt).getTime():null;return T?e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0":"p-6",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(ee,{className:"h-6 w-6 animate-spin text-content-muted"}),e.jsx("span",{className:"ml-2 text-content-secondary",children:s("common.loadingSettings")})]})})}):m?e.jsx(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:e.jsx(y,{className:t?"px-0 pb-0":"p-6",children:e.jsxs("div",{className:"flex items-center justify-center text-red-600",children:[e.jsx(G,{className:"mr-2 h-6 w-6"}),e.jsx("span",{children:m.message})]})})}):e.jsxs("div",{className:t?"space-y-6":"space-y-3",children:[e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 py-0":void 0,children:e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2 text-lg",children:[!t&&e.jsx(hs,{className:"h-5 w-5"}),s("settings.instanceConfig.sesTitle")]}),e.jsx(L,{children:s("settings.instanceConfig.sesDescription")})]}),e.jsxs(C,{onClick:()=>p.mutate({aws_ses_fallback:j}),disabled:p.isPending,className:"shrink-0",children:[e.jsx(H,{className:"mr-2 h-4 w-4"}),s("settings.instanceConfig.saveSection")]})]})}),e.jsxs(y,{className:`space-y-4 pt-4 ${t?"px-0 pb-0":""}`,children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-ses-region",children:s("settings.instanceConfig.region")}),e.jsx(w,{id:"instance-ses-region",value:j.region,onChange:d=>h(v=>({...v,region:d.target.value})),placeholder:"ap-south-1",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-ses-access-key",children:s("settings.instanceConfig.accessKeyId")}),e.jsx(w,{id:"instance-ses-access-key",value:j.accessKeyId,onChange:d=>h(v=>({...v,accessKeyId:d.target.value})),className:"mt-1 font-mono text-sm"})]})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-ses-secret",children:s("settings.instanceConfig.secretAccessKey")}),e.jsx(de,{id:"instance-ses-secret",value:j.secretAccessKey,onChange:d=>h(v=>({...v,secretAccessKey:d.target.value})),className:"mt-1 font-mono text-sm",autoComplete:"new-password"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-ses-from",children:s("settings.instanceConfig.fromEmail")}),e.jsx(w,{id:"instance-ses-from",type:"email",value:j.fromEmail,onChange:d=>h(v=>
1({...v,fromEmail:d.target.value})),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-ses-reply",children:s("settings.instanceConfig.replyToEmail")}),e.jsx(w,{id:"instance-ses-reply",type:"email",value:j.replyToEmail,onChange:d=>h(v=>({...v,replyToEmail:d.target.value})),className:"mt-1"})]})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 py-0":void 0,children:e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2 text-lg",children:[!t&&e.jsx(ae,{className:"h-5 w-5"}),s("settings.instanceConfig.fxTitle")]}),e.jsx(L,{children:s("settings.instanceConfig.fxDescription")})]}),e.jsxs(C,{onClick:()=>p.mutate({fx_rate_api:x}),disabled:p.isPending,className:"shrink-0",children:[e.jsx(H,{className:"mr-2 h-4 w-4"}),s("settings.instanceConfig.saveSection")]})]})}),e.jsxs(y,{className:`space-y-4 pt-4 ${t?"px-0 pb-0":""}`,children:[e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-fx-url",children:s("settings.instanceConfig.apiBaseUrl")}),e.jsx(w,{id:"instance-fx-url",value:x.apiBaseUrl,onChange:d=>k(v=>({...v,apiBaseUrl:d.target.value})),placeholder:"https://open.er-api.com/v6/latest",className:"mt-1 font-mono text-sm"})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-fx-key",children:s("settings.instanceConfig.apiKey")}),e.jsx(de,{id:"instance-fx-key",value:x.apiKey,onChange:d=>k(v=>({...v,apiKey:d.target.value})),className:"mt-1 font-mono text-sm",autoComplete:"new-password"})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 py-0":void 0,children:e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2 text-lg",children:[!t&&e.jsx(gs,{className:"h-5 w-5"}),s("settings.instanceConfig.billingTitle")]}),e.jsx(L,{children:s("settings.instanceConfig.billingDescription")})]}),e.jsxs(C,{onClick:()=>p.mutate({message_credit_billing:{storedMessageUnits:l.storedMessageUnits,statusUpdateUnits:l.statusUpdateUnits,billableStatusUpdates:l.billableStatusUpdates.split(",").map(d=>d.trim().toLowerCase()).filter(Boolean),estimatedStatusUpdateCount:l.estimatedStatusUpdateCount}}),disabled:p.isPending,className:"shrink-0",children:[e.jsx(H,{className:"mr-2 h-4 w-4"}),s("settings.instanceConfig.saveSection")]})]})}),e.jsxs(y,{className:`space-y-4 pt-4 ${t?"px-0 pb-0":""}`,children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-billing-stored",children:s("settings.instanceConfig.storedMessageUnits")}),e.jsx(w,{id:"instance-billing-stored",type:"number",min:"0",value:l.storedMessageUnits,onChange:d=>i(v=>({...v,storedMessageUnits:Math.max(0,Math.floor(Number(d.target.value)||0))})),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-billing-status",children:s("settings.instanceConfig.statusUpdateUnits")}),e.jsx(w,{id:"instance-billing-status",type:"number",min:"0",value:l.statusUpdateUnits,onChange:d=>i(v=>({...v,statusUpdateUnits:Math.max(0,Math.floor(Number(d.target.value)||0))})),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-billing-estimated",children:s("settings.instanceConfig.estimatedUpdates")}),e.jsx(w,{id:"instance-billing-estimated",type:"number",min:"0",value:l.estimatedStatusUpdateCount,onChange:d=>i(v=>({...v,estimatedStatusUpdateCount:Math.max(0,Math.floor(Number(d.target.value)||0))})),className:"mt-1"})]})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"instance-billing-statuses",children:s("settings.instanceConfig.billableStatuses")}),e.jsx(w,{id:"instance-billing-statuses",value:l.billableStatusUpdates,onChange:d=>i(v=>({...v,billableStatusUpdates:d.target.value})),className:"mt-1 font-mono text-sm"})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsxs(D,{className:t?"px-0 py-0":void 0,children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2 text-lg",children:[!t&&e.jsx(ae,{className:"h-5 w-5"}),s("settings.instanceConfig.statusTitle")]}),e.jsx(L,{children:s("settings.instanceConfig.statusDescription")})]}),e.jsxs(y,{className:`space-y-3 pt-4 text-sm ${t?"px-0 pb-0":""}`,children:[e.jsxs("div",{className:"rounded-lg border border-line bg-surface-muted p-3",children:[e.jsx("p",{className:"font-medium",children:s("settings.instanceConfig.workerHeartbeat")}),S?e.jsxs("div",{className:"mt-1 space-y-1 text-content-secondary",children:[e.jsxs("p",{children:[s("settings.instanceConfig.status"),": ",String(S.status||"-")," · ",s("settings.instanceConfig.role"),": ",String(S.role||"-")," · PID ",String(S.pid??"-")]}),e.jsxs("p",{className:"font-mono text-xs",children:[s("settings.instanceConfig.lastSeen"),": ",String(S.updatedAt||"-"),q!=null?` (${Math.max(0,Math.round(q/1e3))}s ${s("settings.instanceConfig.ago")})`:""]})]}):e.jsx("p",{className:"mt-1 text-content-tertiary",children:s("settings.instanceConfig.notAvailable")})]}),e.jsxs("div",{className:"rounded-lg border border-line bg-surface-muted p-3",children:[e.jsx("p",{className:"font-medium",children:s("settings.instanceConfig.capacityRecords")}),I?e.jsxs("div",{className:"mt-1 space-y-1 text-content-secondary",children:[e.jsxs("p",{children:[s("settings.instanceConfig.totalMessages"),": ",Number(I.totalMessagesAllTime||0).toLocaleStr
1ing()]}),e.jsxs("p",{children:[s("settings.instanceConfig.peakThroughput"),": ",Number(I.peakMessagesPerSecond?.combined||0),"/s"]}),e.jsxs("p",{children:[s("settings.instanceConfig.lastSampled"),": ",String(I.lastSampledAt||"-")]})]}):e.jsx("p",{className:"mt-1 text-content-tertiary",children:s("settings.instanceConfig.notAvailable")})]})]})]})]})}function We({borderless:t=!1}){const{t:s}=M(),{toast:a}=re(),[o,j]=F.useState(!1),[h,x]=F.useState([]),[k,l]=F.useState(!1),[i,N]=F.useState({zoneId:"",apiToken:"",appDomain:"",fallbackDomainName:"",customerCnameFqdn:"",enabled:!1}),{isLoading:T,refetch:m,data:p,error:S}=Q({queryKey:["cloudflare-saas-settings"],refetchOnWindowFocus:!1,queryFn:async()=>{const n=await E("GET","/api/system-settings/cloudflare-saas");if(!n.ok)throw new Error("Failed to fetch settings");const u=await n.json();return u&&(N({zoneId:u.zoneId||"",apiToken:u.apiToken||"",appDomain:u.appDomain||"",fallbackDomainName:u.fallbackDomainName||"",customerCnameFqdn:u.customerCnameFqdn||"",enabled:u.enabled||!1,fallbackOrigin:u.fallbackOrigin,cnameTarget:u.cnameTarget,dcvDelegationTarget:u.dcvDelegationTarget,zoneName:u.zoneName,setupComplete:u.setupComplete,setupStatus:u.setupStatus,setupSteps:u.setupSteps}),u.setupSteps&&x(u.setupSteps)),u}}),I=B({mutationFn:async()=>{const n=await E("PUT","/api/system-settings/cloudflare-saas",{fallbackDomainName:i.fallbackDomainName,customerCnameFqdn:i.customerCnameFqdn,zoneId:i.zoneId,apiToken:i.apiToken,appDomain:i.appDomain,enabled:i.enabled});if(!n.ok){const u=await n.json();throw new Error(u.error||"Failed to save settings")}return n.json()},onSuccess:()=>{a({title:s("common.saved2"),description:s("common.settingsSavedSuccessfully")}),j(!1),ce.invalidateQueries({queryKey:["cloudflare-saas-settings"]}),(i.fallbackDomainName||i.customerCnameFqdn)&&(a({title:s("common.settingUpCloudflare"),description:s("common.autoSetupIsRunningCheckProgressBelow"),variant:"default"}),setTimeout(()=>{d.mutate()},500))},onError:n=>{a({title:s("common.saveFailed2"),description:n.message,variant:"destructive"})}}),q=B({mutationFn:async()=>{const n=await E("POST","/api/system-settings/cloudflare-saas/test");if(!n.ok){const u=await n.json();throw new Error(u.error||"Test failed")}return n.json()},onSuccess:n=>{a({title:s("common.connectionOk"),description:`Zone "${n.zoneName}" verified.`})},onError:n=>{a({title:s("common.connectionFailed"),description:n.message,variant:"destructive"})}}),d=B({mutationFn:async()=>{const n=await E("POST","/api/system-settings/cloudflare-saas/setup-rules");if(!n.ok){const u=await n.json();throw new Error(u.error||"Setup failed")}return n.json()},onSuccess:n=>{x(n.steps||[]),n.success?a({title:s("common.setupComplete"),description:s("common.customDomainsAreReadyToUse")}):a({title:s("common.partialSetup"),description:s("common.someStepsNeedAttention"),variant:"destructive"}),m()},onError:n=>{a({title:s("common.setupFailed"),description:n.message,variant:"destructive"})}});if(T)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(K,{className:"w-4 h-4 animate-spin"})});const v=i.setupComplete||p?.setupComplete,r=i.setupStatus||p?.setupStatus||"not_started",c=h.some(n=>n.step==="Fetch DCV delegation"&&n.status==="manual");return i.zoneId||i.apiToken||i.appDomain,e.jsxs("div",{className:"space-y-3",children:[e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 pt-0":void 0,children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2",children:[!t&&e.jsx(os,{className:"w-5 h-5"}),"Cloudflare SaaS"]}),e.jsx(L,{className:"mt-1",children:s("common.configureTheSharedDomainInfrastructureUs1a5ef2")})]}),e.jsx("div",{className:"flex items-center gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>{j(!1),m()},children:s("common.cancel")}),e.jsx(C,{size:"sm",onClick:()=>I.mutate(),disabled:I.isPending||!i.zoneId||!i.apiToken,children:I.isPending?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 mr-1 animate-spin"}),s("common.saving")]}):e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"w-4 h-4 mr-1"}),s("common.save")]})})]}):e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>q.mutate(),disabled:!i.zoneId||!i.apiToken||q.isPending,children:q.isPending?e.jsx(K,{className:"w-4 h-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(fs,{className:"w-4 h-4 mr-1"}),s("common.test")]})}),e.jsx(C,{size:"sm",onClick:()=>d.mutate(),disabled:!i.zoneId||!i.apiToken||!i.appDomain||d.isPending,children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 mr-1 animate-spin"}),s("common.settingUp")]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 mr-1"}),v?"Re-run Setup":"Auto-Setup"]})}),e.jsxs(C,{size:"sm",onClick:()=>j(!0),children:[e.jsx(Ns,{className:"w-4 h-4 mr-1"}),"Edit"]}),e.jsx(C,{variant:"outline",size:"sm",disabled:k,onClick:async()=>
1{l(!0);try{const u=await(await E("POST","/api/system-settings/cloudflare-saas/purge-cache")).json();a({title:u.success?"Cache Purged":"Purge Failed",description:u.detail||u.error,variant:u.success?"default":"destructive"})}catch(n){a({title:s("common.error"),description:n.message,variant:"destructive"})}finally{l(!1)}},children:k?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 mr-1 animate-spin"}),s("common.purging")]}):e.jsxs(e.Fragment,{children:[e.jsx(cs,{className:"w-4 h-4 mr-1"}),s("common.purgeCache")]})})]})})]})}),e.jsxs(y,{className:`space-y-5 ${t?"px-0 pb-0":""}`,children:[S&&e.jsxs(Y,{className:"border-2 border-tint-danger-border bg-tint-danger",children:[e.jsx(G,{className:"h-4 w-4 text-red-600"}),e.jsxs(V,{className:"flex items-center justify-between gap-3 text-red-900 text-sm",children:[e.jsx("span",{children:s("common.failedToLoadCloudflareSaasSettings")}),e.jsx(C,{type:"button",variant:"outline",size:"sm",onClick:()=>m(),children:"Retry"})]})]}),r==="completed"?null:r==="failed"?e.jsxs(Y,{className:"border-2 border-tint-danger-border bg-tint-danger",children:[e.jsx(G,{className:"h-4 w-4 text-red-600"}),e.jsxs(V,{className:"text-red-900 text-sm",children:[e.jsx("strong",{children:s("common.setupFailed2")})," Check the steps below and click Re-run Setup."]})]}):r==="in_progress"?e.jsxs(Y,{className:"border-2 border-tint-warning-border bg-tint-warning",children:[e.jsx(W,{className:"h-4 w-4 text-yellow-600"}),e.jsxs(V,{className:"text-yellow-900 text-sm",children:[e.jsx("strong",{children:s("common.setupInProgress")})," Check status below."]})]}):e.jsxs(Y,{className:"border-2 border-tint-info-border bg-tint-info",children:[e.jsx(ds,{className:"h-4 w-4 text-blue-600"}),e.jsxs(V,{className:"text-blue-900 text-sm",children:[e.jsx("strong",{children:"Quick setup:"})," Enter fields below → Save → Click Auto-Setup."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{children:s("common.zoneId")}),e.jsx(w,{placeholder:s("common.pasteYourCloudflareZoneId"),value:i.zoneId,onChange:n=>N({...i,zoneId:n.target.value}),disabled:!o,className:"font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-content-secondary",children:["Your Cloudflare Zone ID for this domain. Find it in the"," ",e.jsx("a",{href:"https://dash.cloudflare.com",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 underline",children:"Cloudflare dashboard"})," ","Overview sidebar, and use an API token with SSL/Certificates Edit and DNS Edit permissions."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{children:s("common.apiToken")}),e.jsx(de,{placeholder:s("common.pasteYourCloudflareApiToken"),value:i.apiToken,onChange:n=>N({...i,apiToken:n.target.value}),disabled:!o,className:"font-mono text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{children:s("common.zoneDomain")}),e.jsx(w,{placeholder:s("common.eGExampleIn"),value:i.appDomain,onChange:n=>N({...i,appDomain:n.target.value}),disabled:!o,className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-content-tertiary",children:"Your primary Cloudflare zone domain. This is the base zone used for fallback hosts, customer CNAME targets, and catalog landing pages."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(f,{children:[s("common.fallbackDomainName"),e.jsx("span",{className:"text-content-muted font-normal",children:"(optional)"})]}),e.jsx(w,{placeholder:"e.g. fallback.example.in (defaults to fallback.{zoneName})",value:i.fallbackDomainName,onChange:n=>N({...i,fallbackDomainName:n.target.value}),disabled:!o,className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-content-tertiary",children:"Attach this hostname to your Caddy proxy service and keep it proxied in Cloudflare."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(f,{children:[s("common.customerCnameTarget"),e.jsx("span",{className:"text-content-muted font-normal",children:"(optional)"})]}),e.jsx(w,{placeholder:"e.g. store.example.in (defaults to store.{zoneName})",value:i.customerCnameFqdn,onChange:n=>N({...i,customerCnameFqdn:n.target.value}),disabled:!o,className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-content-tertiary",children:"Customers will point their domains to this CNAME. Auto-created during setup and routed through the fallback proxy."})]}),c&&e.jsxs("div",{className:"bg-tint-warning border border-tint-warning-border rounded-lg p-3 space-y-2",children:[e.jsx(f,{className:"text-yellow-900 text-sm",children:s("common.dcvDelegationTargetAutoDetectFailed")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(w,{placeholder:s("c
1ommon.eGC239702eeb072c00DcvCloudflareCom"),value:i.dcvDelegationTarget||"",onChange:n=>N({...i,dcvDelegationTarget:n.target.value}),className:"font-mono text-sm flex-1"}),e.jsxs(C,{size:"sm",onClick:async()=>{if(i.dcvDelegationTarget?.trim())try{if(!(await E("PUT","/api/system-settings/cloudflare-saas",{zoneId:i.zoneId,apiToken:i.apiToken,appDomain:i.appDomain,fallbackDomainName:i.fallbackDomainName,customerCnameFqdn:i.customerCnameFqdn,enabled:i.enabled,dcvDelegationTarget:i.dcvDelegationTarget.trim()})).ok)throw new Error("Failed to save");a({title:s("common.dcvSaved"),description:s("common.dcvDelegationTargetSavedSuccessfully")}),m()}catch(n){a({title:s("common.saveFailed2"),description:n.message,variant:"destructive"})}},children:[e.jsx(H,{className:"w-4 h-4 mr-1"}),"Save DCV"]})]}),e.jsx("p",{className:"text-xs text-yellow-800",children:"Find in Cloudflare → SSL/TLS → Custom Hostnames → DCV Delegation"})]}),e.jsxs("div",{className:`py-3 ${t?"":"border-y"} flex items-center gap-3`,children:[e.jsx(X,{checked:i.enabled,onCheckedChange:n=>N({...i,enabled:n}),disabled:!o}),e.jsx("span",{className:"text-sm font-medium",children:i.enabled?"Custom domains enabled":"Custom domains disabled"})]})]})]}),(h.length>0||d.isPending)&&e.jsxs(b,{className:d.isPending?"border-tint-info-border bg-tint-info":t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 pt-0":void 0,children:e.jsxs(A,{className:"text-base flex items-center gap-2",children:[d.isPending&&e.jsx(K,{className:"w-4 h-4 animate-spin text-blue-600"}),"Setup Status"]})}),e.jsxs(y,{className:t?"px-0 pb-0":void 0,children:[d.isPending&&e.jsx("div",{className:"mb-4 p-3 bg-tint-info-strong border border-tint-info-border rounded-lg",children:e.jsxs("p",{className:"text-sm text-blue-900",children:[e.jsx("strong",{children:s("common.autoSetupInProgress")})," Please wait while we configure fallback origin, DCV, and DNS records."]})}),e.jsx("div",{className:"space-y-1.5",children:h.map((n,u)=>e.jsxs("div",{className:"flex items-center gap-3 py-2 px-3 rounded bg-surface-muted",children:[n.status==="ok"?e.jsx(ms,{className:"w-5 h-5 text-green-600 flex-shrink-0"}):n.status==="manual"?e.jsx(W,{className:"w-5 h-5 text-yellow-600 flex-shrink-0"}):n.status==="failed"?e.jsx(xs,{className:"w-5 h-5 text-red-600 flex-shrink-0"}):e.jsx(K,{className:"w-5 h-5 text-blue-600 flex-shrink-0 animate-spin"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-content",children:n.step}),n.detail&&e.jsx("p",{className:"text-xs text-content-secondary mt-0.5",children:n.detail})]})]},u))}),(i.fallbackOrigin||i.cnameTarget)&&e.jsxs("div",{className:"mt-4 pt-3 border-t space-y-1",children:[e.jsx("p",{className:"text-xs font-semibold text-content-muted uppercase",children:s("common.autoConfigured")}),i.fallbackOrigin&&e.jsxs("p",{className:"text-sm",children:["Fallback: ",e.jsx("code",{className:"bg-surface-subtle px-1 rounded text-xs",children:i.fallbackOrigin})]}),i.cnameTarget&&e.jsxs("p",{className:"text-sm",children:["CNAME Target: ",e.jsx("code",{className:"bg-surface-subtle px-1 rounded text-xs",children:i.cnameTarget})]}),i.dcvDelegationTarget&&e.jsxs("p",{className:"text-sm",children:["DCV: ",e.jsx("code",{className:"bg-surface-subtle px-1 rounded text-xs",children:i.dcvDelegationTarget})]})]})]})]}),e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 pt-0":void 0,children:e.jsx(A,{className:"text-base",children:s("common.howItWorksForUsers")})}),e.jsx(y,{className:t?"px-0 pb-0":void 0,children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-tint-info-strong text-tint-info-fg-muted flex items-center justify-center flex-shrink-0 text-xs font-bold",children:"1"}),e.jsxs("p",{className:"text-content-secondary",children:["You first need a separate reverse-proxy server for custom domains, either with Nginx or by running this app in ",e.jsx("code",{children:"APP_MODE=proxy"})," on a VPS server."]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-tint-info-strong text-tint-info-fg-muted flex items-center justify-center flex-shrink-0 text-xs font-bold",children:"2"}),e.jsx("p",{className:"text-content-secondary",children:"User enters their domain in Catalog Settings → Storefront and clicks Verify."})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-tint-info-strong text-tint-info-fg-muted flex items-center justify-center flex-shrink-0 text-xs font-bold",children:"3"}),e.jsx("p",{className:"text-content-secondary",children:s("common.systemShowsTheCnameRecordTheUserMustAddA0c7382")})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-tint-success-strong text-tint-success-fg-muted flex items-center justify-center flex-shrink-0 text-xs font-bold",children:"4"}),e.jsx("p",{className:"text-content-secondary",children:"Cloudflare validates the hostname, SSL is auto-issued, and the domain goes live through the proxy."})]})]})})]})]})}const Ds={enabled:!1,useRailwayForWhitelabel:!1,apiToken:"",projectId:"",environmentId:"",serviceId:"",fallbackCnameTarget:""};function Ge({borderless:t=!1}){const{t:s}=M(),{toast:a}=re(),[o,j]=F.useState(!1),[h,x]=F.useState(Ds),{isLoading:k,error:l,refetch:i}=Q({queryKey:["railway-saas-settings"],refetchOnWindowFocus:!1,queryFn:async()=>{const m=await E("GET","/api/system-settings/railway-saas");if(!m.ok)throw new Error("Failed to fetch Railway settings");const p=await m.json();return x({enabled:!!p.enabled,useRailwayForWhitelabel:!!p.useRailwayForWhitelabel,apiToken:String(p.apiToken||""),projectId:String(p.projectId||""),environmentId:String(p.environmentId||""),serviceId:String(p.serviceId||""),fallbackCnameTarget:String(p.fallbackCnameTarget||"")}),p}}),N=B({mutationFn:async()=>{const m=await E("PUT","/api/system-settings/railway-saas",h);if(!m.ok){const p=await m.json().catch(()=>({}));throw new Error(p.error||"Failed to save Railway settings")}return m.json()},onSuccess:()=>{a({title:s("common.saved"),description:s("common.railwaySaasSettingsUpdated")}),j(!1),ce.invalidateQueries({queryKey:["railway-saas-settings"]})},onError:m=>{a({title:s("common.saveFailed"),description:m.message,variant:"destructive"})}}),T=B({mutationFn:async()=>{const m=await E("POST","/api/system-settings/railway-saas/test");
1if(!m.ok){const p=await m.json().catch(()=>({}));throw new Error(p.error||"Railway test failed")}return m.json()},onSuccess:m=>{a({title:s("common.connectionOk"),description:m?.data?.accountEmail?`Connected as ${m.data.accountEmail}`:"Railway token verified."})},onError:m=>{a({title:s("common.connectionFailed2"),description:m.message,variant:"destructive"})}});return k?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(K,{className:"h-4 w-4 animate-spin"})}):e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 pt-0":void 0,children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs(A,{className:t?void 0:"flex items-center gap-2",children:[!t&&e.jsx(us,{className:"h-5 w-5"}),"Railway for SaaS"]}),e.jsx(L,{children:"Optionally onboard whitelabel customer domains through Railway instead of Cloudflare."})]}),e.jsx("div",{className:"flex gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"outline",onClick:()=>{j(!1),i()},children:"Cancel"}),e.jsxs(C,{onClick:()=>N.mutate(),disabled:N.isPending,children:[N.isPending?e.jsx(K,{className:"mr-1 h-4 w-4 animate-spin"}):e.jsx(H,{className:"mr-1 h-4 w-4"}),"Save"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"outline",onClick:()=>T.mutate(),disabled:T.isPending||!h.apiToken,children:[T.isPending?e.jsx(K,{className:"mr-1 h-4 w-4 animate-spin"}):e.jsx(Ue,{className:"mr-1 h-4 w-4"}),"Test"]}),e.jsx(C,{onClick:()=>j(!0),children:s("common.edit")})]})})]})}),e.jsxs(y,{className:`space-y-4 ${t?"px-0 pb-0":""}`,children:[l?e.jsx(Y,{children:e.jsx(V,{children:s("common.failedToLoadRailwaySaasSettings")})}):null,e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:s("common.enableRailwayForSaas")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("common.allowStoringRailwayConfigForDomainOnboarding")})]}),e.jsx(X,{checked:h.enabled,disabled:!o,onCheckedChange:m=>x(p=>({...p,enabled:m}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:s("common.useRailwayForWhitelabelSetup")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("common.ifEnabledManagedWhitelabelPurchasesUseRa194588")})]}),e.jsx(X,{checked:h.useRailwayForWhitelabel,disabled:!o,onCheckedChange:m=>x(p=>({...p,useRailwayForWhitelabel:m}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:s("common.railwayApiToken2")}),e.jsx(de,{value:h.apiToken,disabled:!o,onChange:m=>x(p=>({...p,apiToken:m.target.value})),placeholder:s("common.railwayApiToken")})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:s("common.projectId")}),e.jsx(w,{value:h.projectId,disabled:!o,onChange:m=>x(p=>({...p,projectId:m.target.value})),placeholder:s("common.railwayProjectId")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:s("common.environmentId")}),e.jsx(w,{value:h.environmentId,disabled:!o,onChange:m=>x(p=>({...p,environmentId:m.target.value})),placeholder:s("common.railwayEnvironmentId")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:s("common.serviceId")}),e.jsx(w,{value:h.serviceId,disabled:!o,onChange:m=>x(p=>({...p,serviceId:m.target.value})),placeholder:s("common.railwayServiceId")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:s("common.fallbackCnameTarget")}),e.jsx(w,{value:h.fallbackCnameTarget,disabled:!o,onChange:m=>x(p=>({...p,fallbackCnameTarget:m.target.value})),placeholder:s("common.exampleUpRailwayApp")})]})]})]})]})}function P({enabled:t,label:s}){return e.jsxs(ie,{tone:t?"success":"neutral",children:[t?e.jsx(te,{className:"mr-1 h-3 w-3"}):e.jsx(Ne,{className:"mr-1 h-3 w-3"}),s]})}function He({borderless:t=!1}){const{t:s}=M(),{data:a,isLoading:o,isError:j,error:h,refetch:x,isFetching:k}=Q({queryKey:["license-status"],refetchOnWindowFocus:!1,queryFn:async()=>await(await E("GET","/api/system-settings/license-status")).json()}),l=a?.data,i=!!l?.valid;return e.jsxs(b,{className:t?"border-0 bg-transparent shadow-none":void 0,children:[e.jsx(D,{className:t?"px-0 pt-0":void 0,children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs(A,{className:"flex items-center gap-2",children:[i?e.jsx(Ue,{className:"h-5 w-5 text-emerald-600"}):e.jsx(bs,{className:"h-5 w-5 text-amber-600"}),"Install Licence Status"]}),e.jsx(L,{children:"Check whether this instance has an active install license."})]}),e.jsxs(C,{variant:"outline",onClick:()=>x(),disabled:k,children:[e.jsx(ee,{className:`mr-2 h-4 w-4 ${k?"animate-spin":""}`}),"Recheck"]})]})}),e.jsxs(y,{className:`space-y-4 ${t?"px-0 pb-0":""}`,children:[o?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ee,{className:"h-4 w-4 animate-spin"}),"Checking license status..."]}):null,j?e.jsxs(Y,{variant:"destructive",children:[e.jsx(G,{className:"h-4 w-4"}),e.jsx(be,{children:s("common.licenseCheckFailed")}),e.jsx(V,{children:h?.message||"Could not fetch license status."})]}):null,!o&&!j&&l?e.jsxs(e.Fragment,{children:[e.jsxs(Y,{variant:i?"default":"destructive",children:[i?e.jsx(te,{className:"h-4 w-4"}):e.jsx(G,{className:"h-4 w-4"}),e.jsx(be,{children:i?"License Active":"License Not Active"}),e.jsx(V,{children:l.message})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[l.company&&e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s("admin.company")}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:l.company})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s("common.host")}),e.jsx("div",{className:"mt-1 break-all text-sm font-medium",children:l.requestHost||"Unknown"})]}),l.maxInstances!=null&&e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s("common.instances")}),e.jsxs("div",{className:"mt-1 text-sm font-medium",children:[l.activeInstances??"—"," / ",l.maxInstances]})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s("common.expires")}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:l.licenseExpiresAt?new Date(l.licenseExpiresAt).toLocaleDateString():"Never"})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s("common.checkedAt")}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:new Date(l.checkedAt).toLocaleStr
1ing()})]}),l.error&&e.jsxs("div",{className:"rounded-lg border p-3 sm:col-span-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s("common.errorCode")}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:l.error})]})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s("common.featureFlags")}),e.jsx(C,{size:"sm",variant:"outline",asChild:!0,children:e.jsxs("a",{href:"https://skyfree.io/self-hosted",target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ys,{className:"mr-1.5 h-4 w-4"}),s("common.upgrade")]})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-muted-foreground mb-2",children:s("common.licenseFlags")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{enabled:l.whiteLabelAllowed,label:"White Label"}),e.jsx(P,{enabled:l.selfManaged,label:"Self Managed"})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-muted-foreground mb-2",children:s("common.channelFlags")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{enabled:!!l.channelWhatsappAllowed,label:"WhatsApp Channel"}),e.jsx(P,{enabled:!!l.channelFacebookAllowed,label:"Facebook Channel"}),e.jsx(P,{enabled:!!l.channelInstagramAllowed,label:"Instagram Channel"}),e.jsx(P,{enabled:!!l.channelTelegramAllowed,label:"Telegram Channel"}),e.jsx(P,{enabled:!!l.channelTiktokAllowed,label:"TikTok Channel"}),e.jsx(P,{enabled:!!l.channelWebchatAllowed,label:"Webchat Channel"}),e.jsx(P,{enabled:!!l.channelEventsAllowed,label:"Events Channel"})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-muted-foreground mb-2",children:s("common.addons")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{enabled:!!l.mobileBuildsAllowed,label:"Mobile Builds"}),e.jsx(P,{enabled:!!l.creditLineAllowed,label:"Credit Line"}),e.jsx(P,{enabled:!!l.roadmapAllowed,label:"Roadmap"}),e.jsx(P,{enabled:!!l.aiAssistAllowed,label:"AI Assist"}),e.jsx(P,{enabled:!!l.mcpAllowed,label:"MCP"}),e.jsx(P,{enabled:!!l.tutorialsAllowed,label:"Tutorials"})]})]})]})]})]}):null]})]})}const As=3650,Es=[{key:"user_activity_logs",defaultDays:90,minDays:7,defaultEnabled:!0},{key:"contact_activity_logs",defaultDays:180,minDays:30,defaultEnabled:!0},{key:"meta_webhook_relay_logs",defaultDays:1,minDays:1,defaultEnabled:!0},{key:"automation_webhook_triggers",defaultDays:30,minDays:7,defaultEnabled:!1,tenantScoped:!0},{key:"automation_execution_logs",defaultDays:30,minDays:7,defaultEnabled:!1,tenantScoped:!0},{key:"automation_executions",defaultDays:30,minDays:7,defaultEnabled:!1,tenantScoped:!0},{key:"cron_run_log",defaultDays:30,minDays:7,defaultEnabled:!0},{key:"messages_archive",defaultDays:730,minDays:180,defaultEnabled:!1,highRisk:!0,tenantScoped:!0}];Es.filter(t=>t.tenantScoped);const he=["/api/system-settings/data-retention"];async function oe(t,s){if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o?.error||s)}return(await t.json()).data}function Qe({borderless:t=!1}){const{t:s}=M(),{toast:a}=re(),[o,j]=F.useState(null),[h,x]=F.useState(null),[k,l]=F.useState(!1),[i,N]=F.useState(!1),{data:T,isLoading:m,error:p}=Q({queryKey:he,queryFn:async()=>oe(await E("GET","/api/system-settings/data-retention"),s("settings.dataRetention.loadFailed"))});F.useEffect(()=>{T&&j(T.settings)},[T]);const S=B({mutationFn:async g=>oe(await E("PUT","/api/system-settings/data-retention",g),s("settings.dataRetention.saveFailed")),onSuccess:()=>{ce.invalidateQueries({queryKey:he}),a({title:s("settings.dataRetention.saved")})},onError:g=>a({title:s("settings.dataRetention.saveFailed"),description:g.message,variant:"destructive"})}),I=B({mutationFn:async()=>oe(await E("POST","/api/system-settings/data-retention/preview"),s("settings.dataRetention.previewFailed")),onSuccess:x,onError:g=>a({title:s("settings.dataRetention.previewFailed"),description:g.message,variant:"destructive"})}),q=B({mutationFn:async()=>oe(await E("POST","/api/system-settings/data-retention/run",{confirm:!0}),s("settings.dataRetention.runFailed")),onSuccess:g=>{x(null),ce.invalidateQueries({queryKey:he});const z=g.results.reduce((O,se)=>O+se.rows,0);a({title:s("settings.dataRetention.runDone",{count:z})})},onError:g=>a({title:s("settings.dataRetention.runFailed"),description:g.message,variant:"destructive"})}),d=t?"border-0 bg-transparent shadow-none":void 0;if(m||!o&&!p)return e.jsx(b,{className:d,children:e.jsx(y,{className:`${t?"px-0 py-2":"p-6"} flex flex-col items-center`,children:e.jsx(js,{})})});if(p||!T||!o)return e.jsx(b,{className:d,children:e.jsx(y,{className:`${t?"px-0 py-2":"p-6"} text-center text-sm text-content-tertiary`,children:p?.message||s("settings.dataRetention.loadFailed")})});const v=JSON.stringify(o)!==JSON.stringify(T.settings),r=T.lastRun,c=S.isPending||I.isPending||q.isPending,n=(g,z)=>j(O=>O&&{...O,policies:{...O.policies,[g]:{...O.policies[g],...z}}}),u=T.policies.some(g=>g.highRisk&&o.policies[g.key].enabled&&!T.settings.policies[g.key].enabled),R=()=>u?N(!0):S.mutate(o),Je=g=>h?.results.find(z=>z.key===g),Ye=g=>r?.results.find(z=>z.key===g);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs(b,{className:d,children:[e.jsx(D,{className:t?"px-0 pt-0":void 0,children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsx(A,{children:s("settings.dataRetention.title")}),e.jsx(L,{className:"mt-1 max-w-2xl",children:s("settings.dataRetention.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>I.mutate(),disabled:c||v,children:[I.isPending?e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(vs,{className:"mr-2 h-4 w-4"}),s("settings.dataRetention.preview")]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>l(!0),disabled:c||v||!o.enabled,children:[e.jsx(je,{className:"mr-2 h-4 w-4"}),s("settings.dataRetention.runNow")]}),e.jsxs(C,{size:"sm",onClick:R,disabled:c||!v,children:[S.isPending?e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(H,{className:"mr-2 h-4 w-4"}),s("settings.dataRetention.save")]})]})]})}),e.jsxs(y,{className:`space-y-4 ${t?"px-0 pb-0":""}`,children:[e.jsxs("div",{className:"rounded-lg border border-line p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-content",children:s("settings.dataRetention.masterTitle")}),e.jsx("p",{className:"text-sm text-content-secondary",children:s("settings.dataRetention.masterDescription")})]}),e.jsx(X,{checked:o.enabled,onCheckedChange:g=>j({...o,enabled:g})})]}),e.jsxs("p",{className:"mt-3 text-xs text-content-tertiary",children:[r?s("settings.dataRetention.lastRun",{date:new Date(r.at).toLocaleStr
1ing()}):s("settings.dataRetention.neverRun"),r?.tenantRows?` ${s("settings.dataRetention.tenantRows",{count:r.tenantRows.toLocaleString()})}`:""]})]}),T.policies.map(g=>{const z=o.policies[g.key],O=T.approxRows[g.key],se=Je(g.key),le=Ye(g.key);return e.jsxs("div",{className:"rounded-lg border border-line p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-content",children:s(`settings.dataRetention.policies.${g.key}.title`)}),e.jsx("p",{className:"text-sm text-content-secondary",children:s(`settings.dataRetention.policies.${g.key}.description`)}),g.highRisk&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[e.jsx(Z,{className:"h-3.5 w-3.5 shrink-0"}),s("settings.dataRetention.highRisk")]})]}),e.jsx(X,{checked:z.enabled,disabled:!o.enabled,onCheckedChange:ue=>n(g.key,{enabled:ue})})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-end gap-6",children:[e.jsxs("div",{className:"w-[200px] space-y-2",children:[e.jsx(f,{htmlFor:`retention-days-${g.key}`,children:s("settings.dataRetention.keepDays")}),e.jsx(w,{id:`retention-days-${g.key}`,type:"number",min:g.minDays,max:As,value:z.days,disabled:!o.enabled||!z.enabled,onChange:ue=>n(g.key,{days:Number(ue.target.value)})}),e.jsx("p",{className:"text-xs text-content-tertiary",children:s("settings.dataRetention.minimumDays",{days:g.minDays})})]}),e.jsxs("div",{className:"space-y-1 text-xs text-content-tertiary",children:[O!==void 0&&e.jsx("p",{children:s("settings.dataRetention.approxRows",{count:O.toLocaleString()})}),se&&!se.skipped&&e.jsx("p",{className:"text-content-secondary",children:se.error?s("settings.dataRetention.policyError"):s("settings.dataRetention.wouldDelete",{count:se.rows.toLocaleString()})}),le&&!le.skipped&&!le.error&&e.jsx("p",{children:s("settings.dataRetention.lastDeleted",{count:le.rows.toLocaleString()})})]})]})]},g.key)})]})]}),e.jsx(ye,{open:k,onOpenChange:l,children:e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:s("settings.dataRetention.confirmTitle")}),e.jsx(ke,{children:s("settings.dataRetention.confirmDescription")})]}),e.jsxs(Te,{children:[e.jsx(Re,{children:s("settings.dataRetention.cancel")}),e.jsx(Fe,{onClick:()=>q.mutate(),children:s("settings.dataRetention.confirmRun")})]})]})}),e.jsx(ye,{open:i,onOpenChange:N,children:e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:s("settings.dataRetention.confirmEnableTitle")}),e.jsx(ke,{children:s("settings.dataRetention.confirmEnableDescription")})]}),e.jsxs(Te,{children:[e.jsx(Re,{children:s("settings.dataRetention.cancel")}),e.jsx(Fe,{onClick:()=>S.mutate(o),children:s("settings.dataRetention.confirmEnable")})]})]})})]})}const ge=(t,s)=>Ve.getState().t(t,s);function Is(){const[t,s]=F.useState("cloudflare_saas"),{whiteLabelAllowed:a}=Le();return e.jsx(Xe,{title:ge("settings.whitelabelSetup"),subtitle:"Configure your whitelabel setup",children:e.jsxs(Ie,{value:t,onValueChange:s,className:"space-y-4",children:[e.jsx(es,{children:e.jsxs(ss,{className:"inline-flex h-auto min-w-full w-auto flex-wrap justify-start gap-1 bg-transparent p-0",children:[e.jsx(_,{value:"cloudflare_saas",className:"whitespace-nowrap px-3 py-2 text-sm",children:"Cloudflare for SaaS"}),a&&e.jsx(_,{value:"railway_saas",className:"whitespace-nowrap px-3 py-2 text-sm",children:"Railway for SaaS"}),e.jsx(_,{value:"server_stats",className:"whitespace-nowrap px-3 py-2 text-sm",children:"Stats"}),e.jsx(_,{value:"cron_jobs",className:"whitespace-nowrap px-3 py-2 text-sm",children:"Cron Jobs"}),e.jsx(_,{value:"instance_config",className:"whitespace-nowrap px-3 py-2 text-sm",children:ge("settings.instanceConfig.tabName")}),e.jsx(_,{value:"data_retention",className:"whitespace-nowrap px-3 py-2 text-sm",children:ge("settings.dataRetention.tabName")}),e.jsx(_,{value:"license",className:"whitespace-nowrap px-3 py-2 text-sm",children:"Licence"})]})}),e.jsx($,{value:"cloudflare_saas",children:e.jsx(We,{})}),a&&e.jsx($,{value:"railway_saas",children:e.jsx(Ge,{})}),e.jsx($,{value:"server_stats",children:e.jsx(Ss,{})}),e.jsx($,{value:"cron_jobs",children:e.jsx(Oe,{})}),e.jsx($,{value:"instance_config",children:e.jsx(Ke,{})}),e.jsx($,{value:"data_retention",children:e.jsx(Qe,{})}),e.jsx($,{value:"license",children:e.jsx(He,{})})]})})}function ne({icon:t,title:s,subtitle:a,children:o}){return e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-bg)]",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--nova-border)] px-4 py-3 sm:px-5",children:[e.jsx("span",{className:"text-[var(--nova-text-secondary)]",children:t}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[var(--nova-text-primary)]",children:s}),a&&e.jsx("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:a})]})]}),e.jsx("div",{className:"space-y-3 px-4 py-4 sm:px-5",children:o})]})}function U({label:t,value:s,mono:a}){return e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm text-[var(--nova-text-secondary)]",children:t}),e.jsx("span",{className:`text-sm text-[var(--nova-text-primary)] ${a?"font-mono":""}`,children:s})]})}function Ps(){const{t}=M(),{data:s,isLoading:a,error:o}=Q({queryKey:["/api/server-stats"],queryFn:async()=>(await E("GET","/api/server-stats")).json(),refetchInterval:5e3,retry:1});if(a)return e.jsx("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-bg)] p-6 text-center text-sm text-[var(--nova-text-secondary)]",children:t("common.loadingServerStats")}
1);if(o)return e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-bg)] p-6 text-center",children:[e.jsx("p",{className:"mb-1 text-sm font-medium text-tint-danger-fg",children:t("common.failedToLoadServerStats")}),e.jsx("p",{className:"text-sm text-[var(--nova-text-secondary)]",children:o?.message||"Please ensure you have owner access"})]});if(!s||!s.server||!s.cpu||!s.memory||!s.worker||!s.queue)return e.jsx("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-bg)] p-6 text-center",children:e.jsx("p",{className:"text-sm font-medium text-tint-danger-fg",children:t("common.invalidServerData")})});const j=s.memory?.usagePercent||0,h=j>80?"bg-red-500":j>60?"bg-yellow-500":"bg-green-500",x=s.cpu?.loadAverage?.[0]||0,k=s.cpu?.cores||1,l=Math.min(x/k*100,100),i=l>80?"bg-red-500":l>60?"bg-yellow-500":"bg-green-500";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(ne,{icon:e.jsx(Pe,{className:"h-4 w-4"}),title:"Server Information",subtitle:t("common.basicServerDetails"),children:[e.jsx(U,{label:t("common.hostname"),value:s.server.hostname,mono:!0}),e.jsx(U,{label:t("admin.platform"),value:s.server.platform,mono:!0}),e.jsx(U,{label:t("common.architecture"),value:s.server.architecture,mono:!0}),e.jsx(U,{label:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(W,{className:"h-4 w-4"}),"Uptime"]}),value:s.server.uptime.formatted,mono:!0})]}),e.jsxs(ne,{icon:e.jsx(_e,{className:"h-4 w-4"}),title:"CPU",subtitle:t("common.processorInformation"),children:[e.jsx(U,{label:t("common.coresAllocated"),value:`${s.cpu.cores} cores`}),s.cpu.physicalCores&&s.cpu.physicalCores!==s.cpu.cores&&e.jsx(U,{label:t("common.physicalCores"),value:`${s.cpu.physicalCores} cores (host)`}),e.jsx(U,{label:t("common.model"),value:`${s.cpu.model.substring(0,30)}...`,mono:!0}),s.server.containerLimits&&e.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg bg-tint-info px-3 py-2 text-xs text-tint-info-fg",children:[e.jsx(xe,{className:"h-3.5 w-3.5 shrink-0"}),"Container: ",s.server.containerLimits.allocatedCPU," vCPU allocated (from ",s.server.containerLimits.physicalCPU," physical cores)"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{label:t("common.loadAverage1m"),value:x.toFixed(2),mono:!0}),e.jsx(me,{value:l,className:`h-2 ${i}`}),e.jsxs("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:[l.toFixed(0),"% utilization"]})]})]}),e.jsxs(ne,{icon:e.jsx($e,{className:"h-4 w-4"}),title:"Memory",subtitle:t("common.ramUsage"),children:[e.jsx(U,{label:s.memory.physicalTotal&&s.memory.total!==s.memory.physicalTotal?"Total RAM (Allocated)":"Total RAM",value:`${s.memory.total} GB`}),s.memory.physicalTotal&&s.memory.total!==s.memory.physicalTotal&&e.jsx(U,{label:t("common.physicalRam"),value:`${s.memory.physicalTotal} GB (host)`}),e.jsx(U,{label:t("common.used"),value:`${s.memory.used} GB`}),e.jsx(U,{label:t("common.free"),value:`${s.memory.free} GB`}),s.server.containerLimits?.allocatedRAM&&e.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg bg-tint-info px-3 py-2 text-xs text-tint-info-fg",children:[e.jsx(xe,{className:"h-3.5 w-3.5 shrink-0"}),"Container: ",s.server.containerLimits.allocatedRAM," GB allocated (from ",s.server.containerLimits.physicalRAM," GB physical)"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(me,{value:s.memory.usagePercent,className:`h-2 ${h}`}),e.jsxs("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:[s.memory.usagePercent,"% used"]})]})]}),e.jsxs(ne,{icon:e.jsx(fe,{className:"h-4 w-4"}),title:"Campaign Worker",subtitle:t("common.backgroundJobProcessor"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm text-[var(--nova-text-secondary)]",children:t("common.status")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${s.worker.isRunning?"bg-green-500 animate-pulse":"bg-red-500"}`}),e.jsx("span",{className:`text-sm font-semibold ${s.worker.isRunning?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:s.worker.status==="running"?"Running":"Stopped"})]})]}),e.jsx(U,{label:t("common.activeWorkers"),value:`${s.worker.activeWorkers} worker${s.worker.activeWorkers!==1?"s":""}`}),e.jsx(U,{label:t("common.concurrency"),value:`${s.worker.concurrency} jobs at once`}),e.jsx(U,{label:t("common.rateLimit"),value:`${s.worker.rateLimit} messages/sec`}),s.worker.error?e.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg bg-tint-warning px-3 py-2 text-xs text-tint-warning-fg",children:[e.jsx(Z,{className:"h-3.5 w-3.5 shrink-0"}),s.worker.error]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-lg bg-[var(--nova-panel-elevated)] px-3 py-2",children:e.jsxs("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:["Auto-detected: ",s.worker.description]})}),e.jsxs("div",{className:`flex items-center gap-1.5 rounded-lg px-3 py-2 text-xs ${s.worker.isRunning?"bg-tint-success text-tint-success-fg":"bg-tint-danger text-tint-danger-fg"}`,children:[s.worker.isRunning?e.jsx(te,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(Z,{className:"h-3.5 w-3.5 shrink-0"}),s.worker.isRunning?"Worker is active and processing campaigns":"No workers detected - campaigns will not process"]})]})]})]}),e.jsx(ne,{icon:e.jsx(qe,{className:"h-4 w-4"}),title:"Campaign Queue Status",subtitle:t("common.realTimeMessageQueueStatistics"),children:s.queue.error?e.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg bg-tint-warning px-3 py-2 text-sm text-tint-warning-fg",children:[e.jsx(Z,{className:"h-4 w-4 shrink-0"}),s.queue.error]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-5",children:[e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-elevated)] p-4 text-center",children:[e.jsx(ae,{className:"mx-auto mb-2 h-6 w-6 text-blue-500"}),e.jsx("p",{className:"text-2xl font-bold text-[var(--nova-text-primary)]",children:s.queue.active}),e.jsx("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:t("common.active")})]}),e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-elevated)] p-4 text-center",children:[e.jsx(W,{className:"mx-auto mb-2 h-6 w-6 text-yellow-500"}),e.jsx("p",{className:"text-2xl font-bold text-[var(--nova-text-primary)]",children:s.queue.waiting}),e.jsx("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:t("common.waiting")})]}),e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-elevated)] p-4 text-center",children:[e.jsx(W,{className:"mx-auto mb-2 h-6 w-6 text-orange-500"}),e.jsx("p",{className:"text-2xl font-bold text-[var(--nova-text-primary)]",children:s.queue.delayed}),e.jsx("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:t("common.scheduled")})]}),e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-elevated)] p-4 text-center",children:[e.jsx(te,{className:"mx-auto mb-2 h-6 w-6 text-green-500"}),e.jsx("p",{className:"text-2xl font-bold text-[var(--nova-text-primary)]",children:s.queue.completed}),e.jsx("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:t("admin.completed")})]}),e.jsxs("div",{className:"rounded-lg border border-[var(--nova-border)] bg-[var(--nova-panel-elevated)] p-4 text-center",children:[e.jsx(Ne,{className:"mx-auto mb-2 h-6 w-6 text-red-500"}),e.jsx("p",{className:"text-2xl font-bold text-[var(--nova-text-primary)]",children:s.queue.failed}),e.jsx("p",{className:"text-xs text-[var(--nova-text-secondary)]",children:t("inbox.failed")})]})]}),s.queue.waiting>0&&e.jsxs("div",{className:"rounded-lg bg-tint-info px-3 py-3 text-sm text-tint-info-fg",children:[e.jsxs("p",{className:"flex items-center gap-1.5 font-medium",children:[e.jsx(Me,{className:"h-4 w-4 shrink-0"}),"Estimated processing time: ",Math.ceil(s.queue.waiting/s.worker.rateLimit)," seconds"]}),e.jsxs("p",{className:"mt-1 text-xs opacity-80",children:["At ",s.worker.rateLimit," messages/second with ",s.worker.concurrency," concurrent workers"]})]})]})}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-[var(--nova-text-secondary)]",children:[e.jsx(ae,{className:"h-3 w-3 animate-pulse"}),e.jsx("span",{children:t("common.autoRefreshingEvery5Seconds")})]})]})}function Us(){const[t,s]=F.useState("cloudflare_saas"),{whiteLabelAllowed:a}
1=Le(),{t:o}=M();return e.jsx(ws,{title:o("settings.whitelabelSetup"),panel:!1,children:e.jsxs(Ie,{value:t,onValueChange:s,className:"nova-tab-content",children:[e.jsxs(Cs,{children:[e.jsx(_,{value:"cloudflare_saas",className:J,children:o("settings.cloudflareForSaas")}),a&&e.jsx(_,{value:"railway_saas",className:J,children:o("settings.railwayForSaas")}),e.jsx(_,{value:"cron_jobs",className:J,children:o("settings.cronJobs")}),e.jsx(_,{value:"instance_config",className:J,children:o("settings.instanceConfig.tabName")}),e.jsx(_,{value:"data_retention",className:J,children:o("settings.dataRetention.tabName")}),e.jsx(_,{value:"license",className:J,children:o("settings.licence")}),e.jsx(_,{value:"server_stats",className:J,children:o("settings.stats")})]}),e.jsx($,{value:"cloudflare_saas",className:"pt-4",children:e.jsx(We,{borderless:!0})}),a&&e.jsx($,{value:"railway_saas",className:"pt-4",children:e.jsx(Ge,{borderless:!0})}),e.jsx($,{value:"cron_jobs",className:"pt-4",children:e.jsx(Oe,{borderless:!0})}),e.jsx($,{value:"instance_config",className:"pt-4",children:e.jsx(Ke,{borderless:!0})}),e.jsx($,{value:"data_retention",className:"pt-4",children:e.jsx(Qe,{borderless:!0})}),e.jsx($,{value:"license",className:"pt-4",children:e.jsx(He,{borderless:!0})}),e.jsx($,{value:"server_stats",className:"pt-4",children:e.jsx(Ps,{})})]})})}function gi(){const{isNova:t}=Ze();return t?e.jsx(Us,{}):e.jsx(Is,{})}export{gi as InstanceSettingsPage};

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.