/* eslint-disable @typescript-eslint/naming-convention */
// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Watch } from '../Decorators/WatchDecorator';
import { Attribute } from '../Decorators/AttributeDecorator';
import { Property } from '../Decorators/PropertyDecorator';
/**
 * @public
 */
export const Filterable = (base) => {
    class FilterableElement extends base {
        // #region Fields
        _showFilter;
        _filterMemberPath;
        _filter;
        _filterPlaceholder;
        // #endregion
        // #region Ctor
        /**
         * Constructs a new instance of the `FilterableElement` class.
         *
         * @public
         */
        constructor(...args) {
            super(args);
            this._showFilter = false;
            this._filterMemberPath = '';
            this._filter = '';
            this._filterPlaceholder = '';
        }
        // #endregion
        // #region Properties
        /**
         * Gets or sets the `showFilter` property.
         *
         * @public
         * @attr
         */
        get showFilter() {
            return this._showFilter;
        }
        set showFilter(value) {
            if (this._showFilter !== value) {
                this._showFilter = value;
                this.requestUpdate('showFilter');
            }
        }
        /**
         * Gets or sets the `filterMemberPath` property.
         *
         * @public
         */
        get filterMemberPath() {
            return this._filterMemberPath;
        }
        set filterMemberPath(value) {
            if (this._filterMemberPath !== value) {
                this._filterMemberPath = value;
                this.requestUpdate('filterMemberPath');
            }
        }
        /**
         * Gets or sets the `filter` property.
         *
         * @public
         */
        get filter() {
            return this._filter;
        }
        set filter(value) {
            if (this._filter !== value) {
                this._filter = value;
                this.requestUpdate('filter');
            }
        }
        /**
         * Gets or sets the `filterPlaceholder` property.
         *
         * @public
         */
        get filterPlaceholder() {
            return this._filterPlaceholder;
        }
        set filterPlaceholder(value) {
            if (this._filterPlaceholder !== value) {
                this._filterPlaceholder = value;
                this.requestUpdate('filterPlaceholder');
            }
        }
    }
    __decorate([
        Attribute({ type: Boolean }),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [Boolean])
    ], FilterableElement.prototype, "showFilter", null);
    __decorate([
        Property({ type: String }),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], FilterableElement.prototype, "filterMemberPath", null);
    __decorate([
        Property({ type: String }),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], FilterableElement.prototype, "filter", null);
    __decorate([
        Property({ type: String }),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], FilterableElement.prototype, "filterPlaceholder", null);
    return FilterableElement;
};
/**
 * The `FilterableChild` mix-in enables automatic hiding based on a parent filter.
 *
 * @public
 */
export const FilterableChild = (base) => {
    class FilterableChildElement extends base {
        // #region Fields
        _isFiltered = false;
        // #endregion
        // #region Properties
        /**
         * Gets or sets the `filtered` property.
         * If true, the element is hidden via `display: none`.
         *
         * @public
         */
        get isFiltered() {
            return this._isFiltered;
        }
        set isFiltered(value) {
            if (this._isFiltered !== value) {
                this._isFiltered = value;
                this.requestUpdate('isFiltered');
            }
        }
        // #endregion
        // #region Methods
        /**
         * @protected
         */
        onIsFilteredPropertyChanged(_, next) {
            if (next) {
                this.setAttribute('is-filtered', '');
            }
            else {
                this.removeAttribute('is-filtered');
            }
        }
    }
    __decorate([
        Attribute({ type: Boolean }),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [Boolean])
    ], FilterableChildElement.prototype, "isFiltered", null);
    __decorate([
        Watch('isFiltered'),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [String, String]),
        __metadata("design:returntype", void 0)
    ], FilterableChildElement.prototype, "onIsFilteredPropertyChanged", null);
    return FilterableChildElement;
};
/**
 * Returns a value by member path.
 *
 * @public
 */
export function getMemberValue(self, memberKey) {
    // @ts-ignore fix suppressImplicitAnyIndexErrors
    return memberKey.split('.').reduce((a, b) => a[b], self);
}
/**
 * Determines whether the specified string contains the specified value.
 *
 * @public
 */
export function contains(self, match, ignoreCase) {
    if (ignoreCase) {
        return self.toUpperCase().includes(match.toUpperCase());
    }
    return self.includes(match);
}
//# sourceMappingURL=Filterable.js.map