import * as i0 from '@angular/core';
import { input, model, booleanAttribute, output, signal, computed, effect, untracked, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i1 from '@angular/forms';
import { FormsModule } from '@angular/forms';
import { Button } from '@masterteam/components/button';
import { DateField } from '@masterteam/components/date-field';
import { SelectField } from '@masterteam/components/select-field';
import { TextField } from '@masterteam/components/text-field';
import * as i2 from 'primeng/popover';
import { PopoverModule } from 'primeng/popover';

const DEFAULT_MAX_FILTERS = 20;
function toLabel(value) {
    const normalized = value.split('.').pop() ?? value;
    return normalized
        .replace(/[_-]/g, ' ')
        .replace(/([a-z])([A-Z])/g, '$1 $2')
        .trim()
        .replace(/\b\w/g, (char) => char.toUpperCase());
}
function normalizeFieldOption(value) {
    if (typeof value === 'string') {
        return {
            key: value,
            label: toLabel(value),
        };
    }
    if (!value?.key) {
        return null;
    }
    return {
        key: value.key,
        label: value.label?.trim() || toLabel(value.key),
        viewType: value.viewType,
    };
}
function inferValueMode(operator) {
    switch (operator) {
        case 'In':
            return 'multi';
        case 'Between':
            return 'range';
        case 'IsNull':
        case 'IsNotNull':
            return 'none';
        default:
            return 'single';
    }
}
function normalizeOperatorOption(value) {
    if (typeof value === 'string') {
        return {
            key: value,
            label: toLabel(value),
            valueMode: inferValueMode(value),
        };
    }
    if (!value?.key) {
        return null;
    }
    return {
        key: value.key,
        label: value.label?.trim() || toLabel(value.key),
        valueMode: value.valueMode ?? inferValueMode(value.key),
    };
}
function toStringValue(value) {
    if (value === null || value === undefined)
        return '';
    return String(value);
}
function normalizeFieldType(viewType) {
    const normalized = viewType?.toLowerCase().trim() ?? '';
    if (normalized === 'number' ||
        normalized === 'decimal' ||
        normalized === 'integer' ||
        normalized === 'percentage' ||
        normalized === 'progress') {
        return 'number';
    }
    if (normalized === 'datetime' || normalized === 'datetimeoffset') {
        return 'datetime';
    }
    if (normalized === 'date') {
        return 'date';
    }
    if (normalized === 'boolean' || normalized === 'bool') {
        return 'boolean';
    }
    return 'text';
}
function toInputType(viewType) {
    const normalized = normalizeFieldType(viewType);
    if (normalized === 'number')
        return 'number';
    if (normalized === 'date')
        return 'date';
    if (normalized === 'datetime')
        return 'datetime-local';
    return 'text';
}
function parseBoolean(value) {
    const normalized = value.toLowerCase();
    if (normalized === 'true' || normalized === '1' || normalized === 'yes') {
        return true;
    }
    if (normalized === 'false' || normalized === '0' || normalized === 'no') {
        return false;
    }
    return value;
}
function parseValueByViewType(rawValue, viewType) {
    if (rawValue === null || rawValue === undefined)
        return '';
    if (rawValue instanceof Date) {
        return rawValue.toISOString();
    }
    const value = String(rawValue).trim();
    if (!value.length)
        return '';
    switch (normalizeFieldType(viewType)) {
        case 'number': {
            const parsed = Number(value);
            return Number.isFinite(parsed) ? parsed : value;
        }
        case 'boolean':
            return parseBoolean(value);
        default:
            return value;
    }
}
function hasInputValue(rawValue) {
    if (rawValue === null || rawValue === undefined)
        return false;
    if (rawValue instanceof Date)
        return true;
    return String(rawValue).trim().length > 0;
}
class PropertyFilterBuilder {
    schema = input(null, ...(ngDevMode ? [{ debugName: "schema" }] : []));
    filters = model([], ...(ngDevMode ? [{ debugName: "filters" }] : []));
    title = input('Advanced Filters', ...(ngDevMode ? [{ debugName: "title" }] : []));
    buttonLabel = input('Filter', ...(ngDevMode ? [{ debugName: "buttonLabel" }] : []));
    disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : {}), transform: booleanAttribute });
    applied = output();
    cleared = output();
    rowSeed = signal(0, ...(ngDevMode ? [{ debugName: "rowSeed" }] : []));
    syncedSignature = signal('', ...(ngDevMode ? [{ debugName: "syncedSignature" }] : []));
    drafts = signal([], ...(ngDevMode ? [{ debugName: "drafts" }] : []));
    fieldOptions = computed(() => (this.schema()?.allowedFields ?? [])
        .map(normalizeFieldOption)
        .filter((entry) => entry !== null), ...(ngDevMode ? [{ debugName: "fieldOptions" }] : []));
    operatorOptions = computed(() => (this.schema()?.allowedOperators ?? []).map(normalizeOperatorOption).filter((entry) => entry !== null), ...(ngDevMode ? [{ debugName: "operatorOptions" }] : []));
    hasSchema = computed(() => this.fieldOptions().length > 0 && this.operatorOptions().length > 0, ...(ngDevMode ? [{ debugName: "hasSchema" }] : []));
    maxFilters = computed(() => Math.max(1, this.schema()?.maxFilters ?? DEFAULT_MAX_FILTERS), ...(ngDevMode ? [{ debugName: "maxFilters" }] : []));
    canAddFilter = computed(() => {
        return this.hasSchema() && this.drafts().length < this.maxFilters();
    }, ...(ngDevMode ? [{ debugName: "canAddFilter" }] : []));
    activeFilterCount = computed(() => this.filters().length, ...(ngDevMode ? [{ debugName: "activeFilterCount" }] : []));
    constructor() {
        effect(() => {
            const fields = this.fieldOptions();
            const operators = this.operatorOptions();
            const appliedFilters = this.filters();
            const signature = JSON.stringify({
                fieldKeys: fields.map((field) => field.key),
                operatorKeys: operators.map((operator) => operator.key),
                filters: appliedFilters,
            });
            const hasDrafts = untracked(() => this.drafts().length > 0);
            const lastSyncedSignature = untracked(() => this.syncedSignature());
            if (!fields.length || !operators.length) {
                this.drafts.set([]);
                this.syncedSignature.set(signature);
                return;
            }
            if (hasDrafts && lastSyncedSignature === signature) {
                return;
            }
            if (!appliedFilters.length) {
                this.drafts.set([this.createDraft(fields[0].key, operators[0].key)]);
                this.syncedSignature.set(signature);
                return;
            }
            const nextDrafts = appliedFilters.map((rule) => {
                const operatorKey = operators.some((option) => option.key === rule.op)
                    ? rule.op
                    : operators[0].key;
                const fieldKey = fields.some((option) => option.key === rule.field)
                    ? rule.field
                    : fields[0].key;
                const mode = this.getValueMode(operatorKey);
                return this.createDraft(fieldKey, operatorKey, mode === 'range' ? '' : this.toDraftValue(rule), mode === 'range' ? toStringValue(rule.from) : '', mode === 'range' ? toStringValue(rule.to) : '');
            });
            this.drafts.set(nextDrafts.length
                ? nextDrafts
                : [this.createDraft(fields[0].key, operators[0].key)]);
            this.syncedSignature.set(signature);
        });
    }
    onPopoverToggle(event, popover) {
        if (!this.hasSchema() || this.disabled()) {
            return;
        }
        popover.toggle(event);
    }
    addFilter() {
        const fields = this.fieldOptions();
        const operators = this.operatorOptions();
        if (!fields.length || !operators.length)
            return;
        this.drafts.update((current) => {
            if (current.length >= this.maxFilters()) {
                return current;
            }
            return [...current, this.createDraft(fields[0].key, operators[0].key)];
        });
    }
    removeFilter(index) {
        this.drafts.update((current) => {
            if (current.length <= 1) {
                return current;
            }
            return current.filter((_, rowIndex) => rowIndex !== index);
        });
    }
    clearAll(popover) {
        const fields = this.fieldOptions();
        const operators = this.operatorOptions();
        if (fields.length && operators.length) {
            this.drafts.set([this.createDraft(fields[0].key, operators[0].key)]);
        }
        else {
            this.drafts.set([]);
        }
        this.filters.set([]);
        this.cleared.emit();
        popover.hide();
    }
    apply(popover) {
        const rules = this.buildRulesFromDrafts();
        this.filters.set(rules);
        this.applied.emit(rules);
        popover.hide();
    }
    onFieldChange(index, field) {
        this.patchDraft(index, { field: field || '' });
    }
    onOperatorChange(index, op) {
        const mode = this.getValueMode(op);
        this.patchDraft(index, {
            op: op || '',
            value: mode === 'range' ? '' : (this.drafts()[index]?.value ?? ''),
            from: mode === 'range' ? (this.drafts()[index]?.from ?? '') : '',
            to: mode === 'range' ? (this.drafts()[index]?.to ?? '') : '',
        });
    }
    onValueChange(index, value) {
        this.patchDraft(index, { value: value ?? '' });
    }
    onFromChange(index, from) {
        this.patchDraft(index, { from: from ?? '' });
    }
    onToChange(index, to) {
        this.patchDraft(index, { to: to ?? '' });
    }
    getValueMode(op) {
        return (this.operatorOptions().find((option) => option.key === op)?.valueMode ??
            inferValueMode(op));
    }
    getValueInputType(field, op) {
        if (this.getValueMode(op) === 'multi') {
            return 'text';
        }
        return toInputType(this.getFieldViewType(field));
    }
    isDateField(field) {
        const normalized = normalizeFieldType(this.getFieldViewType(field));
        return normalized === 'date' || normalized === 'datetime';
    }
    isDateTimeField(field) {
        return normalizeFieldType(this.getFieldViewType(field)) === 'datetime';
    }
    buildRulesFromDrafts() {
        return this.drafts()
            .map((draft) => {
            if (!draft.field || !draft.op) {
                return null;
            }
            const mode = this.getValueMode(draft.op);
            const viewType = this.getFieldViewType(draft.field);
            const rule = {
                field: draft.field,
                op: draft.op,
            };
            if (mode === 'none') {
                return rule;
            }
            if (mode === 'range') {
                if (!hasInputValue(draft.from) && !hasInputValue(draft.to)) {
                    return null;
                }
                if (hasInputValue(draft.from)) {
                    rule.from = parseValueByViewType(draft.from, viewType);
                }
                if (hasInputValue(draft.to)) {
                    rule.to = parseValueByViewType(draft.to, viewType);
                }
                return rule;
            }
            if (!hasInputValue(draft.value)) {
                return null;
            }
            if (mode === 'multi') {
                const values = String(draft.value)
                    .split(',')
                    .map((value) => value.trim())
                    .filter((value) => value.length > 0)
                    .map((value) => parseValueByViewType(value, viewType));
                if (!values.length) {
                    return null;
                }
                rule.values = values;
                return rule;
            }
            rule.value = parseValueByViewType(draft.value, viewType);
            return rule;
        })
            .filter((rule) => rule !== null)
            .slice(0, this.maxFilters());
    }
    getFieldViewType(fieldKey) {
        return this.fieldOptions().find((option) => option.key === fieldKey)
            ?.viewType;
    }
    patchDraft(index, patch) {
        this.drafts.update((current) => current.map((row, rowIndex) => rowIndex === index
            ? {
                ...row,
                ...patch,
            }
            : row));
    }
    createDraft(field, op, value = '', from = '', to = '') {
        this.rowSeed.update((seed) => seed + 1);
        return {
            id: `pfb-${this.rowSeed()}`,
            field,
            op,
            value,
            from,
            to,
        };
    }
    toDraftValue(rule) {
        if (Array.isArray(rule.values)) {
            return rule.values.map((entry) => toStringValue(entry)).join(', ');
        }
        return toStringValue(rule.value);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: PropertyFilterBuilder, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: PropertyFilterBuilder, isStandalone: true, selector: "mt-property-filter-builder", inputs: { schema: { classPropertyName: "schema", publicName: "schema", isSignal: true, isRequired: false, transformFunction: null }, filters: { classPropertyName: "filters", publicName: "filters", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, buttonLabel: { classPropertyName: "buttonLabel", publicName: "buttonLabel", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { filters: "filtersChange", applied: "applied", cleared: "cleared" }, host: { classAttribute: "block" }, ngImport: i0, template: "<mt-button\r\n  [label]=\"buttonLabel()\"\r\n  severity=\"secondary\"\r\n  icon=\"general.filter-funnel-01\"\r\n  [badge]=\"activeFilterCount() > 0 ? activeFilterCount().toString() : undefined\"\r\n  [disabled]=\"disabled() || !hasSchema()\"\r\n  (onClick)=\"onPopoverToggle($event, popover)\"\r\n/>\r\n\r\n<p-popover #popover [style]=\"{ width: 'min(980px, 92vw)' }\" appendTo=\"body\">\r\n  <div class=\"flex flex-col gap-4\">\r\n    <div\r\n      class=\"flex items-center justify-between border-b border-surface-200 pb-3 px-3\"\r\n    >\r\n      <div class=\"flex flex-col\">\r\n        <h3 class=\"m-0 text-lg font-semibold\">{{ title() }}</h3>\r\n      </div>\r\n\r\n      <mt-button\r\n        variant=\"text\"\r\n        severity=\"secondary\"\r\n        label=\"Clear all\"\r\n        (onClick)=\"clearAll(popover)\"\r\n      />\r\n    </div>\r\n\r\n    <div class=\"flex flex-col gap-3 px-3\">\r\n      @for (draft of drafts(); track draft.id; let index = $index) {\r\n        <div\r\n          class=\"grid grid-cols-[80px_minmax(0,1fr)_auto] items-center gap-2 max-lg:grid-cols-1 max-lg:items-start\"\r\n        >\r\n          <div class=\"text-sm text-color\" [class.invisible]=\"index > 0\">\r\n            Where\r\n          </div>\r\n\r\n          <div\r\n            class=\"grid grid-cols-[minmax(170px,1fr)_minmax(170px,1fr)_minmax(220px,2fr)] gap-3 max-lg:grid-cols-1\"\r\n          >\r\n            <mt-select-field\r\n              [hasPlaceholderPrefix]=\"false\"\r\n              placeholder=\"Property\"\r\n              optionLabel=\"label\"\r\n              optionValue=\"key\"\r\n              [options]=\"fieldOptions()\"\r\n              [showClear]=\"false\"\r\n              [ngModel]=\"draft.field\"\r\n              (ngModelChange)=\"onFieldChange(index, $event)\"\r\n            />\r\n\r\n            <mt-select-field\r\n              [hasPlaceholderPrefix]=\"false\"\r\n              placeholder=\"Condition\"\r\n              optionLabel=\"label\"\r\n              optionValue=\"key\"\r\n              [options]=\"operatorOptions()\"\r\n              [showClear]=\"false\"\r\n              [ngModel]=\"draft.op\"\r\n              (ngModelChange)=\"onOperatorChange(index, $event)\"\r\n            />\r\n\r\n            @switch (getValueMode(draft.op)) {\r\n              @case (\"none\") {\r\n                <div\r\n                  class=\"flex min-h-10 items-center rounded-lg border border-dashed border-surface-300 px-3 text-sm text-color-secondary\"\r\n                >\r\n                  No value required\r\n                </div>\r\n              }\r\n              @case (\"range\") {\r\n                <div class=\"grid grid-cols-2 gap-2 max-lg:grid-cols-1\">\r\n                  @if (isDateField(draft.field)) {\r\n                    <mt-date-field\r\n                      [placeholder]=\"'From'\"\r\n                      [showTime]=\"isDateTimeField(draft.field)\"\r\n                      [showIcon]=\"false\"\r\n                      [ngModel]=\"draft.from\"\r\n                      (ngModelChange)=\"onFromChange(index, $event)\"\r\n                    />\r\n                    <mt-date-field\r\n                      [placeholder]=\"'To'\"\r\n                      [showTime]=\"isDateTimeField(draft.field)\"\r\n                      [showIcon]=\"false\"\r\n                      [ngModel]=\"draft.to\"\r\n                      (ngModelChange)=\"onToChange(index, $event)\"\r\n                    />\r\n                  } @else {\r\n                    <mt-text-field\r\n                      [type]=\"getValueInputType(draft.field, draft.op)\"\r\n                      [placeholder]=\"'From'\"\r\n                      [ngModel]=\"draft.from\"\r\n                      (ngModelChange)=\"onFromChange(index, $event)\"\r\n                    />\r\n                    <mt-text-field\r\n                      [type]=\"getValueInputType(draft.field, draft.op)\"\r\n                      [placeholder]=\"'To'\"\r\n                      [ngModel]=\"draft.to\"\r\n                      (ngModelChange)=\"onToChange(index, $event)\"\r\n                    />\r\n                  }\r\n                </div>\r\n              }\r\n              @default {\r\n                @if (\r\n                  getValueMode(draft.op) !== \"multi\" && isDateField(draft.field)\r\n                ) {\r\n                  <mt-date-field\r\n                    [placeholder]=\"'Value'\"\r\n                    [showTime]=\"isDateTimeField(draft.field)\"\r\n                    [showIcon]=\"false\"\r\n                    [ngModel]=\"draft.value\"\r\n                    (ngModelChange)=\"onValueChange(index, $event)\"\r\n                  />\r\n                } @else {\r\n                  <mt-text-field\r\n                    [type]=\"getValueInputType(draft.field, draft.op)\"\r\n                    [placeholder]=\"\r\n                      getValueMode(draft.op) === 'multi'\r\n                        ? 'Value (comma separated)'\r\n                        : 'Value'\r\n                    \"\r\n                    [ngModel]=\"draft.value\"\r\n                    (ngModelChange)=\"onValueChange(index, $event)\"\r\n                  />\r\n                }\r\n              }\r\n            }\r\n          </div>\r\n\r\n          <mt-button\r\n            icon=\"general.x-close\"\r\n            severity=\"secondary\"\r\n            variant=\"text\"\r\n            [disabled]=\"drafts().length <= 1\"\r\n            (onClick)=\"removeFilter(index)\"\r\n          />\r\n        </div>\r\n      }\r\n    </div>\r\n\r\n    <div\r\n      class=\"flex items-center justify-between p-2 max-lg:flex-col max-lg:items-stretch max-lg:gap-3\"\r\n    >\r\n      <mt-button\r\n        label=\"Add Filter\"\r\n        icon=\"general.plus\"\r\n        variant=\"outlined\"\r\n        [disabled]=\"!canAddFilter()\"\r\n        (onClick)=\"addFilter()\"\r\n      />\r\n\r\n      <div class=\"flex gap-2 max-lg:w-full\">\r\n        <mt-button\r\n          severity=\"secondary\"\r\n          variant=\"outlined\"\r\n          label=\"Cancel\"\r\n          (onClick)=\"popover.hide()\"\r\n        />\r\n        <mt-button label=\"Apply\" (onClick)=\"apply(popover)\" />\r\n      </div>\r\n    </div>\r\n  </div>\r\n</p-popover>\r\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "component", type: DateField, selector: "mt-date-field", inputs: ["field", "label", "placeholder", "class", "readonly", "showIcon", "showClear", "showTime", "pInputs", "required"] }, { kind: "ngmodule", type: PopoverModule }, { kind: "component", type: i2.Popover, selector: "p-popover", inputs: ["ariaLabel", "ariaLabelledBy", "dismissable", "style", "styleClass", "appendTo", "autoZIndex", "ariaCloseLabel", "baseZIndex", "focusOnShow", "showTransitionOptions", "hideTransitionOptions", "motionOptions"], outputs: ["onShow", "onHide"] }, { kind: "component", type: SelectField, selector: "mt-select-field", inputs: ["field", "label", "placeholder", "hasPlaceholderPrefix", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "clearAfterSelect", "required", "group", "size", "optionGroupLabel", "optionGroupChildren", "loading", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape"], outputs: ["onChange"] }, { kind: "component", type: TextField, selector: "mt-text-field", inputs: ["field", "hint", "label", "placeholder", "class", "type", "readonly", "pInputs", "required", "icon", "iconPosition"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: PropertyFilterBuilder, decorators: [{
            type: Component,
            args: [{ selector: 'mt-property-filter-builder', standalone: true, imports: [
                        FormsModule,
                        Button,
                        DateField,
                        PopoverModule,
                        SelectField,
                        TextField,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'block',
                    }, template: "<mt-button\r\n  [label]=\"buttonLabel()\"\r\n  severity=\"secondary\"\r\n  icon=\"general.filter-funnel-01\"\r\n  [badge]=\"activeFilterCount() > 0 ? activeFilterCount().toString() : undefined\"\r\n  [disabled]=\"disabled() || !hasSchema()\"\r\n  (onClick)=\"onPopoverToggle($event, popover)\"\r\n/>\r\n\r\n<p-popover #popover [style]=\"{ width: 'min(980px, 92vw)' }\" appendTo=\"body\">\r\n  <div class=\"flex flex-col gap-4\">\r\n    <div\r\n      class=\"flex items-center justify-between border-b border-surface-200 pb-3 px-3\"\r\n    >\r\n      <div class=\"flex flex-col\">\r\n        <h3 class=\"m-0 text-lg font-semibold\">{{ title() }}</h3>\r\n      </div>\r\n\r\n      <mt-button\r\n        variant=\"text\"\r\n        severity=\"secondary\"\r\n        label=\"Clear all\"\r\n        (onClick)=\"clearAll(popover)\"\r\n      />\r\n    </div>\r\n\r\n    <div class=\"flex flex-col gap-3 px-3\">\r\n      @for (draft of drafts(); track draft.id; let index = $index) {\r\n        <div\r\n          class=\"grid grid-cols-[80px_minmax(0,1fr)_auto] items-center gap-2 max-lg:grid-cols-1 max-lg:items-start\"\r\n        >\r\n          <div class=\"text-sm text-color\" [class.invisible]=\"index > 0\">\r\n            Where\r\n          </div>\r\n\r\n          <div\r\n            class=\"grid grid-cols-[minmax(170px,1fr)_minmax(170px,1fr)_minmax(220px,2fr)] gap-3 max-lg:grid-cols-1\"\r\n          >\r\n            <mt-select-field\r\n              [hasPlaceholderPrefix]=\"false\"\r\n              placeholder=\"Property\"\r\n              optionLabel=\"label\"\r\n              optionValue=\"key\"\r\n              [options]=\"fieldOptions()\"\r\n              [showClear]=\"false\"\r\n              [ngModel]=\"draft.field\"\r\n              (ngModelChange)=\"onFieldChange(index, $event)\"\r\n            />\r\n\r\n            <mt-select-field\r\n              [hasPlaceholderPrefix]=\"false\"\r\n              placeholder=\"Condition\"\r\n              optionLabel=\"label\"\r\n              optionValue=\"key\"\r\n              [options]=\"operatorOptions()\"\r\n              [showClear]=\"false\"\r\n              [ngModel]=\"draft.op\"\r\n              (ngModelChange)=\"onOperatorChange(index, $event)\"\r\n            />\r\n\r\n            @switch (getValueMode(draft.op)) {\r\n              @case (\"none\") {\r\n                <div\r\n                  class=\"flex min-h-10 items-center rounded-lg border border-dashed border-surface-300 px-3 text-sm text-color-secondary\"\r\n                >\r\n                  No value required\r\n                </div>\r\n              }\r\n              @case (\"range\") {\r\n                <div class=\"grid grid-cols-2 gap-2 max-lg:grid-cols-1\">\r\n                  @if (isDateField(draft.field)) {\r\n                    <mt-date-field\r\n                      [placeholder]=\"'From'\"\r\n                      [showTime]=\"isDateTimeField(draft.field)\"\r\n                      [showIcon]=\"false\"\r\n                      [ngModel]=\"draft.from\"\r\n                      (ngModelChange)=\"onFromChange(index, $event)\"\r\n                    />\r\n                    <mt-date-field\r\n                      [placeholder]=\"'To'\"\r\n                      [showTime]=\"isDateTimeField(draft.field)\"\r\n                      [showIcon]=\"false\"\r\n                      [ngModel]=\"draft.to\"\r\n                      (ngModelChange)=\"onToChange(index, $event)\"\r\n                    />\r\n                  } @else {\r\n                    <mt-text-field\r\n                      [type]=\"getValueInputType(draft.field, draft.op)\"\r\n                      [placeholder]=\"'From'\"\r\n                      [ngModel]=\"draft.from\"\r\n                      (ngModelChange)=\"onFromChange(index, $event)\"\r\n                    />\r\n                    <mt-text-field\r\n                      [type]=\"getValueInputType(draft.field, draft.op)\"\r\n                      [placeholder]=\"'To'\"\r\n                      [ngModel]=\"draft.to\"\r\n                      (ngModelChange)=\"onToChange(index, $event)\"\r\n                    />\r\n                  }\r\n                </div>\r\n              }\r\n              @default {\r\n                @if (\r\n                  getValueMode(draft.op) !== \"multi\" && isDateField(draft.field)\r\n                ) {\r\n                  <mt-date-field\r\n                    [placeholder]=\"'Value'\"\r\n                    [showTime]=\"isDateTimeField(draft.field)\"\r\n                    [showIcon]=\"false\"\r\n                    [ngModel]=\"draft.value\"\r\n                    (ngModelChange)=\"onValueChange(index, $event)\"\r\n                  />\r\n                } @else {\r\n                  <mt-text-field\r\n                    [type]=\"getValueInputType(draft.field, draft.op)\"\r\n                    [placeholder]=\"\r\n                      getValueMode(draft.op) === 'multi'\r\n                        ? 'Value (comma separated)'\r\n                        : 'Value'\r\n                    \"\r\n                    [ngModel]=\"draft.value\"\r\n                    (ngModelChange)=\"onValueChange(index, $event)\"\r\n                  />\r\n                }\r\n              }\r\n            }\r\n          </div>\r\n\r\n          <mt-button\r\n            icon=\"general.x-close\"\r\n            severity=\"secondary\"\r\n            variant=\"text\"\r\n            [disabled]=\"drafts().length <= 1\"\r\n            (onClick)=\"removeFilter(index)\"\r\n          />\r\n        </div>\r\n      }\r\n    </div>\r\n\r\n    <div\r\n      class=\"flex items-center justify-between p-2 max-lg:flex-col max-lg:items-stretch max-lg:gap-3\"\r\n    >\r\n      <mt-button\r\n        label=\"Add Filter\"\r\n        icon=\"general.plus\"\r\n        variant=\"outlined\"\r\n        [disabled]=\"!canAddFilter()\"\r\n        (onClick)=\"addFilter()\"\r\n      />\r\n\r\n      <div class=\"flex gap-2 max-lg:w-full\">\r\n        <mt-button\r\n          severity=\"secondary\"\r\n          variant=\"outlined\"\r\n          label=\"Cancel\"\r\n          (onClick)=\"popover.hide()\"\r\n        />\r\n        <mt-button label=\"Apply\" (onClick)=\"apply(popover)\" />\r\n      </div>\r\n    </div>\r\n  </div>\r\n</p-popover>\r\n" }]
        }], ctorParameters: () => [], propDecorators: { schema: [{ type: i0.Input, args: [{ isSignal: true, alias: "schema", required: false }] }], filters: [{ type: i0.Input, args: [{ isSignal: true, alias: "filters", required: false }] }, { type: i0.Output, args: ["filtersChange"] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], buttonLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "buttonLabel", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], applied: [{ type: i0.Output, args: ["applied"] }], cleared: [{ type: i0.Output, args: ["cleared"] }] } });

/**
 * Generated bundle index. Do not edit.
 */

export { PropertyFilterBuilder };
//# sourceMappingURL=masterteam-components-property-filter-builder.mjs.map
