'use strict';

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

const index = require('./index-58ea899e.js');
const vegaEventId = require('./vega-event-id-d9994eb3.js');
const eventEmitSlimmer = require('./event-emit-slimmer-80e1c8ca.js');
const accessibility = require('./accessibility-a5ef2038.js');
const component = require('./component-1e352960.js');
const globalSlimmerRegistry = require('./global-slimmer-registry-b3bce7e0.js');
const componentUsageRuntimeMetrics = require('./component-usage-runtime-metrics-4572c5b7.js');
const formFieldControllerSlimmer = require('./form-field-controller-slimmer-a07e3de0.js');
const toggleSwitchRequiredRule = require('./toggle-switch-required-rule-88a51b36.js');
const staticSubjectTitle = require('./static-subject-title-5829a298.js');
const changeManager = require('./change-manager-a297e4d2.js');
require('./dynamic-slimmer-f31fdfd7.js');
require('./dom-node-subject-observer-factory-9110cb94.js');
require('./observer-f49483e8.js');
require('./ui-ae4ee13d.js');
require('./internal-vega-event-manager-7e0d966d.js');
require('./try-get-document-c0ebd39a.js');
require('./string-39438062.js');
require('./misc-3d30df91.js');
require('./vega-internal-event-id-87014e4f.js');
require('./internal-translation-controller-8360a89c.js');
require('./index-592b4052.js');
require('./page-resize-observer-slimmer-273d62ef.js');
require('./breakpoints-1cc2c4c6.js');
require('./ui-32120990.js');
require('./breakpoints-ebde4837.js');
require('./internal-form-field-validation-rule.abstract-07cdff46.js');
require('./mutation-observer-slimmer-749d5020.js');
require('./mutation-observer-filters-38cebc6d.js');
require('./array-249289f2.js');
require('./number-4816603d.js');
require('./sub-state-observer-slimmer-b8f6f27b.js');

const vegaToggleSwitchCss = ":host{display:inline-block}:host .vega-error{display:inline-block;padding-left:8px;padding-right:8px;padding-top:12px;font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px;letter-spacing:0px;color:rgba(var(--v-text-error, 189, 41, 71, 1))}@media screen and (min-width: 768px) and (max-width: 1023px){:host .vega-error{font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px;letter-spacing:0px}}@media screen and (min-width: 1024px) and (max-width: 1439px){:host .vega-error{font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px;letter-spacing:0px}}@media screen and (min-width: 1440px) and (max-width: 9999px){:host .vega-error{font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px;letter-spacing:0px}}:host .vega-hidden{display:none}div.vega-container{display:flex;justify-content:flex-start;align-items:center;border-radius:9999px;position:relative;box-sizing:content-box;height:24px;width:48px;padding:4px;background-color:rgba(var(--v-bg-toggle-switch, 107, 116, 125, 0.7))}div.vega-container:hover{background-color:rgba(var(--v-bg-toggle-switch-hover, 107, 116, 125, 1))}div.vega-container.vega-container-checked{background-color:rgba(var(--v-bg-action, 19, 98, 226, 1))}div.vega-container.vega-container-checked:hover{background-color:rgba(var(--v-bg-action-hover, 4, 112, 236, 1))}div.vega-container.vega-container-disabled{background-color:rgba(var(--v-bg-disabled, 176, 180, 181, 1))}div.vega-container.vega-container-checked.vega-container-disabled{background-color:rgba(var(--v-bg-toggle-switch-selected-disabled, 153, 192, 255, 1))}div.vega-container-small-size{box-sizing:border-box;height:20px;width:32px;padding:2px}div.vega-container>span{margin-left:0px;transition-property:margin;transition-duration:0.1s;transition-timing-function:linear}div.vega-container:focus-within{outline:2px solid rgba(var(--v-border-color-action, 19, 98, 226, 1));outline-offset:2px}div.vega-container-checked>span{margin-left:24px}div.vega-container-checked.vega-container-small-size>span{margin-left:12px}div.vega-container>input{position:absolute;cursor:pointer;opacity:0;left:0px;top:0px;width:100%;height:100%;margin:0px;-webkit-tap-highlight-color:transparent}div.vega-container input:disabled{cursor:default}div.vega-container>span{display:inline-block;border-radius:9999px;box-shadow:var(--v-shadow-form-field, 0px 1px 2px 0px rgba(0, 0, 0, 0.06), 0px 1px 2px 0px rgba(0, 0, 0, 0.1));width:24px;height:24px;background-color:rgba(var(--v-bg-primary, 252, 252, 252, 1));box-shadow:var(--v-shadow-form-field, 0px 1px 2px 0px rgba(0, 0, 0, 0.06), 0px 1px 2px 0px rgba(0, 0, 0, 0.1));transition-property:margin;transition-duration:0.1s;transition-timing-function:linear}div.vega-container-small-size{height:20px}div.vega-container-small-size>span{width:16px;height:16px}div{align-self:center}";

