function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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 _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useEffect, useState } from 'react';
import { PisellModal, PisellCustomCheckboxGroup, PisellCard, PisellAvatar } from '@pisell/materials';
import { isMobile, locales } from '@pisell/utils';
import ErrorTip from "../ErrorTip";
import { mock } from "../../mock";
import "./index.less";
var PisellSelectHolder = function PisellSelectHolder(_ref) {
  var _ref$open = _ref.open,
    open = _ref$open === void 0 ? false : _ref$open,
    onCancel = _ref.onCancel,
    _onOk = _ref.onOk,
    _onClick = _ref.onClick,
    onAdd = _ref.onAdd,
    _ref$options = _ref.options,
    options = _ref$options === void 0 ? mock.holder || [] : _ref$options,
    value = _ref.value,
    title = _ref.title,
    okText = _ref.okText,
    showCancel = _ref.showCancel,
    disabled = _ref.disabled,
    errorTipText = _ref.errorTipText;
  var _useState = useState(),
    _useState2 = _slicedToArray(_useState, 2),
    errorTip = _useState2[0],
    setErrorTip = _useState2[1];
  useEffect(function () {
    if (open && !disabled) {
      setErrorTip('');
    }
  }, [open, disabled]);

  /**
   * @title: 渲染卡片
   * @description:
   * @param {any} item
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-13 12:19
   */
  var renderCard = function renderCard(item) {
    return /*#__PURE__*/React.createElement(PisellCard, {
      key: item.id,
      padding: 20,
      selected: value == item.id
    }, /*#__PURE__*/React.createElement("div", {
      className: "select-holder-card"
    }, /*#__PURE__*/React.createElement(PisellAvatar, {
      src: item.avatar,
      size: "xxl"
    }), /*#__PURE__*/React.createElement("span", {
      className: "select-holder-name"
    }, item.name)));
  };

  /**
   * @title: 渲染添加项
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-13 12:04
   */
  var renderAddItem = function renderAddItem() {
    return /*#__PURE__*/React.createElement(PisellCard, {
      padding: 20
    }, /*#__PURE__*/React.createElement("div", {
      className: "select-holder-card select-holder-add-card"
    }, /*#__PURE__*/React.createElement(PisellAvatar, {
      size: "xxl",
      className: "select-holder-card-avatar"
    }), /*#__PURE__*/React.createElement("span", {
      className: "select-holder-name"
    }, locales.getText('pisell2.event.create'))));
  };
  return /*#__PURE__*/React.createElement(PisellModal, {
    open: open,
    title: isMobile() ? '' : title,
    platform: isMobile() ? 'h5' : 'pc',
    okText: okText,
    cancelVisible: false,
    closable: showCancel,
    onCancel: onCancel,
    onOk: function onOk(e) {
      if (disabled) {
        return setErrorTip(errorTipText);
      }
      _onOk && _onOk(e);
    },
    bodyStyle: {
      padding: isMobile() ? '0 16px 16px' : 20
    },
    mobileModalHeight: 'auto',
    destroyOnClose: true,
    className: "select-holder-modal ".concat(isMobile() ? 'select-holder-modal-mobile' : ''),
    headerDivider: false
  }, isMobile() ? /*#__PURE__*/React.createElement("div", {
    className: "select-holder-modal-title"
  }, title) : null, errorTip ? /*#__PURE__*/React.createElement(ErrorTip, {
    text: errorTip
  }) : null, /*#__PURE__*/React.createElement(PisellCustomCheckboxGroup, {
    dataSource: options,
    renderItem: renderCard,
    renderAddItem: renderAddItem,
    columns: isMobile() ? 2 : 3,
    horizontalGap: 16,
    verticalGap: 16,
    allowAdd: true,
    onClick: function onClick(e) {
      return _onClick && _onClick(e);
    }
  }));
};
export default PisellSelectHolder;