import { isNull } from "util";


export default function licenses(globalData: IGlobalData): void {

    var licenseBrowser: BrowserMp = null;
    var licenseTimer;
    var globalName;
    var globalInfo;

    mp.events.add("ShowLicenses", (name, info) => {
        if (licenseBrowser == null) {
            licenseBrowser = mp.browsers.new('package://assets/html/licenses/scheine.html');
            globalName = name;
            globalInfo = info;
            
        }
    });

    mp.events.add("CEF:LicenseLoaded", () => {
        licenseBrowser.execute(`add_licenses('${JSON.stringify(globalInfo)}');`);
        licenseBrowser.execute(`add_licensesholder('${JSON.stringify(globalName)}');`);
        licenseTimer = setInterval(DestroyLicenses, 15000);
    });
   

    function DestroyLicenses() {
        licenseBrowser.destroy()
        licenseBrowser = null;
        clearInterval(licenseTimer);
        mp.events.callRemote("CLIENT:InteractionMenu_EndShow");
    }

}