"use strict";
const vue = require("vue");
const types = require("./types.js");
const styleClass = require("../_utils/style-class.js");
const is = require("../_utils/is.js");
const provide = require("../checkbox/provide.js");
const provide$1 = require("../radio/provide.js");
const _hoisted_1 = {
  key: 0,
  class: "o-toggle-prefix"
};
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "OToggle",
  props: types.buttonToggleProps,
  emits: ["update:checked", "change"],
  setup(__props, { emit: __emit }) {
    const checkboxInjection = vue.inject(provide.checkboxInjectKey, null);
    const radioInjection = vue.inject(provide$1.radioInjectKey, null);
    const props = __props;
    const round = styleClass.getRoundClass(props, "toggle");
    const isChecked = vue.ref(props.checked ?? props.defaultChecked);
    const emits = __emit;
    vue.watch(
      () => props.checked,
      (val) => {
        if (!is.isUndefined(val)) {
          isChecked.value = val;
        }
      }
    );
    const onClick = (ev) => {
      if (props.disabled || checkboxInjection || radioInjection) {
        return;
      }
      isChecked.value = !isChecked.value;
      emits("update:checked", isChecked.value);
      vue.nextTick(() => {
        emits("change", isChecked.value, ev);
      });
    };
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass(["o-toggle", [
            vue.unref(round).class.value,
            {
              "o-toggle-disabled": props.disabled,
              "o-toggle-checked": isChecked.value
            }
          ]]),
          onClick
        },
        [
          props.icon || _ctx.$slots.icon ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_1, [
            vue.renderSlot(_ctx.$slots, "icon", {}, () => [
              (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(props.icon)))
            ])
          ])) : vue.createCommentVNode("v-if", true),
          vue.renderSlot(_ctx.$slots, "default")
        ],
        2
        /* CLASS */
      );
    };
  }
});
module.exports = _sfc_main;
