"use strict";

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

var _extends2 = require("babel-runtime/helpers/extends");

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require("babel-runtime/helpers/createClass");

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require("babel-runtime/helpers/inherits");

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _checkbox = require("../checkbox");

var _checkbox2 = _interopRequireDefault(_checkbox);

var _Group = require("./Group");

var _Group2 = _interopRequireDefault(_Group);

require("@whalecloud/fdx-theme-fdx/check-item.less");

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

var CheckItem = function (_React$Component) {
    (0, _inherits3["default"])(CheckItem, _React$Component);

    function CheckItem(props) {
        (0, _classCallCheck3["default"])(this, CheckItem);

        var _this = (0, _possibleConstructorReturn3["default"])(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;
    }

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

            return _react2["default"].createElement(
                "span",
                { className: "check-item" },
                _react2["default"].createElement(_checkbox2["default"], (0, _extends3["default"])({}, this.props, { checked: checked, className: checked ? "input inputSelected" : "input", onChange: this.handelChange })),
                _react2["default"].createElement(
                    "span",
                    { className: "innerWrapTop" },
                    label
                ),
                _react2["default"].createElement(
                    "span",
                    { className: "innerWrapBtm" },
                    label
                )
            );
        }
    }], [{
        key: "getDerivedStateFromProps",
        value: function getDerivedStateFromProps(nextProps) {
            if ("checked" in nextProps) {
                return {
                    checked: nextProps.checked
                };
            }
            return null;
        }
    }]);
    return CheckItem;
}(_react2["default"].Component);

CheckItem.Group = _Group2["default"];
exports["default"] = CheckItem;
module.exports = exports['default'];