"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactRouter = require("react-router");
var _addonActions = require("@storybook/addon-actions");
var _ReactRouterLinkHelper = require("../../common/Links/ReactRouterLinkHelper");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var View = function View(_ref) {
  var currentPage = _ref.currentPage,
    setCurrentPage = _ref.setCurrentPage;
  var params = (0, _reactRouter.useParams)();
  (0, _react.useEffect)(function () {
    var matchPage = +params.page;
    if (currentPage !== matchPage) {
      (0, _addonActions.action)('Page change via router')(params);
      setCurrentPage(matchPage);
    }
  }, [currentPage, setCurrentPage, params]);
  return _react.default.createElement("pre", null, _react.default.createElement("code", null, JSON.stringify(params, null, 2)));
};
var PaginationRouteHelper = function PaginationRouteHelper(_ref2) {
  var children = _ref2.children,
    currentPage = _ref2.currentPage,
    setCurrentPage = _ref2.setCurrentPage;
  return _react.default.createElement(_ReactRouterLinkHelper.Provider, null, children, _react.default.createElement(_reactRouter.Routes, null, _react.default.createElement(_reactRouter.Route, {
    path: "/:page",
    element: _react.default.createElement(View, {
      currentPage: currentPage,
      setCurrentPage: setCurrentPage
    })
  })));
};
var _default = exports.default = PaginationRouteHelper;