import { useState } from 'react' import { useTranslation } from 'next-i18next' import useBackend from 'site/hooks/useBackend.js' import Link from 'next/link' import { Choice } from '../shared.js' export const namespaces = ['control'] const welcomeSteps = { 1: { href: '/docs/guide/', steps: 0, }, 2: { href: '/welcome/newsletter', steps: 3, }, 3: { href: '/welcome/newsletter', steps: 5, }, 4: { href: '/welcome/newsletter', steps: 7, }, 5: { href: '/', steps: 0, }, } export const ControlSettings = ({ app, title = false, welcome = false }) => { const backend = useBackend(app) const { t } = useTranslation(namespaces) const [selection, setSelection] = useState(app.account.control || 2) const update = async (control) => { if (control !== selection) { const result = await backend.updateAccount({ control }) if (result) setSelection(control) } } return ( <> {title ?

{t('title')}

: null} {[1, 2, 3, 4, 5].map((val) => { if (selection === 1 && val > 2) return null if (selection === 2 && val > 3) return null if (selection === 3 && val > 4) return null if (selection === 5 && val < 4) return null else return ( {selection === 1 && val === 2 ? t('showMore') : t(`${val}t`)} {selection > 1 ? ( {t(`${val}d`)} ) : null} ) })} {welcome ? ( <> {t('continue')} {welcomeSteps[selection].steps ? ( <> 1 / {welcomeSteps[selection].steps} ) : null} ) : null} ) } export default ControlSettings