import '@material/mwc-icon'
import '@operato/i18n/ox-i18n.js'

import { html } from 'lit-html'

import { navigate, store } from '@operato/shell'
import { ADD_MORENDA } from '@things-factory/more-base/client'
import { hasPrivilege } from '@things-factory/auth-base/dist-client'

export * from './components/role-selector.js'
export * from './components/domain-switch.js'
export * from './components/invite-user.js'

export async function setAuthManagementMenus() {
  if (
    await hasPrivilege({ privilege: 'mutation', category: 'user', domainOwnerGranted: true, superUserGranted: true })
  ) {
    store.dispatch({
      type: ADD_MORENDA,
      morenda: {
        icon: html` <mwc-icon>how_to_reg</mwc-icon> `,
        name: html` <ox-i18n msgid="text.role_management"></ox-i18n> `,
        action: () => {
          navigate('roles')
        }
      }
    })

    store.dispatch({
      type: ADD_MORENDA,
      morenda: {
        icon: html` <mwc-icon>devices</mwc-icon> `,
        name: html` <ox-i18n msgid="text.appliance"></ox-i18n> `,
        action: () => {
          navigate('appliance-home')
        }
      }
    })

    store.dispatch({
      type: ADD_MORENDA,
      morenda: {
        icon: html` <mwc-icon>apps</mwc-icon> `,
        name: html` <ox-i18n msgid="text.application management"></ox-i18n> `,
        action: () => {
          navigate('applications')
        }
      }
    })

    store.dispatch({
      type: ADD_MORENDA,
      morenda: {
        icon: html` <mwc-icon>people</mwc-icon> `,
        name: html` <ox-i18n msgid="text.user management"></ox-i18n> `,
        action: () => {
          navigate('users')
        }
      }
    })

    store.dispatch({
      type: ADD_MORENDA,
      morenda: {
        icon: html` <mwc-icon>badge</mwc-icon> `,
        name: html` <ox-i18n msgid="text.auth-provider management"></ox-i18n> `,
        action: () => {
          navigate('auth-providers')
        }
      }
    })
  }

  if (await hasPrivilege({ superUserGranted: true })) {
    store.dispatch({
      type: ADD_MORENDA,
      morenda: {
        icon: html` <mwc-icon>business</mwc-icon> `,
        name: html` <ox-i18n msgid="text.domain management"></ox-i18n> `,
        action: () => {
          navigate('domains')
        }
      }
    })

    store.dispatch({
      type: ADD_MORENDA,
      morenda: {
        icon: html` <mwc-icon>dataset</mwc-icon> `,
        name: html` <ox-i18n msgid="text.attribute management"></ox-i18n> `,
        action: () => {
          navigate('attributes')
        }
      }
    })
  }
}
