'use strict';

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

var normalizeComponent = require('./normalize-component-6fa50395.js');
var ThemeMixin = require('./ThemeMixin-a2f817cd.js');
var IsDisabledMixin = require('./IsDisabledMixin-c3297ff2.js');

var script = {
  name: 'ToggleAtom',
  props: {
    size: {
      type: String,
      required: true,
      validator: function validator(value) {
        return ['normal', 'mini'].indexOf(value) !== -1;
      }
    }
  },
  computed: {
    toggleAtomCssClass: function toggleAtomCssClass() {
      return ThemeMixin._objectSpread2(ThemeMixin._objectSpread2({}, this.themeCssClass), {}, ThemeMixin._defineProperty({}, "size-".concat(this.size), true));
    }
  },
  mixins: [ThemeMixin.ThemeMixin]
};

/* script */
const __vue_script__ = script;

/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('label',{staticClass:"toggle-atom",class:_vm.toggleAtomCssClass},[_vm._t("default"),_vm._v(" "),_c('span',{staticClass:"toggle-atom-handle"})],2)};
var __vue_staticRenderFns__ = [];

  /* style */
  const __vue_inject_styles__ = undefined;
  /* scoped */
  const __vue_scope_id__ = undefined;
  /* module identifier */
  const __vue_module_identifier__ = undefined;
  /* functional template */
  const __vue_is_functional_template__ = false;
  /* style inject */
  
  /* style inject SSR */
  

  
  var ToggleAtom = normalizeComponent.__vue_normalize__(
    { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    undefined,
    undefined
  );

var script$1 = {
  name: 'VToggle',
  inheritAttrs: false,
  props: {
    value: {
      type: [String, Boolean],
      default: false
    },
    modelValue: {
      type: null,
      default: false
    },
    trueValue: {
      type: null,
      default: true
    },
    falseValue: {
      type: null,
      default: false
    },
    size: {
      type: String,
      default: 'normal'
    }
  },
  computed: {
    isChecked: function isChecked() {
      var isListHandling = this.modelValue instanceof Array;

      if (isListHandling) {
        return this.modelValue.includes(this.value);
      }

      return this.modelValue === this.trueValue;
    },
    toggleCssClass: function toggleCssClass() {
      return ThemeMixin._defineProperty({
        'is-checked': this.isChecked,
        'is-disabled': this.$attrs.disabled
      }, "size-".concat(this.size), true);
    }
  },
  methods: {
    handleChange: function handleChange(event) {
      var checked = event.target.checked;
      var isListHandling = this.modelValue instanceof Array;

      if (!isListHandling) {
        this.$emit('change', checked ? this.trueValue : this.falseValue);
        return;
      }

      var newValue = ThemeMixin._toConsumableArray(this.modelValue);

      if (this.modelValue.includes(this.value)) {
        newValue.splice(newValue.indexOf(this.value), 1);
      } else {
        newValue.push(this.value);
      }

      this.$emit('change', newValue);
    }
  },
  mixins: [ThemeMixin.ThemeMixin, IsDisabledMixin.IsDisabledMixin],
  components: {
    ToggleAtom: ToggleAtom
  },
  model: {
    prop: 'modelValue',
    event: 'change'
  }
};

/* script */
const __vue_script__$1 = script$1;

/* template */
var __vue_render__$1 = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"v-toggle",class:_vm.themeCssClass},[_c('toggle-atom',{class:_vm.toggleCssClass,attrs:{"size":_vm.size}},[_c('input',_vm._b({staticClass:"v-toggle-control",attrs:{"title":"","type":"checkbox"},domProps:{"checked":_vm.isChecked,"value":_vm.value},on:{"change":_vm.handleChange}},'input',_vm.$attrs,false))]),_vm._v(" "),(_vm.$slots.default)?_c('span',{staticClass:"v-toggle-label"},[_vm._t("default")],2):_vm._e()],1)};
var __vue_staticRenderFns__$1 = [];

  /* style */
  const __vue_inject_styles__$1 = undefined;
  /* scoped */
  const __vue_scope_id__$1 = undefined;
  /* module identifier */
  const __vue_module_identifier__$1 = undefined;
  /* functional template */
  const __vue_is_functional_template__$1 = false;
  /* style inject */
  
  /* style inject SSR */
  

  
  var VToggle = normalizeComponent.__vue_normalize__(
    { render: __vue_render__$1, staticRenderFns: __vue_staticRenderFns__$1 },
    __vue_inject_styles__$1,
    __vue_script__$1,
    __vue_scope_id__$1,
    __vue_is_functional_template__$1,
    __vue_module_identifier__$1,
    undefined,
    undefined
  );

exports.default = VToggle;
