'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-17105557.js');
const index$1 = require('./index-62760a9c.js');
const utils = require('@sankhyalabs/ezui/dist/collection/utils');
const core = require('@sankhyalabs/core');
const index$3 = require('./index-8d94b7e0.js');
const FieldBuilder = require('@sankhyalabs/ezui/dist/collection/components/ez-form-view/fieldbuilder/FieldBuilder');
const index$2 = require('./index-22a8223a.js');
const DataType = require('@sankhyalabs/core/dist/dataunit/metadata/DataType');

const snkExpressionGroupCss = ".sc-snk-expression-group-h{display:block;--snk-expression-group--container-condition--width:184px;--snk-expression-group--container-condition--height:38px;--snk-expression-group--container-condition--border-radius:var(--border--radius-medium, 12px);--snk-expression-group--container-option--width:85px;--snk-expression-group__container-condition--background-and:#66B6A0;--snk-expression-group__container-condition--background-or:#EBC65E;--snk-expression-group__container-expression--padding-left:26px;--snk-expression-group__background-color-dashed:var(--background--body, #fafcff);--ez-text-input__margin-bottom:0px}.snk-expression-group__container-condition.sc-snk-expression-group{width:var(--snk-expression-group--container-condition--width);height:var(--snk-expression-group--container-condition--height);border-radius:var(--snk-expression-group--container-condition--border-radius);z-index:var(--more-visible--2x, 3);padding:var(--space--nano, 2px)}.snk-expression-group__container-option.sc-snk-expression-group{width:var(--snk-expression-group--container-option--width)}.snk-expression-group__container-condition[data-condition=\"AND\"].sc-snk-expression-group{background-color:var(--snk-expression-group__container-condition--background-and)}.snk-expression-group__container-condition[data-condition=\"OR\"].sc-snk-expression-group{background-color:var(--snk-expression-group__container-condition--background-or)}.snk-expression-group__container-expression.sc-snk-expression-group{padding-left:var(--snk-expression-group__container-expression--padding-left)}.dashes.sc-snk-expression-group{z-index:var(--visible, 1);background:var(--snk-expression-group__background-color-dashed);border-left:2px dashed var(--text-secondary, #A2ABB9);position:absolute;width:15px;height:58px;margin-left:-15px;margin-top:-36.5px}.horizontal-dashes.sc-snk-expression-group{z-index:var(--more-visible, 2);border-bottom:2px dashed var(--text-secondary, #A2ABB9);position:absolute;width:15px;height:54px;margin-left:-15px;margin-top:-33.5px}.hidden.sc-snk-expression-group{display:none}";

