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 FinancialToolsSavings = () => {
  // Mapping der Tool-Namen zu ihren URLs
  const getToolUrl = (toolName: string): string => {
    const toolUrlMap: { [key: string]: string } = {
      "Benefit of Spending Less": "https://www.cchwebsites.com/content/calculators/SpendLess.html",
      "CD Ladder Calculator": "https://www.cchwebsites.com/content/calculators/CDLadder.html",
      "Certificate of Deposit Calculator": "https://www.cchwebsites.com/content/calculators/CertDeposit.html",
      "College Savings": "https://www.cchwebsites.com/content/calculators/CollegeSavings.html",
      "Compare Savings Rates": "https://www.cchwebsites.com/content/calculators/CompareSavings.html",
      "Compound Savings Calculator": "https://www.cchwebsites.com/content/calculators/CompoundSavings.html",
      "Compounding and Your Return": "https://www.cchwebsites.com/content/calculators/CompoundInterest.html",
      "Cool Million": "https://www.cchwebsites.com/content/calculators/Millionaire.html",
      "Credit Union Certificate Calculator": "https://www.cchwebsites.com/content/calculators/CUDeposit.html",
      "Credit Union Certificate Ladder Calculator": "https://www.cchwebsites.com/content/calculators/CertificateLadder.html",
      "Don't Delay Your Savings!": "https://www.cchwebsites.com/content/calculators/WaitCost.html",
      "Emergency Savings Calculator": "https://www.cchwebsites.com/content/calculators/Emergency.html",
      "Home Buyer Savings Calculator": "https://www.cchwebsites.com/content/calculators/HomeBuyerSavings.html",
      "Lunch Savings": "https://www.cchwebsites.com/content/calculators/LunchSaver.html",
      "Savings Distribution Calculator": "https://www.cchwebsites.com/content/calculators/DistribSavings.html",
      "Savings Goals": "https://www.cchwebsites.com/content/calculators/Savings.html",
      "Savings, Taxes, and Inflation": "https://www.cchwebsites.com/content/calculators/SavingsVariables.html",
      "Vice Savings": "https://www.cchwebsites.com/content/calculators/ViceSaver.html"
    };
    
    return toolUrlMap[toolName] || "#";
  };

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

  const savingsTools = [
    {
      name: "Benefit of Spending Less",
      description: "Reducing your spending can be worth more than you might think. Use this calculator to see just how much your budget reductions may be worth."
    },
    {
      name: "CD Ladder Calculator",
      description: "Use this calculator to examine the benefits of investing in a series of Certificates of Deposits with different maturities, also called a CD Ladder."
    },
    {
      name: "Certificate of Deposit Calculator",
      description: "Use this calculator to find out how much interest you can earn on a Certificate of Deposit (CD)."
    },
    {
      name: "College Savings",
      description: "Use this calculator to help develop or fine tune your education savings plan."
    },
    {
      name: "Compare Savings Rates",
      description: "Even a small difference in the interest you are paid on your savings can add up over time. Use this calculator to see how different savings rates can impact your savings strategy!"
    },
    {
      name: "Compound Savings Calculator",
      description: "Find out how consistent investments over a number of years can be an effective strategy to accumulate wealth."
    },
    {
      name: "Compounding and Your Return",
      description: "This calculator demonstrates how compounding can affect your savings."
    },
    {
      name: "Cool Million",
      description: "Find out when your savings plan may make you a millionaire!"
    },
    {
      name: "Credit Union Certificate Calculator",
      description: "Use this calculator to find out how much you can earn on a Certificate. Just enter a few pieces of information and we will calculate your Annual Percentage Yield (APY) and ending balance."
    },
    {
      name: "Credit Union Certificate Ladder Calculator",
      description: "Use this calculator to examine the benefits of investing in a series of Certificates with different maturities, also called a Certificate Ladder."
    },
    {
      name: "Don't Delay Your Savings!",
      description: "Waiting to begin your savings plan can have a huge impact on your results. This calculator helps show you how much postponing your savings plan can really cost."
    },
    {
      name: "Emergency Savings Calculator",
      description: "This calculator helps you determine how much emergency savings you may need, and how you can begin saving toward this important goal."
    },
    {
      name: "Home Buyer Savings Calculator",
      description: "Use this tool to help you calculate what it might take to save for your new house."
    },
    {
      name: "Lunch Savings",
      description: "Use this calculator to see how a simple change such as bringing a bagged lunch to work can really add up."
    },
    {
      name: "Savings Distribution Calculator",
      description: "Use this calculator to determine savings balance after a series monthly, quarterly or annual withdrawals."
    },
    {
      name: "Savings Goals",
      description: "What will it take to reach your savings goal? This financial calculator helps you find out."
    },
    {
      name: "Savings, Taxes, and Inflation",
      description: "Use this calculator to determine how much your savings will be worth with these two important variables in mind."
    },
    {
      name: "Vice Savings",
      description: "Use this calculator to see how a simple changes in your spending habits for common vices such as smoking, drinking or even eating out can really add up."
    }
  ];

  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">
                    Savings Tools
                  </h1>
                  <p className="text-body-lg text-white/90">
                    Savings planning and goal calculators to help you build wealth over time
                  </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>

        {/* Savings 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">
                {savingsTools.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 Savings Planning?
              </h2>
              
              <p className="text-body-lg text-cream/90 mb-8 leading-relaxed">
                Our experienced CPA team can help you develop a comprehensive savings strategy and understand the best approach for your financial goals.
              </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 Savings Consultation
              </Button>
            </div>
          </div>
        </section>
      </main>
      <Footer />
      <ScrollToTop />
    </div>
  );
};

export default FinancialToolsSavings;
