"use client"
import { useState } from "react"
import Link from "next/link"

const privatePlans = [
  {
    id: "free",
    name: "Free",
    price: "$0",
    period: "forever",
    apps: "5",
    coverLetters: "5",
    badge: "",
    highlight: false,
    features: ["5 AI applications/month", "AI resume tailoring", "AI cover letters", "Application tracker"],
    cta: "Get Started",
    ctaStyle: "bg-white/10 hover:bg-white/20"
  },
  {
    id: "starter",
    name: "Starter",
    price: "$29",
    period: "/mo",
    apps: "20",
    coverLetters: "20",
    badge: "",
    highlight: false,
    features: ["20 AI applications/month", "AI resume tailoring", "AI cover letters", "Add your own API keys"],
    cta: "Start Now",
    ctaStyle: "bg-blue-500 hover:bg-blue-600"
  },
  {
    id: "pro",
    name: "Pro",
    price: "$69",
    period: "/mo",
    apps: "100",
    coverLetters: "100",
    badge: "Most Popular",
    highlight: true,
    features: ["100 AI applications/month", "AI resume tailoring", "AI cover letters", "LinkedIn import", "Add your own API keys", "Priority support"],
    cta: "Go Pro",
    ctaStyle: "bg-blue-500 hover:bg-blue-600"
  },
  {
    id: "ultra",
    name: "Ultra",
    price: "$149",
    period: "/mo",
    apps: "200",
    coverLetters: "200",
    badge: "",
    highlight: false,
    features: ["200 AI applications/month", "AI resume tailoring", "AI cover letters", "LinkedIn import", "Add your own API keys", "SMS notifications"],
    cta: "Go Ultra",
    ctaStyle: "bg-slate-600 hover:bg-slate-500"
  },
  {
    id: "unlimited",
    name: "Unlimited",
    price: "$199",
    period: "/mo",
    apps: "Unlimited",
    coverLetters: "Unlimited",
    badge: "Best Value",
    highlight: false,
    features: ["Unlimited AI applications", "AI resume tailoring", "AI cover letters", "LinkedIn import", "Add your own API keys", "24/7 priority support"],
    cta: "Go Unlimited",
    ctaStyle: "bg-green-600 hover:bg-green-500"
  },
]

const agencyPlans = [
  {
    id: "agency_starter",
    name: "Starter",
    price: "$555",
    period: "/mo",
    submissions: "1,000",
    clients: "10",
    badge: "",
    highlight: false,
    features: ["1,000 submissions/month", "10 client profiles", "AI resume tailoring", "White-label dashboard"],
    cta: "Start Agency",
    ctaStyle: "bg-purple-600 hover:bg-purple-500"
  },
  {
    id: "agency_growth",
    name: "Growth",
    price: "$999",
    period: "/mo",
    submissions: "3,000",
    clients: "50",
    badge: "Most Popular",
    highlight: true,
    features: ["3,000 submissions/month", "50 client profiles", "AI resume tailoring", "White-label dashboard", "Priority support"],
    cta: "Grow Agency",
    ctaStyle: "bg-purple-600 hover:bg-purple-500"
  },
  {
    id: "agency_scale",
    name: "Scale",
    price: "$1,499",
    period: "/mo",
    submissions: "5,000",
    clients: "150",
    badge: "",
    highlight: false,
    features: ["5,000 submissions/month", "150 client profiles", "AI resume tailoring", "White-label dashboard", "Dedicated manager"],
    cta: "Scale Up",
    ctaStyle: "bg-slate-600 hover:bg-slate-500"
  },
  {
    id: "agency_pro",
    name: "Pro",
    price: "$3,699",
    period: "/mo",
    submissions: "10,000",
    clients: "500",
    badge: "Best Value",
    highlight: false,
    features: ["10,000 submissions/month", "500 client profiles", "AI resume tailoring", "White-label dashboard", "Custom integrations"],
    cta: "Go Pro",
    ctaStyle: "bg-slate-600 hover:bg-slate-500"
  },
  {
    id: "agency_enterprise",
    name: "Enterprise",
    price: "Custom",
    period: "",
    submissions: "Unlimited",
    clients: "Unlimited",
    badge: "",
    highlight: false,
    features: ["Unlimited submissions", "Unlimited clients", "AI resume tailoring", "White-label dashboard", "Dedicated manager", "SLA guarantee"],
    cta: "Contact Us",
    ctaStyle: "bg-slate-600 hover:bg-slate-500"
  },
]

