import type { IconName } from "@/app/(admin)/_components/Icon";

/* ------------------------------------------------------------------ */
/* Languages & regions                                                 */
/* ------------------------------------------------------------------ */

export const LANGS = {
  en: "English",
  fr: "Français",
  es: "Español",
  de: "Deutsch",
  ar: "العربية",
  zh: "中文",
} as const;
export type Lang = keyof typeof LANGS;

export type Region = {
  id: string;
  name: string;
  slug: string;
  langs: Lang[];
  /** Login hero headline, split into lines. */
  head: string[];
  sub: string;
  stats: [string, string][];
  /** Share of global volume, used to scale dashboard figures. */
  f: number;
};

export const REGIONS: Region[] = [
  { id: "global", name: "Global", slug: "/", langs: ["en", "fr", "es", "de", "ar", "zh"], head: ["Powering Nations,", "Feeding the World."], sub: "Manage landing pages, campaigns, donations and partners across every region from one place.", stats: [["209+", "Countries"], ["600+", "Logistics hubs"], ["1M+", "Partners"]], f: 1 },
  { id: "na", name: "North America", slug: "/na", langs: ["en", "es", "fr"], head: ["Feeding North America", "with AI-driven supply."], sub: "Regional landing page, campaigns and partner network for the US, Canada and Mexico.", stats: [["3", "Countries"], ["48", "Logistics hubs"], ["1,240", "Partners"]], f: 0.22 },
  { id: "sa", name: "South America", slug: "/sa", langs: ["es", "en"], head: ["Sustainable farming", "across South America."], sub: "Ethical sourcing partnerships and campaigns across the continent.", stats: [["12", "Countries"], ["36", "Logistics hubs"], ["980", "Partners"]], f: 0.09 },
  { id: "we", name: "Western Europe", slug: "/we", langs: ["en", "fr", "de"], head: ["Europe’s partner in", "responsible food trade."], sub: "Content, compliance and campaigns for Western European markets.", stats: [["18", "Countries"], ["92", "Logistics hubs"], ["2,310", "Partners"]], f: 0.26 },
  { id: "ee", name: "Eastern Europe", slug: "/ee", langs: ["en", "de"], head: ["Building resilient supply", "chains in Eastern Europe."], sub: "Regional hubs, partner onboarding and campaign management.", stats: [["22", "Countries"], ["41", "Logistics hubs"], ["760", "Partners"]], f: 0.08 },
  { id: "naf", name: "North Africa", slug: "/naf", langs: ["ar", "fr", "en"], head: ["Securing food supply", "for North Africa."], sub: "Arabic and French content, hunger-zone campaigns and logistics.", stats: [["6", "Countries"], ["27", "Logistics hubs"], ["540", "Partners"]], f: 0.07 },
  { id: "ssa", name: "Sub-Saharan Africa", slug: "/ssa", langs: ["en", "fr"], head: ["Food for the Future", "in Sub-Saharan Africa."], sub: "Impact campaigns, partner resources and donor reporting.", stats: [["46", "Countries"], ["58", "Logistics hubs"], ["1,120", "Partners"]], f: 0.1 },
  { id: "ea", name: "East Asia", slug: "/ea", langs: ["zh", "en"], head: ["AI-powered agriculture", "for East Asia."], sub: "Mandarin-first landing page with regional trade partners.", stats: [["8", "Countries"], ["64", "Logistics hubs"], ["1,480", "Partners"]], f: 0.13 },
  { id: "oc", name: "Oceania", slug: "/oc", langs: ["en"], head: ["Smart warehousing", "across Oceania."], sub: "Landing content and campaigns for Australia, NZ and the Pacific.", stats: [["14", "Countries"], ["19", "Logistics hubs"], ["310", "Partners"]], f: 0.05 },
];

export const getRegion = (id: string): Region => REGIONS.find((r) => r.id === id) ?? REGIONS[0];

/* ------------------------------------------------------------------ */
/* Navigation                                                          */
/* ------------------------------------------------------------------ */

export type NavItem = { id: string; label: string; icon: IconName; badge?: number };

