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 { Building, ExternalLink, ArrowLeft } from "lucide-react";
import { Link } from "react-router-dom";

const FinancialToolsBusiness = () => {
  // Mapping der Tool-Namen zu ihren URLs
  const getToolUrl = (toolName: string): string => {
    const toolUrlMap: { [key: string]: string } = {
      "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"
    };
    
    return toolUrlMap[toolName] || "#";
  };

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

  const businessTools = [
    {
      name: "Breakeven Analysis",
      description: "Find out how many and what price you must sell your product at to make a profit."
    },
    {
      name: "Business Debt Consolidation Calculator",
      description: "Should your business consolidate its debt? Use this calculator to find out."
    },
    {
      name: "Business Valuation - Discounted Cash Flow",
      description: "This tool calculates a business valuation based upon the discounted cash flow methodology - illustrating how changes in projected growth rates and capital assumptions impact the business Net Present Value."
    },
    {
      name: "Cash Flow Calculator",
      description: "Having adequate cash flow is essential to keep your business running. Use this calculator to help you determine the cash flow generated by your business."
    },
    {
      name: "Commercial Loan Calculator",
      description: "Use this calculator to estimate your debt service coverage with a new loan. If your debt service coverage is high enough, including your new loan payment, you have a good chance of being approved."
    },
    {
      name: "Debt Service Coverage",
      description: "This tool calculates debt service and illustrates how debt service coverage ratios are impacted by changing income and capital assumptions."
    },
    {
      name: "Equipment Buy vs. Lease",
      description: "Should you lease your equipment or finance it? Find out with this calculator!"
    },
    {
      name: "Financial Ratios",
      description: "This calculator helps you to zero in on areas of your business that may need attention. Areas such as solvency, liquidity, operational efficiency and profitability."
    },
    {
      name: "Inventory Analysis",
      description: "Use this calculator to determine how much inventory you should hold, and efficient timing of your inventory orders."
    },
    {
      name: "Like Kind Exchange",
      description: "This calculator is designed to calculate and the recognized loss, gain and the basis for a Like Kind Exchange."
    },
    {
      name: "Profit Margin Calculator",
      description: "This calculator can help you determine the selling price for your products to achieve a desired profit margin."
    },
    {
      name: "Repossession of Personal Property from a Deferred Payment Sale",
      description: "If you have repossessed personal property from a deferred payment sale, you can this calculator to determine the gain or loss."
    },
    {
      name: "Repossession of Personal Property from an Installment Payment Sale",
      description: "If you have repossessed personal property with installment payments, you can this calculator to determine the gain or loss."
    },
    {
      name: "Repossession of Real Property",
      description: "If you have repossessed real property, you can this calculator to determine the gain or loss as well as its new basis."
    },
    {
      name: "Working Capital Needs",
      description: "Working capital essential to running your business. This calculator assists you in determining your working capital needs for the next year."
    }
  ];

  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">
                  <Building 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">
                    Business Financial Tools
                  </h1>
                  <p className="text-body-lg text-white/90">
                    Business financial analysis and planning tools to help you make informed 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>

        {/* Business 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">
                {businessTools.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">
                          <Building 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 Business Financial Planning?
              </h2>
              
              <p className="text-body-lg text-cream/90 mb-8 leading-relaxed">
                Our experienced CPA team specializes in business financial analysis and can help you interpret these results and develop a comprehensive business 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"
              >
                Schedule Business Consultation
              </Button>
            </div>
          </div>
        </section>
      </main>
      <Footer />
      <ScrollToTop />
    </div>
  );
};

export default FinancialToolsBusiness;
