import{M as V,p as _,c as J,e as o,z as e,f as s,g as d,h as p,k as x,F as h,A as C,o as l,n as y,N as X}from"./vue-CSzJdJby.js";import{_ as Y}from"./ring-alt-BtllWDs8.js";import{$ as c}from"./jquery-BALIvAru.js";import{_ as Z}from"./lodash-uc_7-CSk.js";import{_ as q,a as G,b as H,c as K,d as Q}from"./VacuumModal-Df67OX_Q.js";import{_ as W}from"./ReindexModal-CUkLKkWF.js";import{_ as ee}from"./SizeDistributionBar-CUwS4Z3x.js";import"./highlight.js-CWp04Ajj.js";import"./daterangepicker-i3LpM03M.js";import"./moment-CMyQs7Vz.js";import"./index-ncPPdFzC.js";import"./index-C25aB_MX.js";const te={class:"row"},se={class:"col"},ae={key:0,class:"col text-end"},ne={key:0,class:"text-center"},oe=e("img",{src:Y,class:"fa-fw fa-2x"},null,-1),le=[oe],ie={key:1},re={class:"row"},de={class:"col-4"},ce=e("button",{id:"buttonAnalyze",type:"button",class:"btn btn-outline-secondary","data-bs-toggle":"modal","data-bs-target":"#analyzeModal"},`
              ANALYZE
            `,-1),ue={class:"col-4"},be=e("button",{id:"buttonVacuum",type:"button",class:"btn btn-outline-secondary","data-bs-toggle":"modal","data-bs-target":"#vacuumModal"},`
              VACUUM
            `,-1),_e={class:"col-4"},pe={class:"d-flex"},ye={class:"text-body-secondary small"},me={class:"ms-auto"},xe={class:"btn btn-sm btn-outline-secondary dropdown-toggle",type:"button","data-bs-toggle":"dropdown","aria-haspopup":"true","aria-expanded":"false"},fe={class:"dropdown-menu"},he=e("h6",{class:"dropdown-header"},"Sort by:",-1),ve=["onClick"],ge={key:2,class:"table table-sm"},we=e("thead",null,[e("tr",null,[e("th"),s(),e("th"),s(),e("th",{class:"text-center border-start"},[s(`
            Tables
            `),e("div",{class:"d-inline-block"},[e("div",{class:"progress border rounded-0",style:{height:"7px",width:"10px"}},[e("div",{class:"progress-bar bg-cat1",role:"progressbar",style:{width:"100%"}})])])]),s(),e("th",{class:"text-center border-start"},[s(`
            Indexes
            `),e("div",{class:"d-inline-block"},[e("div",{class:"progress border rounded-0",style:{height:"7px",width:"10px"}},[e("div",{class:"progress-bar bg-cat2",role:"progressbar",style:{width:"100%"}})])])]),s(),e("th",{class:"text-center border-start"},[s(`
            Toast
            `),e("div",{class:"d-inline-block"},[e("div",{class:"progress border rounded-0",style:{height:"7px",width:"10px"}},[e("div",{class:"progress-bar bg-secondary",role:"progressbar",style:{width:"100%"}})])])])])],-1),Te={class:"schema fw-bold"},ze=["href"],Ee={key:0,class:"temboard-tables text-end border-start"},je={class:"badge text-bg-secondary"},ke={class:"d-inline-block",style:{"min-width":"80px"}},Se={key:1,class:"temboard-tables text-center text-body-secondary border-start small"},Ae=e("em",null," No table ",-1),Ne=[Ae],Be={key:2,class:"indexes text-end border-start"},Ue={class:"badge text-bg-secondary"},$e={class:"d-inline-block",style:{"min-width":"80px"}},Ve={key:3,class:"indexes text-center text-body-secondary border-start small"},Ce=e("em",null," No index ",-1),Fe=[Ce],De={class:"temboard-toast text-end border-start"},Re={colspan:"5",class:"border-top-0"},Oe={__name:"Database",props:["apiUrl","instance","database","maintenanceBaseUrl"],setup(z){let N,B,U;const u=z;V("instance",u.instance);const E=_(u.database);V("dbName",E);const b=_("total_bytes"),j=_({name:["Name","asc"],total_bytes:["Database Size","desc"],tables_bytes:["Tables Size","desc"],tables_bloat_ratio:["Tables Bloat","desc"],indexes_bytes:["Indexes Size","desc"],indexes_bloat_ratio:["Indexes Bloat","desc"],toast_bytes:["Toast Size","desc"]}),f=_(!0),m=_({}),k=_([]),S=_([]),A=_([]),$=_(null);function F(){v(),g(),w(),T()}const D=J(()=>{const n=j.value[b.value][1];return Z.orderBy(m.value.schemas,b.value,n)});function v(){c.ajax({url:u.apiUrl,contentType:"application/json",success:function(n){m.value=n,m.value.schemas.forEach(function(a){a.tables_bloat_ratio=0,a.tables_bytes&&(a.tables_bloat_ratio=parseFloat((100*(a.tables_bloat_bytes/a.tables_bytes)).toFixed(1))),a.indexes_bloat_ratio=0,a.indexes_bytes&&(a.indexes_bloat_ratio=parseFloat((100*(a.indexes_bloat_bytes/a.indexes_bytes)).toFixed(1)))})},error:showError,complete:function(){f.value=!1}})}function g(){window.clearTimeout(N);const n=k.value.length;c.ajax({url:u.apiUrl+"/vacuum/scheduled",contentType:"application/json",success:function(a){k.value=a,N=window.setTimeout(function(){g()},5e3),a.length<n&&v()},error:showError})}function R(){const n=c("#vacuumForm").serializeArray(),a=n.filter(function(i){return i.name=="mode"}).map(function(i){return i.value}).join(","),t={};a&&(t.mode=a);const r=n.filter(function(i){return i.name=="datetime"}).map(function(i){return i.value}).join("");r&&(t.datetime=r),c.ajax({method:"POST",url:u.apiUrl+"/vacuum",data:JSON.stringify(t),contentType:"application/json",success:g,error:showError})}function O(n){c.ajax({method:"DELETE",url:u.maintenanceBaseUrl+"/vacuum/"+n,contentType:"application/json",success:g,error:showError})}function w(){window.clearTimeout(B);const n=S.value.length;c.ajax({url:u.apiUrl+"/analyze/scheduled",contentType:"application/json",success:function(a){S.value=a,B=window.setTimeout(function(){w()},5e3),a.length<n&&v()},error:showError})}function I(){const n=c("#analyzeForm").serializeArray(),a=n.filter(function(i){return i.name=="mode"}).map(function(i){return i.value}).join(","),t={};a&&(t.mode=a);const r=n.filter(function(i){return i.name=="datetime"}).map(function(i){return i.value}).join("");r&&(t.datetime=r),c.ajax({method:"POST",url:u.apiUrl+"/analyze",data:JSON.stringify(t),contentType:"application/json",success:w,error:showError})}function L(n){c.ajax({method:"DELETE",url:u.maintenanceBaseUrl+"/analyze/"+n,contentType:"application/json",success:w,error:showError})}function T(){window.clearTimeout(U);const n=A.value.length;c.ajax({url:u.apiUrl+"/reindex/scheduled",contentType:"application/json",success:function(a){A.value=a,U=window.setTimeout(function(){T()},5e3),a.length<n&&v()},error:showError})}function M(){const n=c("#reindexForm").serializeArray(),a={},t=n.filter(function(r){return r.name=="datetime"}).map(function(r){return r.value}).join("");t&&(a.datetime=t),c.ajax({method:"POST",url:[u.apiUrl,"reindex"].join("/"),data:JSON.stringify(a),contentType:"application/json",success:T,error:showError})}function P(n){c.ajax({method:"DELETE",url:u.maintenanceBaseUrl+"/reindex/"+n,contentType:"application/json",success:T,error:showError})}return F(),(n,a)=>(l(),o("div",null,[e("h3",te,[e("div",se,[s(`
        Database: `),e("strong",null,d(E.value),1)]),s(),f.value?p("",!0):(l(),o("div",ae,[s(`
        Size: `),e("strong",null,d(m.value.total_size),1)]))]),s(),f.value?(l(),o("div",ne,le)):p("",!0),s(),f.value?p("",!0):(l(),o("div",ie,[e("div",re,[e("div",de,[e("div",null,[ce,s(),x(K,{onApply:I}),s(),x(q,{scheduledAnalyzes:S.value,onCancel:L},null,8,["scheduledAnalyzes"])])]),s(),e("div",ue,[e("div",null,[be,s(),x(Q,{onApply:R}),s(),x(G,{scheduledVacuums:k.value,onCancel:O},null,8,["scheduledVacuums"])])]),s(),e("div",_e,[e("div",null,[e("button",{id:"buttonReindex",type:"button",class:"btn btn-outline-secondary","data-bs-toggle":"modal","data-bs-target":"#reindexModal",onClick:a[0]||(a[0]=t=>$.value=m.value.name)},`
              REINDEX
            `),s(),x(W,{reindexType:"database",reindexElementName:$.value,onApply:M},null,8,["reindexElementName"]),s(),x(H,{scheduledReindexes:A.value,onCancel:P},null,8,["scheduledReindexes"])])])]),s(),e("div",pe,[e("h4",null,[s(`
          Schemas `),e("span",ye,"("+d(m.value.schemas.length)+")",1)]),s(),e("div",me,[e("button",xe,`
            Sort by `+d(j.value[b.value][0]),1),s(),e("div",fe,[he,s(),(l(!0),o(h,null,C(j.value,(t,r)=>(l(),o("a",{class:"dropdown-item",href:"#",onClick:i=>b.value=r},[e("i",{class:y(["fa fa-fw",{"fa-check":b.value==r}])},null,2),s(" "+d(t[0]),1)],8,ve))),256))])])])])),s(),f.value?p("",!0):(l(),o("table",ge,[we,s(),e("tbody",null,[(l(!0),o(h,null,C(D.value,(t,r)=>(l(),o(h,null,[e("tr",{class:y({"bg-light2":r%2==0})},[e("td",Te,[e("a",{href:`/server/${z.instance.agentAddress}/${z.instance.agentPort}/maintenance/${E.value}/schema/${t.name}`},d(t.name),9,ze)]),s(),e("td",{class:y(["schema-size","text-end",b.value=="total_bytes"?"fw-bold":""])},d(t.total_size),3),s(),t.n_tables>0?(l(),o("td",Ee,[e("span",je,d(t.n_tables),1),s(),e("span",ke,[t.tables_bytes?(l(),o("span",{key:0,class:y([b.value=="tables_bytes"?"fw-bold":""])},d(t.tables_size),3)):p("",!0)]),s(),e("small",{style:{"min-width":"70px"},class:y(["table-bloat","d-inline-block",b.value=="tables_bloat_ratio"?"fw-bold":"text-body-secondary"])},[t.tables_bloat_bytes&&t.tables_bytes?(l(),o(h,{key:0},[s(`
                    Bloat: `+d(t.tables_bloat_ratio.toFixed(1))+`%
                  `,1)],64)):p("",!0)],2)])):(l(),o("td",Se,Ne)),s(),t.n_indexes>0?(l(),o("td",Be,[e("span",Ue,d(t.n_indexes),1),s(),e("span",$e,[t.indexes_bytes?(l(),o("span",{key:0,class:y([b.value=="indexes_bytes"?"fw-bold":""])},d(t.indexes_size),3)):p("",!0)]),s(),e("small",{style:{"min-width":"70px"},class:y(["index-bloat","d-inline-block",b.value=="indexes_bloat_ratio"?"fw-bold":"text-body-secondary"])},[t.indexes_bloat_bytes&&t.indexes_bytes?(l(),o(h,{key:0},[s(`
                  Bloat: `+d(t.indexes_bloat_ratio.toFixed(1))+`%
                `,1)],64)):p("",!0)],2)])):(l(),o("td",Ve,Fe)),s(),e("td",De,[t.toast_bytes?(l(),o("span",{key:0,class:y([b.value=="toast_bytes"?"fw-bold":""])},d(t.toast_size),3)):p("",!0)])],2),s(),e("tr",{class:y({"bg-light2":r%2==0})},[e("td",Re,[x(ee,{height:"7",total:m.value.total_bytes,cat1:t.tables_size,cat1raw:t.tables_bytes,cat1label:"Tables",cat1bis:t.tables_bloat_size,cat1bisraw:t.tables_bloat_bytes,cat1bislabel:"Tables Bloat",cat2:t.indexes_size,cat2raw:t.indexes_bytes,cat2label:"Indexes",cat2bis:t.indexes_bloat_size,cat2bisraw:t.indexes_bloat_bytes,cat2bislabel:"Indexes Bloat",cat3:t.toast_size,cat3raw:t.toast_bytes,cat3label:"Toast"},null,8,["total","cat1","cat1raw","cat1bis","cat1bisraw","cat2","cat2raw","cat2bis","cat2bisraw","cat3","cat3raw"])])],2)],64))),256))])]))]))}};X({components:{maintenancedatabase:Oe}}).mount("#app");
