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


export default class toApp {
    async Start() {
        let form = XRW.mkForm({ ynCreateFolder: 'Y', ynCreateRender: 'Y', renderType: 'Form', anchor: 'grForm' });

        //### FEG description
        form.setFEG("Menu",
            { FE_Prefix: 'GenericButton', FGM_Format: "dY2,dX5,f12,pA,W60,B15,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");` },

        );
        form.setFEG("Header",
            { FE_Prefix: 'HTML', FGM_Format: "dY2,dX5,f12,pA,W60,B15,Vitem", html: "<b>Pos</b>" },
            { FE_Prefix: 'HTML', FGM_Format: "pA,W60,B15,Vitem", html: "<b>Menge</b>" },
            { FE_Prefix: 'HTML', FGM_Format: "pA,W60,B15,Vitem", html: "<b>Einzelpreis</b>" },
            { FE_Prefix: 'HTML', FGM_Format: "pA,W60,B15,Vitem,N", html: "<b>Gesamtpreis</b>" },
        );
        form.setFEG("Artikel",
            { FE_Prefix: 'GenericString', FGM_Key: 'Pos', FGM_Format: "dY10,dX2,f14,Sbold,W80,Vitem", FE_Title: `Vorname` },
            { FE_Prefix: 'GenericString', FGM_Key: 'last_name', FGM_Format: "dX2,W40,Vitem", FE_Title: `Nachname` },
            // { FE_Prefix: 'GenericCheck', FGM_Key: 'is_alive', FGM_Format: "dX2,W30,V,N", FE_Title: `Lebendig` },
            { FE_Prefix: 'GenericText', FGM_Key: 'CV', rows: 6, FGM_Format: "dX2,W180,V,N", FE_Title: `Lebenslauf` },
        );
        form.setFEG("phone_numbers",
            { FE_Prefix: 'GenericString', FGM_Key: 'type', FGM_Format: "dX10,pA1,B15,W60,Vitem", select: ["home", "office", "mobile"], FE_Title: `Typ`, ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: 'number', FGM_Format: "pA,W60,B15,Vitem", FE_Title: `Rufnummer`, ynTableStyle: 'Y' },
            { FE_Prefix: 'GenericString', FGM_Key: 'test', FGM_Format: "pA,W60,B15,Vitem", FE_Title: `Exceltest`, ynTableStyle: 'Y', ynNotAssignNullValue: 'Y', SEautoValue: `#E;let x=Number($value("?relX=-1"));return isNaN(x)?null:x+1;`, defaultValue: 0 },
            { FE_Prefix: 'GenericButton', FGM_Format: "W10,Vitem,N", FE_Title: 'Löschen', ynClearCaption: 'Y', icon: 'delete', iconColor: 'red', SEonClick: `$deleteForm();` },
        );
        form.setFEG("WikiExample",
            { FE_Prefix: 'GenericString', FGM_Key: 'first_name', FGM_Format: "dY10,dX2,f14,Sbold,W80,Vitem", FE_Title: `Vorname` },
            { FE_Prefix: 'GenericString', FGM_Key: 'last_name', FGM_Format: "dX2,W40,Vitem", FE_Title: `Nachname` },
            // { FE_Prefix: 'GenericCheck', FGM_Key: 'is_alive', FGM_Format: "dX2,W30,V,N", FE_Title: `Lebendig` },
            { FE_Prefix: 'GenericString', FGM_Key: 'phone_numbers', FGM_Format: "dX2,W180,V,N", FE_Title: `Telefonnummern` },
            { FE_Prefix: 'GenericText', FGM_Key: 'CV', rows: 6, FGM_Format: "dX2,W180,V,N", FE_Title: `Lebenslauf` },
        );
        //### Demo Form
        form.setSection("S1",
            { FEG_Prefix: "Menu", FEG_Title: "Anzeigen", ynVolatile: 'Y' },
            { FEG_Prefix: "Header", FEG_Title: "Anzeigen", ynVolatile: 'Y' },
            { FEG_Prefix: "Artikel", ynVolatile: 'Y', ynGreedyArg: 'Y' },
            { FEG_Prefix: "phone_numbers", FEG_Title: "Telefon", ynVolatile: 'Y', ynAllowEmptyArg: 'Y' },
            { FEG_Prefix: "WikiExample", FEG_Title: "Anzeigen", ynVolatile: 'Y' },
        );

        form.folder.setArg('WikiExample', XRW.samples.jsonWiki);
        form.folder.debug();
        form.renderPageSection("S1");
        if (false) {
            form.callBack_onChange((control, item) => {
                form.folder.debug();
            });
            console.log(form);
        }
    }
}
globalThis.oApp = new toApp();
