$history newest first, as ConversationStore::listFor() returns them * @param string $currentTitle the open conversation's title, used only when $history does not list it */ public function __construct(private array $history, private int $current, private string $currentTitle = '') {} public function render(): string { $opts = $this->option(0, __('New chat', 'alpaca-bot')); if ($this->current !== 0 && !in_array($this->current, array_map(static fn(array $row): int => (int) $row['id'], $this->history), true)) { $opts .= $this->option($this->current, $this->currentTitle); } foreach ($this->history as $row) { $opts .= $this->option((int) $row['id'], (string) $row['title']); } $select = sprintf( '', Hx::attrs(['get' => '/messages/0', 'trigger' => 'change', 'target' => '#ab-messages', 'swap' => 'outerHTML', 'headers' => Hx::formHeaders()]), $opts, ); return sprintf( '