{"version":3,"file":"Pagination.DXdazCUf.mjs","names":["useState","_Fragment","pages"],"sources":["https:/framerusercontent.com/modules/ry4EezmbyJInROB947pp/WChwwU8eY8MU33FGHk4a/Pagination.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useState,useEffect,useLayoutEffect}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";const LIMIT=12;const OFFSET=0;const SCROLL_THRESHOLD=200;const PREVIOUS_CLASS=\"Previous\";const PREVIOUS_DISABLED_CLASS=\"Previous Disabled\";const NEXT_CLASS=\"Next\";const NEXT_DISABLED_CLASS=\"Next Disabled\";const PAGE_NUMBER_CLASS=\"Page Number\";const PAGE_NUMBER_ACTIVE_CLASS=\"Page Number Active\";const useStore=createStore({limit:LIMIT,offset:OFFSET,totalItems:null,currentPage:1});export const withCollectionList=Component=>{return props=>{const[store,setStore]=useStore();const[newProps,setNewProps]=useState(useState({...props,children:{...props.children,props:{...props.children.props,query:{...props.children.props.query,limit:{type:\"LiteralValue\",value:store.limit}}}}}));useEffect(()=>{if(store.totalItems===null){const queryTotalItems=document.querySelector(`.${props.className}none .${props.className}`).children.length;const newTotalItems=queryTotalItems-OFFSET;setStore({totalItems:Math.max(newTotalItems,0)});}},[props,store]);useLayoutEffect(()=>{setNewProps({...props,children:{...props.children,props:{...props.children.props,query:{...props.children.props.query,limit:{type:\"LiteralValue\",value:store.limit},offset:{type:\"LiteralValue\",value:store.offset}}}}});},[store.offset,store.limit,props]);return /*#__PURE__*/_jsxs(_Fragment,{children:[store.totalItems===null&&/*#__PURE__*/_jsx(\"div\",{className:`${props.className}none`,style:{display:\"none\"},children:/*#__PURE__*/_jsx(Component,{...props})}),/*#__PURE__*/_jsx(Component,{...newProps})]});};};export const withLoadMore=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({offset:OFFSET,totalItems:null,currentPage:1});},[]);return /*#__PURE__*/_jsx(_Fragment,{children:store.limit<store.totalItems&&/*#__PURE__*/_jsx(Component,{...props,onClick:()=>setStore({limit:store.limit+LIMIT})})});};};export const withInfiniteScroll=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({offset:OFFSET,totalItems:null,currentPage:1});},[]);useEffect(()=>{window.addEventListener(\"scroll\",handleScroll);return()=>{window.removeEventListener(\"scroll\",handleScroll);};},[store,store.limit,store.totalItems]);const handleScroll=()=>{if(store.totalItems&&store.limit<store.totalItems&&window.innerHeight+document.documentElement.scrollTop>=document.documentElement.offsetHeight-SCROLL_THRESHOLD){setStore({limit:store.limit+LIMIT});}};return /*#__PURE__*/_jsx(Component,{...props});};};export const withPrevious=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);const handlePreviousPage=()=>{if(store.currentPage>1){const newPage=store.currentPage-1;const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);}};return /*#__PURE__*/_jsx(Component,{...props,onClick:handlePreviousPage,variant:store.currentPage!==1?PREVIOUS_CLASS:PREVIOUS_DISABLED_CLASS});};};export const withNext=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);const handleNextPage=()=>{if(store.currentPage*LIMIT<store.totalItems){const newPage=store.currentPage+1;const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);}};return /*#__PURE__*/_jsx(Component,{...props,onClick:handleNextPage,variant:store.currentPage*LIMIT<store.totalItems?NEXT_CLASS:NEXT_DISABLED_CLASS});};};export const withCurrentPage=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);const[currentPage,setCurrentPage]=useState(()=>store.currentPage.toString());const[totalPages,setTotalPages]=useState(()=>Math.ceil(store.totalItems/LIMIT));useEffect(()=>{setCurrentPage(store.currentPage.toString());setTotalPages(Math.ceil(store.totalItems/LIMIT));},[store.currentPage,store.totalItems]);return /*#__PURE__*/_jsx(Component,{...props,page:`${currentPage}/${totalPages}`});};};export const withPageSelector=Component=>{return props=>{const[store,setStore]=useStore();const[pages,setPages]=useState([]);useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);useEffect(()=>{const generatePages=()=>{const totalPages=Math.ceil(store.totalItems/LIMIT);const newPages=Array.from({length:totalPages},(_,index)=>index+1);setPages(newPages);};generatePages();},[store.totalItems]);const handleNewPage=newPage=>{const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);};return /*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",flexDirection:\"row\"},children:pages.map((item,index)=>{return /*#__PURE__*/_jsx(Component,{...props,page:item.toString(),onClick:()=>handleNewPage(item),variant:store.currentPage===item?PAGE_NUMBER_ACTIVE_CLASS:PAGE_NUMBER_CLASS},index);})});};};export const withTablePagination=Component=>{return props=>{const[store,setStore]=useStore();const[pages,setPages]=useState([]);useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);useEffect(()=>{const generatePages=()=>{const totalPages=Math.ceil(store.totalItems/LIMIT);const adjacentPages=store.currentPage===1||store.currentPage===totalPages?2:1;const pages=[];for(let i=1;i<=totalPages;i++){const isWithinRange=i>=store.currentPage-adjacentPages&&i<=store.currentPage+adjacentPages;if(i===1||i===totalPages||isWithinRange){pages.push(i);}else if(i===store.currentPage-adjacentPages-1&&i!==1||i===store.currentPage+adjacentPages+1&&i!==totalPages){pages.push(\"...\");}}setPages(pages);};generatePages();},[store.totalItems,store.currentPage]);const handleNewPage=newPage=>{const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);};return /*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",flexDirection:\"row\"},children:pages.map((item,index,array)=>{const isEllipsis=item===\"...\";return /*#__PURE__*/_jsx(Component,{...props,page:item.toString(),onClick:()=>!isEllipsis&&handleNewPage(item),variant:store.currentPage===item||isEllipsis?PAGE_NUMBER_ACTIVE_CLASS:PAGE_NUMBER_CLASS},index);})});};};export const withClear=Component=>{return props=>{const[store,setStore]=useStore();const handleClick=()=>{setStore({offset:OFFSET,totalItems:null,currentPage:1,limit:LIMIT});};return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};};\nexport const __FramerMetadata__ = {\"exports\":{\"withPageSelector\":{\"type\":\"reactHoc\",\"name\":\"withPageSelector\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCollectionList\":{\"type\":\"reactHoc\",\"name\":\"withCollectionList\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withInfiniteScroll\":{\"type\":\"reactHoc\",\"name\":\"withInfiniteScroll\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCurrentPage\":{\"type\":\"reactHoc\",\"name\":\"withCurrentPage\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withNext\":{\"type\":\"reactHoc\",\"name\":\"withNext\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPrevious\":{\"type\":\"reactHoc\",\"name\":\"withPrevious\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTablePagination\":{\"type\":\"reactHoc\",\"name\":\"withTablePagination\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLoadMore\":{\"type\":\"reactHoc\",\"name\":\"withLoadMore\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withClear\":{\"type\":\"reactHoc\",\"name\":\"withClear\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Pagination.map"],"mappings":"uPAA+E,IAAsD,IAAqE,CAAM,EAAM,GAAS,EAAO,EAAuL,EAAkB,cAAoB,EAAyB,qBAA2B,EAAS,EAAY,CAAC,MAAM,EAAM,OAAO,EAAO,WAAW,KAAK,YAAY,EAAE,CAAC,CAAc,EAAmB,GAAmB,GAAO,CAAC,GAAK,CAAC,EAAM,GAAU,GAAU,CAAM,CA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