import { i18n } from './i18n'
import { sdk } from './sdk'
import { uiPort } from './utils'

/**
 * Expose the Next.js UI over StartOS's standard HTTP multi-host interface.
 * The UI is unmasked (no shared secret in the URL) because the app has its
 * own password-protected login screen.
 */
export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
  const uiMulti = sdk.MultiHost.of(effects, 'ui-multi')
  const uiMultiOrigin = await uiMulti.bindPort(uiPort, {
    protocol: 'http',
  })
  const ui = sdk.createInterface(effects, {
    name: i18n('Web UI'),
    id: 'ui',
    description: i18n('The browser interface for Proof of Work'),
    type: 'ui',
    masked: false,
    schemeOverride: null,
    username: null,
    path: '',
    query: {},
  })

  const uiReceipt = await uiMultiOrigin.export([ui])

  return [uiReceipt]
})
