'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _jsx = function () { var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; return function createRawReactElement(type, props, key, children) { var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = {}; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : '' + key, ref: null, props: props, _owner: null }; }; }();

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _View = require('../View');

var _View2 = _interopRequireDefault(_View);

var _AbstractButton2 = require('../AbstractButton');

var _AbstractButton3 = _interopRequireDefault(_AbstractButton2);

var _theme = require('../const/theme');

var _styles = require('../helpers/styles');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Checkbox = function (_AbstractButton) {
    _inherits(Checkbox, _AbstractButton);

    function Checkbox() {
        _classCallCheck(this, Checkbox);

        return _possibleConstructorReturn(this, (Checkbox.__proto__ || Object.getPrototypeOf(Checkbox)).apply(this, arguments));
    }

    _createClass(Checkbox, [{
        key: 'render',
        value: function render() {
            return _react2.default.createElement(
                'button',
                _extends({}, this.getDefaultRenderProps(), {
                    className: _styles.css.apply(undefined, _toConsumableArray(this.buildStyleList(STYLE, 'root')))
                }),
                this.state.isChecked && _jsx(_View2.default, {
                    className: (0, _styles.css)(STYLE.viewRoot)
                }, void 0, _jsx('svg', {
                    width: '11',
                    height: '8',
                    viewBox: '0 0 11 7'
                }, void 0, _jsx('path', {
                    d: 'M0.844,2.844 L4.844,6.844 L10.844,0.844 ',
                    className: (0, _styles.css)(STYLE.icon)
                })))
            );
        }
    }]);

    return Checkbox;
}(_AbstractButton3.default);

Checkbox.propTypes = {
    /**
     * Is checkbox disabled.
     */
    isDisabled: _react.PropTypes.bool,
    /**
     * Is checkbox in checked state
     */
    isChecked: _react.PropTypes.bool,
    /**
     * On click event handler
     */
    onClick: _react.PropTypes.func
};
Checkbox.defaultProps = _extends({}, _AbstractButton3.default.defaultProps, {
    isToggleMod: true
});
exports.default = Checkbox;


var STYLE = _styles.StyleSheet.create({
    root: _extends({}, _AbstractButton3.default.BASE_ROOT_STYLE, {
        width: '.8rem',
        height: '.8rem',
        border: '1px solid ' + _theme.COLOR.BORDER,
        borderRadius: '2px',
        boxShadow: _theme.SHADOW.INPUT,
        transition: 'all .05s ease-in'
    }),
    rootIsChecked: {
        background: _theme.COLOR.ACTIVE,
        boxShadow: 'none'
    },
    rootIsDisabled: {
        cursor: 'default',
        transition: 'none',
        border: '1px solid #c3cacd',
        boxShadow: 'none',
        background: _theme.COLOR.DISABLED
    },
    rootIsFocused: {
        boxShadow: _theme.SHADOW.FOCUS + ', ' + _theme.SHADOW.INPUT
    },
    viewRoot: {
        alignItems: 'center',
        justifyContent: 'center'
    },
    iconRoot: {
        width: '100%',
        height: '100%'
    },
    icon: {
        stroke: _theme.COLOR.TEXT,
        strokeWidth: '1px',
        fill: 'none',
        fillRule: 'evenodd'
    }
});