const SnkExpressionGroup = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ezFilterGroupChange = index.createEvent(this, "ezFilterGroupChange", 7);
    this.ezFilterGroupRemove = index.createEvent(this, "ezFilterGroupRemove", 7);
    this.ezExpressionGroupLayoutChanged = index.createEvent(this, "ezExpressionLayoutChanged", 7);
    this.FIRST_LEVEL = "0";
    this.LIMIT_GROUP_LEVEL = 4;
    this.application = core.ApplicationContext.getContextValue("__SNK__APPLICATION__");
    this._conditionOperator = index$1.FilterGroupCondition.AND;
    this._group = undefined;
    this._selfTop = 0;
    this.canAddExpression = true;
    this._showDashes = true;
    this.parentTop = 0;
    this.group = undefined;
    this.messagesBuilder = undefined;
    this.filterId = undefined;
    this.entityURI = undefined;
    this.isDefaultFilter = false;
  }
  /**
   * Listener para capturar adição e remoção de grupos e items de expressão.
   */
  todoCompletedHandler(_) {
    this.updateDashes();
  }
  /*
   * Retorna o grupo da expressão.
   */
  async getExpressionGroup() {
    return this._group;
  }
  watchGroup(newValue) {
    this._group = newValue;
    this._conditionOperator = this.getOperand();
  }
  componentWillLoad() {
    this._group = this.group;
    this._conditionOperator = this.getOperand();
    if (!this.getDataGroupLevel()) {
      this._element.setAttribute('data-group-level', this.FIRST_LEVEL);
    }
    this.canAddExpression = this.group.items.every(this.isFilledItem);
  }
  componentDidRender() {
    this.setSelfTop();
  }
  changeHandler() {
    this.ezExpressionGroupLayoutChanged.emit();
  }
  /**
   * Função que define o valor atualizado da propriedade top do elemento em tela para calcular o tamanho do tracejado.
   */
  setSelfTop() {
    this._selfTop = this._element.getBoundingClientRect().top;
  }
  /**
   * Função que calcula o tamanho que deve ter o tracejado.
   */
  getDashedHeight() {
    return this._selfTop - this.parentTop;
  }
  getOperand() {
    return !this._group.operand ? index$1.FilterGroupCondition.AND : this._group.operand;
  }
  getMessage(key, params) {
    return this.application.messagesBuilder.getMessage(key, params);
  }
  updateDashes() {
    this._showDashes = false;
    this.setSelfTop();
    this._showDashes = true;
  }
  renderExpressionItems() {
    var _a;
    return (_a = this._group.items) === null || _a === void 0 ? void 0 : _a.map((item) => (index.h("snk-expression-item", { key: item.id, class: "ez-padding-top--small snk-expression-group__item", expression: item, canRemove: this._group.items.length > 1, onEzFilterItemChange: () => this.handleFilterItemChange(), onEzFilterItemRemove: (evt) => this.handleFilterItemRemove(evt, item.id), messagesBuilder: this.messagesBuilder, entityURI: this.entityURI, isDefaultFilter: this.isDefaultFilter })));
  }
  renderGroups() {
    var _a;
    const currentLevel = parseInt(this.getDataGroupLevel() || '0');
    const newLevel = currentLevel + 1;
    return (_a = this._group.childrenGroups) === null || _a === void 0 ? void 0 : _a.map((group) => (index.h("snk-expression-group", { key: group.id, group: group, messagesBuilder: this.messagesBuilder, parentTop: this._selfTop, "data-group-level": newLevel, onEzFilterGroupRemove: (evt) => this.handleFilterGroupRemove(evt, group.id), entityURI: this.entityURI })));
  }
  handleFilterGroupRemove(evt, groupId) {
    this.onStopPropagation(evt);
    this._group.childrenGroups = this._group.childrenGroups.filter(group => group.id !== groupId);
    index.forceUpdate(this);
    this.ezFilterGroupChange.emit(this._group);
    this.changeHandler();
  }
  handleFilterItemRemove(evt, itemId) {
    this.onStopPropagation(evt);
    this._group.items = this._group.items.filter(item => item.id !== itemId);
    index.forceUpdate(this);
    this.ezFilterGroupChange.emit(this._group);
    this.changeHandler();
    this.canAddExpression = true;
  }
  isFilledItem(item) {
    if (!item.fieldName || !item.operand)
      return false;
    if (item.operand === 'NULL' || item.operand === 'NOT_NULL') {
      return true;
    }
    else {
      return item.paramVariable || (item.userInterface === 'SWITCH') ? true : !!item.value;
    }
  }
  handleFilterItemChange() {
    this.ezFilterGroupChange.emit(this._group);
    this.canAddExpression = this.group.items.every(this.isFilledItem);
  }
  handleAddExpression() {
    const newItem = {
      id: core.StringUtils.generateUUID(),
      entityName: "",
      fieldName: "",
      description: "",
      label: this.getMessage("snkPersonalizedFilter.info.labelDefaultValue"),
      type: undefined,
      expression: undefined,
      operand: undefined,
      paramVariable: false,
      value: undefined,
      systemConfig: null,
      userConfig: null
    };
    this._group.items.push(newItem);
    index.forceUpdate(this);
    this.ezFilterGroupChange.emit(this.group);
    this.changeHandler();
    this.canAddExpression = false;
  }
  handleAddGroup() {
    var _a;
    const newGroup = {
      id: core.StringUtils.generateUUID(),
      items: [
        {
          id: core.StringUtils.generateUUID(),
          entityName: "",
          fieldName: "",
          description: "",
          label: this.getMessage("snkPersonalizedFilter.info.labelDefaultValue"),
          type: undefined,
          expression: undefined,
          operand: undefined,
          paramVariable: false,
          value: undefined,
          systemConfig: null,
          userConfig: null
        }
      ],
      childrenGroups: [],
      operand: index$1.FilterGroupCondition.AND
    };
    this._group.childrenGroups = (_a = this._group.childrenGroups) !== null && _a !== void 0 ? _a : [];
    this._group.childrenGroups.push(newGroup);
    index.forceUpdate(this);
    if (!this.group.operand) {
      this.group.operand = index$1.FilterGroupCondition.AND;
    }
    this.ezFilterGroupChange.emit(this.group);
    this.changeHandler();
  }
  buildGroupStyle() {
    return {
      height: `${this.getDashedHeight()}px`,
      marginTop: `${-(this.getDashedHeight()) + 20}px`,
    };
  }
  handleConditionOperatorChange(newOperator) {
    this._conditionOperator = newOperator;
    this._group.operand = index$1.FilterGroupCondition[newOperator];
    this.ezFilterGroupChange.emit(this._group);
  }
  confirmRemoveGroup(evt) {
    this.onStopPropagation(evt);
    utils.ApplicationUtils.confirm(this.getMessage("snkPersonalizedFilter.confirmGroup.title"), this.getMessage("snkPersonalizedFilter.confirmGroup.description"))
      .then((canRemove) => {
      if (canRemove) {
        this.ezFilterGroupRemove.emit(this._group);
      }
    });
  }
  getTooltipMessageForOperator() {
    const groupLevel = this.getDataGroupLevel();
    if (groupLevel === this.FIRST_LEVEL && this._group.items.length === 1) {
      return this.getMessage("snkPersonalizedFilter.operador.firstLevel");
    }
    if (this._conditionOperator === index$1.FilterGroupCondition.AND) {
      return this.getMessage("snkPersonalizedFilter.operador.and");
    }
    else if (this._conditionOperator === index$1.FilterGroupCondition.OR) {
      return this.getMessage("snkPersonalizedFilter.operador.or");
    }
  }
  getDataGroupLevel() {
    return this._element.getAttribute('data-group-level');
  }
  canAddGroup() {
    const dataGroupLevel = Number(this.getDataGroupLevel() || this.FIRST_LEVEL);
    return dataGroupLevel < this.LIMIT_GROUP_LEVEL;
  }
  isFirstLevel() {
    return Boolean(this.getDataGroupLevel() === this.FIRST_LEVEL);
  }
  onStopPropagation(evt) {
    evt.preventDefault();
    evt.stopPropagation();
  }
  getMessageAddTooltip() {
    if (this.isFirstLevel()) {
      const allValidItems = this.group.items.every(item => {
        if (!item.fieldName || !item.operand)
          return false;
        return item.paramVariable || !!item.value;
      });
      return allValidItems ? this.getMessage("snkPersonalizedFilter.info.labelAddNewExpression") : this.getMessage("snkPersonalizedFilter.info.labelDisabledAddExpressionButton");
    }
    else {
      return this.canAddExpression ? this.getMessage("snkPersonalizedFilter.info.labelAddNewExpression") : this.getMessage("snkPersonalizedFilter.info.labelDisabledAddExpressionButton");
    }
  }
  canChangeGroupCondition() {
    const membersCount = this._group.items.length + this._group.childrenGroups.length;
    return membersCount > 1;
  }
  render() {
    const canAddGroup = this.canAddGroup();
    return (index.h(index.Host, null, index.h("div", { class: !this.isFirstLevel() && this._showDashes ? 'dashes' : 'hidden', style: this.buildGroupStyle() }), index.h("div", { class: !this.isFirstLevel() && this._showDashes ? 'horizontal-dashes' : 'hidden' }), index.h("div", { class: 'ez-flex ez-flex--align-items-center' }, index.h("div", { class: 'snk-expression-group__container-condition ez-flex ez-flex-item--align-center ez-flex--align-items-center', "data-condition": this._conditionOperator, title: this.getTooltipMessageForOperator() }, index.h("label", { class: "ez-label ez-padding-right--medium ez-padding-left--medium ez-title--primary" }, this.getMessage("snkPersonalizedFilter.info.condition")), index.h("div", null, index.h("ez-combo-box", Object.assign({ class: "snk-expression-group__container-option", canShowError: false, mode: "slim", suppressEmptyOption: true, enabled: this.canChangeGroupCondition(), value: this._conditionOperator, onEzChange: (evt) => this.handleConditionOperatorChange(evt.detail.value) }, { [core.ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: `comboBoxConditions_level_${this.getDataGroupLevel()}` }), index.h("option", { value: index$1.FilterGroupCondition.AND }, this.getMessage("snkPersonalizedFilter.info.conditionAnd")), index.h("option", { value: index$1.FilterGroupCondition.OR }, this.getMessage("snkPersonalizedFilter.info.conditionOr"))))), index.h("ez-button", { class: "ez-padding-right--medium ez-padding-left--medium", mode: "icon", iconName: "plus", size: "small", enabled: this.canAddExpression, title: this.getMessageAddTooltip(), onClick: () => this.handleAddExpression() }), index.h("ez-button", { label: this.getMessage("snkPersonalizedFilter.info.addGroup"), size: "small", enabled: canAddGroup, title: !canAddGroup ? this.getMessage('snkPersonalizedFilter.info.labelDisabledAddGroupButton', { LIMIT_GROUP_LEVEL: this.LIMIT_GROUP_LEVEL + 1 }) : '', onClick: () => this.handleAddGroup() }, index.h("ez-icon", { class: "ez-padding-right--small", slot: "leftIcon", iconName: "plus" })), !this.isFirstLevel() && index.h("ez-button", { title: this.getMessage("snkPersonalizedFilter.info.labelDeleteExpression"), class: "ez-padding-left--medium", mode: "icon", iconName: "delete", size: "small", onClick: (evt) => this.confirmRemoveGroup(evt) })), index.h("div", { class: "ez-padding-top--small snk-expression-group__container-expression" }, index.h("div", { class: "ez-padding-top--small" }, this.renderExpressionItems())), index.h("div", { class: "ez-padding-top--small snk-expression-group__container-expression" }, index.h("div", { class: "ez-padding-top--small" }, this.renderGroups()))));
  }
  get _element() { return index.getElement(this); }
  static get watchers() { return {
    "group": ["watchGroup"]
  }; }
};
SnkExpressionGroup.style = snkExpressionGroupCss;

