"use client";

import { ShieldCheck, Zap, CreditCard, Play, Globe, Package } from "lucide-react";
import { usePublicVpnCatalog } from "@/features/services/hooks";
import { VPN_FEATURES } from "@/features/services/utils";
import { LoadingCard } from "@/components/atoms";
import { AsyncBlock } from "@/components/molecules/AsyncBlock/AsyncBlock";
import { AlertBanner } from "@/components/molecules/AlertBanner/AlertBanner";
import { VpnPlanCard } from "@/features/services/components/vpn/VpnPlanCard";
import { ServicesBackLink } from "@/features/services/components/base/ServicesBackLink";
import { useServicesBasePath } from "@/features/services/hooks/useServicesBasePath";
import { ServiceHighlights } from "@/features/services/components/base/ServiceHighlights";
import { HowItWorks, type HowItWorksStep } from "@/features/services/components/base/HowItWorks";
import { ServiceCTA } from "@/features/services/components/base/ServiceCTA";
import { ServiceFAQ, type FAQItem } from "@/features/services/components/base/ServiceFAQ";

// Steps for HowItWorks
const vpnSteps: HowItWorksStep[] = [
  {
    icon: <CreditCard className="h-6 w-6" />,
    title: "Sign Up",
    description: "Create your account to get started",
  },
  {
    icon: <Globe className="h-6 w-6" />,
    title: "Choose Region",
    description: "Select US (San Francisco) or UK (London)",
  },
  {
    icon: <Package className="h-6 w-6" />,
    title: "Place Order",
    description: "Complete checkout and receive router",
  },
  {
    icon: <Play className="h-6 w-6" />,
    title: "Connect & Stream",
    description: "Plug in, connect devices, enjoy",
  },
];

// FAQ items for VPN
const vpnFaqItems: FAQItem[] = [
  {
    question: "Which streaming services can I access?",
    answer:
      "Our VPN establishes a network connection that virtually locates you in the designated server location (US or UK). This can help access region-specific content on services like Netflix, Hulu, BBC iPlayer, and others. However, not all services can be unblocked, and we cannot guarantee access to any specific streaming platform.",
  },
  {
    question: "How fast is the VPN connection?",
    answer:
      "The VPN connection speed depends on your existing internet connection. For HD streaming, we recommend at least 10Mbps download speed. The VPN router is optimized for streaming and should provide smooth playback for most content.",
  },
  {
    question: "Can I use multiple devices at once?",
    answer:
      "Yes! Any device connected to the VPN router's WiFi network will be routed through the VPN. This includes smart TVs, streaming boxes, gaming consoles, and more. Your regular internet devices can stay on your normal WiFi.",
  },
  {
    question: "What happens if I need help with setup?",
    answer:
      "We provide full English support for setup and troubleshooting. The router comes pre-configured, so most users just need to plug it in. If you encounter any issues, our support team can assist via email or phone.",
  },
  {
    question: "Is there a contract or commitment period?",
    answer:
      "The VPN service is a monthly rental with no long-term contract required. You can cancel at any time. The one-time activation fee covers initial setup and router preparation.",
  },
];

/**
 * Public VPN Plans View
 *
 * Displays VPN plans for unauthenticated users with full marketing content.
 */
