"use client";

import { useState } from "react";
import type { ReactElement } from "react";
import { Card, SectionHeader } from "@mosaic/ui";

interface QuickAction {
  id: string;
  label: string;
  icon: string;
  iconBg: string;
}

const actions: QuickAction[] = [
  { id: "new-project", label: "New Project", icon: "🚀", iconBg: "rgba(47,128,255,0.15)" },
  { id: "spawn-agent", label: "Spawn Agent", icon: "🤖", iconBg: "rgba(139,92,246,0.15)" },
  { id: "view-telemetry", label: "View Telemetry", icon: "📊", iconBg: "rgba(20,184,166,0.15)" },
  { id: "review-tasks", label: "Review Tasks", icon: "📋", iconBg: "rgba(245,158,11,0.15)" },
];

interface ActionButtonProps {
  action: QuickAction;
}

function ActionButton({ action }: ActionButtonProps): ReactElement {
  const [hovered, setHovered] = useState(false);

  return (
    <button
      type="button"
      onMouseEnter={(): void => {
        setHovered(true);
      }}
      onMouseLeave={(): void => {
        setHovered(false);
      }}
      style={{
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
        justifyContent: "center",
        gap: 8,
        padding: "16px 12px",
        borderRadius: "var(--r-md)",
        border: `1px solid ${hovered ? "var(--ms-border-700)" : "var(--border)"}`,
        background: hovered ? "var(--surface)" : "var(--bg-mid)",
        cursor: "pointer",
        transition: "border-color 0.15s, background 0.15s",
        width: "100%",
      }}
    >
      <div
        style={{
          width: 24,
          height: 24,
          borderRadius: 6,
          background: action.iconBg,
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
          fontSize: "0.875rem",
        }}
      >
        {action.icon}
      </div>
      <span
        style={{
          fontSize: "0.8rem",
          fontWeight: 600,
          color: "var(--text)",
        }}
      >
        {action.label}
      </span>
    </button>
  );
}

export function QuickActions(): ReactElement {
  return (
    <Card>
      <SectionHeader title="Quick Actions" />
      <div
        style={{
          display: "grid",
          gridTemplateColumns: "1fr 1fr",
          gap: 10,
        }}
      >
        {actions.map((action) => (
          <ActionButton key={action.id} action={action} />
        ))}
      </div>
    </Card>
  );
}
