import{n as k,X as K,V as S,g as T,_ as j,b as B,d as F,$ as N,e as O,a0 as V,Q as R,f as X,w as D}from"./registry-DyIszw9-.js";import{_ as E}from"./PageHeader.vue_vue_type_script_setup_true_lang-Cr1rE6nR.js";import{_ as H,a as P,b as z,c as A,d as L}from"./SystemInfoWidget.vue_vue_type_script_setup_true_lang-VIYdddIM.js";import{d as w,aT as i,W as l,bh as _,u as a,F as y,b2 as $,aF as M,Q as v,b6 as Q,a3 as n,U as x,O as C,r as I,a0 as U,bK as m,a2 as W,X as q}from"./vendor-reka-Edfq1EPl.js";import{u as G}from"./useCsrfToken-CgmSjXCB.js";import"./vendor/inertia-CR4tWtMT.js";import"./LocaleSwitcher.vue_vue_type_script_setup_true_lang-4M-c0Clb.js";import"./CardContent.vue_vue_type_script_setup_true_lang-DPd7KJ8I.js";import"./sanitize-WJtyuR8o.js";import"./vendor-charts-DSwSKiaC.js";const J={key:0,class:"flex items-center justify-center rounded-xl border border-dashed bg-muted/30 p-12 text-sm text-muted-foreground"},Y={key:1,class:"grid grid-cols-12 gap-4"},Z={key:1,class:"flex items-center justify-center rounded-xl border border-dashed bg-muted/30 p-8 text-sm text-muted-foreground"},ee=["onClick"],te=w({__name:"WidgetRenderer",props:{widgets:{},hiddenWidgetKeys:{}},emits:["hide"],setup(f,{emit:o}){const{t:r}=k(),s=f,g=o,h={CounterWidget:L,TextWidget:A,ChartWidget:z,SystemInfoWidget:P,StatsWidget:H};function c(t){const b=S.resolveComponent(t);return b||(h[t]??null)}const u={full:"col-span-12",half:"col-span-12 sm:col-span-6",third:"col-span-12 sm:col-span-6 lg:col-span-4"};function p(t){return u[t]??"col-span-12"}const e=C(()=>s.widgets.filter(t=>!s.hiddenWidgetKeys.includes(t.key)));return(t,b)=>e.value.length===0?(i(),l("div",J,_(a(r)("builder.dashboard.no_widgets_visible")),1)):(i(),l("div",Y,[(i(!0),l(y,null,$(e.value,d=>(i(),l("div",{key:d.key,class:M([p(d.width),"group relative"])},[c(d.component)?(i(),v(Q(c(d.component)),{key:0,data:d.data,widget:d},null,8,["data","widget"])):(i(),l("div",Z,_(a(r)("builder.dashboard.unknown_widget",{component:d.component})),1)),d.hideable?(i(),l("button",{key:2,class:"absolute right-2 top-2 flex h-5 w-5 items-center justify-center rounded-full bg-muted text-muted-foreground opacity-0 transition-opacity hover:bg-destructive hover:text-destructive-foreground group-hover:opacity-100",title:"Hide widget",onClick:ae=>g("hide",d.key)},[n(a(K),{class:"h-3 w-3"})],8,ee)):x("",!0)],2))),128))]))}});function se(f){const o=G(),r=T(),s=I([...f]);function g(e){return e.filter(t=>!s.value.includes(t.key))}function h(e){return e.filter(t=>t.hideable)}async function c(e){s.value.includes(e)||(s.value.push(e),await fetch(`/${r}/dashboard/widgets/${e}/hide`,{method:"POST",headers:{"X-CSRF-TOKEN":o,Accept:"application/json"}}))}async function u(e){s.value=s.value.filter(t=>t!==e),await fetch(`/${r}/dashboard/widgets/${e}/show`,{method:"POST",headers:{"X-CSRF-TOKEN":o,Accept:"application/json"}})}async function p(e){s.value.includes(e)?await u(e):await c(e)}return{hiddenKeys:s,visibleWidgets:g,hideableWidgets:h,hideWidget:c,showWidget:u,toggleWidget:p}}const ge=w({__name:"Dashboard",props:{widgets:{},hiddenWidgetKeys:{}},setup(f){const{t:o}=k(),r=f,{hiddenKeys:s,hideableWidgets:g,toggleWidget:h,hideWidget:c}=se(r.hiddenWidgetKeys),u=C(()=>g(r.widgets));return(p,e)=>(i(),l(y,null,[n(E,{title:a(o)("builder.nav.dashboard")},U({_:2},[u.value.length>0?{name:"actions",fn:m(()=>[n(j,null,{default:m(()=>[n(B,{"as-child":""},{default:m(()=>[n(F,{variant:"outline",size:"sm"},{default:m(()=>[n(a(N),{class:"mr-2 h-4 w-4"}),W(" "+_(a(o)("builder.dashboard.manage_widgets")),1)]),_:1})]),_:1}),n(O,{align:"end",class:"min-w-52"},{default:m(()=>[n(V,null,{default:m(()=>[W(_(a(o)("builder.dashboard.widgets")),1)]),_:1}),n(R),(i(!0),l(y,null,$(u.value,t=>(i(),v(X,{key:t.key,class:"justify-between",onClick:b=>a(h)(t.key)},{default:m(()=>[q("span",null,_(t.label),1),a(s).includes(t.key)?x("",!0):(i(),v(a(D),{key:0,class:"h-4 w-4 text-primary"}))]),_:2},1032,["onClick"]))),128))]),_:1})]),_:1})]),key:"0"}:void 0]),1032,["title"]),n(te,{widgets:f.widgets,"hidden-widget-keys":a(s),onHide:a(c)},null,8,["widgets","hidden-widget-keys","onHide"])],64))}});export{ge as default};
