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


export default class toApp {
    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);
        let formMenu = XRW.mkForm({ ynCreateFolder: 'Y', ynCreateRender: 'Y', renderType: 'Form', anchor: 'grForm' });
        //### FEG description
        formMenu.setFEG("Menu",
            { FE_Prefix: 'Icon', FGM_Format: "dY4,dX5,f20,cFill?hex=#288829,cText?col=white,W20,B15,Vitem", defaultValue: 'add', SEonClick: `XRW.message("Icon");` },
            { FE_Prefix: 'HTML', FGM_Format: "cFill?hex=#06AC74,cText?col=white,W190,B15,p?L=5,Vitem,N", html: `<h3>Userlist</h3>` },
            { FE_Prefix: 'GenericButton', FGM_Format: "dX5,f12,pA,W40,B3,Vitem", FE_Title: 'Gerät hinzufügen', caption: "Test", ynClearCaption: 'N', icon: 'add', iconColor: 'blue', iconSize_px: 34, SEonClick: `XRW.message("Hallo");$newForm("phone_numbers");` },
            { FE_Prefix: 'GenericButton', FGM_Format: "f12,pA,W40,B2,Vitem", FE_Title: 'Gerät hinzufügen', caption: "Test", ynClearCaption: 'N', icon: 'add', iconColor: 'blue', iconSize_px: 34, SEonClick: `XRW.message("Hallo");$newForm("phone_numbers");` },
            { FE_Prefix: 'GenericButton', FGM_Format: "f12,pA,W40,B2,Vitem,N", FE_Title: 'Gerät hinzufügen', caption: "Test", ynClearCaption: 'N', icon: 'add', iconColor: 'blue', iconSize_px: 34, SEonClick: `XRW.message("Hallo");$newForm("phone_numbers");` },
            { FE_Prefix: 'Render', FGM_Format: "dX5,f12,W210,H297,B15,Vitem,N", id: "grBoxTable" },
        );
        formMenu.setSection("S1",
            { FEG_Prefix: "Menu", FEG_Title: "Anzeigen", ynVolatile: 'Y' },
        );
        await formMenu.renderPageSection("S1");

        let formGroup = XRW.mkForm({ ynCreateFolder: 'Y', ynCreateRender: 'Y', renderType: 'Form', anchor: 'grBoxTable' });
        formGroup.setFEG("Group",
            { FE_Prefix: 'GenericString', FGM_Key: '_GRP_ID', FGM_Format: "B32,f7,Sbold,W10,Vitem", FE_Title: `_GRP_ID`, ynReadOnly: 'Y', ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: '_GRP_Name', FGM_Format: "B32,f7,Sbold,W60,Vitem", FE_Title: `_GRP_Name`, ynReadOnly: 'Y', ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: '_LOG_Role', FGM_Format: "B32,f7,Sbold,W20,Vitem", FE_Title: `_LOG_Role`, ynReadOnly: 'Y', ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: '_OU_Name', FGM_Format: "B32,f7,Sbold,W20,Vitem", FE_Title: `_OU_Name`, ynReadOnly: 'Y', ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: 'Description', FGM_Format: "B32,f7,Sbold,W40,Vitem", FE_Title: `Description`, ynReadOnly: 'Y', ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: 'GRP_OU_ID', FGM_Format: "B32,f7,Sbold,W10,Vitem", FE_Title: `GRP_OU_ID`, ynReadOnly: 'Y', ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericButton', FGM_Format: "B32,W10,Vitem,N", FE_Title: 'Eintrag löschen', ynClearCaption: 'Y', icon: 'delete', iconColor: 'rot', SEonClick: `XRW.message("Hallo");` },
            // { FE_Prefix: 'GenericString', FGM_Key: 'Icon', FGM_Format: "f7,Sbold,W20,Vitem,N", FE_Title: `Icon` },
        );
        formGroup.setSection("S1",
            { FEG_Prefix: "Group", FEG_Title: "Anzeigen", ynVolatile: 'Y', ynAllowEmptyArg: 'Y' },
        );
        res = await XRW.api.sendPostAsync('/dbp', { dispatch: "pGetAllUserFunction", param: { mode: 'group' } });
        console.log(res);
        formGroup.folder.setArg('Main', { Group: res.result });
        formGroup.folder.debug();
        await formGroup.renderPageSection("S1", { ynTableStyle: 'Y' });
        if (false) {
            form.callBack_onChange((control, item) => {
                form.folder.debug();
            });
            console.log(form);
        }
    }
}
globalThis.oApp = new toApp();
