import type { Metadata } from 'next'
import { getTranslations, setRequestLocale } from 'next-intl/server'
import { redirect } from '@/i18n/navigation'
import { getSession } from '@/lib/session'
import { getGuildMasterGuilds, GUILD_RENAME_PD } from '@/lib/guild'
import { PageShell } from '@/components/PageShell'
import { ServiceBox } from '@/components/ServiceBox'
import { RenameGuildForm } from '@/components/RenameGuildForm'

export const dynamic = 'force-dynamic'

export const metadata: Metadata = { title: 'Renombrar hermandad' }

export default async function RenameGuildPage({ params }: { params: Promise<{ locale: string }> }) {
  const { locale } = await params
  setRequestLocale(locale)
  const t = await getTranslations('Points')

  const session = await getSession()
  if (!session.bnetId) redirect({ href: '/login', locale })
  if (!session.username) redirect({ href: '/select-account', locale })

  const guilds = await getGuildMasterGuilds(session.accountId!)

  return (
    <PageShell title={t('renameGuild.title')}>
      <ServiceBox>
        <br />
        <p>
          {t.rich('renameGuild.intro1', { s: (c) => <span>{c}</span> })}
        </p>
        <br />
        <p>{t('renameGuild.rules')}</p>
        <p>{t('renameGuild.rule1')}</p>
        <p>{t('renameGuild.rule2')}</p>
        <br />
        <p>
          {t('renameGuild.intro2')}
        </p>
        <p>
          {t('renameGuild.intro3')}
        </p>
        <br />
        <fieldset>
          <legend>{t('renameGuild.note')}</legend>
          <div className="separate2">
            <p>
              {t('renameGuild.noteText')}
            </p>
          </div>
        </fieldset>

        <div className="centered">
          <br />
          <br />
          <p>
            {t.rich('renameGuild.requires', {
              pd: GUILD_RENAME_PD,
              s: (c) => <span>{c}</span>,
              y: (c) => <span className="yellow-info">{c}</span>,
            })}
          </p>
          <br />
        </div>

        <RenameGuildForm guilds={guilds} />
      </ServiceBox>
    </PageShell>
  )
}
