import{_ as _extends}from"./_rollupPluginBabelHelpers-B5fk9IVe.js";import React__default,{useState,useEffect}from"react";import PropTypes from"prop-types";import{B as Button}from"./Button.component-BKRhw0J0.js";import{T as TextInput}from"./TextInput.component-CkNlIlj0.js";import{S as Select}from"./Select.component-H9Siw7mx.js";import{S as SelectOption}from"./SelectOption.component-Calg27TZ.js";import{S as Spinner}from"./Spinner.component-3BfGSLKB.js";import{S as Stack}from"./Stack.component-D-jW201_.js";const paginationStyles=`
  jn-flex
  jn-gap-[0.375rem]
  jn-items-center
`,spinnerStyles=`
  jn-ml-3
`,inputStyles=`
  justify-normal
`,Pagination=a=>{let{variant:c="default",currentPage:d=void 0,totalPages:e=void 0,pages:f=void 0,disabled:g=!1,isFirstPage:h=void 0,isLastPage:i=void 0,onPressPrevious:j=void 0,onPressNext:k=void 0,onSelectChange:l=void 0,onInputChange:m=void 0,onKeyPress:n=void 0,onBlur:o=void 0,progress:p=!1,className:q="",...b}=a;const[r,t]=useState(d),[u,v]=useState(f?f:e);useEffect(()=>{t(d),f?v(f):v(e),r>u&&t(u)},[d,e,f]);const w=a=>{const b=parseInt(a);t(b),l&&l(b)},x=a=>{let b=a?.target.value?parseInt(a?.target.value):void 0;1>b?b=1:b>u&&(b=u),t(b),m&&m(b)},y=a=>{"Enter"===a.key&&n&&n(r)},z=()=>{o&&o(r)},A=()=>{let a=isNaN(r)?1:r?.toString().length;a=5<a?5:a;const b=`${(.6*a+2.1).toFixed(1)}rem`;return{width:b}};return React__default.createElement("div",_extends({className:`juno-pagination juno-pagination-${c||"default"} ${paginationStyles} ${q}`},b),React__default.createElement(Button,{icon:"chevronLeft",disabled:!!h||!!g||!!p||!(1!==r),onClick:()=>{let a;r&&1<r&&(a=r-1,t(a)),j&&j(a)},title:"Previous Page"}),p?React__default.createElement(Spinner,{size:"small",color:"default",className:spinnerStyles}):"",c&&!p?(()=>"number"===c?r?React__default.createElement("div",{className:"page-value"}," ",r||""):"":"select"===c?React__default.createElement(Select,{name:"totalPages",width:"auto",value:r?.toString(),onChange:w,disabled:g},(()=>{let a=[];if(u)for(let b=0;b<u;b++){const c=(b+1).toString();a.push(React__default.createElement(SelectOption,{value:c,label:c,key:c}))}return a})()):"input"===c?React__default.createElement(Stack,{gap:"2",alignment:"center"},React__default.createElement("div",{className:`juno-pagination-wrapper`,style:A()},React__default.createElement(TextInput,{value:r?r:"",onChange:x,onBlur:z,onKeyPress:y,disabled:!!g,className:inputStyles,maxLength:"6"})),u?React__default.createElement("span",null,"of ",u):""):"")():"",React__default.createElement(Button,{icon:"chevronRight",disabled:!!i||!!g||!!p||!!(r&&r===u),onClick:()=>{let a;r&&(r<u||!u)&&(a=r+1,t(a)),k&&k(a)},title:"Next Page"}))};Pagination.propTypes={variant:PropTypes.oneOf(["default","number","select","input"]),currentPage:PropTypes.number,totalPages:PropTypes.number,pages:PropTypes.number,disabled:PropTypes.bool,isFirstPage:PropTypes.bool,isLastPage:PropTypes.bool,onPressPrevious:PropTypes.func,onPressNext:PropTypes.func,onSelectChange:PropTypes.func,onInputChange:PropTypes.func,onKeyPress:PropTypes.func,onBlur:PropTypes.func,progress:PropTypes.bool,className:PropTypes.string};export{Pagination as P};