"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var State_1 = require("./State");
exports.getOrCreatePlatform = function (gfxId, platformUsage) {
    var e_1, _a;
    var platforms = State_1.State.API.GetPlatformIds(gfxId);
    try {
        for (var platforms_1 = tslib_1.__values(platforms), platforms_1_1 = platforms_1.next(); !platforms_1_1.done; platforms_1_1 = platforms_1.next()) {
            var platformId_1 = platforms_1_1.value;
            var platform = State_1.State.API.GetComponent(platformId_1);
            var platformUserData_1 = State_1.State.API.GetComponentData(platformId_1);
            if (platformUserData_1.platformUsage === platformUsage) {
                return {
                    id: platformId_1,
                    object: platform,
                };
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (platforms_1_1 && !platforms_1_1.done && (_a = platforms_1.return)) _a.call(platforms_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
    var platformId = State_1.State.API.SetupPlatform(gfxId, false);
    var platformObject = State_1.State.API.GetComponent(platformId);
    var platformUserData = State_1.State.API.GetComponentData(platformId);
    platformUserData.platformUsage = platformUsage;
    State_1.State.API.SetComponentData(platformId, "platformUsage", platformUsage);
    return {
        id: platformId,
        object: platformObject,
    };
};
exports.deletePlatform = function (gfxId, platformUsage) {
    var e_2, _a;
    var platforms = State_1.State.API.GetPlatformIds(gfxId);
    try {
        for (var platforms_2 = tslib_1.__values(platforms), platforms_2_1 = platforms_2.next(); !platforms_2_1.done; platforms_2_1 = platforms_2.next()) {
            var platformId = platforms_2_1.value;
            var platform = State_1.State.API.GetComponent(platformId);
            var platformUserData = State_1.State.API.GetComponentData(platformId);
            if (platformUserData.platformUsage === platformUsage) {
                State_1.State.API.RemoveComponent(platformId);
                continue;
            }
        }
    }
    catch (e_2_1) { e_2 = { error: e_2_1 }; }
    finally {
        try {
            if (platforms_2_1 && !platforms_2_1.done && (_a = platforms_2.return)) _a.call(platforms_2);
        }
        finally { if (e_2) throw e_2.error; }
    }
};
