import React, { useMemo } from "react";
import { Empty, Input, PisellMenu } from "@pisell/materials";
import { SearchOutlined } from "@ant-design/icons";
import "./index.less";
var hasAnyLeaf = function hasAnyLeaf(items) {
  if (!items || !items.length) return false;
  return items.some(function (it) {
    if (!it) return false;
    if (it.type === 'group') {
      return hasAnyLeaf(it.children);
    }
    return true;
  });
};
var SiderMenuPanel = function SiderMenuPanel(_ref) {
  var title = _ref.title,
    searchable = _ref.searchable,
    searchPlaceholder = _ref.searchPlaceholder,
    onSearch = _ref.onSearch,
    items = _ref.items,
    selectedKey = _ref.selectedKey,
    _onSelect = _ref.onSelect,
    emptyText = _ref.emptyText;
  var isEmpty = useMemo(function () {
    return !hasAnyLeaf(items);
  }, [items]);
  return /*#__PURE__*/React.createElement("div", {
    className: "saas-device-profile-panel"
  }, title && /*#__PURE__*/React.createElement("div", {
    className: "saas-device-profile-title"
  }, title), searchable && /*#__PURE__*/React.createElement(Input, {
    allowClear: true,
    prefix: /*#__PURE__*/React.createElement(SearchOutlined, {
      className: "saas-device-profile-search-icon"
    }),
    placeholder: searchPlaceholder !== null && searchPlaceholder !== void 0 ? searchPlaceholder : "Search...",
    onChange: function onChange(e) {
      return onSearch === null || onSearch === void 0 ? void 0 : onSearch(e.target.value);
    }
  }), /*#__PURE__*/React.createElement("div", {
    className: "saas-device-profile-menu-scroll"
  }, isEmpty ? /*#__PURE__*/React.createElement(Empty, {
    image: Empty.PRESENTED_IMAGE_SIMPLE,
    description: emptyText !== null && emptyText !== void 0 ? emptyText : null
  }) : /*#__PURE__*/React.createElement(PisellMenu, {
    mode: "inline",
    theme: "light",
    dataSource: items,
    selectedKeys: [selectedKey],
    onSelect: function onSelect(_ref2) {
      var key = _ref2.key;
      return _onSelect(String(key));
    }
  })));
};
export default SiderMenuPanel;