var _excluded = ["dataSource", "allowAdd", "onAdd", "onClick", "renderAddItem", "disabled", "isMultiple", "value", "onChange", "className"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo } from 'react';
import classNames from 'classnames';
import PisellViewGrid from "../pisellViewGrid";
import "./index.less";
var PisellCustomCheckboxGroup = function PisellCustomCheckboxGroup(_ref) {
  var _ref$dataSource = _ref.dataSource,
    dataSource = _ref$dataSource === void 0 ? [] : _ref$dataSource,
    _ref$allowAdd = _ref.allowAdd,
    allowAdd = _ref$allowAdd === void 0 ? false : _ref$allowAdd,
    onAdd = _ref.onAdd,
    _onClick = _ref.onClick,
    renderAddItem = _ref.renderAddItem,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$isMultiple = _ref.isMultiple,
    isMultiple = _ref$isMultiple === void 0 ? false : _ref$isMultiple,
    value = _ref.value,
    onChange = _ref.onChange,
    className = _ref.className,
    rest = _objectWithoutProperties(_ref, _excluded);
  /**
   * @title: 构建最终数据，如果允许添加，则增加一项
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-08 18:21
   */
  var finalDataSource = useMemo(function () {
    return allowAdd ? [{
      id: 0,
      text: '+',
      isAddCard: true
    }].concat(_toConsumableArray(dataSource)) : dataSource;
  }, [allowAdd, dataSource]);

  /**
   * @title: 渲染卡片
   * @description:
   * @param {any} item
   * @param {number} index
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-08 18:11
   */
  var renderGridItem = function renderGridItem(item, index) {
    var _rest$renderItem;
    return /*#__PURE__*/React.createElement("div", {
      onClick: function onClick() {
        return _onClick(item);
      },
      style: {
        height: '100%'
      }
    }, item !== null && item !== void 0 && item.isAddCard && renderAddItem ? renderAddItem(item) : rest === null || rest === void 0 || (_rest$renderItem = rest.renderItem) === null || _rest$renderItem === void 0 ? void 0 : _rest$renderItem.call(rest, item, index));
  };
  return /*#__PURE__*/React.createElement(PisellViewGrid, _extends({}, rest, {
    dataSource: finalDataSource,
    renderItem: function renderItem(item, index) {
      return renderGridItem(item, index);
    },
    className: classNames('pisell-custom-checkbox-group', className)
  }));
};
export default PisellCustomCheckboxGroup;