{#if showForm}
form.icon = v} /> nameManuallyEdited = true} required placeholder={t('telegramBot.namePlaceholder')} class="flex-1 px-3 py-2 border border-[var(--color-border)] rounded-md text-sm bg-[var(--color-background)]" />
{#if !editing}
{/if}
{/if} {#if bots.length === 0 && !showForm} {:else}
{#each bots as bot}

{bot.name}

{#if bot.bot_username} @{bot.bot_username} {/if}
{(bot.update_mode || 'none') === 'webhook' ? t('telegramBot.webhook') : (bot.update_mode || 'none') === 'polling' ? t('telegramBot.polling') : t('telegramBot.none')}

{bot.token_preview}

editBot(bot)} /> syncCommands(bot.id)} disabled={modeChanging[bot.id]} /> remove(bot.id)} variant="danger" />
{#if expandedSection[bot.id] === 'chats'}
{#if chatsLoading[bot.id] && !chats[bot.id]}

{t('common.loading')}

{:else if (chats[bot.id] || []).length === 0 && !chatsRefreshing[bot.id]}

{t('telegramBot.noChats')}

{:else} {@const gridStyle = "display:grid; grid-template-columns:1fr 80px 40px 100px 50px 130px 60px; align-items:center; gap:0.5rem;"}
{#if chatsRefreshing[bot.id]} {/if}
{t('telegramBot.chatName')} {t('telegramBot.chatType')} {t('telegramBot.chatLang')} {t('telegramBot.langOverride')} {t('telegramBot.cmds')} {t('telegramBot.chatId')}
{#each (chats[bot.id] || []) as chat (chat.id)}
copyChatId(e, chat.chat_id)} onkeydown={(e: KeyboardEvent) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); copyChatId(e as unknown as MouseEvent, chat.chat_id); } }} title={t('telegramBot.clickToCopy')} aria-label={t('telegramBot.clickToCopy')} role="button" tabindex="0"> {chat.title || chat.username || t('common.unknown')} {chatTypeLabel(chat.type)} {(chat.language_code || '—').toUpperCase()}
e.stopPropagation()} onkeydown={(e: KeyboardEvent) => e.stopPropagation()}> updateChatLanguage(bot.id, chat, String(val ?? ''))} />
e.stopPropagation()} onkeydown={(e: KeyboardEvent) => e.stopPropagation()}>
{chat.chat_id}
testChat(e, bot.id, chat.chat_id)} disabled={chatTesting[`${bot.id}_${chat.chat_id}`]} /> { e.stopPropagation(); deleteChat(bot.id, chat.id); }} variant="danger" />
{/each} {#if chatsRefreshing[bot.id] && (chats[bot.id] || []).length === 0}

{t('telegramBot.discoveringChats')}

{/if}
{/if}
{/if} {#if expandedSection[bot.id] === 'listeners'}
{#if botListenerLoading[bot.id]}

{t('common.loading')}

{:else if (botListenerStatus[bot.id] || []).length === 0}

{t('commandTracker.noListeners')}

{:else}
{#each botListenerStatus[bot.id] as trk}
{/each}
{/if}

{t('telegramBot.updateMode')}

{#if (bot.update_mode || 'none') === 'none'} {t('telegramBot.noneActive')} {/if} {#if bot.update_mode === 'polling'} {t('telegramBot.pollingActive')} {/if} {#if bot.update_mode === 'webhook'} {#if webhookStatus[bot.id]} {@const ws = webhookStatus[bot.id]} {ws.url ? t('telegramBot.webhookActive') : t('telegramBot.webhookNotSet')} {#if (ws.pending_update_count ?? 0) > 0} ({ws.pending_update_count} {t('telegramBot.pendingUpdates')}) {/if} {#if ws.last_error_message} {t('telegramBot.webhookError')}: {ws.last_error_message} {/if} {:else} {/if} {/if} {#if !settings.external_url && bot.update_mode === 'webhook'} {t('telegramBot.noExternalDomain')} {/if}
{/if}
{/each}
{/if} confirmDelete?.onconfirm()} oncancel={() => confirmDelete = null} /> blockedBy = null} />