export function PublicVpnPlansView() {
  const servicesBasePath = useServicesBasePath();
  const { data, error } = usePublicVpnCatalog();
  const vpnPlans = data?.plans || [];
  const activationFees = data?.activationFees || [];
  const isLoading = !data && !error;

  if (isLoading || error) {
    return (
      <div className="max-w-6xl mx-auto px-4">
        <ServicesBackLink href={servicesBasePath} label="Back to Services" />

        <AsyncBlock
          isLoading={isLoading}
          error={error}
          loadingText="Loading VPN plans..."
          variant="page"
        >
          <div className="grid grid-cols-1 md:grid-cols-2 gap-6 max-w-4xl mx-auto">
            {Array.from({ length: 4 }).map((_, index) => (
              <LoadingCard key={index} className="h-64" />
            ))}
          </div>
        </AsyncBlock>
      </div>
    );
  }

  return (
    <div className="max-w-6xl mx-auto px-4 pb-16 space-y-8">
      <ServicesBackLink href={servicesBasePath} label="Back to Services" />

      {/* Hero Section */}
      <div className="text-center py-6">
        <div
          className="animate-in fade-in slide-in-from-bottom-4 duration-500"
          style={{ animationDelay: "0ms" }}
        >
          <span className="inline-flex items-center gap-2 rounded-full bg-purple-500/10 border border-purple-500/20 px-4 py-1.5 text-sm text-purple-600 dark:text-purple-400 font-medium mb-4">
            <ShieldCheck className="h-4 w-4" />
            VPN Router Service
          </span>
        </div>
        <h1
          className="text-display-md md:text-display-lg font-display text-foreground tracking-tight animate-in fade-in slide-in-from-bottom-6 duration-700"
          style={{ animationDelay: "100ms" }}
        >
          Stream Content from Abroad
        </h1>
        <p
          className="text-lg text-muted-foreground mt-3 max-w-xl mx-auto leading-relaxed animate-in fade-in slide-in-from-bottom-8 duration-700"
          style={{ animationDelay: "200ms" }}
        >
          Access US and UK streaming services using a pre-configured VPN router. No technical setup
          required.
        </p>

        {/* Order info banner */}
        <div
          className="inline-flex mt-6 animate-in fade-in slide-in-from-bottom-8 duration-700"
          style={{ animationDelay: "300ms" }}
        >
          <div className="bg-success-soft border border-success/25 rounded-xl px-4 py-3">
            <div className="flex items-center gap-2 justify-center">
              <Zap className="h-4 w-4 text-success flex-shrink-0" />
              <p className="text-sm text-foreground">
                <span className="font-medium">Order today</span>
                <span className="text-muted-foreground">
                  {" "}
                  — create account, add payment, and your router ships upon confirmation.
                </span>
              </p>
            </div>
          </div>
        </div>
      </div>

      {/* Service Highlights - uses cp-stagger-children internally */}
      <section>
        <ServiceHighlights features={VPN_FEATURES} />
      </section>

      {/* Plans Section */}
      {vpnPlans.length > 0 ? (
        <section
          className="animate-in fade-in slide-in-from-bottom-8 duration-700"
          style={{ animationDelay: "500ms" }}
        >
          <div className="text-center mb-6">
            <p className="text-sm font-semibold text-primary uppercase tracking-wider mb-2">
              Choose Your Region
            </p>
            <h2 className="text-display-sm font-display text-foreground">Available Plans</h2>
            <p className="text-sm text-muted-foreground mt-2">
              Select one region per router rental
            </p>
          </div>

          <div className="grid grid-cols-1 md:grid-cols-2 gap-6 max-w-4xl mx-auto">
            {vpnPlans.map(plan => (
              <VpnPlanCard key={plan.id} plan={plan} />
            ))}
          </div>

          {activationFees.length > 0 && (
            <AlertBanner variant="info" className="mt-6 max-w-4xl mx-auto" title="Activation Fee">
              A one-time activation fee of ¥3,000 applies per router rental. Tax (10%) not included.
            </AlertBanner>
          )}
        </section>
      ) : (
        <div className="text-center py-12">
          <ShieldCheck className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
          <h3 className="text-lg font-medium text-foreground mb-2">No VPN Plans Available</h3>
          <p className="text-muted-foreground mb-6">
            We couldn&apos;t find any VPN plans available at this time.
          </p>
          <ServicesBackLink
            href={servicesBasePath}
            label="Back to Services"
            align="center"
            className="mt-4 mb-0"
          />
        </div>
      )}

      {/* How It Works */}
      <HowItWorks steps={vpnSteps} eyebrow="Simple Setup" title="How It Works" />

      {/* CTA Section */}
      <ServiceCTA
        eyebrow="Get started today"
        headline="Ready to unlock your content?"
        description="Choose your region and get your pre-configured router shipped to you"
        primaryAction={{
          label: "View Plans",
          href: "#",
          onClick: e => {
            e.preventDefault();
            window.scrollTo({ top: 0, behavior: "smooth" });
          },
        }}
      />

      {/* FAQ Section */}
      <ServiceFAQ
        items={vpnFaqItems}
        eyebrow="Common Questions"
        title="Frequently Asked Questions"
      />

      {/* Disclaimer */}
      <AlertBanner variant="warning" title="Important Disclaimer">
        <p className="text-sm">
          Content subscriptions are NOT included in the VPN package. Our VPN service establishes a
          network connection that virtually locates you in the designated server location. Not all
          services can be unblocked. We do not guarantee access to any specific website or streaming
          service quality.
        </p>
      </AlertBanner>

      {/* Footer Note */}
      <div className="text-center text-sm text-muted-foreground">
        <p>All prices exclude 10% consumption tax.</p>
      </div>
    </div>
  );
}

export default PublicVpnPlansView;
