import { useState, lazy, Suspense } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import IconButton from "@mui/material/IconButton";
import { useAuth } from "../context/AuthContext";
import Forbidden from "../components/Forbidden";
import {
Button,
Tabs,
TabPanel,
PageHeader,
PageEnter,
LoadingState,
} from "../ui";
import OrdersReceived from "./ReceivedOrders";
const IssuedOrders = lazy(() => import("./IssuedOrders"));
const MONTH_NAMES = [
"leden",
"únor",
"březen",
"duben",
"květen",
"červen",
"červenec",
"srpen",
"září",
"říjen",
"listopad",
"prosinec",
];
const PlusIcon = (
);
const ChevronLeftIcon = (
);
const ChevronRightIcon = (
);
export default function Orders() {
const { hasPermission } = useAuth();
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const activeTab =
searchParams.get("tab") === "prijate" ? "prijate" : "vydane";
const setActiveTab = (tab: string) =>
setSearchParams({ tab }, { replace: true });
const [createOpen, setCreateOpen] = useState(false);
const now = new Date();
const [statsMonth, setStatsMonth] = useState(now.getMonth() + 1);
const [statsYear, setStatsYear] = useState(now.getFullYear());
const isCurrentMonth =
statsMonth === now.getMonth() + 1 && statsYear === now.getFullYear();
const monthLabel = `${MONTH_NAMES[statsMonth - 1]} ${statsYear}`;
const prevMonth = () => {
if (statsMonth === 1) {
setStatsMonth(12);
setStatsYear((y) => y - 1);
} else {
setStatsMonth((m) => m - 1);
}
};
const nextMonth = () => {
if (isCurrentMonth) return;
if (statsMonth === 12) {
setStatsMonth(1);
setStatsYear((y) => y + 1);
} else {
setStatsMonth((m) => m + 1);
}
};
if (!hasPermission("orders.view")) return ;
return (
navigate("/orders/issued/new")}
>
Vytvořit objednávku
) : (
)
) : undefined
}
/>
{ChevronLeftIcon}
{monthLabel}
{ChevronRightIcon}
setActiveTab(v)}
tabs={[
{ value: "vydane", label: "Vydané" },
{ value: "prijate", label: "Přijaté" },
]}
/>
}>
);
}