import { PrismaClient } from '@prisma/client';

export const dynamic = 'force-dynamic';

const prisma = new PrismaClient();

export default async function PaymentPage({ params }: { params: { id: string } }) {
  const settings = await prisma.setting.findMany({
    where: { key: { in: ['benefit_iban', 'company_name'] } }
  });
  
  const getVal = (key: string) => settings.find(s => s.key === key)?.value || '';
  const iban = getVal('benefit_iban');
  const company = getVal('company_name');

  // Hardcode payment info for demo
  const amount = "400.00";
  const dueDate = "1st of Every Month";

  return (
    <div className="max-w-xl mx-auto p-6 mt-10 bg-white shadow rounded-lg text-foreground text-center">
      <h1 className="text-2xl font-bold mb-6">Rent Payment</h1>
      
      <div className="bg-gray-50 p-6 rounded-lg mb-6 border">
        <p className="text-gray-500 mb-1">Amount Due</p>
        <p className="text-4xl font-bold text-primary mb-4">{amount} BHD</p>
        
        <p className="text-sm font-semibold mb-2 text-gray-700 border-t pt-4">Pay via BenefitPay IBAN</p>
        <p className="text-lg font-mono tracking-widest">{iban || "BH00 XXXX 0000 0000 0000 00"}</p>
        <p className="text-sm text-gray-500 mt-1">Account Name: {company || "Real Estate Co."}</p>
      </div>

      <div className="border-t pt-6">
        <h2 className="text-lg font-semibold mb-4">Upload Transfer Receipt</h2>
        <form className="space-y-4 text-left">
          <input type="file" accept="image/*" className="w-full border rounded p-2" required />
          <button type="button" className="w-full bg-secondary text-white py-3 rounded text-lg font-bold hover:opacity-90 transition">
            Submit Payment Proof
          </button>
          <p className="text-xs text-gray-400 text-center mt-2">Admin will verify this payment within 24 hours.</p>
        </form>
      </div>
    </div>
  );
}
