'use client'; import type { ReactNode } from 'react'; import { useState } from 'react'; import { validateBotToken, parseAdminIds, validateRunTime, telegramApiBase, buildBotConfigSummary, } from '@/lib/xray/telegram'; import { ToolFrame } from './tool-frame'; import { TextField } from './shared/fields'; import { OutputBlock } from './shared/output-block'; function Status({ ok, children }: { ok: boolean; children: ReactNode }) { return (

{children}

); } export function TelegramSetupHelper() { const [token, setToken] = useState(''); const [adminIds, setAdminIds] = useState(''); const [runTime, setRunTime] = useState('@daily'); const tokenV = validateBotToken(token); const idsV = parseAdminIds(adminIds); const cronV = validateRunTime(runTime); const summary = buildBotConfigSummary({ token, adminIds, runTime }); const settingsText = [ `tgBotEnable = true`, `tgBotToken = ${summary.tgBotToken || ''}`, `tgBotChatId = ${summary.tgBotChatId || ''}`, `tgRunTime = ${summary.tgRunTime || '@daily'}`, ].join('\n'); function reset() { setToken(''); setAdminIds(''); setRunTime('@daily'); } return (
{token ? ( tokenV.valid ? ( Valid — bot id {tokenV.botId} ) : ( {tokenV.error} ) ) : null}
{adminIds ? ( idsV.invalid.length > 0 ? ( Not numeric: {idsV.invalid.join(', ')} ) : ( {idsV.ids.length} admin id{idsV.ids.length === 1 ? '' : 's'} ) ) : null}
{runTime ? ( cronV.valid ? ( Valid ({cronV.kind}) ) : ( {cronV.error} ) ) : null}
'} />
); }