import React from "react";
import { DollarSign, Percent } from "lucide-react";
import { cn } from "@/lib/utils";

interface KnockTypeToggleProps {
  knockT: string;
  setKnockT: (value: string) => void;
}

/**
 * Value / Percentage toggle for knock-in amounts.
 *
 * The two glyphs were boxicons (`bx bx-dollar`, `bx bx-percent`), but boxicons
 * is not loaded anywhere in this app — no stylesheet, no font, no package — so
 * both rendered as nothing. They are lucide icons now, which is already a
 * dependency and is what the rest of the app uses.
 */
const KnockTypeToggle: React.FC<KnockTypeToggleProps> = ({ knockT, setKnockT }) => {
  const options = [
    { value: "", label: "Value", Icon: DollarSign },
    { value: "1", label: "Percentage", Icon: Percent },
  ];

  return (
    <div
      role="radiogroup"
      aria-label="Knock amount type"
      className="flex flex-wrap items-center gap-2"
    >
      {options.map(({ value, label, Icon }) => {
        const isSelected = knockT === value;
        return (
          <label
            key={value}
            className={cn(
              // The whole chip is the target — the old version only gave you the
              // 20px dot plus its label, well under a comfortable touch size.
              "inline-flex min-h-10 cursor-pointer items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors",
              "focus-within:outline focus-within:outline-2 focus-within:outline-offset-2 focus-within:outline-ring",
              isSelected
                ? "border-primary bg-primary-soft font-semibold text-primary"
                : "border-border bg-card font-medium text-foreground hover:bg-muted"
            )}
          >
            <input
              type="radio"
              name="knock_t"
              value={value}
              checked={isSelected}
              onChange={(e) => setKnockT(e.target.value)}
              className="sr-only"
            />
            <span
              className={cn(
                "flex size-4 shrink-0 items-center justify-center rounded-full border-2 transition-colors",
                isSelected ? "border-primary bg-primary" : "border-border-strong bg-card"
              )}
              aria-hidden
            >
              {isSelected && <span className="size-1.5 rounded-full bg-primary-foreground" />}
            </span>
            <Icon className="size-4 shrink-0" aria-hidden />
            {label}
          </label>
        );
      })}
    </div>
  );
};

export default KnockTypeToggle;
