File size: 5,927 Bytes
5a3b695
cd1aa63
 
 
 
 
 
 
 
 
 
5a3b695
 
 
 
 
 
 
 
cd1aa63
 
 
 
 
 
 
 
 
 
ce91fab
 
 
 
cd1aa63
 
 
 
 
 
 
 
 
 
 
ce91fab
 
 
 
cd1aa63
 
5a3b695
cd1aa63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a3b695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd1aa63
5a3b695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd1aa63
5a3b695
 
 
cd1aa63
5a3b695
 
cd1aa63
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { useState } from "react";
import BrainActivity from "./BrainActivity";
import FlyChipStrip from "./FlyChipStrip";
import FlyControls from "./FlyControls";
import FlyList from "./FlyList";
import type { FlyInstanceData } from "./useFlyLayout";
import type { LiveFlyPositions } from "./useLiveFlyState";
import { useStatusSnapshot } from "./useStatusSnapshot";

// Exported so App.tsx can size the collapsed canvas as calc(100% - handle).
export const MOBILE_SHEET_HANDLE_HEIGHT = 48;
const TAB_BAR_HEIGHT = 40;

type SheetTab = "controls" | "flies" | "brain";
const TABS: { id: SheetTab; label: string }[] = [
  { id: "controls", label: "Controls" },
  { id: "flies", label: "Flies" },
  { id: "brain", label: "Brain" },
];

interface MobileControlSheetProps {
  flies: FlyInstanceData[];
  selectedFlyId: string | null;
  onSelectFly: (id: string | null) => void;
  joystickRef: React.RefObject<{ x: number; y: number }>;
  wingSlidersRef: React.RefObject<{ left: number; right: number }>;
  livePositionsRef: React.RefObject<LiveFlyPositions>;
  expanded: boolean;
  onToggleExpanded: () => void;
  flying: boolean;
  onToggleFlying: () => void;
  altitudeLevelIndex: number;
  onAltitudeChange: (index: number) => void;
}

export default function MobileControlSheet({
  flies,
  selectedFlyId,
  onSelectFly,
  joystickRef,
  wingSlidersRef,
  livePositionsRef,
  expanded,
  onToggleExpanded,
  flying,
  onToggleFlying,
  altitudeLevelIndex,
  onAltitudeChange,
}: MobileControlSheetProps) {
  const statusSnapshot = useStatusSnapshot(flies, livePositionsRef);
  const [activeTab, setActiveTab] = useState<SheetTab>("controls");

  return (
    <div
      style={{
        width: "100%",
        height: "100%",
        display: "flex",
        flexDirection: "column",
        overflow: "hidden",
        background: "#14151d",
        borderTop: "1px solid #2a2d3a",
        fontFamily: "system-ui, sans-serif",
        color: "#d8dae0",
        paddingBottom: "calc(8px + env(safe-area-inset-bottom))",
      }}
    >
      <div style={{ display: "flex", alignItems: "center", height: MOBILE_SHEET_HANDLE_HEIGHT, flexShrink: 0 }}>
        <FlyChipStrip flies={flies} selectedFlyId={selectedFlyId} statusSnapshot={statusSnapshot} onSelectFly={onSelectFly} />
        <button
          onClick={onToggleExpanded}
          aria-label={expanded ? "Collapse fly controls" : "Expand fly controls"}
          style={{
            width: 40,
            height: MOBILE_SHEET_HANDLE_HEIGHT,
            flexShrink: 0,
            background: "transparent",
            border: "none",
            borderLeft: "1px solid #2a2d3a",
            color: "#d8dae0",
            cursor: "pointer",
            fontSize: 16,
          }}
        >
          {expanded ? "⌄" : "⌃"}
        </button>
      </div>

      {expanded && (
        <div style={{ flex: 1, minHeight: 0, overflow: "hidden", display: "flex", flexDirection: "column" }}>
          <div style={{ display: "flex", height: TAB_BAR_HEIGHT, flexShrink: 0, borderBottom: "1px solid #2a2d3a" }}>
            {TABS.map((tab) => (
              <button
                key={tab.id}
                type="button"
                onClick={() => setActiveTab(tab.id)}
                style={{
                  flex: 1,
                  background: "transparent",
                  border: "none",
                  borderBottom: activeTab === tab.id ? "2px solid #8e56fc" : "2px solid transparent",
                  color: activeTab === tab.id ? "#d8dae0" : "#8b8d99",
                  font: "inherit",
                  fontSize: 13,
                  cursor: "pointer",
                }}
              >
                {tab.label}
              </button>
            ))}
          </div>

          {/* Each tab gets the FULL remaining height to itself -- avoids the
              previous single-column layout, where stacking FlyControls +
              FlyList + BrainActivity all at once needed flex-shrink to work
              perfectly across every nested level to fit a compact sheet, and
              in practice didn't: BrainActivity (last in the stack) ended up
              laid out far below the visible, clipped area -- present in the
              DOM, but never actually seen. */}
          <div style={{ flex: 1, minHeight: 0, overflowY: "auto" }}>
            {activeTab === "controls" && (
              <>
                <FlyControls
                  disabled={!selectedFlyId}
                  joystickRef={joystickRef}
                  wingSlidersRef={wingSlidersRef}
                  flying={flying}
                  onToggleFlying={onToggleFlying}
                  altitudeLevelIndex={altitudeLevelIndex}
                  onAltitudeChange={onAltitudeChange}
                  size="large"
                />
                <button
                  type="button"
                  onClick={() => onSelectFly(null)}
                  disabled={!selectedFlyId}
                  style={{
                    display: "block",
                    width: "100%",
                    textAlign: "left",
                    padding: "8px 16px",
                    cursor: selectedFlyId ? "pointer" : "default",
                    background: "transparent",
                    border: "none",
                    color: selectedFlyId ? "inherit" : "#5a5d6b",
                    font: "inherit",
                    fontSize: 13,
                  }}
                >
                  ✕ Deselect
                </button>
              </>
            )}

            {activeTab === "flies" && (
              <FlyList flies={flies} selectedFlyId={selectedFlyId} statusSnapshot={statusSnapshot} onSelectFly={onSelectFly} />
            )}

            {activeTab === "brain" && <BrainActivity selectedFlyId={selectedFlyId} livePositionsRef={livePositionsRef} />}
          </div>
        </div>
      )}
    </div>
  );
}