/**
 * Normalización de target para menú contextual (app vs carpeta).
 * La UI real (botones del strip) se muestra/oculta desde main.js.
 */
(function (global) {
    'use strict';

    /**
     * @typedef {Object} ContextTarget
     * @property {'none'|'app'|'folder'} type
     * @property {string} [appStableId]
     * @property {number} [indexInApps]
     * @property {string} [folderId]
     */

    function none() {
        return { type: 'none' };
    }

    function appTarget(appStableId, indexInApps) {
        return { type: 'app', appStableId: String(appStableId), indexInApps: indexInApps | 0 };
    }

    function folderTarget(folderId) {
        return { type: 'folder', folderId: String(folderId) };
    }

    function parseFromDataset(el) {
        if (!el || !el.dataset) return none();
        if (el.dataset.folderId) return folderTarget(el.dataset.folderId);
        if (el.dataset.appStableId) return appTarget(el.dataset.appStableId, parseInt(el.dataset.index, 10));
        var idx = parseInt(el.dataset.index, 10);
        if (!isNaN(idx) && idx >= 0) return { type: 'app', indexInApps: idx, appStableId: '' };
        return none();
    }

    global.GridLauncher = global.GridLauncher || {};
    global.GridLauncher.contextTarget = {
        none: none,
        appTarget: appTarget,
        folderTarget: folderTarget,
        parseFromDataset: parseFromDataset
    };
})(typeof window !== 'undefined' ? window : this);
