import '@material/web/icon/icon.js';
import '@operato/i18n/ox-i18n.js';
import '@things-factory/notification';
import '@things-factory/auth-ui/dist-client'; /* for domain-switch */
import '@operato/dataset/usecase/qc';
import '@operato/dataset/ox-property-editor-qc-limits.js';
import { html } from 'lit-html';
import { registerDefaultGroups } from '@operato/board';
import { navigate, store } from '@operato/shell';
import { OxPropertyEditor } from '@operato/property-editor';
import { appendViewpart, toggleOverlay, TOOL_POSITION, VIEWPART_POSITION } from '@operato/layout';
import { APPEND_APP_TOOL } from '@things-factory/apptool-base/client';
import { setupAppToolPart } from '@things-factory/apptool-ui/dist-client';
import { auth, hasPrivilege } from '@things-factory/auth-base/dist-client';
import { setAuthManagementMenus } from '@things-factory/auth-ui/dist-client';
import { setupMenuPart, updateMenuTemplate } from '@things-factory/lite-menu/dist-client';
import { setupContextUIPart } from '@things-factory/context-ui/dist-client';
import { ADD_MORENDA } from '@things-factory/more-base/client';
import { ADD_SETTING } from '@things-factory/setting-base/dist-client';
import { getMenuTemplate } from './menu';
import { queryDataSets } from './query-data-sets';
console.log(`%c
 ▄▄▄▄▄▄    ▄▄▄▄     ▄▄▄▄    ▄▄   ▄▄   ▄▄▄▄▄
 ▓▓       ▓▓  ▓▓   ▓▓  ▓▓   ▓▓▓ ▓▓▓   ▓▓
 ▓▓       ▓▓       ▓▓  ▓▓   ▓▓▓▓▓▓▓   ▓▓
 ▄▄▄▄      ▄▄▄▄    ▓▓  ▓▓   ▓▓ ▄ ▓▓   ▄▄▄▄
 ▓▓           ▓▓   ▓▓  ▓▓   ▓▓   ▓▓   ▓▓
 ▓▓       ▓▓  ▓▓   ▓▓  ▓▓   ▓▓   ▓▓   ▓▓
 ▄▄▄▄▄     ▄▄▄▄     ▄▄▄▄    ▄▄   ▄▄   ▄▄▄▄▄`, 'background: #222; color: #bada55');
export default async function bootstrap() {
    /* set board-modeller group and default templates */
    registerDefaultGroups();
    OxPropertyEditor.register({
        'qc-limits': 'ox-property-editor-qc-limits'
    });
    await setupAppToolPart({
        toolbar: true,
        busybar: true,
        mdibar: false
    });
    await setupContextUIPart({
        titlebar: 'header',
        contextToolbar: 'page-footer'
    });
    await setupMenuPart({
        slotTemplate: html ` <domain-switch slot="tail" attrname="description"></domain-switch> `,
        hovering: true
    });
    /* 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');
            }
        }
    });
    auth.on('profile', async ({ credential }) => {
        updateMenuTemplate(getMenuTemplate(credential.owner, await queryDataSets()));
        /* set auth management menus into more-panel */
        setAuthManagementMenus();
        if (credential.owner) {
            store.dispatch({
                type: ADD_MORENDA,
                morenda: {
                    icon: html ` <md-icon>pending_actions</md-icon> `,
                    name: html ` <ox-i18n msgid="title.work-shift"></ox-i18n> `,
                    action: () => {
                        navigate('work-shift');
                    }
                }
            });
            store.dispatch({
                type: ADD_MORENDA,
                morenda: {
                    icon: html ` <md-icon>device_hub</md-icon> `,
                    name: html ` <ox-i18n msgid="text.connection"></ox-i18n> `,
                    action: () => {
                        navigate('connection');
                    }
                }
            });
            store.dispatch({
                type: ADD_MORENDA,
                morenda: {
                    icon: html ` <md-icon>format_list_numbered</md-icon> `,
                    name: html ` <ox-i18n msgid="text.scenario"></ox-i18n> `,
                    action: () => {
                        navigate('scenario');
                    }
                }
            });
            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>device_hub</md-icon> `,
                    name: html ` <ox-i18n msgid="text.installable-activities"></ox-i18n> `,
                    action: () => {
                        navigate('installable-activity-list');
                    }
                }
            });
            /* add Integration Analysis menu */
            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>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>help</md-icon> `,
                name: html ` <ox-i18n msgid="text.help"></ox-i18n> `,
                action: () => {
                    navigate('help');
                }
            }
        });
        /* 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: 20,
                template: html ` <notification-setting-let></notification-setting-let> `
            }
        });
        store.dispatch({
            type: ADD_SETTING,
            setting: {
                seq: 21,
                template: html ` <lite-menu-setting-let></lite-menu-setting-let> `
            }
        });
    });
    if (await hasPrivilege({ privilege: 'mutation', category: 'board', domainOwnerGranted: true, superUserGranted: 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>attachment</md-icon> `,
                name: html ` <ox-i18n msgid="menu.attachments"></ox-i18n> `,
                action: () => {
                    navigate('attachment-list');
                }
            }
        });
        store.dispatch({
            type: ADD_MORENDA,
            morenda: {
                icon: html ` <md-icon>dvr</md-icon> `,
                name: html ` <ox-i18n msgid="menu.board-list"></ox-i18n> `,
                action: () => {
                    navigate('board-list');
                }
            }
        });
        store.dispatch({
            type: ADD_MORENDA,
            morenda: {
                icon: html ` <md-icon>airplay</md-icon> `,
                name: html ` <ox-i18n msgid="menu.play-groups"></ox-i18n> `,
                action: () => {
                    navigate('play-list');
                }
            }
        });
    }
    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');
                }
            }
        });
    }
}
//# sourceMappingURL=bootstrap.js.map