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 from 'react';
import { Button } from 'antd';
import { Icon } from '@pisell/materials';
var ModelPickerGrid = function ModelPickerGrid(_ref) {
  var groups = _ref.groups,
    classNamePrefix = _ref.classNamePrefix,
    _ref$separator = _ref.separator,
    separator = _ref$separator === void 0 ? '__' : _ref$separator,
    groupTitleClassName = _ref.groupTitleClassName,
    translation = _ref.translation,
    onSelect = _ref.onSelect,
    getFallbackGroupTitle = _ref.getFallbackGroupTitle,
    renderMeta = _ref.renderMeta,
    _ref$useButton = _ref.useButton,
    useButton = _ref$useButton === void 0 ? true : _ref$useButton;
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(classNamePrefix).concat(separator, "model-groups")
  }, groups.map(function (_ref2) {
    var _items$;
    var _ref3 = _slicedToArray(_ref2, 2),
      typeCode = _ref3[0],
      items = _ref3[1];
    var type = (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.type;
    return /*#__PURE__*/React.createElement("div", {
      key: typeCode || 'default',
      className: "".concat(classNamePrefix).concat(separator, "model-group")
    }, /*#__PURE__*/React.createElement("div", {
      className: groupTitleClassName || "".concat(classNamePrefix).concat(separator, "model-group-title")
    }, type !== null && type !== void 0 && type.icon ? /*#__PURE__*/React.createElement(Icon, {
      type: type.icon
    }) : null, /*#__PURE__*/React.createElement("span", null, translation(type === null || type === void 0 ? void 0 : type.name) || (getFallbackGroupTitle === null || getFallbackGroupTitle === void 0 ? void 0 : getFallbackGroupTitle(typeCode)) || typeCode)), /*#__PURE__*/React.createElement("div", {
      className: "".concat(classNamePrefix).concat(separator, "model-grid")
    }, items.map(function (model) {
      var content = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
        className: "".concat(classNamePrefix).concat(separator, "model-name")
      }, translation(model.name) || model.code), renderMeta === null || renderMeta === void 0 ? void 0 : renderMeta(model));
      return useButton ? /*#__PURE__*/React.createElement(Button, {
        key: model.code,
        className: "".concat(classNamePrefix).concat(separator, "model-card"),
        onClick: function onClick() {
          return onSelect(model);
        }
      }, content) : /*#__PURE__*/React.createElement("div", {
        key: model.code,
        role: "button",
        tabIndex: 0,
        className: "".concat(classNamePrefix).concat(separator, "model-card"),
        onClick: function onClick() {
          return onSelect(model);
        }
      }, content);
    })));
  }));
};
export default ModelPickerGrid;