const t=window.webmapgl.h;import{a as e}from"./chunk-cf921ba9.js";let r=0;class s{constructor(){this.columns=[],this.disableDefaultSort=!1,this.features=[],this.sortOrder="asc"}componentWillLoad(){void 0===this.id&&(this.id="table-"+r.toString(),r+=1)}componentDidLoad(){this.updateColumns()}updateColumns(){this.columns=Array.from(this.el.querySelectorAll("gl-table-column"))}setSort(t){t.attribute===this.sortAttribute?this.sortOrder="asc"===this.sortOrder?"desc":"asc":(this.sortAttribute=t.attribute,this.sortOrder="asc"),this.glTableSort.emit({tableId:this.id,attribute:this.sortAttribute,order:this.sortOrder})}async getSortedFeatures(){return this.sortedFeatures()}sortedFeatures(){if(this.disableDefaultSort)return this.features;let t=[...this.features];return t.sort((t,e)=>{let r=t.properties[this.sortAttribute],s=e.properties[this.sortAttribute];"string"==typeof r&&(r=r.toUpperCase()),"string"==typeof s&&(s=s.toUpperCase());let o=0;return r>s?o=1:r<s&&(o=-1),"desc"===this.sortOrder?-1*o:o}),t}renderHeader(r){let s={};return r.sortable&&(s={class:"sortable sorted-none",tabindex:0,"aria-controls":this.id,"aria-label":`${r.label}: `+e("webmapgl.table.header.sort-action.desc"),onClick:()=>this.setSort(r)},r.attribute===this.sortAttribute&&(s.class=`sortable sorted-${this.sortOrder}`,s["aria-sort"]="asc"===this.sortOrder?"ascending":"descending",s["aria-label"]=`${r.label}: `+e(`webmapgl.table.header.sort-action.${this.sortOrder}`))),t("th",Object.assign({},s),r.label)}async getCellContents(t,e,r){let s=t.properties[e.attribute];return e.component?await this.renderComponentAsText(t,e,s,r):this.renderValue(e,s)}renderValue(t,e){return null==e?null:(t.format&&(e=e.toLocaleString({},t.format)),e.toString())}renderComponentJSX(e,r,s){return t(r.component,Object.assign({feature:e,column:r,value:s},r.componentProps||{}))}async renderComponentAsText(t,e,r,s){let o=document.createElement(e.component),a=e.componentProps||{};for(let t in a)o[t]=a[t];o.feature=t,o.column=e,o.value=r,o.style.display="none",this.el.appendChild(o),await o.componentOnReady();let l="function"==typeof o.formatValue?o.formatValue(s):o.textContent;return this.el.removeChild(o),l}renderCell(e,r){let s=e.properties[r.attribute];return t("td",null,r.component?this.renderComponentJSX(e,r,s):this.renderValue(r,s))}renderRow(e,r){return t("tr",{class:this.rowClassAttribute?e.properties[this.rowClassAttribute]:"row"},r.map(t=>this.renderCell(e,t)))}render(){if(0===this.columns.length)return null;let e=this.sortedFeatures(),r=this.columns.filter(t=>t.visible),s=r.map(t=>this.renderHeader(t)),o=e.map(t=>this.renderRow(t,r));return t("table",{id:this.id},t("thead",null,t("tr",null,s)),t("tbody",null,o))}static get is(){return"gl-table"}static get properties(){return{columns:{state:!0},disableDefaultSort:{type:Boolean,attr:"disable-default-sort"},el:{elementRef:!0},features:{type:"Any",attr:"features"},getCellContents:{method:!0},getSortedFeatures:{method:!0},id:{type:String,attr:"id",reflectToAttr:!0,mutable:!0},rowClassAttribute:{type:String,attr:"row-class-attribute"},sortAttribute:{type:String,attr:"sort-attribute",mutable:!0},sortOrder:{type:String,attr:"sort-order",mutable:!0}}}static get events(){return[{name:"glTableSort",method:"glTableSort",bubbles:!0,cancelable:!0,composed:!0}]}static get listeners(){return[{name:"glTableColumnChanged",method:"updateColumns"}]}static get style(){return"gl-table table{border-collapse:collapse;border-spacing:0;margin:0 0 10px 0;width:100%}gl-table thead{background-color:#eee}gl-table td,gl-table th{border:1px solid #ddd;line-height:1.3;padding:8px 10px}gl-table td:first-child,gl-table th:first-child{border-left:0 none transparent}gl-table td:last-child,gl-table th:last-child{border-right:0 none transparent}gl-table thead th{font-weight:700}gl-table thead th.sortable{cursor:pointer;padding-right:27px;position:relative}gl-table thead th.sortable:after,gl-table thead th.sortable:before{color:#ccc;content:\"\\25B2\";font-size:.7em;margin-top:-1.1em;position:absolute;right:10px;top:50%}gl-table thead th.sortable:after{bottom:50%;content:\"\\25BC\";margin-bottom:-1.1em;margin-top:0;top:auto}gl-table thead th.sorted-asc:before{color:var(--ion-color-primary,#3880ff)}gl-table thead th.sorted-asc:after,gl-table thead th.sorted-desc:before{content:\"\"}gl-table thead th.sorted-desc:after{color:var(--ion-color-primary,#3880ff)}"}}export{s as GlTable};