function PlanCard({ plan, type }: { plan: any, type: string }) {
  const highlightBg = type === "private" 
    ? "bg-gradient-to-br from-blue-600/30 to-purple-600/30 border-blue-500/50" 
    : "bg-gradient-to-br from-purple-600/30 to-pink-600/30 border-purple-500/50"
  
  const checkColor = type === "private" ? "text-green-400" : "text-purple-400"
  const badgeBg = type === "private" ? "bg-blue-500" : "bg-purple-500"
  
  return (
    <div className={`rounded-2xl p-4 border flex flex-col relative h-full ${plan.highlight ? highlightBg : "bg-slate-700/50 border-slate-600"}`}>
      {plan.badge && (
        <div className="absolute -top-2.5 left-1/2 -translate-x-1/2 z-10">
          <span className={`px-2.5 py-0.5 ${badgeBg} text-white text-[10px] font-bold rounded-full whitespace-nowrap`}>{plan.badge}</span>
        </div>
      )}
      <div className="text-center mb-2">
        <div className="text-xs text-slate-400 font-medium mb-0.5">{plan.name}</div>
        <div className="flex items-baseline justify-center gap-0.5">
          <span className="text-xl font-bold text-white">{plan.price}</span>
          <span className="text-slate-400 text-[10px]">{plan.period}</span>
        </div>
        <div className="text-[10px] text-blue-400/80 mt-0.5">
          {type === "private" 
            ? `${plan.apps} apps • ${plan.coverLetters} letters`
            : `${plan.submissions} subs • ${plan.clients} clients`
          }
        </div>
      </div>
      <ul className="space-y-1 mb-3 flex-grow">
        {plan.features.map((f: string) => (
          <li key={f} className="text-slate-300 text-[10px] flex items-start gap-1.5">
            <span className={`${checkColor} flex-shrink-0`}>✓</span> {f}
          </li>
        ))}
      </ul>
      <Link 
        href={plan.id === "agency_enterprise" ? "/autojobs/contact" : `/autojobs/signup?plan=${plan.id}&type=${type}`}
        className={`block text-center px-3 py-2 rounded-lg font-medium text-white text-xs transition mt-auto ${plan.ctaStyle}`}
      >
        {plan.cta}
      </Link>
    </div>
  )
}

// JSON-LD Structured Data for SEO
const jsonLd = {
  "@context": "https://schema.org",
  "@type": "SoftwareApplication",
  "name": "AutoJobs",
  "alternateName": "AutoJobs AI",
  "url": "https://hostpioneers.com/autojobs",
  "description": "AI-powered job application automation platform. AI finds matching jobs, rewrites resumes, generates cover letters, and applies automatically.",
  "applicationCategory": "BusinessApplication",
  "operatingSystem": "Web",
  "offers": {
    "@type": "AggregateOffer",
    "url": "https://hostpioneers.com/autojobs",
    "priceCurrency": "USD",
    "lowPrice": "0",
    "highPrice": "3699",
    "offerCount": "9"
  },
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.8",
    "ratingCount": "127"
  },
  "provider": {
    "@type": "Organization",
    "name": "HostPioneers",
    "url": "https://hostpioneers.com"
  }
}

const privatePlansJsonLd = {
  "@context": "https://schema.org",
  "@type": "ItemList",
  "name": "AutoJobs Private Plans",
  "itemListElement": privatePlans.map((plan, index) => ({
    "@type": "Offer",
    "position": index + 1,
    "name": plan.name,
    "price": plan.price.replace("$", ""),
    "priceCurrency": "USD",
    "description": plan.features.join(", "),
    "url": `https://hostpioneers.com/autojobs/signup?plan=${plan.id}&type=private`
  }))
}

