import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { isLocale, type Locale } from '@ai-radar/shared';
import { SITE, absoluteUrl, localeAlternates } from '@/lib/site';

type Params = Promise<{ lang: string }>;

export async function generateMetadata({ params }: { params: Params }): Promise<Metadata> {
  const { lang } = await params;
  if (!isLocale(lang)) return {};

  return {
    title: lang === 'ar' ? 'عن الموقع' : 'About',
    description: SITE[lang].description,
    alternates: {
      canonical: absoluteUrl(`/${lang}/about`),
      languages: localeAlternates('/about'),
    },
  };
}

/**
 * About and methodology.
 *
 * Two reasons this page is not optional. It is where a reader decides
 * whether to trust the filtering, and it is what an ad-network reviewer
 * reads to understand what the site is. Both are better served by being
 * plain about how the pipeline works — including that it is AI-assisted —
 * than by omitting it.
 */
export default async function AboutPage({ params }: { params: Params }) {
  const { lang } = await params;
  if (!isLocale(lang)) notFound();

  const c = CONTENT[lang];

  return (
    <main id="main" className="page story" style={{ paddingBlock: 'var(--s10)' }}>
      <h1 className="t-h1">{c.title}</h1>
      <p className="story-summary">{c.intro}</p>

      <div className="story-fields">
        {c.sections.map((section) => (
          <section key={section.id} id={section.id} className="story-field">
            <h2 className="why-label">{section.heading}</h2>
            {section.body.map((paragraph, index) => (
              <p key={index} className="t-body" style={{ marginTop: 'var(--s2)' }}>
                {paragraph}
              </p>
            ))}
            {section.list && (
              <ul className="about-list">
                {section.list.map((item) => (
                  <li key={item}>{item}</li>
                ))}
              </ul>
            )}
          </section>
        ))}
      </div>
    </main>
  );
}

interface AboutSection {
  id: string;
  heading: string;
  body: string[];
  list?: string[];
}

interface AboutContent {
  title: string;
  intro: string;
  sections: AboutSection[];
}