var __decorate = (undefined && undefined.__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;
};
const VegaToggleSwitch = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.vegaChange = index.createEvent(this, "vegaChange", 7);
    this.change = index.createEvent(this, "change", 7);
    this.globalSlimmers = {};
    this.vegaComponentUsageRuntimeMetricsSlimmer = new componentUsageRuntimeMetrics.VegaComponentUsageRuntimeMetricsSlimmer();
    this.formFieldController = new formFieldControllerSlimmer.FormFieldControllerSlimmer({
      propertyRules: [
        {
          propertyName: 'required',
          ruleFactory: (isRequired) => isRequired ? new toggleSwitchRequiredRule.ToggleSwitchRequiredRule() : null,
        },
      ],
      validationRulesName: 'validationRules',
      defaultValue: false,
      attributeGetter: (propertyName) => this[propertyName],
      inputContainerGetter: () => this.toggleSwitchContainer,
      touchableAreaGetter: () => [this.toggleSwitchContainer],
    });
    this.changeEventEmitter = eventEmitSlimmer.createEventEmitSlimmer(VegaToggleSwitch, vegaEventId.VegaChange);
    /**
     * Specifies whether the toggle switch is in the checked state.
     *
     * @vegaVersion 1.3.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.checked = false;
    /**
     * The `value` property returns `true` when the toggle switch is checked, and `false` when it is unchecked.
     * This property is included for form control compatibility and can be used interchangeably with the checked property.
     *
     * @vegaVersion 2.25.0
     */
    this.value = false;
    /**
     * Specifies the size of the toggle switch.
     *
     * @vegaVersion 1.3.0
     */
    this.size = 'default';
    /**
     * Specifies whether the toggle switch must be checked
     *    to pass form validation.
     *
     * @vegaVersion 2.25.0
     */
    this.required = false;
    /**
     * Specifies whether the toggle switch is disabled.
     *
     * @vegaVersion 1.3.0
     */
    this.disabled = false;
    /**
     * Defines custom validation rules for the toggle switch.
     *
     * @vegaVersion 2.25.0
     */
    this.validationRules = [];
    /**
     * Determines whether automatic validation should be
     *    implemented for the toggle switch.
     *
     * @vegaVersion 2.25.0
     */
    this.autoValidation = true;
    /**
     * Specifies the validation status of the toggle switch.
     *
     * @vegaVersion 2.25.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.isValid = null;
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-toggle-switch-click-on-label-e2e}
     */
    /* istanbul ignore next */
    this.toggleSwitch = () => {
      if (!this.disabled) {
        this.checked = !this.checked;
      }
    };
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-toggle-switch-change}
     * @see{module:vega-toggle-switch-click-with-disabled}
     */
    /* istanbul ignore next */
    this.updateValue = (e) => {
      const currentTarget = e.currentTarget;
      this.checked = currentTarget.checked;
      e.stopPropagation();
    };
  }
  watchCheckedChange() {
    this.value = this.checked;
    this.changeEventEmitter.emit(this.checked);
    changeManager.ChangeManager.notify(staticSubjectTitle.FORM_ELEMENT_VALUE_CHANGE, {
      host: this.host,
      detail: this.value,
    });
  }
  watchValue(newValue) {
    this.checked = newValue === true;
  }
  watchValidationRules() {
  }
  componentWillLoad() {
    if (!this.checked && this.value === true) {
      this.checked = true;
    }
    else {
      this.value = this.checked;
    }
  }
  render() {
    let divContainerCss = this.checked
      ? 'vega-container vega-container-checked'
      : 'vega-container';
    divContainerCss += this.disabled ? ' vega-container-disabled' : '';
    divContainerCss += this.size === 'small' ? ' vega-container-small-size' : '';
    return component.sanitizeVegaComponent(index.h(index.Host, null, index.h("vega-flex", { gap: "size-8", ref: (node) => (this.toggleSwitchContainer = node) }, index.h("div", { class: `${divContainerCss} vega-flex-shrink-0 v-min-w-min` }, index.h("input", { type: "checkbox", name: "switch", disabled: this.disabled, checked: this.checked, onChange: this.updateValue, "aria-label": this.label || 'No label defined', role: 'button', tabIndex: 0, onKeyDown: accessibility.createEnterKeyHandlerToTriggerClick() }), index.h("span", { class: this.disabled ? 'v-bg-tertiary' : 'v-bg-primary' })), this.renderLabelDom())), this.host);
  }
  renderLabelDom() {
    return this.label ? (index.h("div", { class: "vega-flex-basis-0 vega-flex-grow" }, index.h("vega-field-label", { onClick: this.toggleSwitch, disabled: this.disabled, label: this.label, isFieldRequired: this.required }))) : null;
  }
  get host() { return index.getElement(this); }
  static get watchers() { return {
    "checked": ["watchCheckedChange"],
    "value": ["watchValue"],
    "validationRules": ["watchValidationRules"]
  }; }
};
__decorate([
  componentUsageRuntimeMetrics.InjectVegaGlobalSlimmer()
], VegaToggleSwitch.prototype, "globalSlimmers", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaToggleSwitch.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaToggleSwitch.prototype, "formFieldController", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaToggleSwitch.prototype, "changeEventEmitter", void 0);
VegaToggleSwitch.style = vegaToggleSwitchCss;

exports.vega_toggle_switch = VegaToggleSwitch;
