import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { motion } from "framer-motion"; import Box from "@mui/material/Box"; import { useAuth } from "../context/AuthContext"; import Forbidden from "../components/Forbidden"; import { usePaginatedQuery } from "../hooks/usePaginatedQuery"; import { formatDate } from "../utils/formatters"; import { warehouseInventoryListOptions, type WarehouseInventorySession, } from "../lib/queries/warehouse"; import { Button, Card, DataTable, Pagination, Select, StatusChip, PageHeader, FilterBar, EmptyState, LoadingState, type DataColumn, } from "../ui"; const PER_PAGE = 20; const STATUS_COLOR: Record< string, "warning" | "success" | "error" | "info" | "default" > = { DRAFT: "warning", CONFIRMED: "success", }; const STATUS_LABEL: Record = { DRAFT: "Návrh", CONFIRMED: "Potvrzeno", }; const PlusIcon = ( ); export default function WarehouseInventory() { const { hasPermission } = useAuth(); const navigate = useNavigate(); const [page, setPage] = useState(1); const [statusFilter, setStatusFilter] = useState(""); const { items, pagination, isPending, isFetching } = usePaginatedQuery( warehouseInventoryListOptions({ page, perPage: PER_PAGE, status: statusFilter || undefined, }), ); if (!hasPermission("warehouse.inventory")) return ; const resetFilters = () => { setStatusFilter(""); setPage(1); }; if (isPending) { return ; } const total = pagination?.total ?? items.length; const subtitle = `${total} ${ total === 1 ? "inventura" : total >= 2 && total <= 4 ? "inventury" : "inventur" }`; const columns: DataColumn[] = [ { key: "session_number", header: "Číslo inventury", width: "30%", mono: true, bold: true, render: (s) => s.session_number || "—", }, { key: "status", header: "Stav", width: "20%", render: (s) => ( ), }, { key: "created_at", header: "Vytvořeno", width: "30%", mono: true, render: (s) => formatDate(s.created_at), }, { key: "items", header: "Položky", width: "20%", mono: true, render: (s) => String(s.items?.length ?? 0), }, ]; return ( navigate("/warehouse/inventory/new")} > Nová inventura } />