"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.BulkSelectionMaxSelectionLabel = BulkSelectionMaxSelectionLabel;
exports.fromMultipleSelectionToBoolean = fromMultipleSelectionToBoolean;
exports.reachedMaxSelection = reachedMaxSelection;
exports.showMaxSelectionLabel = showMaxSelectionLabel;
var _react = _interopRequireDefault(require("react"));
var _designSystem = require("@wix/design-system");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/MaxSelection.tsx";
function fromMultipleSelectionToBoolean(multipleSelection) {
  if (multipleSelection === undefined) {
    return false;
  }
  if (typeof multipleSelection === 'boolean') {
    return multipleSelection;
  }
  return multipleSelection > 1;
}
function maxSelectedItemsFromMultipleSelection(multipleSelection) {
  if (typeof multipleSelection === 'undefined') {
    return 1;
  }
  if (typeof multipleSelection === 'boolean') {
    return multipleSelection ? Infinity : 1;
  }
  return multipleSelection;
}
function showMaxSelectionLabel(multipleSelection) {
  const maxSelectedItems = maxSelectedItemsFromMultipleSelection(multipleSelection);
  return !(maxSelectedItems === 1 || maxSelectedItems === Infinity);
}
function BulkSelectionMaxSelectionLabel(props) {
  const {
    selectedCount,
    t,
    multiple,
    dataHook
  } = props;
  const maxSelectedItems = maxSelectedItemsFromMultipleSelection(multiple);
  let text;
  if (props.customLabel) {
    text = props.customLabel({
      num: selectedCount,
      max: maxSelectedItems
    });
  } else if (selectedCount === 0) {
    text = t('cairo.bulkSelected.selectUpTo', {
      max: maxSelectedItems
    });
  } else if (maxSelectedItems > selectedCount) {
    text = t('cairo.picker.itemsSelected', {
      total: selectedCount,
      max: maxSelectedItems
    });
  } else {
    text = t('cairo.bulkSelected.withMaxNumber', {
      num: selectedCount,
      max: maxSelectedItems
    });
  }
  return /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
    dataHook: dataHook,
    secondary: true,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 84,
      columnNumber: 5
    }
  }, text);
}
function reachedMaxSelection({
  collection,
  multiple
}) {
  if (typeof multiple === 'undefined' || typeof multiple === 'boolean' || multiple <= 1) {
    return false;
  }
  return collection.bulkSelect.selectedCount >= multiple;
}
//# sourceMappingURL=MaxSelection.js.map