blob: b57412dd440342bcbc1fce9137cf0ce3ba194d6c [file] [log] [blame]
Sean McCullough618bfb22025-06-25 20:52:30 +00001/**
2 * Demo module for sketch-container-status component
3 */
4
5import { DemoModule } from "./demo-framework/types";
6import {
7 demoUtils,
8 sampleContainerState,
9 lightUsageState,
10 heavyUsageState,
11} from "./demo-fixtures/index";
12
13const demo: DemoModule = {
14 title: "Container Status Demo",
15 description: "Display container status information with usage statistics",
16 imports: ["../sketch-container-status"],
17 styles: ["/dist/tailwind.css"],
18
19 setup: async (container: HTMLElement) => {
20 // Create demo sections
21 const basicSection = demoUtils.createDemoSection(
22 "Basic Container Status",
23 "Shows current container state with usage information",
24 );
25
26 const variationsSection = demoUtils.createDemoSection(
27 "Usage Variations",
28 "Different usage levels and states",
29 );
30
31 // Basic status component
32 const basicStatus = document.createElement(
33 "sketch-container-status",
34 ) as any;
35 basicStatus.id = "basic-status";
36 basicStatus.state = sampleContainerState;
37
38 // Light usage status
39 const lightStatus = document.createElement(
40 "sketch-container-status",
41 ) as any;
42 lightStatus.id = "light-status";
43 lightStatus.state = lightUsageState;
44
45 const lightLabel = document.createElement("h4");
46 lightLabel.textContent = "Light Usage";
47 lightLabel.style.cssText = "margin: 20px 0 10px 0; color: #24292f;";
48
49 // Heavy usage status
50 const heavyStatus = document.createElement(
51 "sketch-container-status",
52 ) as any;
53 heavyStatus.id = "heavy-status";
54 heavyStatus.state = heavyUsageState;
Sean McCullough49577492025-06-26 17:13:28 -070055 heavyStatus.lastCommit = {
56 hash: "deadbeef",
57 pushedBranch: "user/sketch/really-long-branch-name-that-stains-layout",
58 };
Sean McCullough618bfb22025-06-25 20:52:30 +000059 const heavyLabel = document.createElement("h4");
60 heavyLabel.textContent = "Heavy Usage";
61 heavyLabel.style.cssText = "margin: 20px 0 10px 0; color: #24292f;";
62
63 // Control buttons for interaction
64 const controlsDiv = document.createElement("div");
65 controlsDiv.style.cssText = "margin-top: 20px;";
66
67 const updateBasicButton = demoUtils.createButton(
68 "Update Basic Status",
69 () => {
70 const updatedState = {
71 ...sampleContainerState,
72 message_count: sampleContainerState.message_count + 1,
73 total_usage: {
74 ...sampleContainerState.total_usage!,
75 messages: sampleContainerState.total_usage!.messages + 1,
76 total_cost_usd: Number(
77 (sampleContainerState.total_usage!.total_cost_usd + 0.05).toFixed(
78 2,
79 ),
80 ),
81 },
82 };
83 basicStatus.state = updatedState;
84 },
85 );
86
87 const toggleSSHButton = demoUtils.createButton("Toggle SSH Status", () => {
88 const currentState = basicStatus.state;
89 basicStatus.state = {
90 ...currentState,
91 ssh_available: !currentState.ssh_available,
92 ssh_error: currentState.ssh_available ? "Connection failed" : undefined,
93 };
94 });
95
96 const resetButton = demoUtils.createButton("Reset to Defaults", () => {
97 basicStatus.state = sampleContainerState;
98 lightStatus.state = lightUsageState;
99 heavyStatus.state = heavyUsageState;
100 });
101
102 controlsDiv.appendChild(updateBasicButton);
103 controlsDiv.appendChild(toggleSSHButton);
104 controlsDiv.appendChild(resetButton);
105
106 // Assemble the demo
107 basicSection.appendChild(basicStatus);
108 basicSection.appendChild(controlsDiv);
109
110 variationsSection.appendChild(lightLabel);
111 variationsSection.appendChild(lightStatus);
112 variationsSection.appendChild(heavyLabel);
113 variationsSection.appendChild(heavyStatus);
114
115 container.appendChild(basicSection);
116 container.appendChild(variationsSection);
117
118 // Add some real-time updates
119 const updateInterval = setInterval(() => {
120 const states = [basicStatus, lightStatus, heavyStatus];
121 states.forEach((status) => {
122 if (status.state) {
123 const updatedState = {
124 ...status.state,
125 message_count:
126 status.state.message_count + Math.floor(Math.random() * 2),
127 };
128 if (Math.random() > 0.7) {
129 // 30% chance to update
130 status.state = updatedState;
131 }
132 }
133 });
134 }, 3000);
135
136 // Store interval for cleanup
137 (container as any).demoInterval = updateInterval;
138 },
139
140 cleanup: async () => {
141 // Clear any intervals
142 const container = document.getElementById("demo-container");
143 if (container && (container as any).demoInterval) {
144 clearInterval((container as any).demoInterval);
145 delete (container as any).demoInterval;
146 }
147 },
148};
149
150export default demo;