'use strict';

var iconsReact = require('@cloudtower/icons-react');
var index$2 = require('../Button/index.js');
var index$3 = require('../Icon/index.js');
var index$4 = require('../InputInteger/index.js');
var index = require('../Pagination/index.js');
var index$1 = require('../Typo/index.js');
var useParrotTranslation = require('../../hooks/useParrotTranslation.js');
var cs = require('classnames');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var cs__default = /*#__PURE__*/_interopDefault(cs);
var React__default = /*#__PURE__*/_interopDefault(React);

const inputStyle = "E_ivqqkzv";
const SimplePagination = props => {
  const {
    className,
    current,
    count,
    size,
    onPageChange
  } = props;
  const {
    t
  } = useParrotTranslation();
  const pageLength = count === 0 ? 1 : Math.ceil(count / size);
  const showPrev = current > 1;
  const showNext = current * size < count;
  const changeValue = React.useCallback(value => {
    const page = parseInt(value);
    if (page > 0) {
      onPageChange == null ? void 0 : onPageChange(Math.min(pageLength, page));
    } else {
      onPageChange == null ? void 0 : onPageChange(1);
    }
  }, [onPageChange, pageLength]);
  return /* @__PURE__ */React__default.default.createElement("div", {
    className: cs__default.default(index.PaginationStyle, "pagination-wrapper", className)
  }, /* @__PURE__ */React__default.default.createElement("span", {
    className: index$1.Typo.Label.l3_regular_title
  }, t("components.pagination_lots_total", {
    count
  })), /* @__PURE__ */React__default.default.createElement("span", {
    className: "pagination-right"
  }, showPrev && /* @__PURE__ */React__default.default.createElement(index$2, {
    className: "prev-btn",
    type: "quiet",
    size: "small",
    style: {
      marginRight: "8px"
    },
    prefixIcon: /* @__PURE__ */React__default.default.createElement(index$3, {
      alt: "arrowChevronLeftSmall16BoldBlue",
      src: iconsReact.ArrowChevronLeftSmall16BoldBlueIcon
    }),
    onClick: () => {
      onPageChange == null ? void 0 : onPageChange(current - 1);
    }
  }), /* @__PURE__ */React__default.default.createElement(index$4.default, {
    className: cs__default.default(index$1.Typo.Label.l3_regular, inputStyle),
    value: current,
    size: "small",
    onKeyDown: event => {
      if (event.key === "Enter") {
        changeValue(event.target.value);
      }
    },
    onBlur: event => {
      changeValue(event.target.value);
    }
  }), /* @__PURE__ */React__default.default.createElement("span", {
    className: cs__default.default("E_c1wk4q29", index$1.Typo.Label.l3_regular_upper)
  }, `/ ${pageLength}`), showNext && /* @__PURE__ */React__default.default.createElement(index$2, {
    className: "next-btn",
    type: "quiet",
    size: "small",
    style: {
      marginLeft: "8px"
    },
    prefixIcon: /* @__PURE__ */React__default.default.createElement(index$3, {
      alt: "arrowChevronLeftSmall16BoldBlue",
      src: iconsReact.ArrowChevronLeftSmall16BoldBlueIcon
    }),
    onClick: () => {
      onPageChange == null ? void 0 : onPageChange(current + 1);
    }
  })));
};
var SimplePagination$1 = SimplePagination;

module.exports = SimplePagination$1;
