import { ReceiptContextProvider } from "../components/NewReceipt/contexts/ReceiptContext.tsx";
import ReceiptUserSelect from "../components/NewReceipt/components/ReceiptUserSelect.tsx";
import ReceiptEditor from "../components/NewReceipt/components/ReceiptEditor.tsx";
import { Button, Stack } from "@mantine/core";
import { useState } from "react";
import ReceiptQrCodeScan from "../components/ReceiptEditing/components/ReceiptQrCodeScan.tsx";
import PageBlock from "../../../components/PageBlock/PageBlock.tsx";

enum ReceiptType {
    NEW_RECEIPT,
    RECEIPT_EDITING,
    UNDEFINED,
}

const ReceiptPage = () => {
    const [receiptType, setReceiptType] = useState<ReceiptType>(ReceiptType.UNDEFINED);

    const getContent = () => {
        if (receiptType === ReceiptType.UNDEFINED) {
            return (
                <Stack h="95vh">
                    <Button
                        variant="default"
                        onClick={() => setReceiptType(ReceiptType.NEW_RECEIPT)}
                        h="100%"
                    >
                        Начать приемку
                    </Button>
                    <Button
                        variant="default"
                        onClick={() => setReceiptType(ReceiptType.RECEIPT_EDITING)}
                        h="100%"
                    >
                        Редактировать паллет/короб
                    </Button>
                </Stack>
            );
        }
        if (receiptType === ReceiptType.NEW_RECEIPT) {
            return (
                <ReceiptContextProvider>
                    <Stack>
                        <ReceiptUserSelect />
                        <ReceiptEditor />
                    </Stack>
                </ReceiptContextProvider>
            );
        }
        return (
            <ReceiptQrCodeScan />
        );
    };

    return (
        <PageBlock noBorderRadius style={{ minHeight: "100vh" }}>
            {getContent()}
        </PageBlock>
    );
};

export default ReceiptPage;
