"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("ts-debounce"),t=require("@prom-ui/core/useBodyTTag"),n=require("@prom-ui/core/Portal"),o=require("@prom-ui/core/Button"),i=require("@prom-ui/core/Icon"),l=require("@prom-ui/icons/ArrowUp");function u(e){if(e&&"object"==typeof e&&"default"in e)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var c,a=u(e);function f(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function s(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?f(Object(t),!0).forEach((function(r){p(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):f(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function p(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function b(){return b=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},b.apply(this,arguments)}function y(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function d(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,i,l,u=[],c=!0,a=!1;try{if(i=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;c=!1}else for(;!(c=(n=i.call(t)).done)&&(u.push(n.value),u.length!==r);c=!0);}catch(f){a=!0,o=f}finally{try{if(!c&&null!=t.return&&(l=t.return(),Object(l)!==l))return}finally{if(a)throw o}}return u}}(e,r)||function(e,r){if(!e)return;if("string"==typeof e)return m(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return m(e,r)}(e,r)||function(){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 m(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}var v=["children","scrollRef","onClick","scrollDelay","scrollOffset","margin","zIndex"],O={position:"fixed",right:0,bottom:0,width:"100%"},g={position:"sticky",bottom:0,height:0,width:"100%"},h=a.memo((function(e){var u=e.children,f=e.scrollRef,p=e.onClick,m=e.scrollDelay,h=void 0===m?100:m,j=e.scrollOffset,w=void 0===j?100:j,P=e.margin,E=void 0===P?"0 18px 18px 0":P,x=e.zIndex,S=void 0===x?10:x,I=y(e,v),z=t.useBodyTTag().t,A=d(a.useState(!1),2),D=A[0],k=A[1],q=function(){return(null==f?void 0:f.current)||document.documentElement},T=r.debounce((function(){var e=q(),r=e.scrollHeight-e.clientHeight>0,t=e.scrollTop>=w;k(r&&t)}),h);if(a.useEffect((function(){var e=(null==f?void 0:f.current)||document;return e.addEventListener("resize",T),e.addEventListener("scroll",T),T(),function(){e.removeEventListener("resize",T),e.removeEventListener("scroll",T)}}),[]),!D)return null;var B,U,C=null!=f&&f.current?a.Fragment:n.Portal,L=null!=f&&f.current?g:O;return a.createElement(C,null,a.createElement("div",{style:s(s({},L),{},{zIndex:S})},a.createElement(o.Button,b({"button-padding":"xs","button-theme":"white","button-round":"full","aria-label":z(c||(B=["Наверх"],U||(U=B.slice(0)),c=Object.freeze(Object.defineProperties(B,{raw:{value:Object.freeze(U)}}))))},I,{style:{position:"absolute",right:0,bottom:0,margin:E},onClick:function(e){"function"==typeof p&&p(e),q().scroll({top:0,behavior:"smooth"})}}),u||a.createElement(i.Icon,{"icon-as":l.SvgArrowUp,style:{width:24,height:24}}))))}));h.displayName="ButtonPageUp",h.defaultProps={scrollDelay:100,scrollOffset:100,margin:"0 18px 18px 0",zIndex:10},exports.ButtonPageUp=h;
