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, { useState } from 'react';

// 内库使用-start
import DOMUtil from "./../../../../utils/DOMUtil";
// 内库使用-end

/* 测试使用-start
import { DOMUtil } from 'seedsui-react'
测试使用-end */

// 内库使用-start
import ActionSheet from "./../../../ActionSheet";
// 内库使用-end

/* 测试使用-start
import { ActionSheet } from 'seedsui-react'
测试使用-start */

// 图文组合
export default function Tab(_ref) {
  var disabled = _ref.disabled,
    icon = _ref.icon,
    type = _ref.type,
    id = _ref.id,
    name = _ref.name,
    childrenList = _ref.childrenList,
    _onChange = _ref.onChange;
  // ActionSheet
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    visible = _useState2[0],
    setVisible = _useState2[1];
  function handleClick() {
    if (Array.isArray(childrenList) && childrenList.length) {
      setVisible(true);
      return;
    }
    _onChange && _onChange({
      type: type,
      id: id,
      name: name
    });
  }

  // 获取选中状态的Node
  function getIconNode() {
    if (typeof icon === 'string') {
      return /*#__PURE__*/React.createElement("i", {
        className: icon
      });
    }
    if (typeof icon === 'function') {
      return icon({
        type: type,
        id: id,
        name: name
      });
    }
    if ( /*#__PURE__*/React.isValidElement(icon)) {
      return icon;
    }
    return /*#__PURE__*/React.createElement("i", {
      className: "layout-footer-tab-icon-more"
    });
  }
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: DOMUtil.classNames('layout-footer-tab', disabled ? 'disabled' : ''),
    onClick: handleClick
  }, /*#__PURE__*/React.createElement("span", {
    className: "layout-footer-tab-icon"
  }, getIconNode()), /*#__PURE__*/React.createElement("div", {
    className: "layout-footer-tab-name"
  }, name)), Array.isArray(childrenList) && childrenList.length ? /*#__PURE__*/React.createElement(ActionSheet.Modal, {
    visible: visible,
    list: childrenList,
    onChange: function onChange(newValue) {
      _onChange && _onChange(newValue);
      setVisible(false);
    },
    onVisibleChange: setVisible
  }) : null);
}