import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-090d31ca.js';
import { i as VegaChange } from './vega-event-id-a6ccca66.js';
import { c as createEventEmitSlimmer } from './event-emit-slimmer-1c57093d.js';
import { c as createEnterKeyHandlerToTriggerClick } from './accessibility-524cabd2.js';
import { s as sanitizeVegaComponent } from './component-7d906393.js';
import { I as InjectVegaSlimmer } from './global-slimmer-registry-17c4efd4.js';
import { V as VegaComponentUsageRuntimeMetricsSlimmer, I as InjectVegaGlobalSlimmer } from './component-usage-runtime-metrics-46020a03.js';
import { F as FormFieldControllerSlimmer } from './form-field-controller-slimmer-ae8478b5.js';
import { T as ToggleSwitchRequiredRule } from './toggle-switch-required-rule-b3cf4302.js';
import { F as FORM_ELEMENT_VALUE_CHANGE } from './static-subject-title-52f93124.js';
import { C as ChangeManager } from './change-manager-6a7eb88c.js';
import './dynamic-slimmer-90b8af32.js';
import './dom-node-subject-observer-factory-aca0116e.js';
import './observer-3959f9dd.js';
import './ui-b7600a48.js';
import './internal-vega-event-manager-7cdf3c28.js';
import './try-get-document-bef0f526.js';
import './string-a953eafc.js';
import './misc-9fdbcfbb.js';
import './vega-internal-event-id-db974a0d.js';
import './internal-translation-controller-d7dee4a0.js';
import './index-3b327f29.js';
import './page-resize-observer-slimmer-e24d36c5.js';
import './breakpoints-332702ed.js';
import './ui-93922c59.js';
import './breakpoints-d9faf11c.js';
import './internal-form-field-validation-rule.abstract-f5b6bdbf.js';
import './mutation-observer-slimmer-58ebc13c.js';
import './mutation-observer-filters-1a054fb0.js';
import './array-7888f339.js';
import './number-4398f2e1.js';
import './sub-state-observer-slimmer-2adbbe00.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) {
    registerInstance(this, hostRef);
    this.vegaChange = createEvent(this, "vegaChange", 7);
    this.change = createEvent(this, "change", 7);
    this.globalSlimmers = {};
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.formFieldController = new FormFieldControllerSlimmer({
      propertyRules: [
        {
          propertyName: 'required',
          ruleFactory: (isRequired) => isRequired ? new ToggleSwitchRequiredRule() : null,
        },
      ],
      validationRulesName: 'validationRules',
      defaultValue: false,
      attributeGetter: (propertyName) => this[propertyName],
      inputContainerGetter: () => this.toggleSwitchContainer,
      touchableAreaGetter: () => [this.toggleSwitchContainer],
    });
    this.changeEventEmitter = createEventEmitSlimmer(VegaToggleSwitch, 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.notify(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 sanitizeVegaComponent(h(Host, null, h("vega-flex", { gap: "size-8", ref: (node) => (this.toggleSwitchContainer = node) }, h("div", { class: `${divContainerCss} vega-flex-shrink-0 v-min-w-min` }, 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: createEnterKeyHandlerToTriggerClick() }), h("span", { class: this.disabled ? 'v-bg-tertiary' : 'v-bg-primary' })), this.renderLabelDom())), this.host);
  }
  renderLabelDom() {
    return this.label ? (h("div", { class: "vega-flex-basis-0 vega-flex-grow" }, h("vega-field-label", { onClick: this.toggleSwitch, disabled: this.disabled, label: this.label, isFieldRequired: this.required }))) : null;
  }
  get host() { return getElement(this); }
  static get watchers() { return {
    "checked": ["watchCheckedChange"],
    "value": ["watchValue"],
    "validationRules": ["watchValidationRules"]
  }; }
};
__decorate([
  InjectVegaGlobalSlimmer()
], VegaToggleSwitch.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaToggleSwitch.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaToggleSwitch.prototype, "formFieldController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaToggleSwitch.prototype, "changeEventEmitter", void 0);
VegaToggleSwitch.style = vegaToggleSwitchCss;

export { VegaToggleSwitch as vega_toggle_switch };
