import{at as e,k as a,aB as t,aH as s,aI as o,j as n,E as l,h as i,i as r,e as d}from"../../../../vendor-element-plus.js?ver=3.1.8";import{aQ as p,W as c,X as g,ab as m,a5 as h,a9 as f,aa as u,Z as _,Y as y,a8 as b,J as v,az as w,b2 as x}from"../../../../vendor.js?ver=3.1.8";import{P as $}from"../../../../PaginationBar.js?ver=3.1.8";import{D}from"../../../../DataTable.js?ver=3.1.8";import{S as k}from"../../../../SettingsHeader.js?ver=3.1.8";import{_ as E,I as C}from"../../../../fc-bits-ui.js?ver=3.1.8";const L={class:"fcrm_system_logs fcrm_settings fcrm_view"},T={class:"fcrm_body"},S={class:"icon"},j={key:0,class:"icon"},A={class:"icon"},H={key:0,class:"d-flex flex-column gap-1"},I={class:"text-secondary"},z={class:"text-secondary"},P=["innerHTML"];const U=E({name:"SystemLogs",components:{ArrowDown:e,Icons:C,PaginationBar:$,DataTable:D,SettingsHeader:k},data:()=>({logs:[],pagination:{total:0,current_page:1,per_page:20},loading:!1,search:""}),computed:{exportOptions(){return[{range:"7",label:this.$t("Export Last 7 Days")},{range:"15",label:this.$t("Export Last 15 Days")},{range:"30",label:this.$t("Export Last 30 Days")},{range:"all",label:this.$t("Export All")}]}},methods:{fetch(){this.loading=!0,this.storage.set("system_logs_perpage",this.pagination.per_page),this.$get("setting/system-logs",{per_page:this.pagination.per_page,page:this.pagination.current_page,search:this.search}).then(e=>{this.logs=e.logs.data,this.pagination.total=e.logs.total}).catch(e=>{this.handleError(e)}).finally(()=>{this.loading=!1})},exportLogs(e){const a=document.createElement("a");a.href=this.getExportUrl(e),a.target="_blank",a.rel="noopener noreferrer",a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a)},getExportUrl(e){const a=`${window.fcAdmin.rest.url}/setting/system-logs/export`,t=new URLSearchParams;return t.append("_wpnonce",window.fcAdmin.rest.nonce),t.append("range",e||"all"),t.append("query_timestamp",Date.now()),this.search&&t.append("search",this.search),a+(-1===a.indexOf("?")?"?":"&")+t.toString()},deleteAll(){this.loading=!0,this.$del("setting/system-logs/reset").then(e=>{this.$notify.success(e.message),this.logs=[],this.pagination.total=0}).catch(e=>{this.handleError(e)}).finally(()=>{this.loading=!1})},formatDate:e=>e?e.split(" ")[0]:"",formatTime:e=>e&&e.split(" ")[1]||""},mounted(){this.pagination.per_page=parseInt(this.storage.get("system_logs_perpage",20),10)||20,this.fetch()}},[["render",function(e,$,D,k,E,C){const U=a,B=p("SettingsHeader"),F=p("Icons"),O=d,R=p("ArrowDown"),V=l,K=r,M=i,q=n,J=t,N=o,Q=s,W=p("pagination-bar"),X=p("data-table");return c(),g("div",L,[m(B,{title:e.$t("System Logs")},{actions:h(()=>[m(U,{type:"danger",size:"small",onClick:C.deleteAll},{default:h(()=>[f(u(e.$t("Reset")),1)],void 0,!0),_:1},8,["onClick"])]),_:1},8,["title"]),_("div",T,[m(X,{"has-selection":!1},{"header-left":h(()=>[m(O,{modelValue:E.search,"onUpdate:modelValue":$[0]||($[0]=e=>E.search=e),onClear:C.fetch,onKeyup:x(C.fetch,["enter"]),placeholder:e.$t("Type & enter"),clearable:""},{prefix:h(()=>[_("span",S,[m(F,{"icon-name":"search"})])]),_:1},8,["modelValue","onClear","onKeyup","placeholder"])]),"header-actions":h(()=>[m(U,{size:"small",loading:E.loading,onClick:C.fetch},{default:h(()=>[E.loading?b("",!0):(c(),g("span",j,[m(F,{"icon-name":"reload"})])),f(" "+u(e.$t("Refresh")),1)],void 0,!0),_:1},8,["loading","onClick"]),m(q,{size:"small",trigger:"click",onCommand:C.exportLogs},{dropdown:h(()=>[m(M,null,{default:h(()=>[(c(!0),g(v,null,w(C.exportOptions,e=>(c(),y(K,{key:e.range,command:e.range},{default:h(()=>[f(u(e.label),1)],void 0,!0),_:2},1032,["command"]))),128))],void 0,!0),_:1})]),default:h(()=>[m(U,{size:"small"},{default:h(()=>[_("span",A,[m(F,{"icon-name":"export"})]),f(" "+u(e.$t("Export"))+" ",1),m(V,{class:"el-icon--right"},{default:h(()=>[m(R)],void 0,!0),_:1})],void 0,!0),_:1})],void 0,!0),_:1},8,["onCommand"])]),table:h(()=>[E.loading?(c(),y(J,{key:0,style:{padding:"20px"},rows:8})):(c(),y(Q,{key:1,"empty-text":e.$t("No Data Found"),data:E.logs},{default:h(()=>[m(N,{label:e.$t("ID"),prop:"id",width:"120"},null,8,["label"]),m(N,{label:e.$t("Date & Time"),"min-width":"150",property:"created_at"},{default:h(e=>[e.row.created_at?(c(),g("div",H,[_("div",I,u(C.formatDate(e.row.created_at)),1),_("small",z,u(C.formatTime(e.row.created_at)),1)])):b("",!0)]),_:1},8,["label"]),m(N,{label:e.$t("Title"),"min-width":"300"},{default:h(e=>[f(u(e.row.title),1)]),_:1},8,["label"]),m(N,{label:e.$t("Description"),"min-width":"390"},{default:h(e=>[_("div",{innerHTML:e.row.description},null,8,P)]),_:1},8,["label"])],void 0,!0),_:1},8,["empty-text","data"]))]),pagination:h(()=>[E.loading?b("",!0):(c(),y(W,{key:0,pagination:E.pagination,onFetch:C.fetch},null,8,["pagination","onFetch"]))]),_:1})])])}]]);export{U as default};
