import{h as r,r as t,c as e,f as i,H as o,g as s}from"./p-32e583ea.js";import{G as n}from"./p-c5bad0b8.js";import{k as a}from"./p-89b8c724.js";import{i as c,a as d,s as l}from"./p-52d77e1f.js";import{i as u,b as h,a as f,S as g,c as b,g as v,e as w,d as p,f as m,h as k,M as y,o as j,k as C,r as x,j as A,s as _,l as R,m as O,U as S,n as F,p as I,q as E,t as P,u as D,v as M,w as T}from"./p-ff826ebe.js";function W(r){switch(r){case"asc":return 1;case"desc":return-1}}var U;var G=new Uint8Array(16);function H(){if(!U){U=typeof crypto!=="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!=="undefined"&&typeof msCrypto.getRandomValues==="function"&&msCrypto.getRandomValues.bind(msCrypto);if(!U){throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported")}}return U(G)}const N=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function z(r){return typeof r==="string"&&N.test(r)}var L=[];for(var B=0;B<256;++B){L.push((B+256).toString(16).substr(1))}function $(r){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var e=(L[r[t+0]]+L[r[t+1]]+L[r[t+2]]+L[r[t+3]]+"-"+L[r[t+4]]+L[r[t+5]]+"-"+L[r[t+6]]+L[r[t+7]]+"-"+L[r[t+8]]+L[r[t+9]]+"-"+L[r[t+10]]+L[r[t+11]]+L[r[t+12]]+L[r[t+13]]+L[r[t+14]]+L[r[t+15]]).toLowerCase();if(!z(e)){throw TypeError("Stringified UUID is invalid")}return e}function V(r,t,e){r=r||{};var i=r.random||(r.rng||H)();i[6]=i[6]&15|64;i[8]=i[8]&63|128;if(t){e=e||0;for(var o=0;o<16;++o){t[e+o]=i[o]}return t}return $(i)}var K="[object Symbol]";function q(r){return typeof r=="symbol"||u(r)&&h(r)==K}function J(r,t){var e=-1,i=r==null?0:r.length,o=Array(i);while(++e{let n;return r("div",{class:`grid-radio ${t?"checked":""}`,onClick:r=>n.click()},r("input",{type:"radio",name:"selection","aria-setsize":o,"aria-posinset":i,tabindex:"-1",checked:t,"aria-checked":`${t}`,ref:r=>n=r,onClick:r=>s(e)}))};const ke=":host{--wcs-grid-gap:0;--wcs-grid-vertical-align:middle;--wcs-grid-outline-color:var(--wcs-semantic-color-border-focus-base);--wcs-grid-cell-text-color:var(--wcs-semantic-color-text-secondary);--wcs-grid-cell-padding-horizontal:var(--wcs-semantic-spacing-large);--wcs-grid-cell-padding-vertical:var(--wcs-semantic-spacing-base);--wcs-grid-cell-border-bottom:none;--wcs-grid-cell-separator-border:none;--wcs-grid-first-cell-border-radius:0;--wcs-grid-last-cell-border-radius:0;--wcs-grid-highlight-color:var(--wcs-semantic-color-background-surface-accent-lighter);--wcs-grid-row-background-color:var(--wcs-semantic-color-background-surface-primary);--wcs-grid-row-odd-background-color:var(--wcs-grid-row-background-color);--wcs-grid-row-even-background-color:var(--wcs-semantic-color-background-surface-accent-lightest);--wcs-grid-header-background-color-default:var(--wcs-semantic-color-background-action-secondary-default);--wcs-grid-header-background-color-hover:var(--wcs-semantic-color-background-action-secondary-hover);--wcs-grid-header-background-color-press:var(--wcs-semantic-color-background-action-secondary-press);--wcs-grid-header-text-color:var(--wcs-semantic-color-text-primary);--wcs-grid-header-font-weight:var(--wcs-semantic-font-weight-heavy);--wcs-grid-header-font-size:var(--wcs-semantic-font-size-label-1);--wcs-grid-header-line-height:var(--wcs-primitive-font-line-height-140);--wcs-grid-header-padding-vertical:var(--wcs-semantic-spacing-base);--wcs-grid-header-padding-horizontal:var(--wcs-semantic-spacing-large);--wcs-grid-header-border-left:none;--wcs-grid-header-border-radius:0;--wcs-grid-header-border-bottom:solid var(--wcs-semantic-border-width-default) var(--wcs-semantic-color-border-secondary);--wcs-grid-header-transition-duration:var(--wcs-semantic-motion-duration-feedback-fast);--wcs-grid-first-header-background-color:var(--wcs-semantic-color-background-action-secondary-default);--wcs-grid-first-header-border-radius:0;--wcs-grid-last-header-border-radius:0;--wcs-grid-column-selection-width:calc(5 * var(--wcs-semantic-spacing-base));--wcs-grid-header-sort-arrow-color-default:var(--wcs-semantic-color-foreground-action-neutral-default);--wcs-grid-header-sort-arrow-color-hover:var(--wcs-semantic-color-foreground-action-neutral-hover);display:block}:host th{border-radius:var(--wcs-grid-first-header-border-radius);background-color:var(--wcs-grid-first-header-background-color)}:host ::slotted([slot=grid-column]:first-child){--wcs-grid-header-border-left:none}:host :host([selection]) ::slotted([slot=grid-column]:first-child){--wcs-component-grid-header-border-radius-first:0;--wcs-grid-header-border-left:var(--wcs-grid-header-border-left)}:host table{width:100%;border-collapse:collapse;border-spacing:var(--wcs-grid-gap)}:host table thead{border-bottom:var(--wcs-grid-header-border-bottom)}:host table tbody{vertical-align:var(--wcs-grid-vertical-align)}:host td{color:var(--wcs-grid-cell-text-color);margin:0;padding:var(--wcs-grid-cell-padding-vertical) var(--wcs-grid-cell-padding-horizontal)}:host td:focus-visible{outline:var(--wcs-semantic-border-width-large) dashed var(--wcs-grid-outline-color);outline-offset:0;border-radius:0.1rem}:host td:first-child{border-radius:var(--wcs-grid-first-cell-border-radius)}:host td:last-child{border-radius:var(--wcs-grid-last-cell-border-radius)}:host td:not(:first-child){border-left:var(--wcs-grid-cell-separator-border)}:host tr{background-color:var(--wcs-grid-row-background-color)}:host tr:nth-child(odd){background-color:var(--wcs-grid-row-odd-background-color, var(--wcs-grid-row-background-color))}:host tr:nth-child(even){background-color:var(--wcs-grid-row-even-background-color, var(--wcs-grid-row-background-color))}:host tr:not(:last-child) td{border-bottom:var(--wcs-grid-cell-border-bottom)}:host .wcs-grid-selection-column{padding:var(--wcs-grid-cell-padding-vertical) var(--wcs-grid-cell-padding-horizontal);width:var(--wcs-grid-column-selection-width);text-align:start}:host tr.selected{background-color:var(--wcs-grid-highlight-color)}:host .loading{text-align:center}";const ye=ke;const je='.grid-radio{--wcs-grid-radio-outline-color:var(--wcs-semantic-color-border-focus-base);--wcs-grid-radio-padding:calc(var(--wcs-semantic-size-base) / 4);--wcs-grid-radio-transition:var(--wcs-semantic-motion-duration-feedback-base);--wcs-grid-radio-border-color-default:var(--wcs-semantic-color-border-control-indicator-default);--wcs-grid-radio-border-color-selected:var(--wcs-semantic-color-border-control-indicator-selected);--wcs-grid-radio-border-color-hover:var(--wcs-semantic-color-border-control-indicator-hover);--wcs-grid-radio-border-color-disabled:var(--wcs-semantic-color-border-control-indicator-disabled);--wcs-grid-radio-background-color-default:transparent;--wcs-grid-radio-background-color-selected:var(--wcs-semantic-color-background-control-indicator-selected);--wcs-grid-radio-background-color-disabled:var(--wcs-semantic-color-background-control-indicator-disabled);--wcs-grid-radio-inner-border-color:white;width:fit-content;cursor:pointer;padding:var(--wcs-grid-radio-padding, 0.125rem);}.grid-radio:has(input:focus-visible){outline:var(--wcs-semantic-border-width-large) dashed var(--wcs-grid-radio-outline-color);outline-offset:var(--wcs-semantic-spacing-small);border-radius:0.1rem}@supports not selector(:has(input:focus-visible)){.grid-radio:focus-within{outline:var(--wcs-semantic-border-width-large) dashed var(--wcs-grid-radio-outline-color);outline-offset:var(--wcs-semantic-spacing-small);border-radius:0.1rem}}.grid-radio input{position:absolute;opacity:0;height:1px;width:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.grid-radio::before{content:"";display:flex;border-radius:50%;border:2px solid var(--wcs-grid-radio-border-color-default);position:relative;width:1.125rem;height:1.125rem;box-sizing:border-box;background-color:var(--wcs-grid-radio-background-color-default);transition:var(--wcs-grid-radio-transition, 0.175s) ease-in-out}.grid-radio:hover::before{border-color:var(--wcs-grid-radio-border-color-hover)}.grid-radio.checked::before{border-color:var(--wcs-grid-radio-border-color-selected);background-color:var(--wcs-grid-radio-background-color-selected);outline:solid 2px var(--wcs-grid-radio-inner-border-color);outline-offset:-4px}';const Ce=je;const xe=["title"];const Ae=class{constructor(r){t(this,r);this.wcsGridSelectionChange=e(this,"wcsGridSelectionChange",7);this.wcsGridAllSelectionChange=e(this,"wcsGridAllSelectionChange",7);this.wcsFocus=e(this,"wcsFocus",7);this.wcsBlur=e(this,"wcsBlur",7);this.inheritedAttributes={};this.serverMode=false;this.data=undefined;this.loading=undefined;this.selectionConfig="none";this.selectedItems=[];this.wcsGridPaginationId=undefined;this.rowIdPath=undefined;this.rowCssPartsFn=r=>null;this.columns=undefined;this.paginationEl=undefined;this.rows=[];this.cursorPosition={col:0,row:1}}onCursorPositionChange(r){this.getGridColumnsFromTemplate().forEach((t=>t.cursorPosition=r))}onDataChange(r){this.updateGridRows(r);this.refreshSort(false);this.updatePageIndex()}onSelectedItemsPropertyChange(r){this.updateSelectionWithValues(r)}onFocus(r){var t;(t=this.getElementToFocusAtCursorPosition())===null||t===void 0?void 0:t.focus();this.wcsFocus.emit(r)}onBlur(r){this.wcsBlur.emit(r)}async focusFirstCell(){var r;this.cursorPosition={col:this.selectionConfig==="none"?0:1,row:1};(r=this.getElementToFocusAtCursorPosition())===null||r===void 0?void 0:r.focus()}hasSelectionColumn(){return this.selectionConfig!=="none"}getElementToFocusAtCursorPosition(){var r,t;const e=(r=this.gridElementsWithCoordinates.find((r=>{var t,e;return r.col===((t=this.cursorPosition)===null||t===void 0?void 0:t.col)&&r.row===((e=this.cursorPosition)===null||e===void 0?void 0:e.row)})))===null||r===void 0?void 0:r.el;return this.hasSelectionColumn()?(t=e.querySelector('wcs-checkbox,input[type="radio"]'))!==null&&t!==void 0?t:e:e}moveCursorPosition(r,t){var e;this.cursorPosition={col:r==="first"?0:r==="last"?this.totalDisplayedColumnCount()-1:Math.min(Math.max(this.cursorPosition.col+r,0),this.totalDisplayedColumnCount()-1),row:t==="first"?0:t==="last"?this.getRowsForCurrentPage().length:Math.min(Math.max(this.cursorPosition.row+t,0),this.getRowsForCurrentPage().length)};this.handleCursorPositionOnEmptyTh();(e=this.getElementToFocusAtCursorPosition())===null||e===void 0?void 0:e.focus()}handleCursorPositionOnEmptyTh(){if(this.selectionConfig==="single"&&this.cursorPosition.col===0&&this.cursorPosition.row===0){this.cursorPosition={col:1,row:0}}}onHiddenColumnChange(){i(this);this.cursorPosition={col:0,row:1}}onKeyDown(r){var t;if(((t=document.activeElement)===null||t===void 0?void 0:t.tagName)==="WCS-GRID-PAGINATION"){return}let e;switch(this.selectionConfig){case"multiple":e="grid_selection_multiple";break;case"single":e="grid_selection_single";break;case"none":e="grid_no_selection";break}const i=pe(r,e);if(i.length!=0){r.preventDefault()}for(const t of i){this.doActionFromKeyboardEventAssociatedAction(t,r)}}doActionFromKeyboardEventAssociatedAction(r,t){switch(r.kind){case"FocusCell":switch(r.target){case"up":this.moveCursorPosition(0,-1);break;case"down":this.moveCursorPosition(0,1);break;case"left":this.moveCursorPosition(-1,0);break;case"right":this.moveCursorPosition(1,0);break;case"first_of_row":this.moveCursorPosition("first",0);break;case"last_of_row":this.moveCursorPosition("last",0);break;case"first_of_grid":this.moveCursorPosition("first","first");break;case"last_of_grid":this.moveCursorPosition("last","last");break}case"SelectRow":switch(r.target){case"one":t.preventDefault();if(this.cursorPosition.row>0){this.onRowSelection(this.rows[this.cursorPosition.row-1])}break;case"all":this.selectAllRows();break}break;default:throw new Error("Internal error")}}onClick(r){const t=r.composedPath().filter((r=>["TD","TH"].includes(r.nodeName)))[0];if(!t)return;const e=this.gridElementsWithCoordinates.find((r=>r.el===t));this.cursorPosition={col:e.col,row:e.row}}updateSelectionWithValues(r){if(this.selectionConfig==="single"){this.rows.map((r=>r.selected=false));for(const t of this.rows){if(T(t.data,r)){t.selected=true;break}}}else if(this.selectionConfig==="multiple"){this.rows.map((r=>r.selected=false));for(const t of this.rows){if(r.find((r=>T(r,t.data)))){t.selected=true}}}this.rows=we(this.rows)}wcsGridRowToWcsGridRowData(r){return{selected:r.selected,page:r.page,data:r.data}}updateGridRows(r){const t=[];if(r&&this.columns){for(let e=0;er.sortOrder!=="none"));if(t&&!this.serverMode){this.sortBy(t)}r&&this.disableSortOrderForColumns(e)}}disableSortOrderForColumns(r){r===null||r===void 0?void 0:r.forEach((r=>r.sortOrder="none"))}getGridColumnsFromTemplate(){const r=this.el.shadowRoot.querySelector('slot[name="grid-column"]');return r.assignedElements()}getGridPaginationsFromTemplate(){const r=this.el.shadowRoot.querySelector('slot[name="grid-pagination"]');return r.assignedElements()}get gridElementsWithCoordinates(){const r=[];if(this.selectionConfig==="multiple"){r.push({el:this.el.shadowRoot.querySelector("th"),row:0,col:0})}this.getGridColumnsFromTemplate().filter((r=>!r.hidden)).forEach(((t,e)=>{r.push({el:t.shadowRoot.querySelector("th"),row:0,col:e+(this.hasSelectionColumn()?1:0)})}));this.el.shadowRoot.querySelectorAll("td").forEach(((t,e)=>{r.push({el:t,row:1+Math.floor(e/this.totalDisplayedColumnCount()),col:e%this.totalDisplayedColumnCount()})}));return r}sortChangeEventHandler(r){if(r.detail.order==="none"||!this.columns)return;this.disableSortOrderForColumns(this.columns.filter((t=>t!==r.detail.column)));if(this.serverMode)return;this.sortBy(r.detail.column);this.updatePageIndex()}sortBy(r){if(r.sortFn){this.rows=we(this.rows).sort(((t,e)=>r.sortFn(t.data,e.data,r)*W(r.sortOrder)))}else{this.rows=we(this.rows).sort(((t,e)=>{const i=r.path;return(Pr(t.data,i)Pr(e.data,i)?1:0)*W(r.sortOrder)}))}}updatePageIndex(){if(!this.serverMode&&this.paginationEl){this.paginationEl.itemsCount=this.data.length;this.paginationEl.pageCount=Math.ceil(this.data.length/this.paginationEl.pageSize);if(this.paginationEl.pageCount<=1){this.paginationEl.currentPage=n.INDEX_FIRST_PAGE}else if(this.paginationEl.pageCount>0&&this.paginationEl.currentPage+1>this.paginationEl.pageCount){this.paginationEl.currentPage=this.paginationEl.pageCount-1}const r=we(this.rows);r.forEach(((r,t)=>r.page=Math.floor(t/this.paginationEl.pageSize)));this.rows=[...r]}}paginationChangeEventHandler(){this.onPaginationChange()}paginationChangeEventHandlerOutside(r){if(this.wcsGridPaginationId&&this.wcsGridPaginationId===r.target.id){this.onPaginationChange()}}onPaginationChange(){if(this.serverMode)return;this.updatePageIndex()}onRowSelection(r){if(this.selectionConfig==="single"){this.rows.filter((t=>t.uuid!==r.uuid)).map((r=>r.selected=false))}r.selected=!r.selected;if(this.selectionConfig!=="single"||r.selected){this.wcsGridSelectionChange.emit({selectedRows:this.selectedRows.map((r=>this.wcsGridRowToWcsGridRowData(r))),changedRow:this.wcsGridRowToWcsGridRowData(r)})}this.rows=we(this.rows)}get selectedRows(){return this.rows.filter((r=>r.selected))}selectAllRows(){const r=this.getRowsForCurrentPage();const t=!this.allRowsAreSelected();r.map((r=>r.selected=t));this.wcsGridAllSelectionChange.emit({rows:t?r.map((r=>this.wcsGridRowToWcsGridRowData(r))):[]});this.wcsGridSelectionChange.emit({selectedRows:this.selectedRows.map((r=>this.wcsGridRowToWcsGridRowData(r))),changedRow:"allCheckbox"});this.rows=we(this.rows)}allRowsAreSelected(){const r=this.getRowsForCurrentPage();return r.length>0&&r.filter((r=>r.selected)).length===r.length}getRowsForCurrentPage(){if(!this.serverMode&&this.paginationEl){return this.rows.filter((r=>r.page===this.paginationEl.currentPage))}return this.rows}renderSelectionColumn(t,e){var i,o,s,n;switch(this.selectionConfig){case"none":return;case"single":return r("td",{"aria-colindex":this.atLeastOneColumnHidden()?1:null,tabIndex:((i=this.cursorPosition)===null||i===void 0?void 0:i.col)===0&&e+1===((o=this.cursorPosition)===null||o===void 0?void 0:o.row)?0:-1},r(me,{checked:t.selected,row:t,rowIndex:e+1,totalRows:this.rows.length,onClick:r=>{if(!r.selected){this.onRowSelection(r)}}}));case"multiple":return r("td",{"aria-colindex":this.atLeastOneColumnHidden()?1:null,tabIndex:((s=this.cursorPosition)===null||s===void 0?void 0:s.col)===0&&e+1===((n=this.cursorPosition)===null||n===void 0?void 0:n.row)?0:-1},r("wcs-checkbox",{tabIndex:-1,part:"row-checkbox",checked:t.selected,onWcsChange:this.onRowSelection.bind(this,t)}))}}getCellContent(t,e){if(e.formatter){return e.formatter(r,e.column,this.wcsGridRowToWcsGridRowData(t))}return e.content}totalColumnCount(){if(!this.columns){return 0}return this.columns.length+(this.hasSelectionColumn()?1:0)}totalDisplayedColumnCount(){var r,t;return(t=this.totalColumnCount()-((r=this.columns)===null||r===void 0?void 0:r.filter((r=>r.hidden)).length))!==null&&t!==void 0?t:0}atLeastOneColumnHidden(){return this.totalDisplayedColumnCount()!==this.totalColumnCount()}render(){var t,e,i,s;return r(o,{key:"1e9b1d5dc405c67428750276de3e38e8e163d20e"},r("table",Object.assign({key:"42e610c403c108f36c2f5e4eb276b9e1c6349b8c",role:"grid",ref:r=>this.nativeTable=r,"aria-rowcount":!this.loading&&((t=this.rows)===null||t===void 0?void 0:t.length),"aria-colcount":!this.loading&&this.totalDisplayedColumnCount()},this.inheritedAttributes),r("thead",{key:"365bf4de9329c94c5c891040b14ca844c6e8fd99"},r("tr",{key:"9d1e4c4cf0418f585679a055edbb88ca08493d3d","aria-rowindex":"1"},this.selectionConfig==="none"?"":r("th",{class:"wcs-grid-selection-column"},this.selectionConfig==="single"?"":r("wcs-checkbox",{tabIndex:((e=this.cursorPosition)===null||e===void 0?void 0:e.col)===0&&((i=this.cursorPosition)===null||i===void 0?void 0:i.row)===0?0:-1,part:"all-rows-checkbox",checked:this.allRowsAreSelected(),onWcsChange:this.selectAllRows.bind(this)})),r("slot",{key:"4c1ed31eeaf61d0f94a156cc97b393abafdfb6e3",name:"grid-column"}))),r("tbody",{key:"5758c76c248e9e54759bd008310047a5c670339a"},this.loading?r("tr",{"aria-busy":"true"},r("td",{colSpan:this.totalColumnCount(),class:"loading"},r("wcs-spinner",null))):(s=this.rows)===null||s===void 0?void 0:s.filter((r=>this.serverMode||!this.paginationEl||r.page===this.paginationEl.currentPage)).map(((r,t)=>this.renderRow(r,t))))),r("slot",{key:"170e79b086e8235ae736c8cc54512b0e3bb0e7ab",name:"grid-pagination"}))}renderRow(t,e){var i,o;let s=0;return r("tr",{class:t.selected?"selected":"",part:(i=this.rowCssPartsWithoutEmptyList(t))===null||i===void 0?void 0:i.join(" "),"aria-selected":t.selected?"true":null,"aria-rowindex":e+2},this.renderSelectionColumn(t,e),(o=t.cells)===null||o===void 0?void 0:o.map(((i,o)=>{var n,a;if(i.column.hidden){s++;return}const c=o-s+1+(this.hasSelectionColumn()?1:0);const d=c-1===((n=this.cursorPosition)===null||n===void 0?void 0:n.col)&&e+1===((a=this.cursorPosition)===null||a===void 0?void 0:a.row);return i.column.customCells?r("td",{tabIndex:d?0:-1,"aria-colindex":this.atLeastOneColumnHidden()?c:null},r("slot",{name:i.column.id+"-"+Pr(t.data,this.rowIdPath)})):r("td",{tabIndex:d?0:-1,"aria-colindex":this.atLeastOneColumnHidden()?c:null,part:i.column.path+"-column"},this.getCellContent(t,i))})))}rowCssPartsWithoutEmptyList(r){const t=this.rowCssPartsFn(r);return(t===null||t===void 0?void 0:t.length)===0?null:t}get el(){return s(this)}static get watchers(){return{cursorPosition:["onCursorPositionChange"],data:["onDataChange"],selectedItems:["onSelectedItemsPropertyChange"]}}};Ae.style=ye+Ce;export{Ae as wcs_grid}; //# sourceMappingURL=p-f2f7595e.entry.js.map