import { writeFileSync } from 'fs';

import initialKeys from '../src/assets/localization/initialKeys';
import readFallbackStrings from '../src/util/data/readFallbackStrings';
import { pick } from '../src/util/iteratees';

const HEADER = `/* eslint-disable */
// This file is generated by dev/generateInitialLangFallback.ts. Do not edit it manually.\n
import type { LangPackStringValue } from '../../api/types';
import type { LangKey } from '../../types/language';\n`;

async function main() {
  const data = await readFallbackStrings(true);

  const selectedKeys = pick(data.langPack.strings, initialKeys);
  const json = JSON.stringify(selectedKeys, undefined, 2);
  const text = `${HEADER}\nexport default ${json} as Record<LangKey, LangPackStringValue>;\n`;
  writeFileSync('./src/assets/localization/initialStrings.ts', text, 'utf8');
}

main();
