import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["value","onChange","total","getTotalLabel","size","form","className"];import"./PaginationNumberInput.css";import React,{forwardRef,useCallback,useEffect,useMemo}from"react";import{useIMask}from"react-imask";import{Text}from"../../Text";import{TextField}from"../../TextField";import{useMutableRef}from"../../../hooks/useMutableRef";import{cnMixFlex}from"../../../mixs/MixFlex";import{cn}from"../../../utils/bem";import{isNotNil}from"../../../utils/type-guards";import{paginationPropFormDefault,paginationPropSizeDefault}from"../types";var cnPaginationNumberInput=cn("PaginationNumberInput"),defaultGetTotalLabel=function(a){return"\u0438\u0437 ".concat(a)};export var PaginationNumberInput=forwardRef(function(a,b){var c=a.value,d=a.onChange,f=a.total,g=a.getTotalLabel,h=void 0===g?defaultGetTotalLabel:g,i=a.size,j=void 0===i?paginationPropSizeDefault:i,k=a.form,l=void 0===k?paginationPropFormDefault:k,m=a.className,n=_objectWithoutProperties(a,_excluded),o=useIMask({mask:Number,scale:0,min:1,max:f}),p=o.ref,q=o.value,r=o.setValue,s=useMutableRef(d),t=useMutableRef(q),u=useMutableRef(r),v=useMemo(function(){return{ArrowUp:function ArrowUp(a){a.preventDefault();var b=Math.max(Math.min(+t.current+1,f),1);u.current(b.toString())},ArrowDown:function ArrowDown(a){a.preventDefault();var b=Math.max(Math.min(+t.current-1,f),1);u.current(b.toString())},Enter:function Enter(a){if(a.preventDefault(),+t.current){var b;null===(b=s.current)||void 0===b?void 0:b.call(s,+t.current,{e:a})}}}},[f]),w=useCallback(function(a){var b;a.stopPropagation(),null===(b=v[a.key])||void 0===b?void 0:b.call(v,a)},[v]);return useEffect(function(){var a=(null===c||void 0===c?void 0:c.toString())||"";a!==t.current&&u.current(a)},[c]),React.createElement("div",Object.assign({},n,{className:cnPaginationNumberInput({size:j},[cnMixFlex({align:"center",justify:"center",gap:"xs"}),m]),ref:b}),React.createElement(TextField,{defaultValue:c?c.toString():void 0,size:j,form:l,inputRef:p,onKeyDown:w,className:cnPaginationNumberInput("Input")}),isNotNil(f)&&React.createElement(Text,{className:cnPaginationNumberInput("Total"),size:j},h(f)))});
//# sourceMappingURL=PaginationNumberInput.js.map