blob: 8498f55ae65bf239759a8220f391758ed08b24a6 [file] [log] [blame]
bankseand5c849d2025-06-26 15:48:31 +00001import { html } from "lit";
Sean McCulloughd9f13372025-04-21 15:08:49 -07002import { customElement, property } from "lit/decorators.js";
Sean McCullough71941bd2025-04-18 13:31:48 -07003import "./sketch-container-status";
bankseand5c849d2025-06-26 15:48:31 +00004import { SketchTailwindElement } from "./sketch-tailwind-element";
Sean McCullough86b56862025-04-18 13:04:03 -07005
Sean McCullough71941bd2025-04-18 13:31:48 -07006@customElement("sketch-view-mode-select")
bankseand5c849d2025-06-26 15:48:31 +00007export class SketchViewModeSelect extends SketchTailwindElement {
Sean McCullough86b56862025-04-18 13:04:03 -07008 // Current active mode
9 @property()
Philip Zeyliger00bcaef2025-05-30 04:21:15 +000010 activeMode: "chat" | "diff2" | "terminal" = "chat";
Philip Zeyliger64f60462025-06-16 13:57:10 -070011
12 // Diff stats
13 @property({ type: Number })
14 diffLinesAdded: number = 0;
15
16 @property({ type: Number })
17 diffLinesRemoved: number = 0;
18
Sean McCullough86b56862025-04-18 13:04:03 -070019 // Header bar: view mode buttons
20
Sean McCullough86b56862025-04-18 13:04:03 -070021 constructor() {
22 super();
Sean McCullough71941bd2025-04-18 13:31:48 -070023
Sean McCullough86b56862025-04-18 13:04:03 -070024 // Binding methods
25 this._handleViewModeClick = this._handleViewModeClick.bind(this);
26 this._handleUpdateActiveMode = this._handleUpdateActiveMode.bind(this);
27 }
28
29 // See https://lit.dev/docs/components/lifecycle/
30 connectedCallback() {
31 super.connectedCallback();
Sean McCullough71941bd2025-04-18 13:31:48 -070032
Sean McCullough86b56862025-04-18 13:04:03 -070033 // Listen for update-active-mode events
Sean McCullough71941bd2025-04-18 13:31:48 -070034 this.addEventListener(
35 "update-active-mode",
36 this._handleUpdateActiveMode as EventListener,
37 );
Sean McCullough86b56862025-04-18 13:04:03 -070038 }
Sean McCullough71941bd2025-04-18 13:31:48 -070039
Sean McCullough86b56862025-04-18 13:04:03 -070040 /**
41 * Handle view mode button clicks
42 */
Philip Zeyliger00bcaef2025-05-30 04:21:15 +000043 private _handleViewModeClick(mode: "chat" | "diff2" | "terminal") {
Sean McCullough86b56862025-04-18 13:04:03 -070044 // Dispatch a custom event to notify the app shell to change the view
Sean McCullough71941bd2025-04-18 13:31:48 -070045 const event = new CustomEvent("view-mode-select", {
Sean McCullough86b56862025-04-18 13:04:03 -070046 detail: { mode },
47 bubbles: true,
Sean McCullough71941bd2025-04-18 13:31:48 -070048 composed: true,
Sean McCullough86b56862025-04-18 13:04:03 -070049 });
50 this.dispatchEvent(event);
51 }
Sean McCullough71941bd2025-04-18 13:31:48 -070052
Sean McCullough86b56862025-04-18 13:04:03 -070053 /**
54 * Handle updates to the active mode
55 */
56 private _handleUpdateActiveMode(event: CustomEvent) {
57 const { mode } = event.detail;
58 if (mode) {
59 this.activeMode = mode;
60 }
61 }
62
63 // See https://lit.dev/docs/components/lifecycle/
64 disconnectedCallback() {
65 super.disconnectedCallback();
Sean McCullough71941bd2025-04-18 13:31:48 -070066
Sean McCullough86b56862025-04-18 13:04:03 -070067 // Remove event listeners
Sean McCullough71941bd2025-04-18 13:31:48 -070068 this.removeEventListener(
69 "update-active-mode",
70 this._handleUpdateActiveMode as EventListener,
71 );
Sean McCullough86b56862025-04-18 13:04:03 -070072 }
73
74 render() {
75 return html`
bankseand5c849d2025-06-26 15:48:31 +000076 <div
banksean3eaa4332025-07-19 02:19:06 +000077 class="flex mr-2.5 bg-gray-100 dark:bg-gray-800 rounded border border-gray-300 dark:border-gray-600 overflow-hidden"
bankseand5c849d2025-06-26 15:48:31 +000078 >
Sean McCullough86b56862025-04-18 13:04:03 -070079 <button
80 id="showConversationButton"
banksean3eaa4332025-07-19 02:19:06 +000081 class="px-3 py-2 bg-none border-0 border-b-2 cursor-pointer text-xs flex items-center gap-1.5 text-gray-600 dark:text-gray-400 border-transparent transition-all whitespace-nowrap ${this
bankseand5c849d2025-06-26 15:48:31 +000082 .activeMode === "chat"
banksean3eaa4332025-07-19 02:19:06 +000083 ? "border-b-blue-600 dark:border-b-gray-500 text-blue-600 font-medium bg-blue-50 dark:bg-gray-700"
84 : "hover:bg-gray-200 dark:hover:bg-gray-700"} @xl:px-3 @xl:py-2 @max-xl:px-2.5 @max-xl:[&>span:not(.tab-icon):not(.diff-stats)]:hidden @max-xl:[&>.diff-stats]:inline @max-xl:[&>.diff-stats]:text-xs @max-xl:[&>.diff-stats]:ml-0.5 border-r border-gray-200 dark:border-gray-600 last-of-type:border-r-0"
Sean McCullough86b56862025-04-18 13:04:03 -070085 title="Conversation View"
Sean McCullough71941bd2025-04-18 13:31:48 -070086 @click=${() => this._handleViewModeClick("chat")}
Sean McCullough86b56862025-04-18 13:04:03 -070087 >
bankseand5c849d2025-06-26 15:48:31 +000088 <span class="tab-icon text-base">💬</span>
89 <span class="max-sm:hidden sm:max-xl:hidden">Chat</span>
Sean McCullough86b56862025-04-18 13:04:03 -070090 </button>
91 <button
Philip Zeyliger272a90e2025-05-16 14:49:51 -070092 id="showDiff2Button"
banksean3eaa4332025-07-19 02:19:06 +000093 class="px-3 py-2 bg-none border-0 border-b-2 cursor-pointer text-xs flex items-center gap-1.5 text-gray-600 dark:text-gray-400 border-transparent transition-all whitespace-nowrap ${this
bankseand5c849d2025-06-26 15:48:31 +000094 .activeMode === "diff2"
banksean3eaa4332025-07-19 02:19:06 +000095 ? "border-b-blue-600 dark:border-b-gray-500 text-blue-600 font-medium bg-blue-50 dark:bg-gray-700"
96 : "hover:bg-gray-200 dark:hover:bg-gray-700"} @xl:px-3 @xl:py-2 @max-xl:px-2.5 @max-xl:[&>span:not(.tab-icon):not(.diff-stats)]:hidden @max-xl:[&>.diff-stats]:inline @max-xl:[&>.diff-stats]:text-xs @max-xl:[&>.diff-stats]:ml-0.5 border-r border-gray-200 dark:border-gray-600 last-of-type:border-r-0"
Philip Zeyliger64f60462025-06-16 13:57:10 -070097 title="Diff View - ${this.diffLinesAdded > 0 ||
98 this.diffLinesRemoved > 0
99 ? `+${this.diffLinesAdded} -${this.diffLinesRemoved}`
100 : "No changes"}"
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700101 @click=${() => this._handleViewModeClick("diff2")}
Sean McCullough86b56862025-04-18 13:04:03 -0700102 >
bankseand5c849d2025-06-26 15:48:31 +0000103 <span class="tab-icon text-base">±</span>
104 <span class="diff-tex max-sm:hidden sm:max-xl:hidden">Diff</span>
Philip Zeyliger64f60462025-06-16 13:57:10 -0700105 ${this.diffLinesAdded > 0 || this.diffLinesRemoved > 0
bankseand5c849d2025-06-26 15:48:31 +0000106 ? html`<span
107 class="diff-stats text-xs ml-1 opacity-80 ${this.activeMode ===
108 "diff2"
109 ? "opacity-100"
110 : ""}"
Philip Zeyliger64f60462025-06-16 13:57:10 -0700111 >+${this.diffLinesAdded} -${this.diffLinesRemoved}</span
112 >`
113 : ""}
Sean McCullough86b56862025-04-18 13:04:03 -0700114 </button>
Autoformatter8c463622025-05-16 21:54:17 +0000115
Sean McCullough86b56862025-04-18 13:04:03 -0700116 <button
117 id="showTerminalButton"
banksean3eaa4332025-07-19 02:19:06 +0000118 class="px-3 py-2 bg-none border-0 border-b-2 cursor-pointer text-xs flex items-center gap-1.5 text-gray-600 dark:text-gray-400 border-transparent transition-all whitespace-nowrap ${this
bankseand5c849d2025-06-26 15:48:31 +0000119 .activeMode === "terminal"
banksean3eaa4332025-07-19 02:19:06 +0000120 ? "border-b-blue-600 !dark:border-b-gray-500 text-blue-600 font-medium bg-blue-50 dark:bg-gray-700"
121 : "hover:bg-gray-200 dark:hover:bg-gray-700"} @xl:px-3 @xl:py-2 @max-xl:px-2.5 @max-xl:[&>span:not(.tab-icon):not(.diff-stats)]:hidden @max-xl:[&>.diff-stats]:inline @max-xl:[&>.diff-stats]:text-xs @max-xl:[&>.diff-stats]:ml-0.5 border-r border-gray-200 dark:border-gray-600 last-of-type:border-r-0"
Sean McCullough86b56862025-04-18 13:04:03 -0700122 title="Terminal View"
Sean McCullough71941bd2025-04-18 13:31:48 -0700123 @click=${() => this._handleViewModeClick("terminal")}
Sean McCullough86b56862025-04-18 13:04:03 -0700124 >
bankseand5c849d2025-06-26 15:48:31 +0000125 <span class="tab-icon text-base">💻</span>
126 <span class="max-sm:hidden sm:max-xl:hidden">Terminal</span>
Sean McCullough86b56862025-04-18 13:04:03 -0700127 </button>
128 </div>
129 `;
130 }
131}
132
133declare global {
134 interface HTMLElementTagNameMap {
135 "sketch-view-mode-select": SketchViewModeSelect;
136 }
Sean McCullough71941bd2025-04-18 13:31:48 -0700137}