import type { ReleaseSummary } from '../core/store/ReleaseStore'; import { Button, HStack, Label, Popup, TextField, Theme } from '../ui'; import { dialogButtons } from './FormDialog'; const LINK_WIDTH = 420; /** * "Release…" (#266): the link that plays only the game, with Copy and Open, and Publish – or Update * release and Take down once there is one. Every action closes the dialog and hands the choice on; * the caller opens it again on the new state. */ export class ReleaseDialog extends Popup { private readonly linkField: TextField | null = null; private readonly shown: { state: string; warnings: string[] }; constructor( release: ReleaseSummary | null, link: string | null, state: string, warnings: readonly string[], actions: { onPublish(): void; onTakeDown(): void; onCopy(link: string): void; onOpen(link: string): void; }, ) { super({ modal: true, padding: Theme.padding * 2, gap: Theme.gap }); this.minWidth = LINK_WIDTH; this.shown = { state, warnings: [...warnings] }; this.content.add(new Label('Release', { style: 'bodyBold' })); this.content.add(new Label(state, { style: 'muted' })); if (link) { this.linkField = new TextField(link, { readOnly: true, width: LINK_WIDTH }); const row = new HStack({ gap: Theme.gap, align: 'center' }); row.add(this.linkField, 1); row.add(new Button('Copy link', { onClick: () => actions.onCopy(link) })); row.add(new Button('Open', { onClick: () => actions.onOpen(link) })); this.content.add(row); } for (const warning of warnings) this.content.add(new Label(warning, { style: 'warning' })); const publish = new Button(release ? 'Update release' : 'Publish', { variant: 'primary', onClick: this.closeThen(() => actions.onPublish()), }); const takeDown = release ? new Button('Take down', { variant: 'danger', onClick: this.closeThen(() => actions.onTakeDown()) }) : undefined; this.content.add(dialogButtons(this.closeThen(), publish, takeDown)); } /** The link as shown – null while there is none – the state line and the warnings (test hook). */ info(): { link: string | null; state: string; warnings: string[] } { return { link: this.linkField?.value ?? null, ...this.shown, warnings: [...this.shown.warnings] }; } }