import '@things-factory/notification';
import '@things-factory/board-ui';
import '@operato/help/ox-help-panel.js';
import '@operato/i18n/ox-i18n.js';
import '@things-factory/auth-ui/dist-client/index.js'; /* for domain-switch */
import '@things-factory/setting-ui/dist-client/index.js'; /* secure-iplist-setting-let, theme-mode-setting-let */
import './viewparts/menu-tools.js';
import { html } from 'lit-html';
import { registerDefaultGroups } from '@operato/board/register-default-groups.js';
import { appendViewpart, toggleOverlay, TOOL_POSITION, updateViewpart, VIEWPART_LEVEL, VIEWPART_POSITION } from '@operato/layout';
import { hasPrivilege } from '@things-factory/auth-base/dist-client/index.js';
import { APPEND_APP_TOOL } from '@things-factory/apptool-base/client/index.js';
import { setupAppToolPart } from '@things-factory/apptool-ui/dist-client/index.js';
import { setAuthManagementMenus } from '@things-factory/auth-ui/dist-client/index.js';
import { setupContextUIPart } from '@things-factory/context-ui/dist-client/index.js';
import { ADD_MORENDA, ADD_MORENDA_TAIL } from '@things-factory/more-base/client/index.js';
import { ADD_SETTING } from '@things-factory/setting-base/dist-client/index.js';
import { navigate, store, UPDATE_BASE_URL } from '@operato/shell';
export default async function bootstrap() {
    /*
      set board-modeller group and default templates - should be called befor BoardModeller open
    */
    registerDefaultGroups();
    await setupAppToolPart({
        toolbar: true,
        busybar: true,
        mdibar: false
    });
    await setupContextUIPart({
        titlebar: 'header',
        contextToolbar: 'page-footer'
    });
    store.dispatch({
        type: UPDATE_BASE_URL
    });
    /* append top-menu to layout */
    var state = store.getState();
    var width = state.layout?.width || 'WIDE';
    appendViewpart({
        name: 'board-topmenu',
        viewpart: {
            show: true,
            template: html ` <menu-tools></menu-tools> `
        },
        position: width == 'WIDE' ? VIEWPART_POSITION.NAVBAR : VIEWPART_POSITION.FOOTERBAR
    });
    store.subscribe(async () => {
        var state = store.getState();
        if (state.layout.width == width) {
            return;
        }
        width = state.layout.width;
        updateViewpart('board-topmenu', {
            position: width == 'WIDE' ? VIEWPART_POSITION.NAVBAR : VIEWPART_POSITION.FOOTERBAR,
            level: VIEWPART_LEVEL.TOPMOST
        });
    });
    /* add setting morenda */
    store.dispatch({
        type: ADD_MORENDA,
        morenda: {
            icon: html ` <md-icon>settings</md-icon> `,
            name: html ` <ox-i18n msgid="label.setting"></ox-i18n> `,
            action: () => {
                navigate('setting');
            }
        }
    });
    setAuthManagementMenus();
    if (await hasPrivilege({ privilege: 'mutation', category: 'user', domainOwnerGranted: true, superUserGranted: true })) {
        store.dispatch({
            type: ADD_MORENDA,
            morenda: {
                icon: html ` <md-icon>vpn_key</md-icon> `,
                name: html ` <ox-i18n msgid="text.oauth2-clients"></ox-i18n> `,
                action: () => {
                    navigate('oauth2-clients');
                }
            }
        });
    }
    store.dispatch({
        type: ADD_MORENDA,
        morenda: {
            icon: html ` <md-icon>extension</md-icon> `,
            name: html ` <ox-i18n msgid="text.api-sandbox"></ox-i18n> `,
            action: () => {
                navigate('api-swagger');
            }
        }
    });
    store.dispatch({
        type: ADD_MORENDA,
        morenda: {
            icon: html ` <md-icon>hub</md-icon> `,
            name: html ` <ox-i18n msgid="text.integration analysis"></ox-i18n>&nbsp;(beta)`,
            action: () => {
                navigate('integration-analysis');
            }
        }
    });
    store.dispatch({
        type: ADD_MORENDA,
        morenda: {
            icon: html ` <md-icon>help</md-icon> `,
            name: html ` <ox-i18n msgid="text.help"></ox-i18n> `,
            action: () => {
                navigate('help');
            }
        }
    });
    if (await hasPrivilege({ privilege: 'mutation', category: 'state-register', domainOwnerGranted: true })) {
        store.dispatch({
            type: ADD_MORENDA,
            morenda: {
                icon: html ` <md-icon>app_registration</md-icon> `,
                name: html ` <ox-i18n msgid="title.state-register"></ox-i18n> `,
                action: () => {
                    navigate('state-register-page');
                }
            }
        });
    }
    if (await hasPrivilege({ privilege: 'mutation', category: 'board', domainOwnerGranted: true })) {
        store.dispatch({
            type: ADD_MORENDA,
            morenda: {
                icon: html ` <md-icon>font_download</md-icon> `,
                name: html ` <ox-i18n msgid="menu.fonts"></ox-i18n> `,
                action: () => {
                    navigate('font-list');
                }
            }
        });
        // store.dispatch({
        //   type: ADD_MORENDA,
        //   morenda: {
        //     icon: html` <md-icon>draw</md-icon> `,
        //     name: html` <ox-i18n msgid="text.theme"></ox-i18n> `,
        //     action: () => {
        //       navigate('theme-list')
        //     }
        //   }
        // })
    }
    if (await hasPrivilege({ superUserGranted: true })) {
        store.dispatch({
            type: ADD_MORENDA,
            morenda: {
                icon: html ` <md-icon>event_repeat</md-icon> `,
                name: html ` <ox-i18n msgid="title.schedule list"></ox-i18n> `,
                action: () => {
                    navigate('schedule-list');
                }
            }
        });
    }
    // store.dispatch({
    //   type: ADD_MORENDA,
    //   morenda: {
    //     icon: html` <md-icon>dashboard</md-icon> `,
    //     name: html` <ox-i18n msgid="menu.board-template"></ox-i18n> `,
    //     action: () => {
    //       navigate('board-template-list')
    //     }
    //   }
    // })
    store.dispatch({
        type: ADD_MORENDA_TAIL,
        template: html ` <domain-switch attrname="description" slot="tail"></domain-switch> `
    });
    /* append favorite tool to app-tools */
    var acceptedPages = ['board-viewer'];
    store.dispatch({
        type: APPEND_APP_TOOL,
        tool: {
            name: 'favorite-tool',
            template: html ` <favorite-tool .acceptedPages=${acceptedPages}></favorite-tool> `,
            position: TOOL_POSITION.REAR
        }
    });
    /* setting app-tools */
    store.dispatch({
        type: APPEND_APP_TOOL,
        tool: {
            name: 'notification-badge',
            template: html `
        <notification-badge
          @click=${e => {
                toggleOverlay('notification', {
                    backdrop: true
                });
            }}
        >
        </notification-badge>
      `,
            position: TOOL_POSITION.REAR
        }
    });
    appendViewpart({
        name: 'notification',
        viewpart: {
            show: false,
            hovering: 'edge',
            template: html ` <notification-list style="min-width: 300px;"></notification-list> `
        },
        position: VIEWPART_POSITION.ASIDEBAR
    });
    store.dispatch({
        type: ADD_SETTING,
        setting: {
            seq: 10,
            template: html ` <theme-mode-setting-let></theme-mode-setting-let> `
        }
    });
    store.dispatch({
        type: ADD_SETTING,
        setting: {
            seq: 20,
            template: html ` <notification-setting-let></notification-setting-let> `
        }
    });
    store.dispatch({
        type: ADD_SETTING,
        setting: {
            seq: 21,
            template: html ` <board-view-setting-let></board-view-setting-let> `
        }
    });
    if (await hasPrivilege({
        privilege: 'mutation',
        category: 'security',
        domainOwnerGranted: true,
        superUserGranted: true
    })) {
        store.dispatch({
            type: ADD_SETTING,
            setting: {
                seq: 31,
                template: html ` <secure-iplist-setting-let></secure-iplist-setting-let> `
            }
        });
    }
}
//# sourceMappingURL=bootstrap.js.map