"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ListIcon = exports.ListItem = exports.List = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireWildcard(require("react"));

var _Box = require("../Box");

var _Icon = require("../Icon");

var _PseudoBox = require("../PseudoBox");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var __jsx = _react["default"].createElement;
var List = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var _ref$styleType = _ref.styleType,
      styleType = _ref$styleType === void 0 ? 'none' : _ref$styleType,
      _ref$stylePos = _ref.stylePos,
      stylePos = _ref$stylePos === void 0 ? 'inside' : _ref$stylePos,
      children = _ref.children,
      props = (0, _objectWithoutProperties2["default"])(_ref, ["styleType", "stylePos", "children"]);
  return __jsx(_Box.Box, (0, _extends2["default"])({
    ref: ref,
    as: "ul",
    listStyleType: styleType,
    listStylePosition: stylePos
  }, props), _react.Children.map(children, function (child, index) {
    if (! /*#__PURE__*/(0, _react.isValidElement)(child)) {
      return null;
    }

    var isLast = index + 1 === _react.Children.count(children);

    if (isLast) {
      return child;
    }

    return /*#__PURE__*/(0, _react.cloneElement)(child);
  }));
});
exports.List = List;
var ListItem = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  return __jsx(_PseudoBox.PseudoBox, (0, _extends2["default"])({
    ref: ref,
    as: "li",
    mb: "spacing-xs"
  }, props));
});
exports.ListItem = ListItem;

var ListIcon = function ListIcon(_ref2) {
  var icon = _ref2.icon,
      props = (0, _objectWithoutProperties2["default"])(_ref2, ["icon"]);

  if (typeof icon === 'string') {
    return __jsx(_Icon.Icon, (0, _extends2["default"])({
      name: icon,
      mr: "spacing"
    }, props));
  }

  return __jsx(_Box.Box, (0, _extends2["default"])({
    as: icon,
    d: "inline",
    focusable: "false",
    size: "1em",
    color: "currentColor",
    mr: "spacing"
  }, props));
};

exports.ListIcon = ListIcon;
//# sourceMappingURL=List.js.map