import { _ as _applyDecoratedDescriptor } from '../_rollupPluginBabelHelpers-9wjJaosZ.js';
import { setComponentTemplate } from '@ember/component';
import { precompileTemplate } from '@ember/template-compilation';
import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import { and, not } from 'ember-truth-helpers';
import randomId from '../-private/random-id.js';
import argOrDefault from '../helpers/arg-or-default.js';
import classNames from '../helpers/class-names.js';
import EuiIcon from './eui-icon.js';

var _class;
let EuiSwitch = setComponentTemplate(precompileTemplate(`
    {{#let
      (argOrDefault @type "button")
      (argOrDefault @showLabel true)
      (argOrDefault @id (randomId))
      (randomId)
      (and (has-block "label") (not (argOrDefault @isFakeLabelBlock false)))
      as |type showLabel switchId labelId hasLabelBlock|
    }}
      {{#let
        (classNames
          (if @compressed "euiSwitch--compressed") "euiSwitch" @containerClass
        )
        as |classes|
      }}
        <div class={{classes}}>
          <button
            type={{type}}
            id={{switchId}}
            aria-checked={{if @checked "true" "false"}}
            class="euiSwitch__button"
            role="switch"
            aria-label={{if (not showLabel) @label}}
            aria-labelledby={{if showLabel labelId undefined}}
            disabled={{@disabled}}
            ...attributes
            {{on "click" this.onClick}}
          >
            <span class="euiSwitch__body">
              <span class="euiSwitch__thumb"></span>
              <span class="euiSwitch__track">
                {{#unless @compressed}}
                  <EuiIcon
                    @type="cross"
                    @size="m"
                    @iconClasses="euiSwitch__icon"
                  />
                  <EuiIcon
                    @type="check"
                    @size="m"
                    @iconClasses="euiSwitch__icon euiSwitch__icon--checked"
                  />
                {{/unless}}
              </span>
            </span>
          </button>
          {{#if showLabel}}
            {{! template-lint-disable}}
            <span
              class="euiSwitch__label"
              id={{labelId}}
              {{on "click" this.onClick}}
            >
              {{#if hasLabelBlock}}
                {{yield to="label"}}
              {{else}}
                {{@label}}
              {{/if}}
            </span>
            {{! template-lint-enable}}
          {{/if}}
        </div>
      {{/let}}
    {{/let}}
  `, {
  strictMode: true,
  scope: () => ({
    argOrDefault,
    randomId,
    and,
    not,
    classNames,
    on,
    EuiIcon
  })
}), (_class = class EuiSwitch extends Component {
  onClick(e) {
    if (this.args.disabled) {
      return;
    }
    e.target.checked = !this.args.checked;
    this.args.onChange?.(e);
  }
}, (_applyDecoratedDescriptor(_class.prototype, "onClick", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onClick"), _class.prototype)), _class));

export { EuiSwitch as default };
//# sourceMappingURL=eui-switch.js.map
