"use strict";

exports.__esModule = true;
exports.Checkbox = void 0;
var _react = _interopRequireWildcard(require("react"));
var _typography = require("../typography");
var _icon = require("../icon");
var _box = _interopRequireDefault(require("../templates/box"));
var _flex = _interopRequireDefault(require("../templates/flex"));
var _styled = require("./styled");
var _excluded = ["checked", "disabled", "iconProps", "checkboxProps", "indeterminate", "Label", "label", "labelProps", "labelPosition", "onChange"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
var Checkbox = exports.Checkbox = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var checked = _ref.checked,
    disabled = _ref.disabled,
    iconProps = _ref.iconProps,
    _ref$checkboxProps = _ref.checkboxProps,
    checkboxProps = _ref$checkboxProps === void 0 ? {} : _ref$checkboxProps,
    indeterminate = _ref.indeterminate,
    _ref$Label = _ref.Label,
    Label = _ref$Label === void 0 ? _typography.Text : _ref$Label,
    label = _ref.label,
    labelProps = _ref.labelProps,
    _ref$labelPosition = _ref.labelPosition,
    labelPosition = _ref$labelPosition === void 0 ? "right" : _ref$labelPosition,
    onChange = _ref.onChange,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var onClick = function onClick(e) {
    e.preventDefault();
    if (disabled) return;
    onChange == null || onChange(!checked, e);
  };
  return /*#__PURE__*/_react["default"].createElement(_flex["default"], _extends({
    as: "label",
    position: "relative",
    alignItems: "center",
    gap: 1,
    cursor: disabled ? "auto" : "pointer",
    rowReverse: labelPosition === "right",
    "data-testid": "checkbox",
    disabled: disabled
  }, rest, {
    onClick: onClick
  }), label && /*#__PURE__*/_react["default"].createElement(_typography.Text, _extends({
    as: Label,
    opacity: disabled ? 0.4 : 1
  }, labelProps), label), /*#__PURE__*/_react["default"].createElement(_box["default"], {
    width: "16px",
    height: "16px"
  }, /*#__PURE__*/_react["default"].createElement(_styled.HiddenCheckboxInput, _extends({
    "data-testid": "checkbox-input",
    ref: ref,
    disabled: disabled
  }, indeterminate && {
    "data-indeterminate": true
  }, {
    "data-checked": checked
  })), /*#__PURE__*/_react["default"].createElement(_styled.Checkbox, _extends({
    "data-testid": "styled-checkbox",
    disabled: disabled
  }, checkboxProps), (!!checked || !!indeterminate) && /*#__PURE__*/_react["default"].createElement(_icon.Icon, _extends({
    disabled: disabled,
    name: indeterminate ? "checkmark_partial_s" : "checkmark_s",
    width: "16px",
    height: "16px",
    color: "accent",
    hoverColor: "primary"
  }, iconProps)))));
});