use dioxus::prelude::*;

use crate::app::Route;
use crate::components::{PageHeader, PricingCard};
use crate::i18n::{t, tw, Locale};
use crate::models::PricingPlan;

/// Organization pricing page displaying three plan tiers.
///
/// Clicking "Get Started" on any plan navigates to the
/// organization dashboard.
#[component]
pub fn OrgPricingPage() -> Element {
    let locale = use_context::<Signal<Locale>>();
    let l = *locale.read();

    let navigator = use_navigator();
    let plans = mock_plans(l);

    rsx! {
        section { class: "pricing-page",
            PageHeader {
                title: t(l, "org.pricing_title"),
                subtitle: t(l, "org.pricing_subtitle"),
            }
            div { class: "pricing-grid",
                for plan in plans {
                    PricingCard {
                        key: "{plan.id}",
                        plan,
                        on_select: move |_| {
                            navigator.push(Route::OrgDashboardPage {});
                        },
                    }
                }
            }
        }
    }
}

/// Returns mock pricing plans with translated names and features.
///
/// # Arguments
///
/// * `l` - The active locale for translating user-facing plan text
fn mock_plans(l: Locale) -> Vec<PricingPlan> {
    vec![
        PricingPlan {
            id: "starter".into(),
            name: t(l, "pricing.starter"),
            price_eur: 49,
            features: vec![
                tw(l, "pricing.up_to_users", &[("n", "5")]),
                t(l, "pricing.llm_provider_1"),
                t(l, "pricing.tokens_100k"),
                t(l, "pricing.community_support"),
                t(l, "pricing.basic_analytics"),
            ],
            highlighted: false,
            max_seats: Some(5),
        },
        PricingPlan {
            id: "team".into(),
            name: t(l, "pricing.team"),
            price_eur: 199,
            features: vec![
                tw(l, "pricing.up_to_users", &[("n", "25")]),
                t(l, "pricing.all_providers"),
                t(l, "pricing.tokens_1m"),
                t(l, "pricing.priority_support"),
                t(l, "pricing.advanced_analytics"),
                t(l, "pricing.custom_mcp"),
                t(l, "pricing.sso"),
            ],
            highlighted: true,
            max_seats: Some(25),
        },
        PricingPlan {
            id: "enterprise".into(),
            name: t(l, "pricing.enterprise"),
            price_eur: 499,
            features: vec![
                t(l, "pricing.unlimited_users"),
                t(l, "pricing.all_providers"),
                t(l, "pricing.unlimited_tokens"),
                t(l, "pricing.dedicated_support"),
                t(l, "pricing.full_observability"),
                t(l, "pricing.custom_integrations"),
                t(l, "pricing.sla"),
                t(l, "pricing.on_premise"),
            ],
            highlighted: false,
            max_seats: None,
        },
    ]
}
