(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../typography/P2", "../hooks/useStateProps", "./styles"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importDefault)(require("react"));
    var P2_1 = (0, tslib_1.__importDefault)(require("../typography/P2"));
    var useStateProps_1 = require("../hooks/useStateProps");
    var styles_1 = require("./styles");
    var CheckBox = react_1.default.forwardRef(function (_a, ref) {
        var className = _a.className, label = _a.label, inputRef = _a.inputRef, tabIndex = _a.tabIndex, isChecked = _a.isChecked, onChange = _a.onChange, isDisabled = _a.isDisabled, name = _a.name, isIndeterminate = _a.isIndeterminate, onBlur = _a.onBlur, onFocus = _a.onFocus, _b = _a.testId, testId = _b === void 0 ? "testIDWithoutName" : _b, props = (0, tslib_1.__rest)(_a, ["className", "label", "inputRef", "tabIndex", "isChecked", "onChange", "isDisabled", "name", "isIndeterminate", "onBlur", "onFocus", "testId"]);
        var _c = (0, tslib_1.__read)((0, useStateProps_1.useStateProps)(typeof isChecked === "undefined" ? false : isChecked), 2), checked = _c[0], setChecked = _c[1];
        var handleChange = function (event) {
            setChecked(function (prevState) { return !prevState; });
            onChange === null || onChange === void 0 ? void 0 : onChange(event, !checked);
        };
        var handlePressEnter = function (event) {
            if (event.key === "Enter") {
                setChecked(function (prevState) { return !prevState; });
                onChange === null || onChange === void 0 ? void 0 : onChange(event, !checked);
            }
        };
        return (react_1.default.createElement(styles_1.CheckBoxStyled, (0, tslib_1.__assign)({}, props, { className: className, "data-testid": testId + "_checkBox", "data-element": "checkBox", ref: ref, onClick: function (event) {
                var _a;
                event.stopPropagation();
                (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
            }, onMouseDown: function (e) { return e.preventDefault(); }, isDisabled: isDisabled, isIndeterminate: isIndeterminate, isChecked: checked }),
            checked && !isIndeterminate && (react_1.default.createElement(styles_1.IconBrokenTickStyled, { width: 24, height: 24, className: "checkbox-icon" })),
            isIndeterminate && (react_1.default.createElement(styles_1.IconBrokenMinusStyled, { width: 24, height: 24, className: "checkbox-icon" })),
            react_1.default.createElement(styles_1.InputStyled, { "data-element": "checkBox-input", checked: checked, ref: inputRef, tabIndex: tabIndex, type: "checkbox", onChange: handleChange, onKeyUp: handlePressEnter, disabled: isDisabled, name: name, onFocus: onFocus, onBlur: onBlur, isIndeterminate: isIndeterminate, isChecked: checked }),
            react_1.default.createElement(P2_1.default, { type: "corvus", "data-element": "checkBox-label" }, label)));
    });
    CheckBox.displayName = "CheckBox";
    exports.default = CheckBox;
});
