import{r as g,d as h,a as u,h as a,ao as _,b as p,ap as m,aq as k,e as b,J as v,g as y}from"./index-yJ8X--q8.js";import{t as i}from"./i18n-H9CUbi---DysS2qV6.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const C=class{constructor(e){g(this,e),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._tableSettings={columns:[]}}handleTableSettingsChange(e){this.tableSettings=Object.assign(Object.assign({},e),{columns:this.sortColumnsByPosition(e.columns)})}componentWillLoad(){this.handleTableSettingsChange(this._tableSettings)}sortColumnsByPosition(e){return[...e].sort((t,s)=>t.position-s.position)}moveColumn(e,t){const s=[...this.tableSettings.columns],n=s.findIndex(l=>l.key===e),o=t==="up"?n-1:n+1,r=s[n],c=s[o],d=s.map(l=>l.key===r.key?Object.assign(Object.assign({},l),{position:c.position}):l.key===c.key?Object.assign(Object.assign({},l),{position:r.position}):l);this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.sortColumnsByPosition(d)})}handleVisibilityChange(e,t){this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.tableSettings.columns.map(s=>s.key===e?Object.assign(Object.assign({},s),{visible:!!t}):s)})}handleWidthChange(e,t){this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.tableSettings.columns.map(s=>s.key===e?Object.assign(Object.assign({},s),{width:Number(t)}):s)})}handleCancel(){var e;(e=this.popoverRef)===null||e===void 0||e.hidePopover()}handleSubmit(e){var t;if(e.preventDefault(),this.tableSettings.columns.some(n=>n.visible))this.host&&(this.errorMessage=null,h(this.host,u.settingsChange,this.tableSettings),(t=this.popoverRef)===null||t===void 0||t.hidePopover());else{this.errorMessage=this.translateErrorAllInvisible;return}}render(){const e=[...this.tableSettings.columns].sort((t,s)=>t.position-s.position);return a(v,{key:"b930aa153c7461f4a57b937c0156cf84e60edd2d",ref:t=>this.popoverRef=t,class:"kol-table-settings",_icons:"codicon codicon-settings-gear",_label:this.translateTableSettings,_popoverAlign:"top",_hideLabel:!0},a("div",{key:"cdd88e4955f8433fe19101a8ac9905332b917975",class:"kol-table-settings__content"},a(_,{key:"fd70365f0f8ef1c4455d0c093c82a35474372f21",_label:this.translateTableSettings,_level:0}),this.errorMessage&&a(p,{key:"08bac933be1eb8e724882ee7b53370e408a1de26",_type:"error",_label:this.errorMessage,_variant:"msg",class:"kol-table-settings__error-message"}),a("form",{key:"946f7a022247721eb75479661a4b0d1ddab8b52c",onSubmit:this.handleSubmit.bind(this)},a("div",{key:"413b8b20e47111b90b93b938d7623b6987c755c5",class:"kol-table-settings__columns-container"},a("div",{key:"68bf65989d9f1d790cac1d18431c3c32a4f828de",class:"kol-table-settings__columns"},e.map((t,s)=>a("div",{key:t.key,class:"kol-table-settings__column"},a(m,{_checked:t.visible,_label:i("kol-table-settings-show-column",{placeholders:{column:t.label}}),_value:!0,_hideLabel:!0,_on:{onInput:(n,o)=>this.handleVisibilityChange(t.key,o)}}),a("span",null,t.label),a(k,{_hideLabel:!0,_value:t.width,_label:i("kol-table-settings-column-width",{placeholders:{column:t.label}}),_min:1,_on:{onInput:(n,o)=>this.handleWidthChange(t.key,o)}}),a(b,{_icons:"codicon codicon-arrow-up",_label:i("kol-table-settings-move-up",{placeholders:{column:t.label}}),_hideLabel:!0,_buttonVariant:"ghost",_on:{onClick:()=>this.moveColumn(t.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:t.label}}),_hideLabel:!0,_buttonVariant:"ghost",_on:{onClick:()=>this.moveColumn(t.key,"down")},_disabled:s===e.length-1,"data-testid":"table-settings-move-down"}))))),a("div",{key:"2859d138a7052eaebb3b13a56609e362d8dd8304",class:"kol-table-settings__actions"},a(b,{key:"d83024f7231425239b24665b3845735ecbd60604",_label:this.translateTableSettingsCancel,_buttonVariant:"secondary",_on:{onClick:()=>this.handleCancel()},"data-testid":"table-settings-cancel"}),a(b,{key:"783f2d4cc52b8d14060f4dbd125d8d5ad5f38fdc",_label:this.translateTableSettingsApply,_buttonVariant:"primary",_type:"submit","data-testid":"table-settings-apply"})))))}get host(){return y(this)}static get watchers(){return{_tableSettings:["handleTableSettingsChange"]}}};export{C as kol_table_settings_wc};
//# sourceMappingURL=kol-table-settings-wc.entry-BuGtlqPs.js.map
