import type { UserManagerSettings } from 'oidc-client'
import { WebStorageStateStore } from 'oidc-client'

import { client } from 'config/clients'
import { AUTH_SERVICE } from 'config/routes'

export const getClientSettings = (): UserManagerSettings => ({
  authority: AUTH_SERVICE,
  automaticSilentRenew: true,
  client_id: client.auth.clientId,
  filterProtocolClaims: false,
  loadUserInfo: false,
  metadataUrl: `${AUTH_SERVICE}/.well-known/openid-configuration${client.auth.metaDataUrlParams || ''}`,
  redirect_uri: `${window.origin}/redirect`,
  response_mode: 'query',
  response_type: 'id_token token',
  scope: 'openid',
  silent_redirect_uri: `${window.origin}/silent-refresh.html`,
  silentRequestTimeout: 2000,
  userStore: new WebStorageStateStore({ store: window.localStorage }),
})
