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;
};
import { Component, Prop, Element, Method, Watch, Event } from '@stencil/core';
import { RequiredFieldRule } from '../../helpers/validator/rules/required-field-rule';
import { sanitizeVegaComponent } from '../../utils/component';
import { isArrayOfType, isDropdownSourceItemType } from '../../types/type-guard';
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer, methodPlaceholder, } from 'vega-slimmer/core';
import { FormFieldControllerSlimmer } from '../../helpers/slimmers/form-field-controller-slimmer';
import { ChildNodesEventPreventSlimmer } from '../../helpers/event-manager/slimmers/child-nodes-event-prevent-slimmer';
import { createEventEmitSlimmer, } from '../../helpers/event-manager/slimmers/event-emit-slimmer';
import { VegaChange, VegaCreate, VegaSearch } from '../../helpers/event-manager/event-id/vega-event-id';
import { FORM_ELEMENT_VALUE_CHANGE } from '../../helpers/change-manager/subject/static-subject/static-subject-title';
import ChangeManager from '../../helpers/change-manager/change-manager';
import { VegaComponentUsageRuntimeMetricsSlimmer } from '../../helpers/slimmers/component-usage-runtime-metrics';
import { VegaComboBoxRuntimeMetricsPayloadDefinition } from '../../constants/runtime-metrics-payload-definition/vega-combo-box/runtime-metrics-payload-definition';
import { VegaComboBoxDropdownRenderer } from './slimmers/renderers/vega-combo-box-dropdown-renderer';
import { VegaComboBoxValueController } from './slimmers/controllers/vega-combo-box-value-controller';
import { VegaComboBoxRenderer } from './slimmers/renderers/vega-combo-box-renderer';
import { VegaComboBoxKeyboardController } from './slimmers/controllers/vega-combo-box-keyboard-controller';
import { VegaComboBoxItemsSlotController } from './slimmers/controllers/vega-combo-box-items-slot-controller';
import { VegaComboBoxSourceController } from './slimmers/controllers/vega-combo-box-source-controller';
/**
 * @vegaVersion 1.11.0
 */
