/*! bxs-vue-ui v3.3.0 */
'use strict';

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

require('../utils/entry-virtual.js');
var normalizeComponent = require('../utils/normalize-component.js');
var isArray = require('../utils/is-array.js');
var slice = require('../utils/slice.js');
var emitter = require('../utils/emitter.js');

//
var script = normalizeComponent.create({
  name: 'switch',
  mixins: [emitter.Emitter],
  props: {
    value: {
      type: Boolean,
      default: false
    },
    activeColor: {
      type: String,
      default: '#508cee'
    }
  },
  data: function data() {
    return {};
  },
  computed: {
    style: function style() {
      var style = {};

      if (this.activeColor && this.selected) {
        style.backgroundColor = this.activeColor;
      } else {
        style.backgroundColor = '#fff';
      }

      return style;
    },
    selected: {
      get: function get() {
        return this.value;
      },
      set: function set(val) {
        this.$emit('input', val);
      }
    }
  },
  methods: {
    onClick: function onClick() {
      this.selected = !this.selected;
    }
  },
  watch: {
    selected: function selected() {
      this.$emit('change', this.selected);
      this.dispatch('bxs-form-item', 'form.item.validate');
    }
  }
});

var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('div', {
    staticClass: "bx-switch-box"
  }, [_c('input', {
    directives: [{
      name: "model",
      rawName: "v-model",
      value: _vm.selected,
      expression: "selected"
    }],
    staticClass: "bx-switch",
    style: _vm.style,
    attrs: {
      "type": "checkbox"
    },
    domProps: {
      "checked": isArray._Array$isArray(_vm.selected) ? _vm._i(_vm.selected, null) > -1 : _vm.selected
    },
    on: {
      "change": function change($event) {
        var $$a = _vm.selected,
            $$el = $event.target,
            $$c = $$el.checked ? true : false;

        if (isArray._Array$isArray($$a)) {
          var $$v = null,
              $$i = _vm._i($$a, $$v);

          if ($$el.checked) {
            $$i < 0 && (_vm.selected = normalizeComponent._concatInstanceProperty($$a).call($$a, [$$v]));
          } else {
            var _context;

            $$i > -1 && (_vm.selected = normalizeComponent._concatInstanceProperty(_context = slice._sliceInstanceProperty($$a).call($$a, 0, $$i)).call(_context, slice._sliceInstanceProperty($$a).call($$a, $$i + 1)));
          }
        } else {
          _vm.selected = $$c;
        }
      }
    }
  }), _c('span', {
    staticClass: "bx-switch-circle",
    on: {
      "click": _vm.onClick
    }
  })]);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

var index = 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 = index;
