use leptos::prelude::*;
use rustelo_content::rustelo_core_lib::i18n::content_helper::create_content_provider_reactive;
use crate::content_graph::ProjectGraphSection;

struct Feature {
    title_key: &'static str,
    desc_key: &'static str,
    emoji: &'static str,
}

const FEATURES: &[Feature] = &[
    Feature {
        title_key: "secretumvault-feat-pqc-title",
        desc_key: "secretumvault-feat-pqc-desc",
        emoji: "\u{1f510}",
    },
    Feature {
        title_key: "secretumvault-feat-engines-title",
        desc_key: "secretumvault-feat-engines-desc",
        emoji: "\u{1f511}",
    },
    Feature {
        title_key: "secretumvault-feat-storage-title",
        desc_key: "secretumvault-feat-storage-desc",
        emoji: "\u{1f4be}",
    },
    Feature {
        title_key: "secretumvault-feat-cedar-title",
        desc_key: "secretumvault-feat-cedar-desc",
        emoji: "\u{1f6e1}\u{fe0f}",
    },
    Feature {
        title_key: "secretumvault-feat-cloud-title",
        desc_key: "secretumvault-feat-cloud-desc",
        emoji: "\u{2601}\u{fe0f}",
    },
    Feature {
        title_key: "secretumvault-feat-enterprise-title",
        desc_key: "secretumvault-feat-enterprise-desc",
        emoji: "\u{1f3e6}",
    },
];

const TECH_BADGES: &[&str] = &[
    "Rust",
    "Axum",
    "Tokio",
    "ML-KEM-768",
    "ML-DSA-65",
    "OQS",
    "OpenSSL",
    "AWS-LC",
    "etcd",
    "SurrealDB",
    "PostgreSQL",
    "Cedar",
    "Docker",
    "Kubernetes",
    "Helm",
    "Prometheus",
    "NATS",
    "Shamir SSS",
];

#[component]
pub fn UnifiedSecretumvaultPage(
    #[prop(default = rustelo_content::rustelo_core_lib::config::get_default_language().to_string())]
    _language: String,
    #[prop(optional)] lang_content: Option<std::collections::HashMap<String, String>>,
) -> impl IntoView {
    let content = create_content_provider_reactive(lang_content.clone());

    view! {
        <div class="ds-bg-page min-h-screen">

          // ── Hero ─────────────────────────────────────────────────────────────
          <section class="relative py-ds-8 ds-container">
            <div class="mx-auto max-w-4xl text-center">
              <div class="flex flex-col items-center gap-4 mb-6">
                <img
                  src="/images/logos/projects/secretumvault.svg"
                  alt="SecretumVault"
                  class="h-28"
                />
              </div>
              <p class="ds-caption ds-text-secondary mb-2 font-mono italic">
                {content.t("secretumvault-tagline")}
              </p>
              <span class="inline-block px-3 py-1 ds-caption ds-bg border ds-border ds-rounded-md ds-text-secondary mb-4">
                {content.t("secretumvault-badge")}
              </span>
              <h1 class="text-balance text-4xl font-bold leading-11 tracking-tight ds-text sm:text-5xl mb-4">
                {content.t("secretumvault-page-title")}
              </h1>
              <p class="ds-body ds-text-secondary max-w-3xl mx-auto">
                {content.t("secretumvault-page-subtitle")}
              </p>
              <div class="flex flex-col sm:flex-row gap-4 justify-center mt-8">
                <a
                  href="https://repo.example.com/org/secretumvault"
                  target="_blank"
                  rel="noopener noreferrer"
                  class="no-underline ds-btn-primary"
                >
                  {content.t("secretumvault-cta-explore")}
                </a>
              </div>
            </div>
          </section>

          // ── Why SecretumVault (Problem / Solution) ───────────────────────────
          <section class="py-ds-6 ds-bg ds-rounded-lg">
            <div class="ds-container-lg ds-container">
              <div class="text-center mb-ds-12">
                <h2 class="text-3xl font-bold ds-text">{content.t("secretumvault-why-title")}</h2>
              </div>
              <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="ds-bg-page p-ds-6 ds-rounded-lg border-l-4 border-red-500/50 ds-border border ds-shadow-sm">
                  <h3 class="ds-heading-4 ds-text mb-3">{content.t("secretumvault-problem-title")}</h3>
                  <p class="ds-caption ds-text-secondary leading-relaxed">{content.t("secretumvault-problem-desc")}</p>
                </div>
                <div class="ds-bg-page p-ds-6 ds-rounded-lg border-l-4 ds-border border ds-shadow-sm">
                  <h3 class="ds-heading-4 ds-text mb-3">{content.t("secretumvault-solution-title")}</h3>
                  <p class="ds-caption ds-text-secondary leading-relaxed">{content.t("secretumvault-solution-desc")}</p>
                </div>
              </div>
            </div>
          </section>

          // ── Core Capabilities ────────────────────────────────────────────────
          <section class="py-ds-6 ds-rounded-lg">
            <div class="ds-container-lg ds-container">
              <div class="text-center mb-ds-12">
                <h2 class="text-3xl font-bold ds-text">{content.t("secretumvault-features-title")}</h2>
              </div>
              <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                {FEATURES.iter().map(|f| {
                    let title = content.t(f.title_key);
                    let desc  = content.t(f.desc_key);
                    let emoji = f.emoji;
                    view! {
                        <div class="ds-bg p-ds-6 ds-rounded-lg ds-shadow-sm border-l-4 ds-border">
                          <div class="flex items-center gap-3 mb-3">
                            <span class="text-xl">{emoji}</span>
                            <h3 class="ds-heading-4 ds-text">{title}</h3>
                          </div>
                          <p class="ds-caption ds-text-secondary leading-relaxed">{desc}</p>
                        </div>
                    }
                }).collect_view()}
              </div>
            </div>
          </section>

          // ── Tech Stack ───────────────────────────────────────────────────────
          <section class="py-ds-6 ds-bg ds-rounded-lg">
            <div class="ds-container-lg ds-container">
              <div class="text-center mb-ds-8">
                <h2 class="text-3xl font-bold ds-text">{content.t("secretumvault-tech-stack-title")}</h2>
              </div>
              <div class="flex flex-wrap gap-3 justify-center">
                {TECH_BADGES.iter().map(|badge| {
                    view! {
                        <span class="px-3 py-2 ds-bg-page border ds-border ds-rounded-md ds-caption font-mono ds-text">
                          {*badge}
                        </span>
                    }
                }).collect_view()}
              </div>
            </div>
          </section>

          // ── CTA ──────────────────────────────────────────────────────────────
          <section class="py-ds-6 ds-rounded-lg">
            <div class="mx-auto max-w-3xl ds-container text-center">
              <h2 class="text-3xl font-bold ds-text mb-ds-4">{content.t("secretumvault-cta-title")}</h2>
              <p class="ds-text-secondary mb-8 ds-body">{content.t("secretumvault-cta-subtitle")}</p>
              <div class="flex flex-col sm:flex-row gap-4 justify-center">
                <a
                  href="https://repo.example.com/org/secretumvault"
                  target="_blank"
                  rel="noopener noreferrer"
                  class="no-underline ds-btn-primary"
                >
                  {content.t("secretumvault-cta-explore")}
                </a>
              </div>
            </div>
          </section>


        <ProjectGraphSection node_id="secretumvault".to_string() />

        </div>
    }
}
