/**
 * Единая нормализация onlineMode для Stimulus/record.js.
 * dataset и API могут отдавать true/false, "1"/"0", 1/0.
 */
function isOnlineMode(value) {
    if (value === true || value === 1) {
        return true;
    }

    if (value === false || value === 0 || value === null || value === undefined) {
        return false;
    }

    const normalized = String(value).trim().toLowerCase();

    if (normalized === '' || normalized === '0' || normalized === 'false' || normalized === 'no' || normalized === 'off') {
        return false;
    }

    if (normalized === '1' || normalized === 'true' || normalized === 'yes' || normalized === 'on') {
        return true;
    }

    return false;
}

function toOnlineType(value) {
    return isOnlineMode(value) ? 1 : 0;
}

module.exports = {
    isOnlineMode,
    toOnlineType,
};
