import _extends from "babel-runtime/helpers/extends";
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
import _createClass from "babel-runtime/helpers/createClass";
import _possibleConstructorReturn from "babel-runtime/helpers/possibleConstructorReturn";
import _inherits from "babel-runtime/helpers/inherits";
import React from "react";
import Checkbox from "../checkbox";
import Group from "./Group";
import "@whalecloud/fdx-theme-fdx/check-item.less";

var CheckItem = function (_React$Component) {
    _inherits(CheckItem, _React$Component);

    function CheckItem(props) {
        _classCallCheck(this, CheckItem);

        var _this = _possibleConstructorReturn(this, (CheckItem.__proto__ || Object.getPrototypeOf(CheckItem)).call(this, props));

        _this.handelChange = function (e) {
            var onChange = _this.props.onChange;
            var checked = e.target.checked;

            if (onChange) {
                onChange(e);
            }
            _this.setState({ checked: checked });
        };
        _this.state = {
            checked: props.checked || props.defaultChecked
        };
        return _this;
    }

    _createClass(CheckItem, [{
        key: "render",
        value: function render() {
            var label = this.props.label;
            var checked = this.state.checked;

            return React.createElement(
                "span",
                { className: "check-item" },
                React.createElement(Checkbox, _extends({}, this.props, { checked: checked, className: checked ? "input inputSelected" : "input", onChange: this.handelChange })),
                React.createElement(
                    "span",
                    { className: "innerWrapTop" },
                    label
                ),
                React.createElement(
                    "span",
                    { className: "innerWrapBtm" },
                    label
                )
            );
        }
    }], [{
        key: "getDerivedStateFromProps",
        value: function getDerivedStateFromProps(nextProps) {
            if ("checked" in nextProps) {
                return {
                    checked: nextProps.checked
                };
            }
            return null;
        }
    }]);

    return CheckItem;
}(React.Component);

CheckItem.Group = Group;
export default CheckItem;