import React, { useEffect, useRef, useState } from 'react' import { names } from './names.js' import { layout } from './layout.js' // Tab for a stream panel: double-click to rename (viewer-side label, kept in this browser). Empty = back to user · title. export default function Tab({ api, params }) { const id = api.id const custom = names.use(s => s.streams[id]) const base = `${params.user} · ${params.title}` const [editing, setEditing] = useState(false) const [draft, setDraft] = useState('') const ref = useRef(null) useEffect(() => { if (editing) { ref.current?.focus(); ref.current?.select() } }, [editing]) const start = e => { e.stopPropagation(); setDraft(custom || ''); setEditing(true) } const commit = () => { if (!editing) return; const v = draft.trim(); names.rename(id, v); api.setTitle(v || base); layout.markCustom(); setEditing(false) } return (