"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PagesButtons = PagesButtons;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _button = require("../button");
var _useTranslation = require("../hooks/use-translation");
var _utils = require("./utils");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function PagesButtons({
  pageCount,
  selectedPage,
  onPageSelect
}) {
  const layoutArray = (0, _react.useMemo)(() => (0, _utils.getPaginationLayout)({
    selectedPage,
    pageCount
  }), [selectedPage, pageCount]);
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
    children: layoutArray.map((item, index, array) => {
      if (item === '...') {
        return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "pagination-buttons-dots",
          children: "..."
        }, index);
      }
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
        accentType: _button.ACCENT_TYPES.GHOST,
        onClick: () => {
          if (item !== selectedPage) {
            onPageSelect(item);
          }
        },
        "aria-current": item === selectedPage,
        "aria-label": t('Page {{number}}', {
          number: item + 1
        }),
        className: (0, _classnames.default)('page-button', {
          active: item === selectedPage,
          first: index === 0,
          last: index === array.length - 1
        }),
        testId: `page-button-${item + 1}`,
        children: item + 1
      }, index);
    })
  });
}