var _excluded = ["optionProps", "list", "value", "onReLoad", "onSelect"];
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 _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, { Fragment, forwardRef } from 'react';

// 内库使用-start
import LocaleUtil from "../../../utils/LocaleUtil";
import Result from "./../../Result";
import Button from "./../../Button";
import IndexBar from "./../../IndexBar";
// 内库使用-end

/* 测试使用-start
import { LocaleUtil, Result, Button, IndexBar } from 'seedsui-react'
测试使用-end */

var ListItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var optionProps = _ref.optionProps,
    list = _ref.list,
    value = _ref.value,
    onReLoad = _ref.onReLoad,
    onSelect = _ref.onSelect,
    props = _objectWithoutProperties(_ref, _excluded);
  // 错误信息
  var status = '500';

  // 显示分栏
  var indexes = {};
  if (Array.isArray(list) && !list.length) {
    // eslint-disable-next-line
    list = LocaleUtil.locale('暂无数据', 'SeedsUI_no_data');
    status = 'empty';
  }
  return /*#__PURE__*/React.createElement("div", _extends({}, props, {
    className: "cascader-main".concat(props !== null && props !== void 0 && props.className ? ' ' + props.className : ''),
    ref: ref
  }), typeof list === 'string' && /*#__PURE__*/React.createElement(Result, {
    title: list,
    status: status,
    className: "cascader-main-result"
  }, status === '500' && onReLoad && /*#__PURE__*/React.createElement(Button, {
    className: "primary result-button",
    onClick: onReLoad
  }, LocaleUtil.locale('重新加载', 'SeedsUI_reload'))), Array.isArray(list) && list.map(function (item, index) {
    var _value$some;
    // 字母分栏
    var anchorBar = null;
    if (item.anchor && !indexes[item.anchor]) {
      indexes[item.anchor] = true;
      anchorBar = /*#__PURE__*/React.createElement(IndexBar.Anchor, {
        className: "cascader-list-divider",
        name: item.anchor
      }, item.anchor);
    }
    return /*#__PURE__*/React.createElement(Fragment, {
      key: item.id || index
    }, anchorBar, /*#__PURE__*/React.createElement("div", _extends({}, optionProps, {
      className: "cascader-option".concat(optionProps.className ? ' ' + optionProps.className : '').concat(value !== null && value !== void 0 && (_value$some = value.some) !== null && _value$some !== void 0 && _value$some.call(value, function (selected) {
        return selected.id === item.id;
      }) ? ' active' : ''),
      onClick: function onClick(e) {
        e.stopPropagation();
        onSelect(item);
      }
    }), /*#__PURE__*/React.createElement("p", {
      className: "cascader-option-title"
    }, item.name), /*#__PURE__*/React.createElement("i", {
      className: "cascader-option-icon"
    })));
  }));
});
export default ListItem;