import { checkDataUrl, checkExtension, LoaderParserPriority } from 'pixi.js';
import { extensions, ExtensionType, settings } from '@pixi/core';

const validHTMLExtension = '.html';
const validHTMLMIME = 'text/html';

/** Loader that fetches raw HTML snippets for rules screens. */
export const loadHtml = {

    name: 'loadHtml',

    extension: {
        type: ExtensionType.LoadParser,
        priority: LoaderParserPriority.Low,
    },

    test(url: string): boolean
    {
        return checkDataUrl(url, validHTMLMIME) || checkExtension(url, validHTMLExtension);
    },

    async load(url: string): Promise<string>
    {
        const response = await settings.ADAPTER.fetch(url);

        return await response.text();
    },
} as const;

console.log('ADD LOAD HTML EXTENSION');
extensions.add(loadHtml);
