import { useRef, useState, type CSSProperties } from 'react' import type { CuePoint } from '../api' import { CUE_TYPE_LABELS, cueColor, cueIcon, withAlpha } from '../lib/cues' import { Icon } from '../lib/icons' interface Props { cues: CuePoint[] /** Bank size, from capabilities — not every platform has eight. */ slotCount: number /** How a slot is labelled ("1".."8" or "A".."H"). */ slotLabel: (slot: number) => string selectedSlot: number | null onSlotPress: (slot: number) => void onSlotRelease: (slot: number) => void /** Right-click on a pad: the deck opens its Type / Colour / Rename / Delete menu. */ onSlotMenu: (slot: number, x: number, y: number) => void /** The pad whose name is being edited in place, if any. */ renamingSlot: number | null onRenameCommit: (slot: number, name: string) => void onRenameCancel: () => void } // The narrowest a pad gets (a letter-only square) and the gap between pads. const PAD_MIN = 40 const PAD_GAP = 6 const READONLY_LABELS: Record = { platform_managed: 'Managed by the DJ app — not editable here', } /** * The 8 hotcue slots, colour-coded by cue type when assigned (gray when empty). * Rendered as a flex-1 group inside the hotcue row; the parent supplies the row * chrome and the trailing edit controls. Slots respond to press AND release * (pointer capture, so a release outside the button still fires) so the parent * can implement momentary "cue preview" (play while held). Press creates when * empty and jumps/triggers when assigned; release ends any preview. * * A cue the adapter will not edit (`editable: false`) shows a lock and only * seeks; the backend would refuse the edit, and showing that up front is better * than surfacing the refusal as an error. */ export function HotcueBar({ cues, slotCount, slotLabel, selectedSlot, onSlotPress, onSlotRelease, onSlotMenu, renamingSlot, onRenameCommit, onRenameCancel, }: Props) { return ( // The group takes the row's spare width; each pad is capped, so on a wide // window the pads keep a pad's proportions and the space is left empty // rather than stretching them into bars. It never goes below a bank of // PAD_MIN pads: squeezed further, the pads' padding spilled them out of // the group and over the tempo controls.
{Array.from({ length: slotCount }, (_, i) => i).map((slot) => { const cue = cues.find((c) => c.role === 'hotcue' && c.slot === slot) ?? null // Gate on `editable`, never on why: a platform-owned cue is a read-only // case, not a Traktor-companion case. const locked = cue != null && !cue.editable const selected = selectedSlot === slot && !locked const color = cue ? cueColor(cue) : null const icon = cue && !locked ? cueIcon(cue) : null return ( ) })}
) } /** * A lit pad: tinted glass in the cue's colour with a soft glow of it, the way a * backlit controller pad reads. Selection brightens the tint and rings it in * the colour itself, so it stays legible whichever colour the cue is. */ function padStyle(color: string, selected: boolean): CSSProperties { return { // The cue colour sits on a DARK GROUND (the last layer), not on bare glass: // over a bright or warm ambient wash a thin tint alone came out the same hue // as the backdrop and the pad dissolved into it. The ground keeps every pad // the same deep base whatever track is loaded. background: [ `linear-gradient(180deg, ${withAlpha(color, selected ? 0.52 : 0.34)}, ${withAlpha( color, selected ? 0.26 : 0.12, )})`, 'rgba(8,10,18,0.55)', ].join(', '), boxShadow: [ 'inset 0 1px 0 rgba(255,255,255,0.22)', `inset 0 0 0 ${selected ? 2 : 1}px ${withAlpha(color, selected ? 0.95 : 0.7)}`, `0 0 ${selected ? 24 : 18}px -4px ${withAlpha(color, selected ? 0.8 : 0.55)}`, ].join(', '), } } /** A cue colour lifted toward white, for the pad's number: the raw colour is * too dark to read as text on its own tint (blue especially). */ function lighten(hex: string, amount = 0.35): string { const v = parseInt(hex.slice(1, 7), 16) const mix = (c: number) => Math.round(c + (255 - c) * amount) return `rgb(${mix(v >> 16)},${mix((v >> 8) & 255)},${mix(v & 255)})` } /** The pad's name, edited in place. Enter or clicking away commits; Esc cancels. */ function RenameField({ initial, onCommit, onCancel, }: { initial: string onCommit: (name: string) => void onCancel: () => void }) { const [val, setVal] = useState(initial) // Enter commits and unmounts the field, which can fire a trailing blur. const done = useRef(false) const finish = (commit: boolean) => { if (done.current) return done.current = true if (commit && val.trim() !== initial) onCommit(val.trim()) else onCancel() } return ( setVal(e.target.value)} onFocus={(e) => e.currentTarget.select()} onBlur={() => finish(true)} // The pad is a button: keep its press/preview handlers out of the field. onPointerDown={(e) => e.stopPropagation()} onPointerUp={(e) => e.stopPropagation()} onKeyDown={(e) => { e.stopPropagation() // digits and Space must type, not trigger the deck if (e.key === 'Enter') finish(true) else if (e.key === 'Escape') finish(false) }} className="w-full min-w-0 rounded bg-well px-1 text-[11px] leading-4 text-text outline-none ring-1 ring-accent" /> ) }