/**
 * «ليه تختارنا؟», 17 October 2026: the first text of the /whyus page in both languages, plus its link in the
 * footer's academy column, placed right after «عن الأكاديمية».
 *
 * The owner's brief: sell the learning journey and what the platform actually does, not the price; the student is
 * the audience today and the teacher the next phase (a space of their own, under Thinkera's content standards).
 * Every claim was checked against the live platform the same day:
 *   - hundreds of questions per lesson (387–681) and thousands in all, tagged on the six Bloom levels, 9 types;
 *   - every option of every multiple-choice and true/false question carries its explanation (11,728 of 11,728);
 *   - three practice levels per lesson; 15 exams per unit, each attempt drawing at random from the unit's bank;
 *   - essays marked by the AI against a model answer; the in-lesson assistant answers from the course only;
 *   - live sessions are booked by one student with one teacher («حصتك الخاصة»), not as a group;
 *   - the chat is answered by people, with no promised hours yet — so nothing here says «24 ساعة».
 * The teacher's space is not built: it is written as the next phase, in the future tense.
 *
 *   ./tk cms-tools npx tsx src/scripts/2026-10-17-whyus.ts
 *
 * Safe to re-run: it writes the same text again. Backs the page and the footer up first.
 */
import fs from 'node:fs'
import path from 'node:path'
import { getPayload } from 'payload'
import config from '@payload-config'

type L = 'ar' | 'en'
const payload = await getPayload({ config })
const get = (slug: string, locale: L) => payload.findGlobal({ slug: slug as never, locale, depth: 0 }) as Promise<any>
const set = (slug: string, locale: L, data: any) =>
  payload.updateGlobal({ slug: slug as never, locale, data, depth: 0 }) as Promise<any>

const C = (title: string, line: string, text = '') => ({ title, line, text })

