import{D as $}from"./DataGrid-CbtTsx8d.js";import{u as q,G as T}from"./useGridLayout-DCIiMD42.js";import{u as U}from"./status-CE0GKX14.js";import{d as Y,u as Z,Y as j,S as J,N as Q,e as f,h as l,i as b,t as X,q as m,f as k,Z as ee,g as _,k as a,r as D,o as d,a0 as H,P as te,y as oe,a1 as se,a2 as le,x as ne,_ as ie}from"./index-D92x6h1h.js";const re={class:"status-grid-wrapper"},ae={key:0,class:"status-grid__selection-strip","aria-live":"polite"},ue=["aria-label","aria-pressed"],de=Y({__name:"StatusGrid",props:{endpoint:{},notificationClass:{},columns:{},keyField:{},storageKey:{},defaultSort:{},selectable:{type:Boolean},helpPage:{}},setup(p,{expose:P}){const o=p,{t:v}=Z(),h=le();function A(){o.helpPage&&h.toggle(o.helpPage).catch(()=>{})}const F=a(()=>o.defaultSort?{field:o.defaultSort.key,dir:o.defaultSort.dir==="DESC"?"DESC":"ASC"}:void 0),s=q({storageKey:o.storageKey,columns:()=>o.columns,defaultSort:F.value,gridKey:o.storageKey}),G=a(()=>s.sort.value?.field),W=a(()=>s.sort.value?.order??1);function x(e){if(typeof e.sortField!="string"||e.sortField.length===0)return;const t=e.sortOrder===-1?"DESC":"ASC";s.setSort(e.sortField,t)}const u=U(o.endpoint,o.notificationClass,o.keyField),R=j(),C=a(()=>o.selectable===!0||!!R.toolbarActions),i=D([]);function S(){i.value=[]}function w(e){const t=e[o.keyField];if(t==null)return;const r=i.value.findIndex(n=>n[o.keyField]===t);r>=0?i.value=i.value.filter((n,c)=>c!==r):i.value=[...i.value,e]}const B=J();Q(()=>{u.fetch()});const E=a(()=>{const e={};for(const t of o.columns)e[t.field]=t.label??t.field;return e});function K(){return!1}function z(e){const t=e.element.dataset.field;if(!t)return;const r=e.element.offsetWidth;s.setColumnWidth(t,r)}function I(e){s.setColumnOrder(e)}function g(e){const t=o.columns.find(r=>r.field===e);t&&s.setColumnHidden(e,!s.isHidden(t))}function L(e,t){s.moveColumn(e,t)}function M(e,t){if(t===null){s.clearSort();return}s.setSort(e,t==="desc"?"DESC":"ASC")}const y=D(null);function N(){s.reset(),y.value?.destroyColumnWidthStyle()}function O(e){return{headerCell:{"data-field":e.field},bodyCell:{"data-field":e.field}}}const V=a(()=>({"data-grid-key":o.storageKey}));return P({selection:i,clearSelection:S,toggleSelect:w}),(e,t)=>{const r=ne("tooltip");return d(),f("div",re,[C.value&&!l(B)&&i.value.length>0?(d(),f("output",ae,[b("span",null,X(i.value.length)+" selected",1),b("button",{type:"button",class:"status-grid__selection-clear",onClick:S}," Clear selection ")])):m("",!0),k($,{ref_key:"dataGridRef",ref:y,selection:i.value,"onUpdate:selection":t[0]||(t[0]=n=>i.value=n),"bem-prefix":"status-grid",entries:l(u).entries,loading:l(u).loading,error:l(u).error,columns:l(s).orderedColumns.value,"key-field":p.keyField,selectable:C.value,lazy:!1,"sort-field":G.value,"sort-order":W.value,"is-column-hidden":l(s).isHidden,"is-width-custom":n=>l(s).isWidthCustom(n.field),"column-pt":O,"root-data-attrs":V.value,"resizable-columns":!0,"column-resize-mode":"expand","reorderable-columns":!0,"column-actions":{sort:!0,hide:!0,resetWidth:!0},class:"status-grid",onSort:x,onSetSort:M,onColumnResizeEnd:z,onReorderColumns:I,onHideColumn:g,onResetWidthColumn:t[1]||(t[1]=n=>l(s).clearColumnWidth(n))},ee({toolbarRight:_(({isPhone:n})=>[H(e.$slots,"toolbarMeta",{isPhone:n},void 0,!0),n?m("",!0):(d(),te(T,{key:0,columns:l(s).orderedColumns.value,"column-labels":E.value,"effective-level":"basic",locked:!1,"is-hidden":l(s).isHidden,"is-locked":K,"hide-level-section":!0,"defaults-active":l(s).isAtDefaults.value,onToggleColumn:g,onMoveColumn:L,onReset:N},null,8,["columns","column-labels","is-hidden","defaults-active"])),o.helpPage?oe((d(),f("button",{key:1,type:"button",class:"status-grid-help","aria-label":l(v)("Help"),"aria-pressed":l(h).isOpen.value,onClick:A},[k(l(se),{size:16,"stroke-width":2})],8,ue)),[[r,l(v)("Help"),void 0,{bottom:!0}]]):m("",!0)]),_:2},[e.$slots.toolbarActions?{name:"toolbarActions",fn:_(({selection:n,clearSelection:c})=>[H(e.$slots,"toolbarActions",{selection:n,clearSelection:c},void 0,!0)]),key:"0"}:void 0]),1032,["selection","entries","loading","error","columns","key-field","selectable","sort-field","sort-order","is-column-hidden","is-width-custom","root-data-attrs"])])}}}),ve=ie(de,[["__scopeId","data-v-a42136cf"]]);export{ve as S};
