1import {
2 alternateComposerDispatchAction,
3 type ActiveTurnComposerAction,
4} from "@t3tools/client-runtime/state/composer-dispatch";
5
6import type { FollowUpBehavior } from "../../lib/followUpBehavior";
7
8export interface ComposerSendPresentation {
9 readonly label: string;
10 readonly icon:
11 | "arrow.up"
12 | "tray.and.arrow.up"
13 | "checkmark"
14 | "list.number"
15 | "arrow.turn.left.up";
16 readonly action: ActiveTurnComposerAction | null;
17 readonly alternate: ActiveTurnComposerAction | null;
18 readonly offersFollowUpChoice: boolean;
19}
20
21const ACTION_LABEL: Record<ActiveTurnComposerAction, string> = {
22 queue: "Queue",
23 steer: "Steer",
24 restart: "Restart",
25};
26
27export function resolveComposerSendPresentation(input: {
28 readonly editingQueuedMessage: boolean;
29 readonly running: boolean;
30 readonly canSteer: boolean;
31 readonly followUpBehavior: FollowUpBehavior;
32 readonly deliveryDeferred: boolean;
33}): ComposerSendPresentation {
34 if (input.editingQueuedMessage) {
35 return {
36 label: "Update queued message",
37 icon: "checkmark",
38 action: null,
39 alternate: null,
40 offersFollowUpChoice: false,
41 };
42 }
43 if (!input.running) {
44 return {
45 label: input.deliveryDeferred ? "Queue" : "Send",
46 icon: input.deliveryDeferred ? "tray.and.arrow.up" : "arrow.up",
47 action: null,
48 alternate: null,
49 offersFollowUpChoice: false,
50 };
51 }
52 const action: ActiveTurnComposerAction = input.canSteer ? input.followUpBehavior : "queue";
53 const alternate = alternateComposerDispatchAction(action);
54 return {
55 label: ACTION_LABEL[action],
56 icon: action === "steer" ? "arrow.turn.left.up" : "list.number",
57 action,
58 alternate: input.canSteer ? alternate : null,
59 offersFollowUpChoice: input.canSteer,
60 };
61}