export const NAV: [string, NavItem[]][] = [
  ["Overview", [{ id: "dashboard", label: "Dashboard", icon: "grid" }]],
  ["Website", [
    { id: "regions", label: "Regions & Landing", icon: "globe" },
    { id: "home-editor", label: "Home Page", icon: "home" },
    { id: "media", label: "Media", icon: "folder" },
    { id: "languages", label: "Languages", icon: "spark" },
    { id: "pages", label: "Inner Pages", icon: "file" },
    { id: "articles", label: "Articles", icon: "news" },
    { id: "services", label: "Services", icon: "cpu" },
    { id: "products", label: "Products", icon: "box" },
    { id: "catalog", label: "Product Catalog", icon: "leaf" },
    // { id: "content", label: "Content & Media", icon: "news" },
  ]],
  ["Fundraising", [
    { id: "campaigns", label: "Campaigns", icon: "flag", badge: 38 },
    { id: "donations", label: "Donations", icon: "heart" },
  ]],
  ["People", [
    { id: "users", label: "Users & Roles", icon: "users" },
    { id: "resources", label: "Partner Resources", icon: "folder" },
    { id: "inquiries", label: "Inquiries", icon: "inbox" },
  ]],
  ["Insights", [
    { id: "impact", label: "Impact Data", icon: "chart" },
    { id: "ai", label: "AI & Localisation", icon: "spark", badge: 5 },
    { id: "reports", label: "Reports", icon: "calendar" },
  ]],
  ["System", [{ id: "settings", label: "Settings", icon: "settings" }]],
];

/* ------------------------------------------------------------------ */
/* Dashboard / fundraising data                                        */
/* ------------------------------------------------------------------ */

export type Tone = "b" | "g" | "a" | "r" | "n";

export type Campaign = {
  name: string;
  region: string;
  target: number;
  raised: number;
  mode: "Auto-close" | "Overfunding";
  status: "Live" | "Overfunded" | "Draft" | "Closed";
};

export const CAMPAIGNS: Campaign[] = [
  { name: "Food for the Future – Sahel", region: "Sub-Saharan Africa", target: 250000, raised: 231400, mode: "Auto-close", status: "Live" },
  { name: "Planting a Forest with Every Order", region: "Global", target: 500000, raised: 512800, mode: "Overfunding", status: "Overfunded" },
  { name: "Winter Meals Drive", region: "Eastern Europe", target: 120000, raised: 64300, mode: "Auto-close", status: "Live" },
  { name: "Crisis Relief Logistics – Gaza Route", region: "North Africa", target: 300000, raised: 188900, mode: "Overfunding", status: "Live" },
  { name: "AI for Social Good – Farmer Training", region: "East Asia", target: 80000, raised: 15200, mode: "Auto-close", status: "Draft" },
  { name: "Fair Trade Farmers Fund", region: "South America", target: 150000, raised: 150000, mode: "Auto-close", status: "Closed" },
];

export type ListItem = { id: string; title: string; meta: string; tone: Tone; icon: IconName; when?: string };

export const APPROVALS: ListItem[] = [
  { id: "ap1", title: "Article: AI in Precision Farming", meta: "AI draft · English · Content team", tone: "b", icon: "spark" },
  { id: "ap2", title: "Home hero – Western Europe (FR)", meta: "AI translation · needs review", tone: "g", icon: "globe" },
  { id: "ap3", title: "Campaign email: Winter Meals", meta: "AI draft · Eastern Europe", tone: "a", icon: "mail" },
  { id: "ap4", title: "Partner: Green Harvest Co-op", meta: "Partner application", tone: "b", icon: "building" },
  { id: "ap5", title: "Product copy: Teas & Coffees", meta: "AI draft · 6 SKUs", tone: "g", icon: "box" },
];

export const ACTIVITY: ListItem[] = [
  { id: "ac1", title: "€2,500 recurring donation", meta: "Planting a Forest · Western Europe · Stripe", tone: "g", icon: "heart", when: "2m ago" },
  { id: "ac2", title: "New partner sign-up: AgriLink Logistics", meta: "North America · awaiting approval", tone: "b", icon: "building", when: "14m ago" },
  { id: "ac3", title: "Home page published", meta: "East Asia · 中文 · by Mei L.", tone: "b", icon: "home", when: "1h ago" },
  { id: "ac4", title: "Stripe Radar flagged a donation", meta: "€9,800 · North Africa · review needed", tone: "r", icon: "shield", when: "2h ago" },
  { id: "ac5", title: "Impact report sent to 1,204 donors", meta: "Food for the Future – Sahel", tone: "g", icon: "mail", when: "Yesterday" },
];

export type Donation = { donor: string; amount: number; currency: string; recurring: boolean; campaign: Campaign; date: string; flagged: boolean };

