// [nexus] Assistant action strip (Phase 9).
//
// 4-button row that sits beneath the input bar: Promote to project,
// Attach, Memory, History. Phase 9 wires the buttons; the promote
// transition itself lands in Phase 12.
import { Paperclip, Brain, FolderClock, Plus } from "lucide-react";
import { cn } from "@/lib/utils";

export interface ActionStripProps {
  /**
   * When true, the Promote button is enabled. The caller decides what
   * "promotable" means — Phase 9 uses "active conversation with at least
   * one user message and one assistant message".
   */
  canPromote: boolean;
  onPromote: () => void;
  onAttach: () => void;
  onOpenMemory: () => void;
  onOpenHistory: () => void;
  className?: string;
}

interface ActionBtnProps {
  label: string;
  icon: typeof Paperclip;
  onClick: () => void;
  disabled?: boolean;
  /**
   * When true, the button renders as a volt-outline (primary) affordance.
   */
  variant?: "outline" | "ghost";
  "data-testid"?: string;
}

function ActionBtn({
  label,
  icon: Icon,
  onClick,
  disabled,
  variant = "ghost",
  ...rest
}: ActionBtnProps) {
  return (
    <button
      type="button"
      onClick={onClick}
      disabled={disabled}
      aria-label={label}
      data-testid={rest["data-testid"]}
      className={cn(
        "inline-flex items-center gap-2 rounded-[4px] px-3 py-1.5 text-[12px] font-medium uppercase tracking-[0.1em]",
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background",
        "transition-colors duration-100",
        variant === "outline"
          ? "border border-primary text-primary hover:bg-primary/10 disabled:border-border disabled:text-muted-foreground disabled:hover:bg-transparent"
          : "text-muted-foreground hover:text-primary disabled:text-muted-foreground/40 disabled:hover:text-muted-foreground/40",
        "disabled:cursor-not-allowed",
      )}
    >
      <Icon className="h-4 w-4" strokeWidth={1.5} />
      <span>{label}</span>
    </button>
  );
}

export function ActionStrip({
  canPromote,
  onPromote,
  onAttach,
  onOpenMemory,
  onOpenHistory,
  className,
}: ActionStripProps) {
  return (
    <div
      data-testid="assistant-action-strip"
      role="toolbar"
      aria-label="Assistant actions"
      className={cn("flex items-center gap-2 pt-3", className)}
    >
      <ActionBtn
        label="Promote to project"
        icon={Plus}
        variant="outline"
        disabled={!canPromote}
        onClick={onPromote}
        data-testid="action-promote"
      />
      <ActionBtn
        label="Attach"
        icon={Paperclip}
        onClick={onAttach}
        data-testid="action-attach"
      />
      <ActionBtn
        label="Memory"
        icon={Brain}
        onClick={onOpenMemory}
        data-testid="action-memory"
      />
      <ActionBtn
        label="History"
        icon={FolderClock}
        onClick={onOpenHistory}
        data-testid="action-history"
      />
    </div>
  );
}
