All files / components/training/components AnatomyControlsHTML.tsx

81.81% Statements 9/11
95.34% Branches 41/43
66.66% Functions 4/6
81.81% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233                                                                    2x                                                                     2x           25x   25x   4x         25x                                                                                       100x   100x     4x                                                                                                                                                                                                      
/**
 * AnatomyControlsHTML - Html UI for toggling anatomy visualization layers
 * 
 * Provides buttons to toggle skeleton, nerves, vascular, and surface layers
 */
 
import React, { useCallback, useState } from "react";
import type { AnatomyLayer } from "./AnatomyOverlay3D";
import { FONT_FAMILY } from "../../../types/constants";
import "../training.css";
 
/**
 * Props for AnatomyControlsHTML component
 */
export interface AnatomyControlsHTMLProps {
  /** Currently visible anatomy layers */
  readonly visibleLayers: readonly AnatomyLayer[];
  /** Callback when layer visibility changes */
  readonly onLayerToggle: (layer: AnatomyLayer) => void;
  /** Whether on mobile device */
  readonly isMobile?: boolean;
}
 
/**
 * Layer button configuration
 */
interface LayerConfig {
  readonly id: AnatomyLayer;
  readonly korean: string;
  readonly english: string;
  readonly icon: string;
  readonly color: string;
}
 
const LAYER_CONFIGS: readonly LayerConfig[] = [
  {
    id: "skeleton",
    korean: "골격",
    english: "Skeleton",
    icon: "🦴",
    color: "#ffffff",
  },
  {
    id: "nerves",
    korean: "μ‹ κ²½",
    english: "Nerves",
    icon: "⚑",
    color: "#ffaa00",
  },
  {
    id: "vascular",
    korean: "ν˜ˆκ΄€",
    english: "Vascular",
    icon: "❀️",
    color: "#ff4444",
  },
  {
    id: "surface",
    korean: "ν‘œλ©΄",
    english: "Surface",
    icon: "πŸ‘€",
    color: "#00ffff",
  },
];
 
/**
 * AnatomyControlsHTML Component
 * UI controls for anatomy layer visibility
 */
export const AnatomyControlsHTML: React.FC<AnatomyControlsHTMLProps> = ({
  visibleLayers,
  onLayerToggle,
  isMobile = false,
}) => {
  // State for hover effects
  const [hoveredLayer, setHoveredLayer] = useState<AnatomyLayer | null>(null);
 
  const handleToggle = useCallback(
    (layer: AnatomyLayer) => {
      onLayerToggle(layer);
    },
    [onLayerToggle]
  );
 
  return (
    <div
      style={{
        background: "rgba(26, 26, 26, 0.85)",
        border: "2px solid rgba(0, 255, 255, 0.9)",
        borderRadius: "12px",
        padding: isMobile ? "12px" : "15px",
        fontFamily: FONT_FAMILY.KOREAN,
        boxShadow: "0 4px 20px rgba(0, 0, 0, 0.5)",
        width: isMobile ? "220px" : "260px",
      }}
      data-testid="anatomy-controls-html"
    >
      {/* Header */}
      <div style={{ marginBottom: "15px" }}>
        <div
          style={{
            fontSize: isMobile ? "14px" : "16px",
            fontWeight: "bold",
            color: "#00ffff",
          }}
        >
          ν•΄λΆ€ν•™ ν‘œμ‹œ
        </div>
        <div
          style={{
            fontSize: isMobile ? "10px" : "12px",
            color: "#999999",
            fontStyle: "italic",
          }}
        >
          Anatomy Display
        </div>
      </div>
 
      {/* Layer toggle buttons */}
      <div
        style={{
          display: "flex",
          flexDirection: "column",
          gap: "8px",
        }}
      >
        {LAYER_CONFIGS.map((config) => {
          const isActive = visibleLayers.includes(config.id);
 
          return (
            <button
              key={config.id}
              onClick={() => handleToggle(config.id)}
              style={{
                display: "flex",
                alignItems: "center",
                gap: "10px",
                background: isActive
                  ? "rgba(0, 255, 255, 0.2)"
                  : "rgba(40, 40, 40, 0.6)",
                border: `2px solid ${isActive ? config.color : "rgba(255, 255, 255, 0.2)"}`,
                borderRadius: "8px",
                padding: isMobile ? "8px 10px" : "10px 12px",
                cursor: "pointer",
                transition: "all 0.2s ease",
                fontFamily: FONT_FAMILY.KOREAN,
                color: "#ffffff",
                width: "100%",
                // Hover effects managed by React state for better maintainability
                transform: hoveredLayer === config.id ? "scale(1.02)" : "scale(1)",
                boxShadow: hoveredLayer === config.id ? `0 0 15px ${config.color}50` : "none",
              }}
              onMouseEnter={() => setHoveredLayer(config.id)}
              onMouseLeave={() => setHoveredLayer(null)}
              data-testid={`anatomy-layer-${config.id}`}
              aria-label={`Toggle ${config.english} layer`}
              aria-pressed={isActive}
            >
              {/* Icon */}
              <span
                style={{
                  fontSize: isMobile ? "18px" : "20px",
                  filter: isActive ? "none" : "grayscale(100%)",
                  opacity: isActive ? 1 : 0.5,
                }}
              >
                {config.icon}
              </span>
 
              {/* Labels */}
              <div
                style={{
                  flex: 1,
                  textAlign: "left",
                }}
              >
                <div
                  style={{
                    fontSize: isMobile ? "12px" : "13px",
                    fontWeight: "bold",
                    color: isActive ? config.color : "#999999",
                  }}
                >
                  {config.korean}
                </div>
                <div
                  style={{
                    fontSize: isMobile ? "9px" : "10px",
                    color: isActive ? "#cccccc" : "#666666",
                  }}
                >
                  {config.english}
                </div>
              </div>
 
              {/* Active indicator */}
              <div
                style={{
                  width: isMobile ? "8px" : "10px",
                  height: isMobile ? "8px" : "10px",
                  borderRadius: "50%",
                  background: isActive ? config.color : "rgba(255, 255, 255, 0.2)",
                  boxShadow: isActive ? `0 0 10px ${config.color}` : "none",
                }}
              />
            </button>
          );
        })}
      </div>
 
      {/* Info text */}
      <div
        style={{
          marginTop: "12px",
          paddingTop: "12px",
          borderTop: "1px solid rgba(255, 255, 255, 0.1)",
          fontSize: isMobile ? "9px" : "10px",
          color: "#888888",
          textAlign: "center",
          lineHeight: "1.4",
        }}
      >
        ν΄λ¦­ν•˜μ—¬ ν‘œμ‹œ/μˆ¨κΉ€
        <br />
        Click to show/hide
      </div>
    </div>
  );
};
 
export default AnatomyControlsHTML;