const defaultsOperand = [
  { label: "snkPersonalizedFilter.operands.equal", value: "EQUAL" },
  { label: "snkPersonalizedFilter.operands.different", value: "DIFFERENT" },
  { label: "snkPersonalizedFilter.operands.like", value: "LIKE" },
  { label: "snkPersonalizedFilter.operands.in", value: "IN" },
  { label: "snkPersonalizedFilter.operands.startWith", value: "START_WITH" },
  { label: "snkPersonalizedFilter.operands.finishedWith", value: "FINISHED_WITH" },
  { label: "snkPersonalizedFilter.operands.null", value: "NULL" },
  { label: "snkPersonalizedFilter.operands.notNull", value: "NOT_NULL" },
];
const FilterOperandDefault = defaultsOperand.concat([
  { label: "snkPersonalizedFilter.operands.larger", value: "LARGER" },
  { label: "snkPersonalizedFilter.operands.largerEqual", value: "LARGER_EQUAL" },
  { label: "snkPersonalizedFilter.operands.smaller", value: "SMALLER" },
  { label: "snkPersonalizedFilter.operands.smallerEqual", value: "SMALLER_EQUAL" }
]);
const FilterOperandTypeTextSearch = defaultsOperand;
const FIELD_TYPE_SEARCH_AND_TEXT = [
  core.UserInterface.SEARCH,
  core.UserInterface.SHORTTEXT,
  core.UserInterface.PASSWORD,
  core.UserInterface.MASKEDTEXT,
  core.UserInterface.LONGTEXT,
  core.UserInterface.HTML
];

