// Auteur : Simon-Pierre Boucher — contact@spboucher.ai
"use client";

import { useState } from "react";

export default function RemoveFavorite({
  app,
  itemId,
}: {
  app: string;
  itemId: string;
}) {
  const [busy, setBusy] = useState(false);
  return (
    <button
      type="button"
      aria-label="Retirer des favoris"
      title="Retirer des favoris"
      disabled={busy}
      className="gk-mono flex h-7 w-7 flex-none items-center justify-center rounded-full border-[1.5px] border-[rgba(20,24,20,0.3)] text-[12px] text-ink-2 transition-colors hover:border-[#b3423a] hover:bg-[#fbe9e7] hover:text-[#7c2f2a]"
      onClick={async () => {
        setBusy(true);
        await fetch("/api/favorites", {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({ action: "remove", app, item_id: itemId }),
        });
        window.location.reload();
      }}
    >
      ✕
    </button>
  );
}
