/**
 * Formato unificado de reloj (es-ES, 24 h) para login FLEXIA, overlay de acceso y barra de tareas.
 */
(function (global) {
    'use strict';

    var LOCALE = 'es-ES';

    function lines(now) {
        var d = now instanceof Date ? now : new Date(now);
        var time = d.toLocaleTimeString(LOCALE, { hour: '2-digit', minute: '2-digit', hour12: false });
        var date = d.toLocaleDateString(LOCALE, {
            weekday: 'short',
            day: 'numeric',
            month: 'short',
            year: 'numeric',
        });
        return { time: time, date: String(date).toUpperCase() };
    }

    function longDate(now) {
        var d = now instanceof Date ? now : new Date(now);
        return d.toLocaleDateString(LOCALE, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' });
    }

    function timeWithSeconds(now) {
        var d = now instanceof Date ? now : new Date(now);
        return d.toLocaleTimeString(LOCALE, { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
    }

    /**
     * @param {Date} now
     * @param {{ mobilePcMode?: boolean, verticalTaskbar?: boolean }} opts
     */
    function taskbarClockPayload(now, opts) {
        opts = opts || {};
        var l = lines(now);
        var longD = longDate(now);
        if (opts.mobilePcMode) {
            return { text: l.time + '\n' + l.date, title: longD };
        }
        if (opts.verticalTaskbar) {
            return { text: l.time + '\n' + longD, title: '' };
        }
        return { text: timeWithSeconds(now) + '\n' + longD, title: '' };
    }

    global.AntaraClockFormat = {
        locale: LOCALE,
        lines: lines,
        longDate: longDate,
        timeWithSeconds: timeWithSeconds,
        taskbarClockPayload: taskbarClockPayload,
    };
})(typeof window !== 'undefined' ? window : this);
