import{r as d,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 f,g as v}from"./index-DscFWUNz.js";import{t as i}from"./i18n-CdSCDnmA-Bln0Fy0B.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const C=class{constructor(t){d(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],g=s[o],h=s.map(l=>l.key===r.key?Object.assign(Object.assign({},l),{position:g.position}):l.key===g.key?Object.assign(Object.assign({},l),{position:r.position}):l);this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.sortColumnsByPosition(h)})}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(f,{key:"ba6964d7d0015211d50a68536b36be024ee0f418",ref:e=>this.popoverRef=e,class:"kol-table-settings",_icons:"codicon codicon-settings-gear",_label:this.translateTableSettings,_popoverAlign:"top",_hideLabel:!0},a("div",{key:"ee4075b1511fa1bec77a7068ff91e7e6a6f26c67",class:"kol-table-settings__content"},a(_,{key:"63f1aba0d47cfd03725a3d458f0b98d9b739022e",_label:this.translateTableSettings,_level:0}),this.errorMessage&&a(p,{key:"6824b98b2b9b62260330053fe79ca0ee30bc15d7",_type:"error",_label:this.errorMessage,_variant:"msg",class:"kol-table-settings__error-message"}),a("form",{key:"2bf2773cacaee3f90007ea3b8b1971732b67b4b5",onSubmit:this.handleSubmit.bind(this)},a("div",{key:"3970a3988ebb05498fda0b485282f134b2fbc513",class:"kol-table-settings__columns-container"},a("div",{key:"3e7e9f1726a3eb9a605563d8cb23966f500c4ec5",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:"f762fa692848ff9161a9a7f8db4e1d4c36d059c8",class:"kol-table-settings__actions"},a(b,{key:"42401475bdf959ddee26b8489d775bb481ce5727",_label:this.translateTableSettingsCancel,_buttonVariant:"secondary",_on:{onClick:()=>this.handleCancel()},"data-testid":"table-settings-cancel"}),a(b,{key:"c24e37a9d6a589d6a395156adfb574f70116c075",_label:this.translateTableSettingsApply,_buttonVariant:"primary",_type:"submit","data-testid":"table-settings-apply"})))))}get host(){return v(this)}static get watchers(){return{_tableSettings:["handleTableSettingsChange"]}}};export{C as kol_table_settings_wc};
//# sourceMappingURL=kol-table-settings-wc.entry-Bf35xSww.js.map
