import React, { useState, useEffect } from 'react';
import classnames from 'classnames';
import CheckboxGroup from './checkbox-group';
var defaultProps = {
    prefixCls: 'ty-checkbox',
    defaultChecked: false,
};
var Checkbox = function (props) {
    var _a;
    var value = props.value, disabled = props.disabled, onChange = props.onChange, indeterminate = props.indeterminate, prefixCls = props.prefixCls, className = props.className, style = props.style, children = props.children;
    var _b = useState(('checked' in props) ? props.checked : props.defaultChecked), checked = _b[0], setChecked = _b[1];
    var cls = classnames(prefixCls, className, (_a = {},
        _a[prefixCls + "_indeterminate"] = indeterminate && !checked,
        _a[prefixCls + "_checked"] = checked && !indeterminate,
        _a[prefixCls + "_disabled"] = disabled,
        _a));
    var _onChange = function (e) {
        if (!disabled) {
            !('checked' in props) && setChecked(e.currentTarget.checked);
            onChange && onChange(e.currentTarget.checked, e);
        }
    };
    useEffect(function () {
        ('checked' in props) && setChecked(props.checked);
    });
    return (React.createElement("label", { className: cls, style: style },
        React.createElement("input", { name: value, disabled: disabled, className: prefixCls + "__native", type: "checkbox", checked: checked, onChange: _onChange }),
        React.createElement("span", { className: prefixCls + "__inner" }),
        React.createElement("span", null, children)));
};
Checkbox.defaultProps = defaultProps;
Checkbox.Group = CheckboxGroup;
export default Checkbox;
//# sourceMappingURL=index.js.map