"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CheckListItem = void 0;
var _react = _interopRequireWildcard(require("react"));
var _list = _interopRequireDefault(require("../list"));
var _nativeProps = require("../../utils/native-props");
var _context = require("./context");
var _devLog = require("../../utils/dev-log");
var _classnames = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const classPrefix = `adm-check-list-item`;
const CheckListItem = props => {
  const context = (0, _react.useContext)(_context.CheckListContext);
  if (context === null) {
    (0, _devLog.devWarning)('CheckList.Item', 'CheckList.Item can only be used inside CheckList.');
    return null;
  }
  const active = context.value.includes(props.value);
  const readOnly = props.readOnly || context.readOnly;
  const defaultExtra = active ? context.activeIcon : null;
  const renderExtra = context.extra ? context.extra(active) : defaultExtra;
  const extra = _react.default.createElement("div", {
    className: `${classPrefix}-extra`
  }, renderExtra);
  return (0, _nativeProps.withNativeProps)(props, _react.default.createElement(_list.default.Item, {
    title: props.title,
    className: (0, _classnames.default)(classPrefix, readOnly && `${classPrefix}-readonly`, active && `${classPrefix}-active`),
    description: props.description,
    prefix: props.prefix,
    onClick: e => {
      var _a;
      if (readOnly) return;
      if (active) {
        context.uncheck(props.value);
      } else {
        context.check(props.value);
      }
      (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
    },
    arrow: false,
    clickable: !readOnly,
    extra: extra,
    disabled: props.disabled || context.disabled
  }, props.children));
};
exports.CheckListItem = CheckListItem;