export class VegaComboBox {
  constructor() {
    this.globalSlimmers = {};
    this.itemsSlotController = new VegaComboBoxItemsSlotController();
    this.keyboardController = new VegaComboBoxKeyboardController();
    this.valueController = new VegaComboBoxValueController();
    this.sourceController = new VegaComboBoxSourceController();
    this.renderer = new VegaComboBoxRenderer();
    this.dropdownRenderer = new VegaComboBoxDropdownRenderer();
    this.formFieldController = new FormFieldControllerSlimmer({
      propertyRules: [
        {
          propertyName: 'required',
          ruleFactory: (isRequired) => (isRequired ? new RequiredFieldRule() : null),
        },
      ],
      validationRulesName: 'validationRules',
      defaultValue: [],
      attributeGetter: (propertyName) => this[propertyName],
      inputContainerGetter: () => this.dropdownRenderer.getDropdownRef(),
      touchableAreaGetter: () => [this.dropdownRenderer.getSearchInputRef()],
    });
    this.changeEventEmit = createEventEmitSlimmer(VegaComboBox, VegaChange);
    this.createEventEmit = createEventEmitSlimmer(VegaComboBox, VegaCreate);
    this.searchEventEmit = createEventEmitSlimmer(VegaComboBox, VegaSearch);
    this.dropdownEventPrevent = new ChildNodesEventPreventSlimmer([VegaCreate, VegaSearch], () => this.dropdownRenderer.getDropdownRef(), {
      customPreventHandle: (e) => {
        e.stopImmediatePropagation();
      },
    });
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer(VegaComboBoxRuntimeMetricsPayloadDefinition);
    /**
     * Specifies the label or title for the combo box.
     *
     * It provides descriptive text that helps identify the
     *    purpose or content expected in the combo box.
     *
     * @vegaVersion 1.11.0
     */
    this.label = '';
    /**
     * Specifies whether a value must be entered for the
     *    combo box to pass form validation.
     *
     * @vegaVersion 1.11.0
     */
    this.required = false;
    /**
     * Specifies the source data used to populate the
     *    dropdown menu associated with the combo box.
     *
     * @vegaVersion 1.11.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.source = [];
    /**
     * Sets the initial or preset values of the combo box.
     *
     * It should be an array of strings representing the selected values.
     *
     * @vegaVersion 1.11.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.value = [];
    /**
     * Specifies the validation status of the combo box component.
     *
     * @vegaVersion 1.11.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.isValid = null;
    /**
     * Determines whether automatic validation should be implemented
     *    when a value is edited in the combo box.
     *
     * @vegaVersion 1.11.0
     */
    this.autoValidation = true;
    /**
     * Specifies custom validation rules for the combo box.
     *
     * @vegaVersion 1.11.0
     */
    this.validationRules = [];
    /**
     * Specifies whether the combo box element is disabled.
     *
     * @vegaVersion 1.11.0
     */
    this.disabled = false;
    /**
     * Sets a placeholder string that provides a temporary hint
     *    or example inside the combo box input field.
     *
     * It indicates the expected format or pattern of the input.
     *
     * @vegaVersion 1.11.0
     */
    this.placeholder = '';
    /**
     * Provides a supplementary prompt message that is displayed
     *    alongside the combo box input field.
     *
     * @vegaVersion 1.11.0
     */
    this.hint = '';
    /**
     * Specifies the size of the combo box.
     *
     * @vegaVersion 1.11.0
     */
    this.size = 'medium';
    /**
     * Specifies partial properties of the `vega-dropdown` component
     *    that are used to configure the dropdown menu
     *    associated with the combo box.
     *
     * @vegaVersion 1.11.0
     */
    this.vegaDropdownProps = {};
    /**
     * Determines whether to display the associated dropdown menu and
     *    filter its options based on the text entered into the combo box.
     *
     * Setting this property to `false` enables custom text input handling
     *    by listening for the `vegaSearch` event.
     *
     * @vegaVersion 1.24.0
     */
    this.useDefaultFilter = true;
  }
  watchSource() {
    this.source = isArrayOfType(this.source, isDropdownSourceItemType)
      ? this.source
      : [];
  }
  watchValue() {
    this.changeEventEmit.emit(this.value);
    ChangeManager.notify(FORM_ELEMENT_VALUE_CHANGE, {
      host: this.host,
      detail: this.value,
    });
  }
  watchValidationRules() {
    methodPlaceholder();
  }
  /**
   * Invoke this method to close the dropdown menu associated with the combo box.
   *
   * @vegaVersion 1.11.0
   */
  async close() {
    if (!this.disabled) {
      await this.dropdownRenderer.hide();
    }
  }
  /**
   * Invoke this method to open the dropdown menu associated with the combo box.
   *
   * @vegaVersion 1.11.0
   */
  async open() {
    if (!this.disabled) {
      await this.dropdownRenderer.show();
    }
  }
  render() {
    return sanitizeVegaComponent(this.renderer.render(), this.host);
  }
  static get is() { return "vega-combo-box"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["vega-combo-box.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["vega-combo-box.css"]
  }; }
  static get properties() { return {
    "label": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies the label or title for the combo box.\n\nIt provides descriptive text that helps identify the\n   purpose or content expected in the combo box."
      },
      "attribute": "label",
      "reflect": false,
      "defaultValue": "''"
    },
    "required": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies whether a value must be entered for the\n   combo box to pass form validation."
      },
      "attribute": "required",
      "reflect": true,
      "defaultValue": "false"
    },
    "source": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "DropdownSourceItem[]",
        "resolved": "DropdownSourceItem[]",
        "references": {
          "DropdownSourceItem": {
            "location": "import",
            "path": "../vega-dropdown/types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies the source data used to populate the\n   dropdown menu associated with the combo box."
      },
      "defaultValue": "[]"
    },
    "value": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "string[]",
        "resolved": "string[]",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Sets the initial or preset values of the combo box.\n\nIt should be an array of strings representing the selected values."
      },
      "defaultValue": "[]"
    },
    "isValid": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies the validation status of the combo box component."
      },
      "attribute": "is-valid",
      "reflect": true,
      "defaultValue": "null"
    },
    "autoValidation": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Determines whether automatic validation should be implemented\n   when a value is edited in the combo box."
      },
      "attribute": "auto-validation",
      "reflect": true,
      "defaultValue": "true"
    },
    "validationRules": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "FormFieldValidationRule<unknown>[]",
        "resolved": "FormFieldValidationRule<unknown>[]",
        "references": {
          "FormFieldValidationRule": {
            "location": "import",
            "path": "../../helpers/validator/rules/form-field-validation-rule"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies custom validation rules for the combo box."
      },
      "defaultValue": "[]"
    },
    "disabled": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies whether the combo box element is disabled."
      },
      "attribute": "disabled",
      "reflect": true,
      "defaultValue": "false"
    },
    "placeholder": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Sets a placeholder string that provides a temporary hint\n   or example inside the combo box input field.\n\nIt indicates the expected format or pattern of the input."
      },
      "attribute": "placeholder",
      "reflect": false,
      "defaultValue": "''"
    },
    "hint": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Provides a supplementary prompt message that is displayed\n   alongside the combo box input field."
      },
      "attribute": "hint",
      "reflect": false,
      "defaultValue": "''"
    },
    "size": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "VegaComboBoxSize",
        "resolved": "\"medium\" | \"small\"",
        "references": {
          "VegaComboBoxSize": {
            "location": "import",
            "path": "./types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies the size of the combo box."
      },
      "attribute": "size",
      "reflect": false,
      "defaultValue": "'medium'"
    },
    "vegaDropdownProps": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "VegaDropdownPropsForComboBox",
        "resolved": "{ maxHeight?: number; positionRelativeTo?: string; matchContainerHeight?: boolean; dynamicOption?: boolean; isLoading?: boolean; }",
        "references": {
          "VegaDropdownPropsForComboBox": {
            "location": "import",
            "path": "./types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "Specifies partial properties of the `vega-dropdown` component\n   that are used to configure the dropdown menu\n   associated with the combo box."
      },
      "defaultValue": "{}"
    },
    "useDefaultFilter": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.24.0"
          }],
        "text": "Determines whether to display the associated dropdown menu and\n   filter its options based on the text entered into the combo box.\n\nSetting this property to `false` enables custom text input handling\n   by listening for the `vegaSearch` event."
      },
      "attribute": "use-default-filter",
      "reflect": false,
      "defaultValue": "true"
    }
  }; }
  static get events() { return [{
      "method": "vegaChange",
      "name": "vegaChange",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }],
        "text": "An event emitter notifying changes in the items of the combo box value,\n   whether triggered programmatically or through user interaction."
      },
      "complexType": {
        "original": "string[]",
        "resolved": "string[]",
        "references": {}
      }
    }, {
      "method": "change",
      "name": "change",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "eventSemantics",
            "text": "namespace:native"
          }, {
            "name": "vegaVersion",
            "text": "2.0.0"
          }],
        "text": "An event emitter notifying changes in the items of the combo box value,\n   whether triggered programmatically or through user interaction."
      },
      "complexType": {
        "original": "string[]",
        "resolved": "string[]",
        "references": {}
      }
    }, {
      "method": "vegaCreate",
      "name": "vegaCreate",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.14.0"
          }],
        "text": "An event emitter notifying when the user has chosen to add a new value\n   to the source and value of the combo box.\n\nThe event's `detail` property contains the new value.\n\nThe combo box _does not_ automatically add the new value to its `source` and `value`."
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "create",
      "name": "create",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "eventSemantics",
            "text": "namespace:native"
          }, {
            "name": "vegaVersion",
            "text": "2.0.0"
          }],
        "text": "An event emitter notifying when the user has chosen to add a new value\n   to the source and value of the combo box.\n\nThe event's `detail` property contains the new value.\n\nThe combo box _does not_ automatically add the new value to its `source` and `value`."
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "vegaSearch",
      "name": "vegaSearch",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.24.0"
          }],
        "text": "An event emitter notifying the user's search action in the combo box,\n   but only if the `useDefaultFilter` property is set to `false`."
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "search",
      "name": "search",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "eventSemantics",
            "text": "namespace:native"
          }, {
            "name": "vegaVersion",
            "text": "2.0.0"
          }],
        "text": "An event emitter notifying the user's search action in the combo box,\n   but only if the `useDefaultFilter` property is set to `false`."
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }]; }
  static get methods() { return {
    "close": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "Invoke this method to close the dropdown menu associated with the combo box.",
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }]
      }
    },
    "open": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "Invoke this method to open the dropdown menu associated with the combo box.",
        "tags": [{
            "name": "vegaVersion",
            "text": "1.11.0"
          }]
      }
    }
  }; }
  static get elementRef() { return "host"; }
  static get watchers() { return [{
      "propName": "source",
      "methodName": "watchSource"
    }, {
      "propName": "value",
      "methodName": "watchValue"
    }, {
      "propName": "validationRules",
      "methodName": "watchValidationRules"
    }]; }
}
__decorate([
  InjectVegaGlobalSlimmer()
], VegaComboBox.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "itemsSlotController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "keyboardController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "valueController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "sourceController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "renderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "dropdownRenderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "formFieldController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "changeEventEmit", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "createEventEmit", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "searchEventEmit", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "dropdownEventPrevent", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaComboBox.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
