"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AtemInfo = exports.literal = void 0;
function literal(val) {
    return val;
}
exports.literal = literal;
class AtemInfo {
    static InputIsBlack(input) {
        return input === 0;
    }
    static InputIsColorBar(input) {
        return input === AtemInfo.Offsets.ColorBars;
    }
    static InputIsColor(input) {
        return input >= AtemInfo.Offsets.Color && input < (AtemInfo.Offsets.Color + 1000);
    }
    static InputIsMediaplayer(input) {
        return input >= AtemInfo.Offsets.MediaPlayer && input < (AtemInfo.Offsets.MediaPlayer + 1000);
    }
    static InputIsMediaplayerKey(input) {
        return input >= AtemInfo.Offsets.MediaPlayer && input < (AtemInfo.Offsets.MediaPlayer + 1000) && (input % 2) === 1;
    }
    static InputIsUpstreamKey(input) {
        return input >= AtemInfo.Offsets.Usk && input < (AtemInfo.Offsets.Usk + 1000);
    }
    static InputIsDownstreamKey(input) {
        return input >= AtemInfo.Offsets.Dsk && input < (AtemInfo.Offsets.Dsk + 1000);
    }
    static InputIsSuperSource(input) {
        return input >= AtemInfo.Offsets.SuperSource && input < (AtemInfo.Offsets.SuperSource + 1000);
    }
    static InputIsCleanfeed(input) {
        return input >= AtemInfo.Offsets.Cleanfeed && input < (AtemInfo.Offsets.Cleanfeed + 1000);
    }
    static InputIsOutput(input) {
        return input >= AtemInfo.Offsets.Output && input < (AtemInfo.Offsets.Output + 1000);
    }
    static InputIsProgram(input) {
        return input >= AtemInfo.Offsets.PgmPrv && input < (AtemInfo.Offsets.PgmPrv + 1000) && (input % 2) === 0;
    }
    static InputIsPreview(input) {
        return input >= AtemInfo.Offsets.PgmPrv && input < (AtemInfo.Offsets.PgmPrv + 1000) && (input % 2) === 1;
    }
    static GetSuportSourceIndex(input) {
        return input - AtemInfo.Offsets.SuperSource;
    }
    static GetSourcesListForType(model, state, subset) {
        const getSource = (id, defShort, defLong) => {
            const input = state.inputs[id];
            const shortName = input ? input.shortName || defShort : defShort;
            const longName = input ? input.longName || defLong : defLong;
            return literal({
                id,
                shortName,
                longName
            });
        };
        const sources = [
            getSource(0, 'Blck', 'Black'),
            getSource(1000, 'Bars', 'Bars'),
            getSource(2001, 'Col1', 'Color 1'),
            getSource(2002, 'Col2', 'Color 2')
        ];
        for (let i = 0; i < model.SSrc; i++) {
            if (model.SSrc === 1) {
                sources.push(getSource(6000, 'SSrc', 'Super Source'));
            }
            else {
                sources.push(getSource(6000 + i, `SSc${i + 1}`, `Super Source ${i + 1}`));
            }
        }
        for (let i = 1; i <= model.inputs; i++) {
            sources.push(getSource(i, `In ${i}`, `Input ${i}`));
        }
        for (let i = 1; i <= model.media.players; i++) {
            sources.push(getSource(3000 + i * 10, `MP ${i}`, `Media Player ${i}`));
            sources.push(getSource(3001 + i * 10, `MP${i}K`, `Media Player ${i} Key`));
        }
        if (!subset || subset === 'mv') {
            for (let i = 1; i <= model.auxes; i++) {
                sources.push(getSource(8000 + i, `Aux${i}`, `Auxiliary ${i}`));
            }
        }
        if (!subset || subset === 'mv' || subset === 'aux') {
            for (let i = 1; i <= model.DSKs; i++) {
                sources.push(getSource(7000 + i, `Cln${i}`, `Clean Feed ${i}`));
            }
        }
        for (let i = 1; i <= model.MEs; i++) {
            if (i === 1 && subset === 'me') {
                // Lower ME's can't be referenced by higher
                // We can't do anything beyond ME1 as it is a static list
                continue;
            }
            sources.push(getSource(10000 + i * 10, `M${i}PG`, `ME ${i} Program`));
            sources.push(getSource(10000 + i * 10 + 1, `M${i}PV`, `ME ${i} Preview`));
        }
        sources.sort((a, b) => a.id - b.id);
        return sources;
    }
    static SourcesToChoices(sources) {
        return sources.map(s => ({
            id: s.id,
            label: s.longName
        }));
    }
}
exports.AtemInfo = AtemInfo;
AtemInfo.Offsets = {
    ColorBars: 1000,
    Color: 2000,
    MediaPlayer: 3000,
    Usk: 4000,
    Dsk: 5000,
    SuperSource: 6000,
    Cleanfeed: 7000,
    Output: 8000,
    PgmPrv: 10000
};
//# sourceMappingURL=AtemInfo.js.map