/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { parseLooseJson } from "../../global/lib/parse-loose-json";
export const gistLoader = async (gistId) => {
    try {
        const res = await fetch(`https://api.github.com/gists/${gistId}`, {
            headers: { Accept: 'application/vnd.github+json' },
        });
        if (!res.ok) {
            throw new Error(`GitHub API error: ${res.status} ${res.statusText}`);
        }
        const gist = await res.json();
        const jsonFile = Object.values(gist.files).find((file) => file === null || file === void 0 ? void 0 : file.filename.endsWith('.json'));
        if (!jsonFile)
            throw new Error('No JSON file found in this gist');
        const resStructure = parseLooseJson(jsonFile === null || jsonFile === void 0 ? void 0 : jsonFile.content);
        return resStructure;
    }
    catch (err) {
        console.error('Error fetching gist JSON:', err.message);
    }
    return undefined;
};