const ar = {
  seo: {
    title: 'ليه تختارنا؟ | أكاديمية Thinkera',
    description: 'فيديو بيسألك، وتدريب بيشرح لك ليه، ومقالي بيتصحّح على طول، وامتحانات بتتغيّر أسئلتها كل مرة. رحلة تعلم كلها نشاط وتفاعل.',
  },
  kicker: 'Thinkera · البرمجة والذكاء الاصطناعي · تانية ثانوي',
  h1: 'مش هتتفرج وتمشي. هنا كل خطوة في الدرس فيها حاجة تعملها.',
  lead: 'رحلة تعلم كلها نشاط وتفاعل: تتفرج وتجاوب، وتتدرّب وتفهم ليه، وتمتحن وتعرف مستواك بجد، ولو وقفت في حتة تلاقي اللي يساعدك.',
  steps: ['اتفرج وجاوب', 'اتدرّب وافهم', 'اكتب واتصحّح', 'امتحن واعرف مستواك', 'مش لوحدك'].map((label) => ({ label })),
  cardsTitle: 'إيه اللي هتلاقيه في Thinkera',
  cards: [
    C('فيديو بيسألك',
      'الفيديو بيقف ويسألك قبل ما يكمّل، وفي الفيديوهات التفاعلية بتختار وتعرف إجابتك على طول.',
      'والشرح بمواقف بتحصل معانا كل يوم، زي الدفع بكود QR. فيديوهات متنتجة بأدوات الذكاء الاصطناعي، ومتراجعة بدقة على كتابك.'),
    C('تتعلم منهج حل، مش تحفظ إجابة',
      'في أسئلة الاختيارات هتعرف إجابتك صح ولا غلط وليه، وكمان الاختيارات التانية غلط ليه.',
      'تلات مستويات تدريب لكل درس، من البسيط للمتقدم. ولو بتحب الورق، فيه شيت أسئلة تطبعه.'),
    C('كتبت إجابة مقالية؟ درجتك على طول',
      'اكتب بأسلوبك، وخد درجتك والتعليق عليها، من غير ما تستنى حد يصحّح.',
      'تعرف ناقصك إيه وإنت لسه فاكر السؤال، وتتمرّن على المقالي اللي الكل بيخاف منه.'),
    C('مئات الأسئلة في كل درس، من السهل للعميق',
      'من السؤال المباشر لحد «فسّر» و«قيّم» و«اقترح»: كل مستوى تفكير ممكن الامتحان يطلبه.',
      'بنوك أسئلة متصنّفة على مستويات بلوم الستة، وفيها 9 أنواع أسئلة: اختيار، وصح وغلط، ومقالي، وتوصيل، وترتيب، وسحب وإفلات، وغيرها.'),
    C('امتحن تاني وتالت، وكل مرة الأسئلة بتتغيّر',
      'في آخر كل وحدة 15 امتحان، من السهل للمتقدم.',
      'كل محاولة بتسحب لك أسئلة عشوائي من بنك الوحدة كله، فتعرف مستواك بجد، مش مستوى ذاكرتك.'),
    C('مش لوحدك',
      'مساعد ذكي جوه الدرس، وفريق حقيقي على الشات، وحصتك الخاصة مع معلم.',
      'المساعد بيجاوبك من منهجك إنت بس. والشات بيرد عليك فيه بني آدم مش روبوت. ولو محتاج شرح أكتر، احجز حصتك الخاصة مع معلم عن درس أو وحدة.'),
    C('مدرستك عربي ولا لغات؟ ليك نسختك',
      'شاشات ومصطلحات بالعربي زي الكتاب العربي، أو بالإنجليزي زي كتاب اللغات، والشرح بالمصري في الاتنين.'),
  ],
  figures: [
    { n: 'آلاف', label: 'الأسئلة على المنصة' },
    { n: '15', label: 'امتحان لكل وحدة' },
    { n: '6', label: 'مستويات تفكير' },
    { n: 'كل اختيار', label: 'في أسئلة الاختيارات والصح والغلط عليه شرح' },
  ],
  audienceTitle: 'معمولة لمين',
  student: {
    tag: 'دلوقتي',
    title: 'الطالب',
    text: 'كل اللي فوق معمول عشانك: تذاكر وتتدرّب وتمتحن وتسأل من مكان واحد، وتدخل الامتحان وإنت عارف مستواك.',
  },
  teacher: {
    tag: 'المرحلة الجاية',
    title: 'المعلم',
    text: 'بنجهّز مساحة خاصة لكل معلم على Thinkera، هيقدّم فيها محتواه لطلابه بأدوات المنصة:',
    points: [
      'الفيديو التفاعلي، وبنوك الأسئلة، والامتحانات المتدرّجة، والتصحيح.',
      'طريقة واضحة يبني بيها محتواه وينظّمه، عشان يوصل للطالب بنفس جودة Thinkera.',
      'كل محتوى هيتراجع على معايير Thinkera قبل ما يتنشر.',
    ].map((text) => ({ text })),
  },
  quotesTitle: 'Thinkera في جملة',
  quotes: [
    'تتعلم منهج حل، مش تحفظ إجابة.',
    'الفيديو بيسألك، والمنصة بتصحّح لك.',
    'كتبت إجابة مقالية؟ درجتك والتعليق عليها على طول.',
    'امتحن تاني وتالت: كل مرة الأسئلة بتتغيّر.',
    'مش بس شيت تحفظه، ده تدريب بيصحّح لك على طول.',
  ].map((text) => ({ text })),
  ctaTitle: 'ابدأ دلوقتي: الوحدة الأولى كلها من غير ما تدفع',
  ctaLead: 'البرمجة والذكاء الاصطناعي، تانية ثانوي.',
  ctaLabel: 'شوف المنهج',
  ctaHref: '/courses',
}

