import { Card, Deck } from "@/Deck"; import { useCallback, useRef, useState } from "react" export const useDeck = () => { const deck = useRef(new Deck()); const shuffle = useCallback(() => { deck.current.shuffle(); }, []) const reshuffle = useCallback(() => { deck.current.reshuffle(); }, []) const createHand = useCallback(() => deck.current.createHand(), []) const drawToHand = useCallback((index: number, count?: number, reshuffle?: boolean) => { deck.current.drawToHand(index, count, reshuffle); }, []) const addCard = useCallback((...cards: Card[]) => { deck.current.addCard(...cards) }, []) const getDeck = useCallback(() => deck.current.getDeck(), []); const getDiscard = useCallback(() => deck.current.getDiscard(), []); const getHands = useCallback(() => deck.current.hands, []); const createDeck = useCallback((cards: Card[]) => { deck.current = new Deck(cards); }, []) return { deck: getDeck(), discard: getDiscard(), hands: getHands(), shuffle, reshuffle, createHand, drawToHand, addCard, createDeck } }