// Copyright (C) 2024 Robert J.A. Wagner; Am Kiefernwald 49b; D-64297 Darmstadt - All Rights Reserved 


export default class toApp {
    formAllFEG() {
        let formAllFEG = XRW.mkForm({ FID: 'formAllFEG', ynCreateFolder: 'N', folder: this.folder, ynCreateRender: 'Y', renderType: 'Form', pageX: 360, pageY: 1000, minPixelPerPoint: 2, anchor: 'grForm' });
        formAllFEG.setFEG("FEG",
            { FE_Prefix: 'Render', FGM_Format: "dY10,dX10,f12,Sbold,W80,Vitem?uri=Typ,W80,Vitem?uri=Nummer,W80,Vitem?uri=Test,N", SEonBuild: `if (ctx.arg._FIX!=1) ctx.item.ynSkip='Y'` },
            { FE_Prefix: 'GenericInteger', FGM_Key: 'APP_ID', FGM_Format: "dX5,W10,B32,Vitem", FE_Title: `Application Index`, ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericWord', FGM_Key: 'APP_Prefix', FGM_Format: "W80,B32,Vitem", FE_Title: `Rufnummer`, ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: 'FEG_Prefix', FGM_Format: "W80,B32,Vitem", FE_Title: `Exceltest`, ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: 'FEG_Title', FGM_Format: "W80,B32,Vitem", FE_Title: `Exceltest`, ynTableStyle: 'Y' },
            { FE_Prefix: 'Icon', FGM_Key: 'Import', FGM_Format: "f12,Acenter,cText?hex=#0000ff,W10,Vitem,N", class: "w3-rw-hover", FE_Title: 'Import', ynClearCaption: 'Y', icon: 'edit', SEonClick: `#A;oApp.eventArgClicked(ctx)` },
        );
        formAllFEG.setSection("S1",
            { FEG_Prefix: "FEG", FEG_Title: "Anzeigen", ynVolatile: 'Y', ynAllowEmptyArg: 'N', ynReadOnlyAll: 'Y' },
        );
        return formAllFEG;
    }
    async eventArgClicked(ctx) {
        console.log(ctx);
        switch (ctx.item.FGM_Key) {
            case 'Import': {
                let { APP_ID, APP_Prefix, FEG_Prefix } = ctx.arg;
                let res = await XRW.api.sendPostAsync('/dbp', { dispatch: 'pGetFEGMember', APP_ID, APP_Prefix, FEG_Prefix });
                XRW.$txt = XRW.upgrade.textFEG_R1_R2(res.result);
                await XRW.confirmASync(`<input type="button" class="w3-button w3-black" value="Copy to Clipboard" onclick="navigator.clipboard.writeText(XRW.$txt)">`);
                console.log(res);
            }
        }
    }
    async Start() {
        var res;
        Object.assign(XRW, XRW.key.url2json("?OU_Name=EGOVC&LOG_Role=ADMIN&USR_EMail=robert.wagner@egovc.de&USR_Pass=Welcome1"));
        res = await XRW.api.login();
        if (!res) return XRW.panic(`User-Admin: login failed`);
        console.log(XRW.SID);
        this.folder = XRW.mkFolder();
        await XRW.upgrade.formList(this.folder, 'FEG');
        this.folder.debug();
        let formAllFEG = this.formAllFEG();
        await XRW.windowResizeCallBack();
    }
}
globalThis.oApp = new toApp();