const CONTENT: Record<Locale, AboutContent> = {
  en: {
    title: 'About AI Radar',
    intro:
      'AI Radar is a daily filter for people who work with AI. The promise is not that we publish the most — it is that we publish the least necessary to keep you informed.',
    sections: [
      {
        id: 'what',
        heading: 'What this is',
        body: [
          'Every day, dozens of things are announced in AI. Most of them do not matter to you. AI Radar reads the primary sources — company blogs, changelogs, release notes — and publishes only what genuinely changes something for developers, founders and technical people.',
          'Each item is short by design. What changed, why it matters, who should care, and whether it is worth trying. If you cannot read it in under a minute, it is too long.',
        ],
      },
      {
        id: 'method',
        heading: 'How it works',
        body: [
          'AI Radar is automated, and we would rather say so plainly than let you assume otherwise.',
          'Sources are checked every two hours. Candidates are filtered by code first — duplicates, old items, routine version bumps — which removes most of them at no cost. What survives is judged for significance, written into the AI Radar format, and fact-checked against the original source before publication.',
          'Items whose claims cannot be verified against the source are held, not published. Being a few hours late is better than being wrong.',
        ],
        list: [
          'Primary sources are preferred over secondary coverage.',
          'Every number, price and benchmark must appear in the original source.',
          'The same event is published once, however many outlets cover it.',
          'Customer case studies, funding PR and marketing posts are rejected.',
        ],
      },
      {
        id: 'ai',
        heading: 'AI assistance',
        body: [
          'The filtering, summarising and translation are AI-assisted. The editorial rules are written by a person, the sources are chosen by a person, and anything the system is unsure about waits for a person.',
          'Arabic articles are translated from the English after it has been fact-checked, so the two languages cannot state different facts.',
        ],
      },
      {
        id: 'independence',
        heading: 'Independence',
        body: [
          'Nothing on this site is paid placement. If sponsored content is ever introduced it will be labelled as such and excluded from ranking entirely — a sponsor cannot buy a place in the daily digest.',
          'Advertising, where it appears, is clearly marked and never placed before you have had something useful.',
        ],
      },
      {
        id: 'contact',
        heading: 'Corrections and contact',
        body: [
          'If something here is wrong, we want to know. Every item links to its original source so you can check it yourself.',
        ],
      },
    ],
  },
  ar: {
    title: 'عن AI Radar',
    intro:
      'AI Radar مرشّح يومي لمن يعمل في الذكاء الاصطناعي. وعدنا ليس أن ننشر الأكثر، بل أن ننشر الحد الأدنى الذي يبقيك مطّلعاً.',
    sections: [
      {
        id: 'what',
        heading: 'ما هذا الموقع',
        body: [
          'كل يوم تُعلن عشرات الأمور في مجال الذكاء الاصطناعي، ومعظمها لا يعنيك. يقرأ AI Radar المصادر الأصلية — مدونات الشركات وسجلات التغييرات وملاحظات الإصدار — وينشر فقط ما يغيّر شيئاً فعلياً للمطورين والمؤسسين والتقنيين.',
          'كل خبر قصير بتصميم مقصود: ما الذي تغيّر، لماذا يهم، لمن يهم، وهل يستحق التجربة. إن لم تستطع قراءته في أقل من دقيقة فهو طويل أكثر من اللازم.',
        ],
      },
      {
        id: 'method',
        heading: 'كيف يعمل',
        body: [
          'AI Radar يعمل آلياً، ونفضّل قول ذلك بوضوح بدل أن تفترض غير ذلك.',
          'تُفحص المصادر كل ساعتين. تُرشَّح المواد أولاً بالبرمجة — المكرر والقديم وتحديثات الإصدارات الروتينية — وهو ما يستبعد معظمها دون أي تكلفة. ما يتبقى يُقيَّم من حيث الأهمية، ثم يُكتب بصيغة AI Radar، ويُتحقق منه أمام المصدر الأصلي قبل النشر.',
          'ما لا يمكن التحقق من ادعاءاته يُحجز ولا يُنشر. التأخر بضع ساعات أفضل من الخطأ.',
        ],
        list: [
          'تُفضَّل المصادر الأصلية على التغطية الثانوية.',
          'كل رقم وسعر ونتيجة اختبار يجب أن يرد في المصدر الأصلي.',
          'الحدث الواحد يُنشر مرة واحدة مهما تعددت الجهات التي غطّته.',
          'تُرفض دراسات حالة العملاء وأخبار التمويل الترويجية والمواد التسويقية.',
        ],
      },
      {
        id: 'ai',
        heading: 'الاستعانة بالذكاء الاصطناعي',
        body: [
          'الترشيح والتلخيص والترجمة تتم بمساعدة الذكاء الاصطناعي. القواعد التحريرية يكتبها إنسان، والمصادر يختارها إنسان، وكل ما يكون النظام غير واثق منه ينتظر مراجعة بشرية.',
          'المواد العربية مترجمة عن الإنجليزية بعد التحقق منها، لذلك لا يمكن أن تختلف اللغتان في الوقائع.',
        ],
      },
      {
        id: 'independence',
        heading: 'الاستقلالية',
        body: [
          'لا شيء في هذا الموقع مدفوع. إن أُدخل محتوى مموّل مستقبلاً فسيُوسم بوضوح ويُستبعد كلياً من الترتيب — لا يستطيع المموّل شراء مكان في الملخص اليومي.',
          'الإعلانات، حيثما ظهرت، موسومة بوضوح ولا توضع قبل أن تحصل على شيء مفيد.',
        ],
      },
      {
        id: 'contact',
        heading: 'التصحيحات والتواصل',
        body: [
          'إن كان هناك خطأ فنريد أن نعرف. كل خبر يرتبط بمصدره الأصلي لتتحقق بنفسك.',
        ],
      },
    ],
  },
};