const DONORS = ["A. Müller", "S. Dubois", "J. Carter", "M. Chen", "F. Haddad", "L. García", "K. Okafor", "E. Novak"];
const CURRENCIES = ["EUR", "EUR", "USD", "CNY", "EUR", "EUR", "USD", "EUR"];
const AMOUNTS = [250, 1200, 75, 5000, 9800, 40, 300, 150];

export const DONATIONS: Donation[] = DONORS.map((donor, i) => ({
  donor,
  amount: AMOUNTS[i],
  currency: CURRENCIES[i],
  recurring: i % 3 !== 0,
  campaign: CAMPAIGNS[i % CAMPAIGNS.length],
  date: `Nov ${16 - i}, 2026`,
  flagged: i === 4,
}));

export type UserRow = { name: string; type: "Donor" | "Partner" | "Consumer" | "Regional Editor" | "Translator"; region: string; status: "Active" | "Pending" | "Invited" };

export const USERS: UserRow[] = [
  { name: "Sophie Laurent", type: "Donor", region: "Western Europe", status: "Active" },
  { name: "AgriLink Logistics", type: "Partner", region: "North America", status: "Pending" },
  { name: "Wei Zhang", type: "Consumer", region: "East Asia", status: "Active" },
  { name: "Green Harvest Co-op", type: "Partner", region: "Sub-Saharan Africa", status: "Active" },
  { name: "Omar Haddad", type: "Donor", region: "North Africa", status: "Active" },
  { name: "Mei Lin", type: "Regional Editor", region: "East Asia", status: "Active" },
  { name: "Lukas Novak", type: "Translator", region: "Eastern Europe", status: "Invited" },
];

/* ------------------------------------------------------------------ */
/* Placeholder module pages                                            */
/* ------------------------------------------------------------------ */

export type ModuleDef = { group: string; title: string; desc: string; items: [string, IconName][] };

export const MODULES: Record<string, ModuleDef> = {
  content: { group: "Website", title: "Content & Media", desc: "Articles, magazine, press releases, careers and the media library.", items: [["Articles / Thought Leadership", "news"], ["Magazine issues", "news"], ["Press releases & press kit", "file"], ["Testimonials & case studies", "award"], ["Careers: jobs & applications", "users"], ["Media library", "folder"]] },
  resources: { group: "People", title: "Partner Resources", desc: "Private portal content uploaded by admins.", items: [["Training resources", "file"], ["Toolkits & guidelines", "folder"], ["Media packs (logos, visuals)", "upload"], ["Campaign case studies & reports", "chart"], ["Partner FAQ", "help"]] },
  leads: { group: "People", title: "Leads & Inquiries", desc: "Everything submitted from the website forms.", items: [["Contact forms", "mail"], ["Quote requests", "file"], ["Strategic meeting requests", "calendar"], ["Partner applications", "building"]] },
  impact: { group: "Insights", title: "Impact Data", desc: "Metrics for the Smart Impact Dashboard.", items: [["Meals donated", "meal"], ["Hunger zones served", "pin"], ["Donation volume by region/campaign", "chart"], ["Partner impact metrics", "users"], ["Excel / Google Sheet import", "upload"], ["GeoJSON hunger-risk dataset", "globe"]] },
  ai: { group: "Insights", title: "AI & Localisation", desc: "Translations, AI drafts and the chatbot, all with approval.", items: [["Languages: EN, FR, ES, DE, AR, ZH", "globe"], ["Translation queue", "spark"], ["AI content drafts → approval", "check"], ["Chatbot knowledge base", "help"], ["Chatbot conversation logs", "inbox"]] },
  reports: { group: "Insights", title: "Reports", desc: "Exportable reports for finance and leadership.", items: [["Donations report", "heart"], ["Campaign performance", "flag"], ["Regional performance", "globe"], ["Partner impact", "users"], ["Donor impact reports", "mail"]] },
  settings: { group: "System", title: "Settings", desc: "Platform configuration.", items: [["General & SEO", "settings"], ["Payments (Stripe, Radar)", "shield"], ["Email templates", "mail"], ["Integrations: OMS, Inventory, Translation", "cpu"], ["Admin roles & permissions", "users"], ["Audit log", "file"]] },
};

/* ------------------------------------------------------------------ */
/* Formatting                                                          */
/* ------------------------------------------------------------------ */

export const fmt = (n: number) =>
  n >= 1e6 ? (n / 1e6).toFixed(2) + "M" : n >= 1e3 ? (n / 1e3).toFixed(1) + "K" : Math.round(n) + "";