const snkExpressionItemCss = ".sc-snk-expression-item-h{display:flex;width:100%;--snk-expression-item--background-color:var(--background--xlight, #fff);--snk-expression-item__itens--padding:var(--space--small, 6px);--snk-expression-item__width--input-operator:220px;--snk-expression-item__width--input-value:240px;--snk-expression-item__width--input-value-variable:176px;--snk-expression-item--border-radius:var(--border--radius-medium, 12px);--snk-expression-item--border-color:var(--color--strokes, #DCE0E8);--snk-expression-item--border-style:var(--border--small, 1px solid);--snk-expression-item__background-color-dashed:var(--background--body, #fafcff)}.box.sc-snk-expression-item{width:100%;height:56px;background:var(--snk-expression-item--background-color);border:var(--snk-expression-item--border-color) var(--snk-expression-item--border-style);border-radius:var(--snk-expression-item--border-radius)}.box__container.sc-snk-expression-item{display:flex;align-items:center;justify-content:space-between;white-space:nowrap;margin:var(--space--small, 6px)}.box__container--input-filter.sc-snk-expression-item{width:100%}.box__container--input-operator.sc-snk-expression-item{display:flex;width:var(--snk-expression-item__width--input-operator);min-width:var(--snk-expression-item__width--input-operator)}.box__container--input-value.sc-snk-expression-item{display:flex;width:var(--snk-expression-item__width--input-value);min-width:var(--snk-expression-item__width--input-value)}.box__container--input-value-variable.sc-snk-expression-item{display:flex;width:var(--snk-expression-item__width--input-value-variable);min-width:var(--snk-expression-item__width--input-value-variable)}.box__container--button-delete.sc-snk-expression-item{display:flex}.box__container.sc-snk-expression-item>div.sc-snk-expression-item{padding-left:var(--snk-expression-item__itens--padding);padding-right:var(--snk-expression-item__itens--padding)}.box__container--button-delete--icon.sc-snk-expression-item{width:42px;min-width:42px}.box__container--input-value-variable--icon.sc-snk-expression-item{cursor:pointer}.dashes.sc-snk-expression-item{z-index:var(--more-visible, 2);background:var(--snk-expression-item__background-color-dashed);border-bottom:2px dashed var(--text-secondary, #A2ABB9);border-left:2px dashed var(--text-secondary, #A2ABB9);position:absolute;width:15px;height:62px;margin-left:-15px;margin-top:-33.5px}";

