'use strict';

var index = require('./index-n_pDKBY2.js');

const setFilterCss = "";

const SetFilter = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.ifxFilterSelect = index.createEvent(this, "ifxFilterSelect", 7);
        this.type = 'text';
        this.filterValues = [];
    }
    handleTextInputChange(event) {
        const target = event.target;
        const value = target.value;
        this.ifxFilterSelect.emit({ filterName: this.filterName, filterValues: [value], type: this.type }); // Emit an array for consistency with the multi select component
    }
    handleSingleSelectChange(event) {
        const value = event.detail.value;
        this.ifxFilterSelect.emit({ filterName: this.filterName, filterValues: [value], type: this.type }); // Emit an array for consistency with the multi select component
    }
    handleMultiselectOptionChange(event) {
        this.filterValues = event.detail.map(option => ({
            label: option.value,
            value: option.value
        }));
        this.ifxFilterSelect.emit({ filterName: this.filterName, filterValues: this.filterValues, type: this.type });
    }
    render() {
        let optionsArray = [];
        // Parse options if it's a string
        if (typeof this.options === 'string') {
            try {
                optionsArray = JSON.parse(this.options);
            }
            catch (e) {
                console.error('Failed to parse options:', e);
                optionsArray = [];
            }
        }
        else if (Array.isArray(this.options)) {
            optionsArray = this.options;
        }
        switch (this.type) {
            case 'text':
                return (index.h("ifx-text-field", { error: false, disabled: false, placeholder: this.placeholder, onIfxInput: event => this.handleTextInputChange(event) }, this.filterLabel));
            case 'single-select':
                return (index.h("ifx-select", { placeholder: "true", "search-enabled": "true", "search-placeholder-value": "Search...", onIfxSelect: event => this.handleSingleSelectChange(event), "ifx-placeholder-value": this.placeholder, "ifx-label": this.filterLabel, "ifx-options": this.options }));
            case 'multi-select':
                return (index.h("ifx-multiselect", { label: this.filterLabel, placeholder: this.placeholder, onIfxSelect: event => this.handleMultiselectOptionChange(event) }, optionsArray.map(option => (index.h("ifx-multiselect-option", { value: option.value || option }, option.label || option)))));
            default:
                return null;
        }
    }
};
SetFilter.style = setFilterCss;

exports.ifx_set_filter = SetFilter;
//# sourceMappingURL=ifx-set-filter.entry.cjs.js.map

//# sourceMappingURL=ifx-set-filter.cjs.entry.js.map