"use client";

import { useState } from "react";
import { deleteExperienceAction } from "./actions";
import { Trash2, Loader2 } from "lucide-react";

export function DeleteExperienceButton({ id }: { id: string }) {
  const [loading, setLoading] = useState(false);

  async function handleDelete() {
    if (confirm("Delete this experience entry? This cannot be undone.")) {
      setLoading(true);
      await deleteExperienceAction(id);
      setLoading(false);
    }
  }

  return (
    <button
      onClick={handleDelete}
      disabled={loading}
      className="p-2 text-muted-foreground hover:text-red-500 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-50"
      title="Delete Experience"
    >
      {loading ? <Loader2 size={16} className="animate-spin" /> : <Trash2 size={16} />}
    </button>
  );
}
