'use strict';

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

var normalizeComponent = require('./normalize-component-6fa50395.js');
var ThemeMixin = require('./ThemeMixin-a2f817cd.js');
var svgAtom = require('./svg-atom-d2541b7d.js');
var iconAtom = require('./icon-atom-65241b51.js');
require('./hover-atom-17a12a07.js');
require('./tooltip-atom-8f536df5.js');
var tooltipMolecule = require('./tooltip-molecule-479b5142.js');
var IsDisabledMixin = require('./IsDisabledMixin-c3297ff2.js');

var script = {
  name: 'VCheckbox',
  props: {
    name: {
      type: String,
      default: 'checkbox'
    },
    value: {
      type: [String, Boolean],
      default: false
    },
    modelValue: {
      type: null,
      default: false
    },
    trueValue: {
      type: null,
      default: true
    },
    falseValue: {
      type: null,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    error: {
      type: String,
      default: null
    },
    tooltipLabel: {
      type: String,
      default: null
    }
  },
  computed: {
    isChecked: function isChecked() {
      var isListHandling = this.modelValue instanceof Array;

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

      return this.modelValue === this.trueValue || this.value === this.trueValue;
    },
    checkboxCssClass: function checkboxCssClass() {
      return Object.assign(this.themeCssClass, {
        'is-checked': this.isChecked,
        'is-disabled': this.disabled || this.isDisabled,
        'is-error': this.error
      });
    }
  },
  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: {
    SvgAtom: svgAtom.SvgAtom,
    IconAtom: iconAtom.IconAtom,
    TooltipMolecule: tooltipMolecule.TooltipMolecule
  },
  model: {
    prop: 'modelValue',
    event: 'change'
  }
};

/* 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:"v-checkbox",class:_vm.checkboxCssClass},[_c('input',{staticClass:"v-checkbox-control",attrs:{"disabled":_vm.disabled,"name":_vm.name,"type":"checkbox"},domProps:{"checked":_vm.isChecked,"value":_vm.value},on:{"change":_vm.handleChange}}),_vm._v(" "),_c('icon-atom',{staticClass:"v-checkbox-frame"},[_c('svg-atom',{staticClass:"v-checkbox-mark",attrs:{"name":"check"}})],1),_vm._v(" "),_c('span',{staticClass:"v-checkbox-label"},[_vm._t("default")],2),_vm._v(" "),(_vm.tooltipLabel)?_c('div',{staticClass:"v-checkbox-tooltip"},[_c('tooltip-molecule',{attrs:{"label":_vm.tooltipLabel}})],1):_vm._e()],1)};
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 VCheckbox = 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
  );

exports.default = VCheckbox;