const SnkExpressionItem = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ezFilterItemChange = index.createEvent(this, "ezFilterItemChange", 7);
    this.ezFilterItemRemove = index.createEvent(this, "ezFilterItemRemove", 7);
    this.application = core.ApplicationContext.getContextValue("__SNK__APPLICATION__");
    this.filterOperandDefault = FilterOperandDefault;
    this.filterOperandTypeTextSearch = FilterOperandTypeTextSearch;
    this.DEFAULT_FIELD_NAME = 'NOT_DEFINED';
    this._showValueVariable = false;
    this._fieldSelected = undefined;
    this._optionNotNull = false;
    this.expression = undefined;
    this.canRemove = true;
    this.messagesBuilder = undefined;
    this.isDefaultFilter = false;
    this.entityURI = undefined;
  }
  expressionChanged(newValue, oldValue) {
    if (newValue !== oldValue) {
      this.ezFilterItemChange.emit(newValue);
      this.updateFieldSelected();
    }
  }
  componentWillLoad() {
    this._dataSourceFetcher = index$2.store.get(`filterFieldsDataSource.${this.entityURI}`);
    index$2.store.onChange(`filterFieldsDataSource.${this.entityURI}`, () => {
      this._dataSourceFetcher = index$2.store.get(`filterFieldsDataSource.${this.entityURI}`);
    });
    if (this.expression) {
      this.updateFieldSelected();
      this._optionNotNull = this.expression.operand === 'NULL' || this.expression.operand === 'NOT_NULL';
    }
  }
  componentDidRender() {
    var _a;
    this._showValueVariable = (_a = this._elValueVariable) === null || _a === void 0 ? void 0 : _a.value;
  }
  updateFieldSelected() {
    const field = {
      dataType: this.expression.type,
      description: this.expression.description,
      name: this.expression.fieldName,
      label: this.expression.fieldLabel,
      entityName: this.expression.entityName,
      onlyDate: false,
      path: this.expression.description,
      properties: this.expressionPropsToFieldProps(this.expression.props),
      type: index$3.SelectedItemType.FIELD,
      uri: "",
      userInterface: this.expression.userInterface
    };
    this._fieldSelected = field;
  }
  buildExpression(entityName, fieldName, entityPath) {
    if (entityPath.length > 0) {
      entityPath.shift();
    }
    return entityPath.length > 0 ? `${entityPath.join("->")}->${fieldName}` : `${entityName}.${fieldName}`;
  }
  setValueExpression(key, value) {
    if (key === "fieldName") {
      this.expression.description = value.path;
      this.expression.expression = this.buildExpression(value.entityName, value.name, value.entityPath);
      this.expression.fieldName = value.name;
      this.expression.fieldLabel = value.label;
      this.expression.type = value.dataType;
      this.expression.userInterface = value.userInterface;
      this.expression.entityName = value.entityName;
      this.expression.value = undefined;
      this.expression.props = this.fieldPropsToExpressionProps(value.properties);
    }
    else {
      this.expression[key] = value;
    }
    this.expressionChanged(this.expression);
  }
  fieldPropsToExpressionProps(properties) {
    const parsedProps = [];
    if (!properties) {
      return parsedProps;
    }
    for (const key in properties) {
      let propValue = properties[key];
      if (typeof propValue == "object") {
        propValue = JSON.stringify(propValue);
      }
      parsedProps.push({ name: key, value: propValue });
    }
    return parsedProps;
  }
  expressionPropsToFieldProps(properties) {
    const parsedProps = {};
    if (!properties) {
      return parsedProps;
    }
    properties.forEach(prop => {
      try {
        parsedProps[prop.name] = JSON.parse(prop.value);
      }
      catch (_a) {
        parsedProps[prop.name] = prop.value;
      }
    });
    return parsedProps;
  }
  getMessage(key, params) {
    return this.application.messagesBuilder.getMessage(key, params);
  }
  handleSelectItem(filterField) {
    if (this.hasNoChanges(filterField)) {
      this._elFilterInput.value = filterField.path;
      return;
    }
    if (filterField.type === index$3.SelectedItemType.FIELD) {
      const field = filterField;
      this._fieldSelected = field;
      this.setValueExpression("fieldName", field);
    }
  }
  hasNoChanges(filterField) {
    return filterField.name === this.expression.fieldName && filterField.path === this.expression.description;
  }
  handleFocus() {
    if (this._elFilterFieldSearch)
      this._elFilterFieldSearch.show();
  }
  handleChangeFilterInput(evt) {
    this._elFilterFieldSearch.applyFilter(evt.detail);
  }
  handleChangeValueVariable(showValueVariable) {
    this._showValueVariable = showValueVariable;
    if (this._elFieldDynamic) {
      this._elFieldDynamic.value = undefined;
      this._elFieldDynamic.enabled = !showValueVariable;
    }
    this.expression["paramVariable"] = showValueVariable;
    this.expressionChanged(this.expression);
  }
  openSnkFilterParamConfig() {
    var _a;
    (_a = this._elFilterParamConfigRef) === null || _a === void 0 ? void 0 : _a.open(this.expression).then(this.onOpenPromiseReady.bind(this)).catch(error => {
      console.error(error);
    });
  }
  onOpenPromiseReady(changes) {
    this.expression = changes;
  }
  buildOptionsOperator() {
    var _a;
    if (FIELD_TYPE_SEARCH_AND_TEXT.includes((_a = this._fieldSelected) === null || _a === void 0 ? void 0 : _a.userInterface)) {
      return this.translateOperandOptions(this.filterOperandTypeTextSearch);
    }
    else {
      return this.translateOperandOptions(this.filterOperandDefault);
    }
  }
  translateOperandOptions(options) {
    return options.map(option => ({ label: this.getMessage(option.label), value: option.value }));
  }
  handleChangeOperator(optionSelected) {
    this.checkOptionIsNull(optionSelected);
    this.setValueExpression("operand", optionSelected);
  }
  checkOptionIsNull(optionSelected) {
    const filterOperandValue = index$1.FilterOperand[optionSelected];
    if ([index$1.FilterOperand.NULL, index$1.FilterOperand.NOT_NULL].includes(filterOperandValue)) {
      this._optionNotNull = true;
      if (this._elFieldDynamic) {
        this._elFieldDynamic.enabled = false;
        this._elFieldDynamic.value = undefined;
      }
    }
    else {
      this._optionNotNull = false;
      if (this._elFieldDynamic) {
        this._elFieldDynamic.enabled = this._showValueVariable ? false : true;
      }
    }
  }
  confirmRemove(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    utils.ApplicationUtils.confirm(this.getMessage("snkPersonalizedFilter.confirmExpression.title"), this.getMessage("snkPersonalizedFilter.confirmExpression.description"))
      .then((canRemove) => {
      if (canRemove) {
        this.ezFilterItemRemove.emit(this.expression);
      }
    });
  }
  buildFieldByType() {
    var _a, _b, _c;
    if (!this._fieldSelected)
      return;
    const inputFieldData = (_a = FieldBuilder.fieldBuilder(this.configureFieldByType())) === null || _a === void 0 ? void 0 : _a.$children$.shift();
    if (this._optionNotNull && inputFieldData || ((_b = this._elValueVariable) === null || _b === void 0 ? void 0 : _b.value) && inputFieldData || this.expression.paramVariable || this._showValueVariable || !((_c = this._fieldSelected) === null || _c === void 0 ? void 0 : _c.dataType)) {
      inputFieldData.$attrs$.enabled = false;
    }
    if (this.expression.value != undefined) {
      inputFieldData.$attrs$.value = this.getExpressiontValue(this.expression);
    }
    inputFieldData.$attrs$.onEzChange = (event) => {
      this.setValueExpression("value", event.target.value);
    };
    if (this.expression.userInterface === 'SWITCH' && this.expression.value == undefined) {
      this.setValueExpression("value", false);
    }
    return index.h(inputFieldData.$tag$, Object.assign(Object.assign({}, inputFieldData.$attrs$), { ref: (el) => {
        this._elFieldDynamic = el;
      }, label: this.expression.fieldLabel || this._fieldSelected.label }));
  }
  getExpressiontValue(expression) {
    return DataType.convertType(expression.type, expression.value);
  }
  configureFieldByType() {
    var _a, _b;
    const field = {
      userInterface: this._fieldSelected.userInterface,
      name: this._fieldSelected.name,
      label: this._fieldSelected.label,
      canShowError: false
    };
    switch (field.userInterface) {
      case core.UserInterface.OPTIONSELECTOR:
        field.props = {
          options: (_b = (_a = this._fieldSelected) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.options,
        };
        break;
      case core.UserInterface.LONGTEXT:
        field.rows = 1;
        break;
      case core.UserInterface.SEARCH:
        field.optionLoader = searchArgument => this.setCriteriaSearch(searchArgument, this.application);
        break;
    }
    return field;
  }
  setCriteriaSearch({ mode, argument }, application) {
    var _a, _b, _c;
    if (application == undefined)
      return;
    const searchOptions = {
      showInactives: false
    };
    const options = {
      entity: (_c = (_b = (_a = this._fieldSelected) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.ENTITYNAME) !== null && _c !== void 0 ? _c : this._fieldSelected.entityName,
      searchOptions,
      entityDescription: this._fieldSelected.description
    };
    return application.executePreparedSearch(mode, argument, options);
  }
  render() {
    var _a;
    return (index.h(index.Host, null, index.h("div", { class: "dashes" }), index.h("div", { class: "box" }, index.h("div", { class: "box__container" }, index.h("div", { class: "box__container--input-filter" }, index.h("ez-filter-input", Object.assign({ ref: ref => this._elFilterInput = ref, value: (_a = this._fieldSelected) === null || _a === void 0 ? void 0 : _a.path, label: this.getMessage("snkPersonalizedFilter.info.labelSearchField"), canShowError: false, onEzChange: (evt) => this.handleChangeFilterInput(evt), onFocus: () => this.handleFocus() }, { [core.ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: `expressionFilterInput_${this.expression.fieldName || this.DEFAULT_FIELD_NAME}` })), index.h("snk-filter-field-search", { ref: ref => this._elFilterFieldSearch = ref, searchable: false, onEzSelectFilterItem: (ev) => this.handleSelectItem(ev.detail), fieldsDataSource: this._dataSourceFetcher })), index.h("div", { class: "box__container--input-operator" }, index.h("ez-combo-box", Object.assign({ label: this.getMessage("snkPersonalizedFilter.info.labelOperator"), value: this.expression.operand, canShowError: false, options: this.buildOptionsOperator(), onEzChange: (evt) => { var _a; return this.handleChangeOperator((_a = evt.detail) === null || _a === void 0 ? void 0 : _a.value); }, suppressEmptyOption: true }, { [core.ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: `comboBoxOperand_${this.expression.fieldName || this.DEFAULT_FIELD_NAME}` }))), index.h("div", { class: "box__container--input-value" }, !this._fieldSelected ? (index.h("ez-number-input", { label: this.getMessage('snkPersonalizedFilter.info.labelDefaultValue'), canShowError: false, enabled: !this._showValueVariable && !this._optionNotNull })) : (this.buildFieldByType())), index.h("div", { class: "box__container--input-value-variable" }, !this._optionNotNull &&
      index.h("ez-tooltip", { message: this.getMessage("snkPersonalizedFilter.info.checkVariableDisabled"), active: this.isDefaultFilter }, index.h("ez-check", { ref: ref => this._elValueVariable = ref, value: this.expression.paramVariable, label: this.getMessage("snkPersonalizedFilter.info.labelValueVarible"), mode: utils.CheckMode.SWITCH, onEzChange: (evt) => this.handleChangeValueVariable(evt.detail), enabled: !this.isDefaultFilter })), (this._showValueVariable && !this._optionNotNull) &&
      index.h("ez-icon", Object.assign({ class: "box__container--input-value-variable--icon", size: "large", iconName: "settings-inverted" }, { [core.ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: 'iconConfig' }, { title: this.getMessage("snkPersonalizedFilter.info.titleTooltip"), onClick: () => this.openSnkFilterParamConfig() })), index.h("snk-filter-param-config", { ref: (el) => this._elFilterParamConfigRef = el, messagesBuilder: this.messagesBuilder })), index.h("div", { class: "box__container--button-delete" }, index.h("div", { class: "box__container--button-delete--icon" }, index.h("ez-button", { mode: "icon", iconName: "delete", enabled: this.canRemove, label: this.getMessage("snkPersonalizedFilter.info.labelDeleteItem"), onClick: (evt) => this.confirmRemove(evt) })))))));
  }
  static get watchers() { return {
    "expression": ["expressionChanged"]
  }; }
};
SnkExpressionItem.style = snkExpressionItemCss;

exports.snk_expression_group = SnkExpressionGroup;
exports.snk_expression_item = SnkExpressionItem;
