
var _userdata = require("userdata.js");
var userData = _userdata.userData;
const fs = require("@system.fs");
var systemCtrl = require("systemCtrl.js");
var lvgl = require("@native.lvgl7");
var router = require("@system.router");
var id_testRtcTimer = null;
var that;
var thatList



var flageMap = {
    "factoryTestColor": "color",
    "factoryTestTouch": "touch",
    "factoryTestWifi": "wifi",
    "factoryTestSound": "sound",
    "factory_testUartComm": "uartComm",
    "factoryTestBright": "bright",
    "factoryTestLicenseAuthor": "licenseAuthor",
    "factoryTestRtc": "rtc",
    "factoryTestTvoc": "tvoc",
    "factoryTestBurnIn": "burnIn",
    "factoryTestsystemCheck": "systemCheck",
    "factoryTestClearAll": "clearAll",
    "factoryTestStart": "start",
    "factoryTestExit": "exit"
};

var autoMovePage = [
    "factoryTestColor",
    "factoryTestTouch",
    "factoryTestWifi",
    "factoryTestSound",
    "factory_testUartComm",
    "factoryTestBright",
    "factoryTestLicenseAuthor",
    "factoryTestRtc",
    "factoryTestTvoc",
    // "factoryTestBurnIn",
    "factoryTestsystemCheck",
    // "factoryTestClearAll",
    // "factoryTestStart"
];

var exitNextPage = "factory_testList";


// ✅ 获取下一个测试页面
function getNextTest(currentTest) {
    var index = autoMovePage.indexOf(currentTest);
    if (index !== -1 && index < autoMovePage.length - 1) {
        return autoMovePage[index + 1];
    }
    return null; // 最后一个页面无下一页
}
function autoFactoryNextPage(curPageName) {
    console.log("---------------");
    if (!curPageName) return;

    console.log("[autoFactoryNextPage] 当前页面：" + curPageName);
    console.log("[autoFactoryNextPage] autoStart状态:" + globalThis.factoryTest.autoStart);

    if (globalThis.factoryTest.autoStart == 1) {
    // if (1) {
        var testKey = flageMap[curPageName];
        if (!testKey) {
            console.warn("[autoFactoryNextPage] 未映射的页面：" + curPageName);
            return;
        }
        globalThis.factoryTest[testKey] = 1;
        if (globalThis.factoryTest[testKey] === 1) {
            var nextPage = getNextTest(curPageName);
            if (nextPage) {
                console.log("[autoFactoryNextPage] 自动跳转到：" + nextPage);
                router.push({ path: nextPage });
            } else {
                console.log("[autoFactoryNextPage] 已到达最后一页，跳转结束。");
                globalThis.factoryTest.autoStart = 0; // 可选：停止自动流程
                router.push({ path: exitNextPage });
            }
        } else {
            console.log("[autoFactoryNextPage] 当前测试未完成，不跳转。");
        }
    }
}


module.exports = {
    autoFactoryNextPage: autoFactoryNextPage,


}