import { useState } from "react";
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 { Input } from "@/components/ui/input";
import { 
  Calculator, 
  Car, 
  Building, 
  CreditCard, 
  Shield, 
  TrendingUp, 
  Home, 
  PiggyBank, 
  DollarSign,
  FileText,
  Search,
  ExternalLink,
  ArrowRight
} from "lucide-react";
import { Link } from "react-router-dom";

const FinancialTools = () => {
  // State für den Mortgage Calculator
  const [loanAmount, setLoanAmount] = useState<string>("300000");
  const [interestRate, setInterestRate] = useState<string>("6.5");
  const [loanTerm, setLoanTerm] = useState<string>("30");
  const [propertyTax, setPropertyTax] = useState<string>("250");
  const [insurance, setInsurance] = useState<string>("100");
  const [calculatedPayment, setCalculatedPayment] = useState<{
    principalAndInterest: number;
    propertyTax: number;
    insurance: number;
    totalPayment: number;
  } | null>({
    principalAndInterest: 1896.20,
    propertyTax: 250,
    insurance: 100,
    totalPayment: 2246.20
  });

  // Mortgage Payment Calculation Function
  const calculateMortgagePayment = () => {
    const principal = parseFloat(loanAmount) || 0;
    const annualRate = parseFloat(interestRate) || 0;
    const years = parseFloat(loanTerm) || 0;
    const monthlyTax = parseFloat(propertyTax) || 0;
    const monthlyInsurance = parseFloat(insurance) || 0;

    if (principal <= 0 || annualRate < 0 || years <= 0) {
      setCalculatedPayment(null);
      return;
    }

    // Convert annual rate to monthly rate
    const monthlyRate = annualRate / 100 / 12;
    // Convert years to months
    const numberOfPayments = years * 12;

    // Calculate monthly principal and interest payment using standard mortgage formula
    let monthlyPI = 0;
    if (monthlyRate > 0) {
      monthlyPI = principal * (monthlyRate * Math.pow(1 + monthlyRate, numberOfPayments)) / 
                 (Math.pow(1 + monthlyRate, numberOfPayments) - 1);
    } else {
      // If interest rate is 0, just divide principal by number of payments
      monthlyPI = principal / numberOfPayments;
    }

    const totalMonthlyPayment = monthlyPI + monthlyTax + monthlyInsurance;

    setCalculatedPayment({
      principalAndInterest: Math.round(monthlyPI * 100) / 100,
      propertyTax: monthlyTax,
      insurance: monthlyInsurance,
      totalPayment: Math.round(totalMonthlyPayment * 100) / 100
    });
  };

  // Format currency for display
  const formatCurrency = (amount: number): string => {
    return new Intl.NumberFormat('en-US', {
      style: 'currency',
      currency: 'USD',
      minimumFractionDigits: 2,
      maximumFractionDigits: 2
    }).format(amount);
  };

  // Mapping der Tool-Namen zu ihren URLs
  const getToolUrl = (toolName: string): string => {
    const toolUrlMap: { [key: string]: string } = {
      // Auto Tools
      "Auto Loan Early Payoff": "https://www.cchwebsites.com/content/calculators/AutoPayoff.html",
      "Auto Rebate vs. Low Interest Financing": "https://www.cchwebsites.com/content/calculators/AutoRebate.html",
      "Auto Refinance Interest Savings": "https://www.cchwebsites.com/content/calculators/ShouldIRefiAuto.html",
      "Bi-weekly Payments for an Auto Loan": "https://www.cchwebsites.com/content/calculators/AutoBiweekly.html",
      "Bi-weekly Payments for an Auto Loan with Fees": "https://www.cchwebsites.com/content/calculators/ImpoundAutoBiweekly.html",
      "Car Loan Calculator": "https://www.cchwebsites.com/content/calculators/AutoLoan.html",
      "Dealer Financing vs. Credit Union Financing": "https://www.cchwebsites.com/content/calculators/CUAutoRebate.html",
      "Home Equity Loan vs. Auto loan": "https://www.cchwebsites.com/content/calculators/AutoEquityLoan.html",
      "Lease vs. Buy": "https://www.cchwebsites.com/content/calculators/BuyvsLease.html",
      "Low Interest Financing Savings": "https://www.cchwebsites.com/content/calculators/AutoLowInterest.html",
      
      // Business Tools
      "Breakeven Analysis": "https://www.cchwebsites.com/content/calculators/BreakEven.html",
      "Business Debt Consolidation Calculator": "https://www.cchwebsites.com/content/calculators/BizConsolidate.html",
      "Business Valuation - Discounted Cash Flow": "https://www.cchwebsites.com/content/calculators/BusinessValuation.html",
      "Cash Flow Calculator": "https://www.cchwebsites.com/content/calculators/CashFlow.html",
      "Commercial Loan Calculator": "https://www.cchwebsites.com/content/calculators/DebtService.html",
      "Debt Service Coverage": "https://www.cchwebsites.com/content/calculators/DebtService2.html",
      "Equipment Buy vs. Lease": "https://www.cchwebsites.com/content/calculators/BizBuyvsLease.html",
      "Financial Ratios": "https://www.cchwebsites.com/content/calculators/Ratios.html",
      "Inventory Analysis": "https://www.cchwebsites.com/content/calculators/Inventory.html",
      "Like Kind Exchange": "https://www.cchwebsites.com/content/calculators/LikeKindExchange.html",
      "Profit Margin Calculator": "https://www.cchwebsites.com/content/calculators/ProfitMargin.html",
      "Repossession of Personal Property from a Deferred Payment Sale": "https://www.cchwebsites.com/content/calculators/RepoPersonalDP.html",
      "Repossession of Personal Property from an Installment Payment Sale": "https://www.cchwebsites.com/content/calculators/RepoPersonalInstall.html",
      "Repossession of Real Property": "https://www.cchwebsites.com/content/calculators/RepoReal.html",
      "Working Capital Needs": "https://www.cchwebsites.com/content/calculators/Capital.html",
      
      // Debt and Credit Cards
      "Accelerated Debt Payoff": "https://www.cchwebsites.com/content/calculators/DebtAccel.html",
      "Consolidation Loan Investment Calculator": "https://www.cchwebsites.com/content/calculators/InvestmentDebt.html",
      "Cost-of-Debt Calculator": "https://www.cchwebsites.com/content/calculators/Debt2Amount.html",
      "Credit Card Minimum Payment Calculator": "https://www.cchwebsites.com/content/calculators/DebtPayoff2.html",
      "Credit Card Optimizer": "https://www.cchwebsites.com/content/calculators/CardOptimizer.html",
      "Credit Card Pay Off": "https://www.cchwebsites.com/content/calculators/PayoffCC.html",
      "Home Equity Debt Consolidation": "https://www.cchwebsites.com/content/calculators/MortgageEquity.html",
      "How much do you owe?": "https://www.cchwebsites.com/content/calculators/DebtAmount.html",
      "Personal Debt Consolidation": "https://www.cchwebsites.com/content/calculators/DebtConsolidate.html",
      "Roll-Down Your Credit Card Debt!": "https://www.cchwebsites.com/content/calculators/DebtRolldown.html",
      "Snowball Debt Elimination Calculator": "https://www.cchwebsites.com/content/calculators/SnowBall2.html",
      "Student Loan Consolidation and Debt Payoff": "https://www.cchwebsites.com/content/calculators/StudentRolldown.html",
      
      // Insurance Tools
      "Comprehensive Life Insurance Analysis": "https://www.cchwebsites.com/content/calculators/EnhancedLifeIns.html",
      "Disability Insurance": "https://www.cchwebsites.com/content/calculators/Disability.html",
      "Fixed Annuity Calculator": "https://www.cchwebsites.com/content/calculators/FixedAnnuity.html",
      "Health Savings Account (HSA) Contribution Calculator": "https://www.cchwebsites.com/content/calculators/HSAContribution.html",
      "Health Savings Account (HSA) Goal Calculator": "https://www.cchwebsites.com/content/calculators/HSAGoal.html",
      "Health Savings Account (HSA) Savings Calculator": "https://www.cchwebsites.com/content/calculators/HSASavings.html",
      "Health Savings Account (HSA) vs. Traditional Health Plan": "https://www.cchwebsites.com/content/calculators/HSAvsTraditional.html",
      "Health Savings Accounts (HSA) Employer Benefit": "https://www.cchwebsites.com/content/calculators/HSABusiness.html",
      "Human Life Value": "https://www.cchwebsites.com/content/calculators/HumanLifeValue.html",
      "Immediate Annuity Calculator": "https://www.cchwebsites.com/content/calculators/ImmediateAnnuity.html",
      "Life Insurance Calculator": "https://www.cchwebsites.com/content/calculators/LifeInsurance.html",
      "Long Term Care Calculator": "https://www.cchwebsites.com/content/calculators/LongtermCare.html",
      "Variable Annuity Calculator": "https://www.cchwebsites.com/content/calculators/Annuity.html",
      "Variable Annuity without Surrender Charges": "https://www.cchwebsites.com/content/calculators/AnnuityNoSurrender.html",
      
      // Investment Tools
      "Annual Rate of Return Calculator": "https://www.cchwebsites.com/content/calculators/AnnualReturn.html",
      "Annual Stock Option Grants": "https://www.cchwebsites.com/content/calculators/StockGrants.html",
      "Asset Allocation Calculator": "https://www.cchwebsites.com/content/calculators/AssetAllocator.html",
      "Compare Investment Fees": "https://www.cchwebsites.com/content/calculators/CompareFees.html",
      "Future Contracts Calculator": "https://www.cchwebsites.com/content/calculators/FutureContracts.html",
      "Future Value Calculator": "https://www.cchwebsites.com/content/calculators/FutureValue.html",
      "Internal Rate of Return (IRR) Calculator": "https://www.cchwebsites.com/content/calculators/IRRReturn.html",
      "Investment Distributions": "https://www.cchwebsites.com/content/calculators/InvestmentDistribution2.html",
      "Investment Goal": "https://www.cchwebsites.com/content/calculators/InvestmentVariables.html",
      "Investment Loan": "https://www.cchwebsites.com/content/calculators/InvestmentLoan.html",
      "Investment Property Calculator": "https://www.cchwebsites.com/content/calculators/InvestmentProperty.html",
      "Investment Questionnaire - Broad Portfolio": "https://www.cchwebsites.com/content/calculators/InvestmentProfile.html",
      "Investment Questionnaire - Cash, Fixed Income and Equities": "https://www.cchwebsites.com/content/calculators/InvestmentQuestionaire.html",
      "Investment Returns": "https://www.cchwebsites.com/content/calculators/InvestmentReturn.html",
      "Investment Savings and Distributions": "https://www.cchwebsites.com/content/calculators/InvestmentDistribution.html",
      "Lump Sum Annual Return Calculator": "https://www.cchwebsites.com/content/calculators/AnnualReturnAmount.html",
      "Lump Sum Future Value Calculator": "https://www.cchwebsites.com/content/calculators/FutureValueAmount.html",
      "Lump Sum Present Value Calculator": "https://www.cchwebsites.com/content/calculators/PresentValueAmount.html",
      "Municipal Bond Tax Equivalent Yield": "https://www.cchwebsites.com/content/calculators/TaxEquivYield.html",
      "Mutual Fund Expense Calculator": "https://www.cchwebsites.com/content/calculators/FundExpense.html",
      "Personal Economic Recovery Calculator": "https://www.cchwebsites.com/content/calculators/RecoverTime.html",
      "Present Value Calculator": "https://www.cchwebsites.com/content/calculators/PresentValue.html",
      "Present Value Goal Calculator": "https://www.cchwebsites.com/content/calculators/PresentValueGoal.html",
      "REIT Tax-Equivalent Distribution": "https://www.cchwebsites.com/content/calculators/REITTaxEquivYield.html",
      "Stock Option Calculator": "https://www.cchwebsites.com/content/calculators/StockOptions.html",
      "Taxable vs. Tax Deferred Investments": "https://www.cchwebsites.com/content/calculators/InvestCompare2.html",
      "Taxable vs. Tax Deferred vs. Tax Free Investment": "https://www.cchwebsites.com/content/calculators/InvestCompare.html",
      
      // Loan Tools
      "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",
      
      // Mortgage Tools
      "Adjustable Rate Mortgage Calculator": "https://www.cchwebsites.com/content/calculators/MortgageAdjustable.html",
      "APR Calculator for Adjustable Rate Mortgages": "https://www.cchwebsites.com/content/calculators/MortgageAprAdjustable.html",
      "ARM & Interest Only ARM vs. Fixed Rate Mortgage": "https://www.cchwebsites.com/content/calculators/MortgageArmvsFixed.html",
      "Balloon Mortgages": "https://www.cchwebsites.com/content/calculators/MortgageBalloon.html",
      "Bi-weekly Payment Calculator": "https://www.cchwebsites.com/content/calculators/Biweekly.html",
      "Bi-weekly Payments for an Existing Mortgage": "https://www.cchwebsites.com/content/calculators/ExistingBiweekly.html",
      "Blended Rate Mortgage Calculator": "https://www.cchwebsites.com/content/calculators/MortgageBlend.html",
      "FHA Maximum Financing Calculator": "https://www.cchwebsites.com/content/calculators/FHAMortgageQualifier.html",
      "Fixed Rate Mortgage vs. Interest Only Mortgage": "https://www.cchwebsites.com/content/calculators/MortgageFixedvsIO.html",
      "Fixed Rate Mortgage vs. LIBOR ARM": "https://www.cchwebsites.com/content/calculators/MortgageFixedvsLibor.html",
      "Interest Only ARM Calculator": "https://www.cchwebsites.com/content/calculators/MortgageIOAdjustable.html",
      "Interest Only Mortgage Calculator": "https://www.cchwebsites.com/content/calculators/MortgageInterestOnly.html",
      "Maximum Mortgage": "https://www.cchwebsites.com/content/calculators/MortgageApr.html",
      "Mortgage APR Calculator": "https://www.cchwebsites.com/content/calculators/MortgageCompare.html",
      "Mortgage Comparison: 15 Years vs. 30 Years": "https://www.cchwebsites.com/content/calculators/MortgageConsolidate.html",
      "Mortgage Debt Consolidation": "https://www.cchwebsites.com/content/calculators/MortgageLoan.html",
      "Mortgage Loan Calculator": "https://www.cchwebsites.com/content/calculators/MortgageLoan2.html",
      "Mortgage Loan Calculator (PITI)": "https://www.cchwebsites.com/content/calculators/MortgagePayoff.html",
      "Mortgage Payoff": "https://www.cchwebsites.com/content/calculators/MortgagePoints.html",
      "Mortgage Points Calculator": "https://www.cchwebsites.com/content/calculators/MortgageQualifier.html",
      "Mortgage Qualifier": "https://www.cchwebsites.com/content/calculators/MortgageRefinance.html",
      "Mortgage Refinance Break Even": "https://www.cchwebsites.com/content/calculators/MortgageIncome.html",
      "Mortgage Required Income": "https://www.cchwebsites.com/content/calculators/MortgageTaxes.html",
      "Mortgage Tax Savings Calculator": "https://www.cchwebsites.com/content/calculators/MortgageFixedvsNegAm.html",
      "Option ARM vs. Fixed Rate Mortgage": "https://www.cchwebsites.com/content/calculators/ShouldIRefi.html",
      "Refinance Interest Savings": "https://www.cchwebsites.com/content/calculators/ReverseMortgage.html",
      "Rent vs. Buy": "https://www.cchwebsites.com/content/calculators/ReverseMortgage.html",
      "Reverse Mortgage Calculator": "https://www.cchwebsites.com/content/calculators/ReverseMortgage.html",
      
      // Personal Finance Tools
      "Basic Calculator": "https://www.cchwebsites.com/content/calculators/FinCalc.html",
      "Basic Financial Calculator": "https://www.cchwebsites.com/content/calculators/FinCalc3.html",
      "Checkbook Balancer": "https://www.cchwebsites.com/content/calculators/CheckBook.html",
      "Credit Assessment": "https://www.cchwebsites.com/content/calculators/CreditAssessment.html",
      "Home Budget Analysis": "https://www.cchwebsites.com/content/calculators/HomeBudget.html",
      "Life Expectancy": "https://www.cchwebsites.com/content/calculators/LifeTime.html",
      "Net Worth": "https://www.cchwebsites.com/content/calculators/NetWorth.html",
      "Should my spouse work?": "https://www.cchwebsites.com/content/calculators/IncomeOneorTwo.html",
      "Student Budget": "https://www.cchwebsites.com/content/calculators/StudentBudget.html",
      
      // Retirement Tools
      "401(k) Calculator": "https://www.cchwebsites.com/content/calculators/Retire401k.html",
      "401(k) Savings with Profit Sharing": "https://www.cchwebsites.com/content/calculators/Retire401kProfitShare.html",
      "401(k) Spend It or Save It Calculator": "https://www.cchwebsites.com/content/calculators/Rollover401k.html",
      "403(b) Savings Calculator": "https://www.cchwebsites.com/content/calculators/Retire403b.html",
      "457 Plan Contribution Effects on Your Paycheck": "https://www.cchwebsites.com/content/calculators/RetirePayrollSavings457.html",
      "457 Plan Withdrawal": "https://www.cchwebsites.com/content/calculators/RetirementWithdrawal457.html",
      "457 Plan: Roth vs. Pre-tax": "https://www.cchwebsites.com/content/calculators/RothvsTraditional457.html",
      "457 Savings Calculator": "https://www.cchwebsites.com/content/calculators/Retire457.html",
      "72(t) Calculator": "https://www.cchwebsites.com/content/calculators/Retire72T.html",
      "72(t) Distribution Impact": "https://www.cchwebsites.com/content/calculators/Retire72Alt.html",
      "Beneficiary Required Minimum Distributions": "https://www.cchwebsites.com/content/calculators/RetireBeneficiary.html",
      "Company Stock Distribution Analysis Calculator": "https://www.cchwebsites.com/content/calculators/StockRollover401k.html",
      "How Important is Social Security?": "https://www.cchwebsites.com/content/calculators/NoSocial.html",
      "How long will my retirement savings last?": "https://www.cchwebsites.com/content/calculators/RetirementDistribution.html",
      "Individual 401(k) Contribution Comparison": "https://www.cchwebsites.com/content/calculators/Individual401kContribution.html",
      "Individual 401(k) Savings Calculator": "https://www.cchwebsites.com/content/calculators/RetireSolo401k.html",
      "IRA Spend It or Save It Calculator": "https://www.cchwebsites.com/content/calculators/RolloverIRA.html",
      "Pension Plan Retirement Options": "https://www.cchwebsites.com/content/calculators/PensionOptions.html",
      "Required Minimum Distribution (RMD)": "https://www.cchwebsites.com/content/calculators/RetireDistrib.html",
      "Required Minimum Distribution (RMD) for Current Year": "https://www.cchwebsites.com/content/calculators/RetireDistrib3.html",
      "Retirement Account Contribution Accelerator": "https://www.cchwebsites.com/content/calculators/RetirePayrollSavings.html",
      "Retirement Contribution Effects on Your Paycheck": "https://www.cchwebsites.com/content/calculators/RetirementIncome.html",
      "Retirement Income": "https://www.cchwebsites.com/content/calculators/RetirementNestegg.html",
      "Retirement Nestegg Calculator": "https://www.cchwebsites.com/content/calculators/RetirementPlan3.html",
      "Retirement Pension Planner": "https://www.cchwebsites.com/content/calculators/RetirementWithdrawal.html",
      "Retirement Plan Withdrawal": "https://www.cchwebsites.com/content/calculators/RetirementPlan.html",
      "Retirement Planner": "https://www.cchwebsites.com/content/calculators/RetirementPlan4.html",
      "Retirement Planner with Retirement Earnings": "https://www.cchwebsites.com/content/calculators/RetireShort.html",
      "Retirement Shortfall": "https://www.cchwebsites.com/content/calculators/StretchIRA.html",
      "RMD & Stretch IRA Calculator": "https://www.cchwebsites.com/content/calculators/RothvsPreTaxAccount.html",
      "Roth (after-tax) Account or Pre-Tax Account?": "https://www.cchwebsites.com/content/calculators/RothvsTraditional401k.html",
      "Roth 401(k) vs. Traditional 401(k)": "https://www.cchwebsites.com/content/calculators/RothvsTraditional403b.html",
      "Roth 403(b) vs. Traditional 403(b)": "https://www.cchwebsites.com/content/calculators/RothIRA.html",
      "Roth IRA Calculator": "https://www.cchwebsites.com/content/calculators/RothTransfer.html",
      "Roth IRA Conversion": "https://www.cchwebsites.com/content/calculators/RothConversion.html",
      "Roth IRA Conversion with Distributions": "https://www.cchwebsites.com/content/calculators/RothvsRegular.html",
      "Roth IRA vs. Traditional IRA": "https://www.cchwebsites.com/content/calculators/Compare401k2.html",
      "Roth vs. Traditional 401(k) and your Paycheck": "https://www.cchwebsites.com/content/calculators/Borrow401k.html",
      "Should you Borrow From a 401(k) or 403(b)?": "https://www.cchwebsites.com/content/calculators/SocialSecurity.html",
      "Social Security Benefits": "https://www.cchwebsites.com/content/calculators/RegularIRA.html",
      "Traditional IRA Calculator": "https://www.cchwebsites.com/content/calculators/RegularIRA.html",
      
      // Savings Tools
      "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",
      
      // Tax Tools
      "1040 Tax Calculator": "https://www.cchwebsites.com/content/calculators/Tax1040.html",
      "457 Payroll Deductions": "https://www.cchwebsites.com/content/calculators/457Payroll.html",
      "Earned Income Credit (EIC) Calculator": "https://www.cchwebsites.com/content/calculators/EarnedIncomeCredit.html",
      "Estate Tax Planning": "https://www.cchwebsites.com/content/calculators/EstatePlan.html",
      "Flexible Spending Account (FSA) Calculator": "https://www.cchwebsites.com/content/calculators/Payroll125.html",
      "Hourly Paycheck Calculator": "https://www.cchwebsites.com/content/calculators/PayrollHourly.html",
      "Marginal Tax Rate Calculator": "https://www.cchwebsites.com/content/calculators/TaxMargin.html",
      "Net to Gross Paycheck Calculator": "https://www.cchwebsites.com/content/calculators/PayrollGross.html",
      "Payroll Deductions Calculator": "https://www.cchwebsites.com/content/calculators/Payroll.html",
      "Self-Employment Tax Calculator": "https://www.cchwebsites.com/content/calculators/TaxSelfEmployment.html",
      "U.S. 1040EZ Tax Form Calculator": "https://www.cchwebsites.com/content/calculators/TaxEZ1040.html"
    };
    
    return toolUrlMap[toolName] || "#";
  };

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

  const calculatorCategories = [
    {
      icon: Car,
      title: "Auto",
      description: "Auto loan calculators and financing tools",
      link: "/financial-tools/auto",
      toolCount: 10
    },
    {
      icon: Building,
      title: "Business",
      description: "Business financial analysis and planning tools",
      link: "/financial-tools/business",
      toolCount: 15
    },
    {
      icon: CreditCard,
      title: "Debt and Credit Cards",
      description: "Debt management and credit card optimization tools",
      link: "/financial-tools/debt-credit-cards",
      toolCount: 12
    },
    {
      icon: Shield,
      title: "Insurance",
      description: "Insurance analysis and planning calculators",
      link: "/financial-tools/insurance",
      toolCount: 14
    },
    {
      icon: TrendingUp,
      title: "Investment",
      description: "Investment analysis and portfolio planning tools",
      link: "/financial-tools/investment",
      toolCount: 27
    },
    {
      icon: DollarSign,
      title: "Loan",
      description: "Loan calculators and payment analysis tools",
      link: "/financial-tools/loan",
      toolCount: 13
    },
    {
      icon: Home,
      title: "Mortgage",
      description: "Mortgage calculators and home financing tools",
      link: "/financial-tools/mortgage",
      toolCount: 28
    },
    {
      icon: FileText,
      title: "Personal Finance",
      description: "Personal finance management and budgeting tools",
      link: "/financial-tools/personal-finance",
      toolCount: 9
    },
    {
      icon: PiggyBank,
      title: "Retirement",
      description: "Retirement planning and savings calculators",
      link: "/financial-tools/retirement",
      toolCount: 40
    },
    {
      icon: DollarSign,
      title: "Savings",
      description: "Savings planning and goal calculators",
      link: "/financial-tools/savings",
      toolCount: 18
    },
    {
      icon: Calculator,
      title: "Tax",
      description: "Tax planning and calculation tools",
      link: "/financial-tools/tax",
      toolCount: 11
    }
  ];

  return (
    <div className="min-h-screen">
      <Navigation />
      <main className="pt-16">
        {/* Hero Section */}
        <section 
          className="relative py-24 flex items-center justify-center text-center"
          style={{
            backgroundImage: "url('/lovable-uploads/f8f08a1a-0132-4376-af8a-c5bb86f0627e.png')",
            backgroundSize: "90% 80%",
            backgroundPosition: "center",
            backgroundRepeat: "no-repeat"
          }}
        >
          <div className="absolute inset-0 bg-forest/60"></div>
          <div className="relative z-10 container mx-auto px-4 text-center">
            <h1 className="text-display-xl font-display font-bold text-cream mb-6">
              Financial Tools
            </h1>
            <p className="text-body-lg text-cream/90 max-w-3xl mx-auto mb-8">
              Should I refinance my mortgage? How much do I need to save for my child's college education? As accounting professionals, these are some of the questions that are posed to us on a daily basis. We are providing these interactive financial calculators and other tools to assist you with some of the day-to-day questions and concerns that may arise.
            </p>
            <div className="bg-white/95 rounded-2xl p-6 card-elevation max-w-2xl mx-auto">
              <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>
        </section>

        {/* Calculator Categories */}
        <section className="py-24 bg-background">
          <div className="container mx-auto px-4">
            <div className="grid md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-8">
              {calculatorCategories.map((category, index) => {
                const Icon = category.icon;
                return (
                  <Link key={index} to={category.link}>
                    <Card className="card-elevation hover:shadow-lg gentle-transition cursor-pointer group rounded-2xl overflow-hidden h-full">
                      <CardContent className="p-8 h-full flex flex-col">
                        <div className="w-16 h-16 bg-brass/20 rounded-2xl flex items-center justify-center mb-6">
                          <Icon className="w-8 h-8 text-brass group-hover:scale-110 gentle-transition" strokeWidth={1.5} />
                        </div>
                        
                        <h3 className="text-display-md font-display font-semibold text-forest mb-3">
                          {category.title}
                        </h3>
                        
                        <p className="text-sage mb-4 leading-relaxed flex-grow">
                          {category.description}
                        </p>
                        
                        <div className="flex items-center justify-between">
                          <span className="text-sm text-brass font-medium">
                            {category.toolCount} calculators
                          </span>
                          <ArrowRight className="w-5 h-5 text-brass group-hover:translate-x-1 gentle-transition" strokeWidth={1.5} />
                        </div>
                      </CardContent>
                    </Card>
                  </Link>
                );
              })}
            </div>
          </div>
        </section>

        {/* Featured Calculator */}
        <section className="py-24 bg-muted/30">
          <div className="container mx-auto px-4">
            <div className="max-w-4xl mx-auto">
              <div className="text-center mb-12">
                <h2 className="text-display-lg font-display font-semibold text-forest mb-4">
                  Featured Calculator
                </h2>
                <p className="text-body-lg text-sage">
                  Try our most popular financial calculator
                </p>
              </div>

              <Card className="rounded-2xl card-elevation">
                <CardContent className="p-8">
                  <div className="grid lg:grid-cols-2 gap-8">
                    <div>
                      <h3 className="text-display-md font-display font-semibold text-forest mb-4">
                        Mortgage Loan Calculator
                      </h3>
                      <p className="text-sage mb-6">
                        Calculate your monthly mortgage payment including principal, interest, taxes, and insurance (PITI).
                      </p>
                      
                      <div className="space-y-4">
                        <div>
                          <label className="block text-sm font-medium text-forest mb-2">
                            Loan Amount ($)
                          </label>
                          <Input 
                            type="number" 
                            value={loanAmount}
                            onChange={(e) => setLoanAmount(e.target.value)}
                            placeholder="300,000"
                            className="rounded-xl"
                          />
                        </div>
                        <div>
                          <label className="block text-sm font-medium text-forest mb-2">
                            Interest Rate (%)
                          </label>
                          <Input 
                            type="number" 
                            value={interestRate}
                            onChange={(e) => setInterestRate(e.target.value)}
                            placeholder="6.5"
                            step="0.01"
                            className="rounded-xl"
                          />
                        </div>
                        <div>
                          <label className="block text-sm font-medium text-forest mb-2">
                            Loan Term (Years)
                          </label>
                          <Input 
                            type="number" 
                            value={loanTerm}
                            onChange={(e) => setLoanTerm(e.target.value)}
                            placeholder="30"
                            className="rounded-xl"
                          />
                        </div>
                        <div className="grid grid-cols-2 gap-4">
                          <div>
                            <label className="block text-sm font-medium text-forest mb-2">
                              Monthly Property Tax ($)
                            </label>
                            <Input 
                              type="number" 
                              value={propertyTax}
                              onChange={(e) => setPropertyTax(e.target.value)}
                              placeholder="250"
                              className="rounded-xl"
                            />
                          </div>
                          <div>
                            <label className="block text-sm font-medium text-forest mb-2">
                              Monthly Insurance ($)
                            </label>
                            <Input 
                              type="number" 
                              value={insurance}
                              onChange={(e) => setInsurance(e.target.value)}
                              placeholder="100"
                              className="rounded-xl"
                            />
                          </div>
                        </div>
                        <Button 
                          className="w-full btn-shadow"
                          onClick={calculateMortgagePayment}
                        >
                          Calculate Payment
                        </Button>
                      </div>
                    </div>
                    
                    <div className="bg-muted/30 rounded-xl p-6">
                      <h4 className="font-display font-semibold text-forest mb-4">
                        Payment Breakdown
                      </h4>
                      {calculatedPayment ? (
                        <div className="space-y-3">
                          <div className="flex justify-between">
                            <span className="text-sage">Principal & Interest:</span>
                            <span className="font-medium text-forest">
                              {formatCurrency(calculatedPayment.principalAndInterest)}
                            </span>
                          </div>
                          <div className="flex justify-between">
                            <span className="text-sage">Property Tax:</span>
                            <span className="font-medium text-forest">
                              {formatCurrency(calculatedPayment.propertyTax)}
                            </span>
                          </div>
                          <div className="flex justify-between">
                            <span className="text-sage">Insurance:</span>
                            <span className="font-medium text-forest">
                              {formatCurrency(calculatedPayment.insurance)}
                            </span>
                          </div>
                          <div className="flex justify-between border-t border-sage/20 pt-3">
                            <span className="font-medium text-forest">Total Monthly Payment:</span>
                            <span className="font-bold text-forest text-lg">
                              {formatCurrency(calculatedPayment.totalPayment)}
                            </span>
                          </div>
                        </div>
                      ) : (
                        <div className="text-center py-8 text-sage">
                          <p>Enter valid loan details and click "Calculate Payment" to see your monthly payment breakdown.</p>
                        </div>
                      )}
                    </div>
                  </div>
                </CardContent>
              </Card>
            </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 Interpreting Your Results?
              </h2>
              
              <p className="text-body-lg text-cream/90 mb-8 leading-relaxed">
                Our financial calculators are a great starting point, but every situation is unique. Let our experienced CPA team help you understand your results and develop a comprehensive financial strategy.
              </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"
                onClick={() => window.location.href = '/contact'}
              >
                Schedule Free Consultation
              </Button>
            </div>
          </div>
        </section>
      </main>
      <Footer />
      <ScrollToTop />
    </div>
  );
};

export default FinancialTools;
