import{r as h,d as c,a as u,h as a,am as _,b as p,an as m,ao as k,e as b,I as v,g as f}from"./index-BvWOSbaR.js";import{t as i}from"./i18n-CdSCDnmA-CsM0aySV.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const C=class{constructor(t){h(this,t),this.tableSettings={columns:[]},this.errorMessage=null,this.translateTableSettings=i("kol-table-settings"),this.translateTableSettingsCancel=i("kol-table-settings-cancel"),this.translateTableSettingsApply=i("kol-table-settings-apply"),this.translateErrorAllInvisible=i("kol-table-settings-error-all-invisible"),this.translateColumnNotHidable=i("kol-table-settings-column-not-hidable"),this._tableSettings={columns:[]}}handleTableSettingsChange(t){this.tableSettings=Object.assign(Object.assign({},t),{columns:this.sortColumnsByPosition(t.columns)})}componentWillLoad(){this.handleTableSettingsChange(this._tableSettings)}sortColumnsByPosition(t){return[...t].sort((e,s)=>e.position-s.position)}moveColumn(t,e){const s=[...this.tableSettings.columns],n=s.findIndex(l=>l.key===t),o=e==="up"?n-1:n+1,r=s[n],d=s[o],g=s.map(l=>l.key===r.key?Object.assign(Object.assign({},l),{position:d.position}):l.key===d.key?Object.assign(Object.assign({},l),{position:r.position}):l);this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.sortColumnsByPosition(g)})}handleVisibilityChange(t,e){this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.tableSettings.columns.map(s=>s.key===t&&s.hidable!==!1?Object.assign(Object.assign({},s),{visible:!!e}):s)})}handleWidthChange(t,e){this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.tableSettings.columns.map(s=>s.key===t?Object.assign(Object.assign({},s),{width:Number(e)}):s)})}handleCancel(){var t;(t=this.popoverRef)===null||t===void 0||t.hidePopover()}handleSubmit(t){var e;if(t.preventDefault(),this.tableSettings.columns.some(n=>n.visible))this.host&&(this.errorMessage=null,c(this.host,u.settingsChange,this.tableSettings),(e=this.popoverRef)===null||e===void 0||e.hidePopover());else{this.errorMessage=this.translateErrorAllInvisible;return}}render(){const t=[...this.tableSettings.columns].sort((e,s)=>e.position-s.position);return a(v,{key:"a320abde186d6157caeaa9cf108e53b7ed3a8549",ref:e=>this.popoverRef=e,class:"kol-table-settings",_icons:"codicon codicon-settings-gear",_label:this.translateTableSettings,_popoverAlign:"top",_hideLabel:!0},a("div",{key:"63e19443ab0fc20a7ac7511416c1224f8129b7a8",class:"kol-table-settings__content"},a(_,{key:"0af8b7aee2718c354173bbbf32aaaaffcad6b433",_label:this.translateTableSettings,_level:0}),this.errorMessage&&a(p,{key:"175223ca9cd38918fd7f96941d9c4747b00e66e3",_type:"error",_label:this.errorMessage,_variant:"msg",class:"kol-table-settings__error-message"}),a("form",{key:"d1008b0f61d2b52e865bbe3ade56ba7515fc9eb0",onSubmit:this.handleSubmit.bind(this)},a("div",{key:"97e2bda0e35103d6fc542630799b4a4adf19bc96",class:"kol-table-settings__columns-container"},a("div",{key:"4ce5682b2d41b505606330ba3a8be4509872cafd",class:"kol-table-settings__columns"},t.map((e,s)=>a("div",{key:e.key,class:"kol-table-settings__column"},a(m,{_checked:e.visible,_label:`${e.label}${e.hidable===!1?` (${this.translateColumnNotHidable})`:""}`,_value:!0,_hideLabel:!0,_disabled:e.hidable===!1,_on:{onInput:(n,o)=>this.handleVisibilityChange(e.key,o)}}),a("span",null,e.label),a(k,{_hideLabel:!0,_value:e.width,_label:i("kol-table-settings-column-width",{placeholders:{column:e.label}}),_min:1,_on:{onInput:(n,o)=>this.handleWidthChange(e.key,o)}}),a(b,{_icons:"codicon codicon-arrow-up",_label:i("kol-table-settings-move-up",{placeholders:{column:e.label}}),_hideLabel:!0,_buttonVariant:"ghost",_on:{onClick:()=>this.moveColumn(e.key,"up")},_disabled:s===0,"data-testid":"table-settings-move-up"}),a(b,{_icons:"codicon codicon-arrow-down",_label:i("kol-table-settings-move-down",{placeholders:{column:e.label}}),_hideLabel:!0,_buttonVariant:"ghost",_on:{onClick:()=>this.moveColumn(e.key,"down")},_disabled:s===t.length-1,"data-testid":"table-settings-move-down"}))))),a("div",{key:"4fdab69de35f27f4e3f52d86430e20148fd4dd98",class:"kol-table-settings__actions"},a(b,{key:"0b8f5a4d0d0b4e0668c61aaeb105e50d09a84d50",_label:this.translateTableSettingsCancel,_buttonVariant:"secondary",_on:{onClick:()=>this.handleCancel()},"data-testid":"table-settings-cancel"}),a(b,{key:"7ea9108aa5eede0c6dcedf80ed46e636358dfa2b",_label:this.translateTableSettingsApply,_buttonVariant:"primary",_type:"submit","data-testid":"table-settings-apply"})))))}get host(){return f(this)}static get watchers(){return{_tableSettings:["handleTableSettingsChange"]}}};export{C as kol_table_settings_wc};
//# sourceMappingURL=kol-table-settings-wc.entry-cgevfcWL.js.map
