import Navigation from "@/components/Navigation";
import Footer from "@/components/Footer";
import ScrollToTop from "@/components/ScrollToTop";
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { DollarSign, ExternalLink, ArrowLeft } from "lucide-react";
import { Link } from "react-router-dom";

const FinancialToolsLoan = () => {
  // Mapping der Tool-Namen zu ihren URLs
  const getToolUrl = (toolName: string): string => {
    const toolUrlMap: { [key: string]: string } = {
      "Alternative Payment Frequencies": "https://www.cchwebsites.com/content/calculators/ComplexLoan.html",
      "Amortizing Loan Calculator": "https://www.cchwebsites.com/content/calculators/SimpleLoan.html",
      "Balloon Loan Calculator": "https://www.cchwebsites.com/content/calculators/BalloonLoan.html",
      "Debt Consolidation Calculator": "https://www.cchwebsites.com/content/calculators/Consolidate.html",
      "Enhanced Loan Calculator": "https://www.cchwebsites.com/content/calculators/EnhancedLoan.html",
      "Equity Line of Credit Payments": "https://www.cchwebsites.com/content/calculators/PaymentLine.html",
      "Existing Loan Calculator": "https://www.cchwebsites.com/content/calculators/ExistingLoan.html",
      "Home Equity Line of Credit Calculator": "https://www.cchwebsites.com/content/calculators/CreditLine.html",
      "Line of Credit Payoff": "https://www.cchwebsites.com/content/calculators/PayoffLine.html",
      "Loan & Credit Line Payment": "https://www.cchwebsites.com/content/calculators/PaymentOptions.html",
      "Loan & Credit Line Tax Savings": "https://www.cchwebsites.com/content/calculators/LineTaxes.html",
      "Loan Comparison Calculator": "https://www.cchwebsites.com/content/calculators/CompareLoan.html",
      "Loan Prequalification Calculator": "https://www.cchwebsites.com/content/calculators/LoanPrequal.html"
    };
    
    return toolUrlMap[toolName] || "#";
  };

  const handleToolClick = (toolName: string) => {
    const url = getToolUrl(toolName);
    if (url !== "#") {
      window.open(url, '_blank', 'noopener,noreferrer');
    }
  };

  const loanTools = [
    {
      name: "Alternative Payment Frequencies",
      description: "Use this calculator to determine your payment or loan amount for different payment frequencies."
    },
    {
      name: "Amortizing Loan Calculator",
      description: "Enter your desired payment - and let us calculate your loan amount. Or, enter in the loan amount and we will calculate your monthly payment!"
    },
    {
      name: "Balloon Loan Calculator",
      description: "A balloon loan can be an excellent option for many borrowers. Use this calculator to see how a balloon loan might work for you."
    },
    {
      name: "Debt Consolidation Calculator",
      description: "Should you consolidate your debt? Use this calculator to find out."
    },
    {
      name: "Enhanced Loan Calculator",
      description: "Use the slider controls to instantly change your monthly payment, loan amount, interest rate or term."
    },
    {
      name: "Equity Line of Credit Payments",
      description: "What will my monthly payments be for an interest only equity line of credit?"
    },
    {
      name: "Existing Loan Calculator",
      description: "Use this calculator to analyze one of your existing loans. Calculate your remaining balance based on the number of monthly payments you have remaining."
    },
    {
      name: "Home Equity Line of Credit Calculator",
      description: "How big of a home equity line of credit can you receive? Use this calculator to find out!"
    },
    {
      name: "Line of Credit Payoff",
      description: "Use this calculator to see what it will take to pay off your line of credit, and what you can change to meet your repayment goals."
    },
    {
      name: "Loan & Credit Line Payment",
      description: "This calculator helps determine your loan or credit line payment."
    },
    {
      name: "Loan & Credit Line Tax Savings",
      description: "This calculator helps determine your tax savings on loans or credit lines with tax deductible interest payments."
    },
    {
      name: "Loan Comparison Calculator",
      description: "Use this calculator to sort through the monthly payments, fees and other costs when comparing loan options."
    },
    {
      name: "Loan Prequalification Calculator",
      description: "Use this calculator as your first step in determining your ability to qualify for a loan."
    }
  ];

  return (
    <div className="min-h-screen">
      <Navigation />
      <main className="pt-16">
        {/* Hero Section */}
        <section
          className="py-24 bg-gradient-subtle relative"
          style={{
            backgroundImage: 'url(/lovable-uploads/financialtools-subpages.png)',
            backgroundSize: 'cover',
            backgroundPosition: 'center',
            backgroundRepeat: 'no-repeat'
          }}
        >
          <div className="absolute inset-0 bg-black/60"></div>
          <div className="container mx-auto px-4 relative z-10">
            <div className="max-w-4xl mx-auto">
              <div className="flex items-center gap-4 mb-8">
                <Link 
                  to="/financial-tools" 
                  className="flex items-center gap-2 text-white hover:text-brass gentle-transition"
                >
                  <ArrowLeft className="w-5 h-5" />
                  <span className="font-medium">Back to Financial Tools</span>
                </Link>
              </div>
              
              <div className="flex items-center gap-4 mb-8">
                <div className="w-16 h-16 bg-brass/20 rounded-2xl flex items-center justify-center">
                  <DollarSign className="w-8 h-8 text-brass" strokeWidth={1.5} />
                </div>
                <div>
                  <h1 className="text-display-xl font-display font-bold text-white mb-2">
                    Loan Tools
                  </h1>
                  <p className="text-body-lg text-white/90">
                    Loan calculators and payment analysis tools to help you make informed borrowing decisions
                  </p>
                </div>
              </div>
              
              <div className="bg-white/95 rounded-2xl p-6 card-elevation">
                <p className="text-forest text-sm">
                  <strong>Disclaimer:</strong> While these financial tools are not a substitute for financial advice from a qualified professional, they can be used as a starting point in the decision making process.
                </p>
              </div>
            </div>
          </div>
        </section>

        {/* Loan Tools Grid */}
        <section className="py-24 bg-background">
          <div className="container mx-auto px-4">
            <div className="max-w-6xl mx-auto">
              <div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                {loanTools.map((tool, index) => (
                  <Card 
                    key={index} 
                    className="rounded-xl card-elevation hover:shadow-lg gentle-transition cursor-pointer h-full"
                    onClick={() => handleToolClick(tool.name)}
                  >
                    <CardContent className="p-6 h-full flex flex-col">
                      <div className="flex items-start justify-between mb-4">
                        <div className="w-12 h-12 bg-brass/20 rounded-xl flex items-center justify-center flex-shrink-0">
                          <DollarSign className="w-6 h-6 text-brass" strokeWidth={1.5} />
                        </div>
                        <ExternalLink className="w-5 h-5 text-brass flex-shrink-0" strokeWidth={1.5} />
                      </div>
                      
                      <h3 className="text-display-sm font-display font-semibold text-forest mb-3 leading-tight">
                        {tool.name}
                      </h3>
                      
                      <p className="text-sage text-sm leading-relaxed flex-grow">
                        {tool.description}
                      </p>
                      
                      <div className="mt-4 pt-4 border-t border-sage/20">
                        <Button 
                          variant="outline" 
                          size="sm" 
                          className="w-full text-brass border-brass hover:bg-brass hover:text-cream"
                        >
                          Use Calculator
                        </Button>
                      </div>
                    </CardContent>
                  </Card>
                ))}
              </div>
            </div>
          </div>
        </section>

        {/* CTA Section */}
        <section className="py-24 bg-gradient-hero">
          <div className="container mx-auto px-4 text-center">
            <div className="max-w-3xl mx-auto">
              <h2 className="text-display-lg font-display font-semibold text-cream mb-6">
                Need Help with Loan Decisions?
              </h2>
              
              <p className="text-body-lg text-cream/90 mb-8 leading-relaxed">
                Our experienced CPA team can help you understand the financial implications of different loan options and develop a borrowing strategy that fits your needs.
              </p>
              
              <Button 
                size="lg" 
                variant="outline"
                className="bg-cream text-forest hover:bg-cream/90 border-cream btn-shadow text-lg px-8 py-3 rounded-2xl"
              >
                Schedule Loan Consultation
              </Button>
            </div>
          </div>
        </section>
      </main>
      <Footer />
      <ScrollToTop />
    </div>
  );
};

export default FinancialToolsLoan;
