import DropdownCellComponent from"./dropdown.svelte";import Fields from"./fields.svelte";import utils from"../../utils";class DropdownPlugin{constructor(e){this.hooks=e,this.namespace="tablesome",this.init()}init(){this.hooks.addFilter("getColumnFormats",this.namespace,this.getColumnFormats),this.hooks.addFilter("getCellComponent",this.namespace,this.getCellComponent),this.hooks.addFilter("getColumnOptionFields",this.namespace,this.getColumnOptionFields),this.hooks.addFilter("getSearchRecords",this.namespace,this.getSearchRecords),this.hooks.addFilter("getSortRecords",this.namespace,this.getSortRecords),this.hooks.addFilter("getFilterRecords",this.namespace,this.getFilterRecords)}getColumnFormats(e){return e.push({format:"dropdown",class:"tablesome__option--basic tablesome__option--basic-dropdown",icon:"list",text:"Dropdown"}),e}getColumnOptionFields(e){return"dropdown"==e.format&&e.fields.push(Fields),e}getCellComponent(e){return"dropdown"==e.cellType&&(e.component=DropdownCellComponent),e}getSearchRecords(e){if("dropdown"==e.cellType){let o=e.cell.value||"";e.isContentMatch=o.toLowerCase().indexOf(e.searchQuery)>=0}return e}getSortRecords(e){return"dropdown"==e.cellType&&(e.valueA="value"in e.rowA&&e.rowA.value?e.rowA.value:"",e.valueB="value"in e.rowB&&e.rowB.value?e.rowB.value:"",e.sortType="text"),e}getFilterRecords(e){if("dropdown"==e.filter.format){let o=e.filter.value,t="value"in e.cell&&e.cell.value?e.cell.value:"";e.filter.contextual||(e.isContentMatch=!0),e.isContentMatch=filterDropdown(e.filter.operator.value,t,o)}return e}}export default DropdownPlugin;const filterDropdown=(e,o,t)=>"="==e?o===t:"!="==e?o!==t:"contains"==e?o.toLowerCase().includes(t.toLowerCase()):"not_contains"!=e||!o.toLowerCase().includes(t.toLowerCase());