"use client";

import Link from "next/link";

import { Bot, Sparkles, UserPlus, Users } from "lucide-react";

import { Button } from "@/components/ui/button";
import { getAuthUser } from "@/lib/auth";

import { OverviewClientDistribution } from "./_components/overview-client-distribution";
import { OverviewGettingStarted } from "./_components/overview-getting-started";
import { OverviewKpiCards } from "./_components/overview-kpi-cards";
import { OverviewRecentClients } from "./_components/overview-recent-clients";

const QUICK_ACTIONS = [
  {
    label: "SiliTalk Admin",
    icon: Users,
    href: "/dashboard/admin/silitalk",
    color: "ss-glass text-[var(--ss-accent)] border border-[var(--ss-accent)]/30",
  },
  {
    label: "Audit Log",
    icon: UserPlus,
    href: "/dashboard/admin/audit",
    color: "ss-glass text-[var(--ss-violet)] border border-[var(--ss-violet)]/30",
  },
  {
    label: "Integrations",
    icon: Bot,
    href: "/portal/integrations",
    color: "ss-glass text-[var(--ss-emerald)] border border-[var(--ss-emerald)]/30",
  },
  {
    label: "Queues",
    icon: Sparkles,
    href: "/dashboard/admin/queues",
    color: "ss-glass text-[var(--ss-warning)] border border-[var(--ss-warning)]/30",
  },
];

function getGreeting() {
  const hour = new Date().getHours();
  if (hour < 12) return "Good morning";
  if (hour < 17) return "Good afternoon";
  return "Good evening";
}

export default function Page() {
  const user = getAuthUser();
  const greeting = getGreeting();

  return (
    <div className="flex flex-col gap-5">
      <div className="flex flex-wrap items-end justify-between gap-3">
        <div>
          <h1 className="font-bold text-2xl">
            {greeting}
            {user?.name ? `, ${user.name.split(" ")[0]}` : ""}
          </h1>
          <p className="mt-0.5 text-muted-foreground text-sm">
            SiliMind staff — audit, admin queues, and SiliTalk operations.
          </p>
        </div>
        <Button asChild size="sm">
          <Link href="/dashboard/admin/queues">
            <UserPlus className="size-4" />
            Admin queues
          </Link>
        </Button>
      </div>

      <div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
        {QUICK_ACTIONS.map(({ label, icon: Icon, href, color }) => (
          <Link
            key={label}
            href={href}
            className="ss-glass-card ss-glass-card-hover flex flex-col items-center gap-1.5 rounded-xl px-2 py-3 text-center transition-[transform,box-shadow,border-color] duration-150 ease-out hover:border-[var(--ss-accent)]/40"
          >
            <div className={`flex size-9 items-center justify-center rounded-lg ${color}`}>
              <Icon className="size-4" />
            </div>
            <span className="font-medium text-xs leading-tight">{label}</span>
          </Link>
        ))}
      </div>

      <OverviewKpiCards />
      <OverviewClientDistribution />

      <div className="grid gap-4 md:grid-cols-2">
        <OverviewRecentClients />
        <OverviewGettingStarted />
      </div>
    </div>
  );
}
