"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _create = _interopRequireDefault(require("../utils/create"));

var _unit = require("../utils/format/unit");

var _loading = _interopRequireDefault(require("../loading"));

var _field = require("../mixins/field");

var _default = (0, _create.default)({
  render: function render() {
    var _vm = this;

    var _h = _vm.$createElement;

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

    return _c('div', {
      class: _vm.b({
        on: _vm.checked,
        loading: _vm.loading,
        disabled: _vm.disabled
      }),
      style: _vm.style,
      attrs: {
        "role": "switch",
        "aria-checked": String(_vm.checked)
      },
      on: {
        "click": _vm.onClick
      }
    }, [_c('div', {
      class: _vm.b('node')
    }, [_vm.loading ? _c('loading', {
      class: _vm.b('-loading'),
      attrs: {
        "color": _vm.checked ? _vm.activeColor : _vm.inactiveColor
      }
    }) : _vm._e()], 1)]);
  },
  name: "switch",
  mixins: [_field.FieldMixin],
  components: {
    Loading: _loading.default
  },
  props: {
    size: [Number, String],
    value: Boolean,
    loading: Boolean,
    disabled: Boolean,
    activeColor: String,
    inactiveColor: String,
    activeValue: {
      type: Boolean,
      default: true
    },
    inactiveValue: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    checked: function checked() {
      return this.value === this.activeValue;
    },
    style: function style() {
      return {
        fontSize: (0, _unit.addUnit)(this.size),
        backgroundColor: this.checked ? this.activeColor : this.inactiveColor
      };
    }
  },
  methods: {
    onClick: function onClick(event) {
      this.$emit("click", event);

      if (!this.disabled && !this.loading) {
        var newValue = this.checked ? this.inactiveValue : this.activeValue;
        this.$emit("input", newValue);
        this.$emit("change", newValue);
      }
    }
  }
});

exports.default = _default;