/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { Loading } from '../loading/index.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import props from './props.js';
import '../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../loading/loading.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '@vue/composition-api';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-2cb61c79.js';
import 'dayjs';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefixMixins = getClassPrefixMixins("switch");
var _Switch = mixins(classPrefixMixins).extend({
  name: "TSwitch",
  props: _objectSpread({}, props),
  model: {
    prop: "value",
    event: "change"
  },
  data: function data() {
    return {
      formDisabled: void 0
    };
  },
  computed: {
    classes: function classes() {
      var _ref;
      return ["".concat(this.componentName), this.commonSizeClassName[this.size], (_ref = {}, _defineProperty(_ref, this.commonStatusClassName.disabled, this.tDisabled), _defineProperty(_ref, this.commonStatusClassName.loading, this.loading), _defineProperty(_ref, this.commonStatusClassName.checked, this.value === this.activeValue), _ref)];
    },
    nodeClasses: function nodeClasses() {
      var _ref2;
      return ["".concat(this.componentName, "__handle"), (_ref2 = {}, _defineProperty(_ref2, this.commonStatusClassName.disabled, this.tDisabled), _defineProperty(_ref2, this.commonStatusClassName.loading, this.loading), _ref2)];
    },
    contentClasses: function contentClasses() {
      return ["".concat(this.componentName, "__content"), this.commonSizeClassName[this.size], _defineProperty({}, this.commonStatusClassName.disabled, this.tDisabled)];
    },
    tDisabled: function tDisabled() {
      return this.formDisabled || this.disabled;
    },
    activeValue: function activeValue() {
      if (this.customValue && this.customValue.length > 0) return this.customValue[0];
      return true;
    },
    inactiveValue: function inactiveValue() {
      if (this.customValue && this.customValue.length > 1) return this.customValue[1];
      return false;
    },
    content: function content() {
      if (typeof this.label === "function") return this.label(this.$createElement, {
        value: this.value
      });
      if (typeof this.label === "string") return this.label;
      if (Array.isArray(this.label)) {
        var label = this.value === this.activeValue ? this.label[0] : this.label[1];
        if (!label) return;
        if (typeof label === "string") return label;
        if (typeof label === "function") return label(this.$createElement);
      }
      if (this.$scopedSlots.label) return this.$scopedSlots.label({
        value: this.value
      });
      return null;
    }
  },
  watch: {
    value: {
      handler: function handler(val) {
        if (this.customValue && this.customValue.length && !this.customValue.includes(val)) throw "value is not in ".concat(JSON.stringify(this.customValue));
      },
      immediate: true
    }
  },
  methods: {
    handleToggle: function handleToggle() {
      var checked = this.value === this.activeValue ? this.inactiveValue : this.activeValue;
      typeof this.onChange === "function" && this.onChange(checked);
      this.$emit("change", checked);
    },
    toggle: function toggle() {
      if (this.tDisabled || this.loading) return;
      this.handleToggle();
    }
  },
  render: function render() {
    var h = arguments[0];
    var loading = this.loading,
      disabled = this.disabled,
      content = this.content,
      nodeClasses = this.nodeClasses,
      classes = this.classes,
      toggle = this.toggle,
      contentClasses = this.contentClasses;
    var switchContent;
    var loadingContent;
    if (loading) loadingContent = h(Loading, {
      "attrs": {
        "size": "small"
      }
    });else if (content) switchContent = content;
    return h("div", {
      "class": classes,
      "attrs": {
        "disabled": disabled
      },
      "on": {
        "click": toggle
      }
    }, [h("span", {
      "class": nodeClasses
    }, [loadingContent]), h("div", {
      "class": contentClasses
    }, [switchContent])]);
  }
});

export { _Switch as default };
//# sourceMappingURL=switch.js.map
