import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';

import checkIsThisLocale from './checkIsThisLocale'
import { extractTextFields } from './extractText'

// const text1 = "营业時間";
// const text2 = "萬事如意";
// const text3 = "Hello world!";
// const text4 = "你好World";
// const text5 = "營業時間";

// console.log(await checkIsThisLocale(text1, "zh"));       // ✅ true
// console.log(await checkIsThisLocale(text2, "zh-hant"));  // ✅ true
// console.log(await checkIsThisLocale(text3, "en"));       // ✅ true
// console.log(await checkIsThisLocale(text4, "zh"));
// console.log(await checkIsThisLocale(text5, "zh-hant"));
// console.log(await checkIsThisLocale(text5, "zh"));

const name = 'cleanshine'

const output_tw = readFileSync(`static/aiSectionScripts/tasks/firstSection/checki18n/data/tw/${name}.json`, 'utf8');

// const result_tw = await Promise.all(
//     JSON.parse(output_tw).map(async (item) => {
//         const texts = extractTextFields(item).join(';');
//         const check = await checkIsThisLocale(texts, 'zh-hant');
//         return check;
//     }))

// console.log(name + ' result_tw: ', result_tw)


const a = "{\n  \"text1\": \"<p><strong>智慧洗衣，無憂無慮</strong></p>\",\n  \"background1\": \"background\",\n  \"image1\": \"Smart laundry cart in action\",\n  \"image2\": \"Employees handling laundry efficiently\",\n  \"image3\": \"Clean and organized laundry space\",\n  \"button1\": \"立即預訂！\",\n  \"contactForm1\": {\n    \"formButtonText\": \"提交\"\n  },\n  \"sectionName\": \"服務介紹\",\n  \"sectionDescription\": \"了解我們的智慧洗衣服務，讓您的生活更輕鬆。\"\n}"


const b = extractTextFields(a).join(';')
console.log(b)
console.log(await checkIsThisLocale(b, 'zh-hant', true))