'use client';

import { useState } from 'react';
import { downloadPDF } from '@/lib/pdf-utils';

interface PDFButtonProps {
  elementId: string;
  filename: string;
  buttonText?: string;
  className?: string;
}

export default function PDFButton({
  elementId,
  filename,
  buttonText = 'PDF 저장',
  className = ''
}: PDFButtonProps) {
  const [isGenerating, setIsGenerating] = useState(false);

  const handleDownload = async () => {
    setIsGenerating(true);
    try {
      await downloadPDF(elementId, filename);
    } finally {
      setIsGenerating(false);
    }
  };

  return (
    <button
      onClick={handleDownload}
      disabled={isGenerating}
      className={className || "bg-gradient-to-r from-indigo-600 to-purple-600 text-white rounded-xl p-6 shadow-lg hover:shadow-xl transition text-center group w-full disabled:opacity-50 disabled:cursor-not-allowed"}
    >
      <div className="text-4xl mb-3">
        {isGenerating ? '⏳' : '📥'}
      </div>
      <h3 className="text-xl font-bold mb-2">
        {isGenerating ? 'PDF 생성 중...' : buttonText}
      </h3>
      <p className="text-sm opacity-90">
        {isGenerating ? '잠시만 기다려주세요' : '결과를 PDF로 저장하기'}
      </p>
    </button>
  );
}