export default function LandingPage() {
  const [activeTab, setActiveTab] = useState<"private" | "agency">("private")

  return (
    <div className="min-h-screen bg-gradient-to-br from-slate-900 via-blue-950 to-slate-900">
      {/* SEO JSON-LD */}
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
      />
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(privatePlansJsonLd) }}
      />

      {/* Nav */}
      <nav className="flex justify-between items-center px-6 py-5 max-w-6xl mx-auto" role="navigation" aria-label="Main navigation">
        <div className="text-2xl font-bold text-white">
          Auto<span className="text-blue-400">Jobs</span>
        </div>
        <div className="flex gap-4 items-center">
          <button className="text-slate-300 hover:text-white transition flex items-center gap-2 text-sm">
            <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
              <path d="M19 3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14m-.5 15.5v-5.3a3.26 3.26 0 0 0-3.26-3.26c-.85 0-1.84.52-2.32 1.3v-1.11h-2.79v8.37h2.79v-4.93c0-.77.62-1.4 1.39-1.4a1.4 1.4 0 0 1 1.4 1.4v4.93h2.79M6.88 8.56a1.68 1.68 0 0 0 1.68-1.68c0-.93-.75-1.69-1.68-1.69a1.69 1.69 0 0 0-1.69 1.69c0 .93.76 1.68 1.69 1.68m1.39 9.94v-8.37H5.5v8.37h2.77z"/>
            </svg>
            Login with LinkedIn
          </button>
          <Link href="/autojobs/signup" className="px-5 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg font-medium transition text-sm">
            Get Started
          </Link>
        </div>
      </nav>

      {/* Hero */}
      <header className="py-14 px-6 text-center">
        <div className="max-w-4xl mx-auto">
          <div className="inline-block px-4 py-1.5 rounded-full bg-blue-500/20 border border-blue-500/30 text-blue-300 text-sm mb-5">
            AI-Powered Job Application Automation
          </div>
          <h1 className="text-4xl md:text-5xl font-bold text-white mb-5 leading-tight">
            Stop Manually Applying.
            <br />
            <span className="text-blue-400">Let AI Handle It.</span>
          </h1>
          <p className="text-lg text-slate-300 mb-7 max-w-2xl mx-auto">
            Upload your resume. Connect LinkedIn. AI finds matching jobs, rewrites your resume + cover letter for each one, and applies automatically while you sleep.
          </p>
          <div className="flex flex-col sm:flex-row gap-3 justify-center">
            <Link 
              href="/autojobs/signup?plan=free"
              className="px-8 py-3 bg-blue-500 hover:bg-blue-600 text-white rounded-xl font-semibold transition shadow-lg shadow-blue-500/25"
            >
              Start Free — 5 Applications
            </Link>
            <button className="px-8 py-3 bg-white/10 hover:bg-white/20 text-white rounded-xl font-semibold border border-white/20 transition flex items-center justify-center gap-2">
              <svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
                <path d="M19 3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14m-.5 15.5v-5.3a3.26 3.26 0 0 0-3.26-3.26c-.85 0-1.84.52-2.32 1.3v-1.11h-2.79v8.37h2.79v-4.93c0-.77.62-1.4 1.39-1.4a1.4 1.4 0 0 1 1.4 1.4v4.93h2.79M6.88 8.56a1.68 1.68 0 0 0 1.68-1.68c0-.93-.75-1.69-1.68-1.69a1.69 1.69 0 0 0-1.69 1.69c0 .93.76 1.68 1.69 1.68m1.39 9.94v-8.37H5.5v8.37h2.77z"/>
              </svg>
              Sign up with LinkedIn
            </button>
          </div>
        </div>
      </header>

      {/* How It Works */}
      <section className="py-10 px-6 bg-slate-800/40" aria-labelledby="how-it-works-heading">
        <div className="max-w-5xl mx-auto">
          <h2 id="how-it-works-heading" className="text-2xl font-bold text-white text-center mb-6">How It Works</h2>
          <div className="grid md:grid-cols-3 gap-5">
            {[
              { step: "01", title: "Create Profile", desc: "Upload resume. Connect LinkedIn. Set job preferences — keywords, location, salary range." },
              { step: "02", title: "AI Customizes", desc: "We search 100+ job boards. For each match, AI rewrites your resume and writes a personalized cover letter." },
              { step: "03", title: "Apply & Track", desc: "Apply with one click or let AI apply automatically. Track every application status in your dashboard." }
            ].map((item) => (
              <article key={item.step} className="bg-slate-700/50 rounded-xl p-5 border border-slate-600 text-center">
                <div className="text-4xl font-bold text-blue-500/20 mb-2">{item.step}</div>
                <h3 className="text-lg font-semibold text-white mb-1">{item.title}</h3>
                <p className="text-slate-400 text-sm">{item.desc}</p>
              </article>
            ))}
          </div>
        </div>
      </section>

      {/* Pricing Toggle + Plans */}
      <section className="py-14 px-6" aria-labelledby="pricing-heading">
        <div className="max-w-6xl mx-auto text-center">
          <h2 id="pricing-heading" className="text-3xl font-bold text-white mb-5">Choose Your Plan</h2>
          
          {/* Toggle Switch */}
          <div className="inline-flex items-center gap-0 bg-slate-800 rounded-full p-1 mb-8 border border-slate-700" role="tablist">
            <button
              onClick={() => setActiveTab("private")}
              role="tab"
              aria-selected={activeTab === "private"}
              className={`px-6 py-2.5 rounded-full font-semibold text-sm transition-all ${
                activeTab === "private"
                  ? "bg-blue-500 text-white shadow-lg"
                  : "text-slate-400 hover:text-white"
              }`}
            >
              👤 Job Seeker
            </button>
            <button
              onClick={() => setActiveTab("agency")}
              role="tab"
              aria-selected={activeTab === "agency"}
              className={`px-6 py-2.5 rounded-full font-semibold text-sm transition-all ${
                activeTab === "agency"
                  ? "bg-purple-500 text-white shadow-lg"
                  : "text-slate-400 hover:text-white"
              }`}
            >
              🏢 Recruiting Agency
            </button>
          </div>

          {/* Private Plans */}
          {activeTab === "private" && (
            <div role="tabpanel" aria-label="Job Seeker Plans">
              <p className="text-slate-400 mb-5 text-sm">Every plan includes AI resume tailoring + AI cover letter generation</p>
              <div className="grid grid-cols-2 md:grid-cols-5 gap-3 max-w-5xl mx-auto items-stretch">
                {privatePlans.map((plan) => (
                  <PlanCard key={plan.id} plan={plan} type="private" />
                ))}
              </div>
            </div>
          )}

          {/* Agency Plans - 5 columns */}
          {activeTab === "agency" && (
            <div role="tabpanel" aria-label="Recruiting Agency Plans">
              <p className="text-slate-400 mb-5 text-sm">Manage multiple clients. Hard caps — no unlimited.</p>
              <div className="grid grid-cols-2 md:grid-cols-5 gap-3 max-w-5xl mx-auto items-stretch">
                {agencyPlans.map((plan) => (
                  <PlanCard key={plan.id} plan={plan} type="agency" />
                ))}
              </div>
              <p className="text-slate-500 text-xs mt-3">All plans have hard submission caps. No unlimited access for agencies.</p>
            </div>
          )}
        </div>
      </section>

      {/* Features */}
      <section className="py-14 px-6 bg-slate-800/40" aria-labelledby="features-heading">
        <div className="max-w-5xl mx-auto">
          <h2 id="features-heading" className="text-2xl font-bold text-white text-center mb-6">Everything You Need</h2>
          <div className="grid md:grid-cols-3 gap-4">
            {[
              { icon: "🎯", title: "AI Resume Tailoring", desc: "Every resume rewritten to match job description keywords for maximum relevance" },
              { icon: "✉️", title: "AI Cover Letters", desc: "Personalized cover letter generated for each company and position" },
              { icon: "🔍", title: "Multi-Source Search", desc: "Jooble, JSearch aggregated and deduplicated — no duplicate applications" },
              { icon: "📊", title: "Application Tracker", desc: "Dashboard tracks status from applied to offer stage" },
              { icon: "🔑", title: "Your Own API Keys", desc: "You control your data and spending — bring your own keys" },
              { icon: "💼", title: "LinkedIn Import", desc: "Import your saved LinkedIn resumes and profile automatically" },
            ].map((f) => (
              <article key={f.title} className="bg-slate-700/50 rounded-xl p-4 border border-slate-600">
                <div className="text-xl mb-1.5" aria-hidden="true">{f.icon}</div>
                <h3 className="font-semibold text-white mb-0.5">{f.title}</h3>
                <p className="text-slate-400 text-sm">{f.desc}</p>
              </article>
            ))}
          </div>
        </div>
      </section>

      {/* FAQ Schema */}
      <section className="py-14 px-6" aria-labelledby="faq-heading">
        <div className="max-w-3xl mx-auto">
          <h2 id="faq-heading" className="text-2xl font-bold text-white text-center mb-6">Frequently Asked Questions</h2>
          <div className="space-y-4">
            {[
              { q: "How does AI resume tailoring work?", a: "Our AI analyzes the job description and rewrites your resume to highlight the skills and experience most relevant to that specific position, increasing your chances of getting noticed." },
              { q: "What job boards does AutoJobs search?", a: "We search across multiple job boards including Jooble, JSearch, and other aggregators, then deduplicate results so you never apply to the same job twice." },
              { q: "Can I use my own API keys?", a: "Yes! On Starter plans and above, you can add your own API keys for AI services, giving you more control over your data and spending." },
              { q: "What happens when I hit my monthly limit?", a: "Your applications are paused until your next billing cycle. You can upgrade at any time for higher limits." },
            ].map((faq, i) => (
              <details key={i} className="bg-slate-700/50 rounded-xl border border-slate-600 p-4 group">
                <summary className="font-semibold text-white cursor-pointer list-none flex justify-between items-center">
                  {faq.q}
                  <span className="text-blue-400 group-open:rotate-180 transition-transform">▼</span>
                </summary>
                <p className="text-slate-400 text-sm mt-2">{faq.a}</p>
              </details>
            ))}
          </div>
        </div>
        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{
            __html: JSON.stringify({
              "@context": "https://schema.org",
              "@type": "FAQPage",
              "mainEntity": [
                {
                  "@type": "Question",
                  "name": "How does AI resume tailoring work?",
                  "acceptedAnswer": {
                    "@type": "Answer",
                    "text": "Our AI analyzes the job description and rewrites your resume to highlight the skills and experience most relevant to that specific position."
                  }
                },
                {
                  "@type": "Question", 
                  "name": "What job boards does AutoJobs search?",
                  "acceptedAnswer": {
                    "@type": "Answer",
                    "text": "We search across multiple job boards including Jooble, JSearch, and other aggregators, then deduplicate results."
                  }
                }
              ]
            })
          }}
        />
      </section>

      {/* Footer */}
      <footer className="py-6 px-6 border-t border-slate-700">
        <div className="max-w-5xl mx-auto text-center text-slate-500 text-sm">
          <p>© 2026 AutoJobs — Built on <a href="https://hostpioneers.com" className="text-blue-400 hover:underline">HostPioneers</a></p>
          <nav className="mt-3 flex justify-center gap-4 text-xs" aria-label="Footer navigation">
            <a href="/autojobs/privacy" className="hover:text-white transition">Privacy Policy</a>
            <a href="/autojobs/terms" className="hover:text-white transition">Terms of Service</a>
            <a href="/autojobs/gdpr" className="hover:text-white transition">GDPR</a>
            <a href="/autojobs/contact" className="hover:text-white transition">Contact</a>
          </nav>
        </div>
      </footer>
    </div>
  )
}