import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useOrders } from "@/hooks/useOrders";
import { Order } from "src/db";
import ErrorMessage from "./ErrorPage";
import LoadingPage from "./Loading";
function StatItem({ title, value }: { title: string; value: string }) {
return (
);
}
function sum(...args: number[]) {
return args.reduce((acc, cur) => acc + cur, 0);
}
function ordersSum(orders: Order[]) {
return orders.reduce((acc, cur) => acc + cur.price * cur.quantity * 1000, 0);
}
export default function Stat() {
const { data: orders, status } = useOrders();
if (status === "pending") {
return ;
}
if (!orders) {
return 주문을 불러오지 못했습니다.;
}
const completed_order = orders.filter(order => order.completed);
const cash_order = completed_order.filter(order => order.payment === "cash");
const account_order = completed_order.filter(order => order.payment === "account");
return (
주문통계
ordersSum(order.orders)))
.toLocaleString("ko-KR", {
style: "currency",
currency: "KRW",
})}
/>
ordersSum(order.orders)))
.toLocaleString("ko-KR", {
style: "currency",
currency: "KRW",
})}
/>
ordersSum(order.orders)))
.toLocaleString("ko-KR", {
style: "currency",
currency: "KRW",
})}
/>
);
}