"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

import {
    Card,
    CardContent,
    CardDescription,
    CardHeader,
    CardTitle,
} from "@/components/ui/card"
import {
    ChartContainer,
    ChartLegend,
    ChartLegendContent,
    ChartTooltip,
    ChartTooltipContent
    
} from "@/components/ui/chart"
import type {ChartConfig} from "@/components/ui/chart";

export const description = "Menampilkan aktivitas toko berdasarkan pesanan yang masuk."

const chartConfig = {
    today: {
        label: "Hari Ini",
        color: "var(--chart-1)",
    },
    yesterday: {
        label: "Kemarin",
        color: "var(--chart-2)",
    },
} satisfies ChartConfig

export function SalesByHourChart({ data }: { data: any[] }) {
    return (
        <Card className="pt-0">
            <CardHeader className="flex items-center gap-2 space-y-0 border-b py-5 sm:flex-row">
                <div className="grid flex-1 gap-1">
                    <CardTitle>Jam Sibuk</CardTitle>
                    <CardDescription>
                        Menampilkan aktivitas toko berdasarkan pesanan yang masuk.
                    </CardDescription>
                </div>
            </CardHeader>
            <CardContent className="px-2 pt-4 sm:px-6 sm:pt-6">
                <ChartContainer
                    config={chartConfig}
                    className="aspect-auto h-[250px] w-full"
                >
                    <AreaChart data={data}>
                        <defs>
                            <linearGradient id="fillToday" x1="0" y1="0" x2="0" y2="1">
                                <stop
                                    offset="5%"
                                    stopColor="var(--color-today)"
                                    stopOpacity={0.8}
                                />
                                <stop
                                    offset="95%"
                                    stopColor="var(--color-today)"
                                    stopOpacity={0.1}
                                />
                            </linearGradient>
                            <linearGradient id="fillYesterday" x1="0" y1="0" x2="0" y2="1">
                                <stop
                                    offset="5%"
                                    stopColor="var(--color-yesterday)"
                                    stopOpacity={0.8}
                                />
                                <stop
                                    offset="95%"
                                    stopColor="var(--color-yesterday)"
                                    stopOpacity={0.1}
                                />
                            </linearGradient>
                        </defs>
                        <CartesianGrid vertical={false} />
                        <XAxis
                            dataKey="hour"
                            tickLine={false}
                            axisLine={false}
                            tickMargin={8}
                        />
                        <ChartTooltip
                            cursor={false}
                            content={<ChartTooltipContent indicator="dot" />}
                        />
                        <Area
                            dataKey="yesterday"
                            type="natural"
                            fill="url(#fillYesterday)"
                            stroke="var(--color-yesterday)"
                        />
                        <Area
                            dataKey="today"
                            type="natural"
                            fill="url(#fillToday)"
                            stroke="var(--color-today)"
                        />
                        <ChartLegend content={<ChartLegendContent />} />
                    </AreaChart>
                </ChartContainer>
            </CardContent>
        </Card>
    )
}