const en = {
  seo: {
    title: 'Why Thinkera | Thinkera Academy',
    description: 'A video that asks you questions, practice that explains why, essays marked straight away, and unit exams that change every attempt.',
  },
  kicker: 'Thinkera · Programming and AI · Grade 11',
  h1: 'You don’t just watch here. Every step of a lesson asks you to do something.',
  lead: 'A learning journey full of activity: watch and answer, practise and understand why, sit the exams and see where you really stand — and when you get stuck, there is help.',
  steps: ['Watch and answer', 'Practise and understand', 'Write and get marked', 'Test yourself', 'Never alone'].map((label) => ({ label })),
  cardsTitle: 'What you get on Thinkera',
  cards: [
    C('A video that asks you',
      'The video stops and asks you before it carries on, and in the interactive videos you pick an answer and see straight away if it is right.',
      'Every idea starts from something that happens to us every day, like paying with a QR code. The videos are produced with AI tools and checked closely against your textbook.'),
    C('Learn how to solve, not what to memorise',
      'In multiple-choice questions you see whether your answer is right and why — and why each of the other options is wrong.',
      'Three practice levels in every lesson, from basic to advanced. If you like paper, there is a question sheet to print too.'),
    C('Wrote an essay answer? Your mark comes straight back',
      'Write it your way and get your mark with comments on it, without waiting for anyone to correct it.',
      'You see what was missing while the question is still fresh, and you practise the essay questions most students dread.'),
    C('Hundreds of questions per lesson, from easy to deep',
      'From the direct question to “explain”, “evaluate” and “propose”: every level of thinking the exam may ask for.',
      'Question banks tagged on the six levels of Bloom’s taxonomy, in 9 question types: multiple choice, true/false, essay, matching, ordering, drag and drop, and more.'),
    C('Sit it again and again — the questions change each time',
      'At the end of every unit there are 15 exams, from easy to advanced.',
      'Each attempt draws questions at random from the whole unit’s bank, so you learn your real level, not how well you remember the exam.'),
    C('Never alone',
      'An AI assistant inside the lesson, a real team on the chat, and your own session with a teacher.',
      'The assistant answers from your course only. On the chat, a person answers you, not a bot. And if you need more, book your own live session with a teacher on a lesson or a unit.'),
    C('Arabic school or language school? There is an edition for you',
      'Screens and terms in Arabic like the Arabic textbook, or in English like the language-schools textbook — explained in Egyptian Arabic in both.'),
  ],
  figures: [
    { n: 'Thousands', label: 'of questions on the platform' },
    { n: '15', label: 'exams per unit' },
    { n: '6', label: 'levels of thinking' },
    { n: 'Every option', label: 'in multiple-choice and true/false is explained' },
  ],
  audienceTitle: 'Who it is for',
  student: {
    tag: 'Now',
    title: 'Students',
    text: 'Everything above is built for you: study, practise, sit exams and ask questions in one place, and walk into the exam knowing your level.',
  },
  teacher: {
    tag: 'Next phase',
    title: 'Teachers',
    text: 'We are preparing a space of their own for every teacher on Thinkera, where they will deliver their content to their students with the platform’s tools:',
    points: [
      'Interactive video, question banks, graded exams and marking.',
      'A clear way to build and structure their content, so it reaches students at Thinkera’s standard.',
      'Every piece of content will be reviewed against Thinkera’s standards before it is published.',
    ].map((text) => ({ text })),
  },
  quotesTitle: 'Thinkera in a line',
  quotes: [
    'Learn how to solve, not what to memorise.',
    'The video asks you, and the platform marks you.',
    'Wrote an essay answer? Your mark and comments come straight back.',
    'Sit it again and again: the questions change every time.',
    'Not just a sheet to memorise — practice that marks you straight away.',
  ].map((text) => ({ text })),
  ctaTitle: 'Start now: all of Unit 1, without paying',
  ctaLead: 'Programming and AI, Grade 11.',
  ctaLabel: 'See the course',
  ctaHref: '/courses',
}

const LINK: Record<L, { label: string; href: string }> = {
  ar: { label: 'ليه تختارنا؟', href: '/whyus' },
  en: { label: 'Why Thinkera?', href: '/whyus' },
}

// ------------------------------------------------------------------ write it
const backup: Record<string, unknown> = {}
for (const locale of ['ar', 'en'] as L[]) {
  backup[`whyus.${locale}`] = await get('whyus', locale)
  backup[`settings.${locale}`] = await get('settings', locale)
}
const file = path.join(process.cwd(), 'src/scripts/backup-2026-10-17-whyus.json')
fs.writeFileSync(file, JSON.stringify(backup, null, 2))
console.log(`backup written to ${file}`)

await set('whyus', 'ar', ar)
await set('whyus', 'en', en)
console.log('whyus written in both languages')

for (const locale of ['ar', 'en'] as L[]) {
  const s = await get('settings', locale)
  const links = [...((s.footer?.links || []) as { label?: string; href?: string }[])]
  if (!links.some((l) => (l.href || '') === LINK[locale].href)) {
    const after = links.findIndex((l) => l.href === '/about')
    links.splice(after >= 0 ? after + 1 : 0, 0, LINK[locale])
  }
  await set('settings', locale, { footer: { ...(s.footer || {}), links } })
  console.log(`${locale}: footer links ${links.map((l) => l.href).join(' ')}`)
}

console.log('done')
process.exit(0)
