All files / components/screens/training/components TrainingControlsOverlayHtml.tsx

100% Statements 15/15
98.66% Branches 74/75
100% Functions 3/3
100% Lines 14/14

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                                                                                                                                        2x               86x 86x 86x 86x   86x 86x   86x                                           86x                   86x 86x   86x                                                                                                                                                             50x                   2x      
/**
 * TrainingControlsOverlayHtml - Html overlay for training controls
 * 
 * Displays start/stop button and training status with consistent Korean theming.
 * Uses KOREAN_COLORS constants and bilingual formatting.
 * 
 * @module components/screens/training
 * @category Training UI
 * @korean 훈련제어오버레이
 */
 
import React from "react";
import {
  FONT_FAMILY,
  KOREAN_COLORS,
} from "../../../../types/constants";
import { SPACING } from "../../../../types/constants/ui";
import { hexToRgbaString } from "../../../../utils/colorUtils";
import {
  formatBilingualText,
  getEnhancedKoreanOverlayStyles,
  getKoreanButtonWithGlow,
  getResponsiveSpacing,
} from "../../../../utils/koreanThemeHelpers";
import {
  getNeonTextShadow,
  getSmoothTransition,
} from "../../../../utils/visualEffects";
import "../training.css";
 
/**
 * Props for TrainingControlsOverlayHtml component
 */
export interface TrainingControlsOverlayHtmlProps {
  /** Whether training is currently active */
  readonly isTraining: boolean;
  /** Callback to start training */
  readonly onStartTraining: () => void;
  /** Callback to stop training */
  readonly onStopTraining: () => void;
  /** Whether on mobile device */
  readonly isMobile: boolean;
  /** Compact mode for embedding inside the slim top HUD */
  readonly variant?: "panel" | "compact";
}
 
/**
 * TrainingControlsOverlayHtml Component
 * 
 * Html overlay showing training status and start/stop controls with Korean theming.
 * All colors use KOREAN_COLORS constants for consistency.
 *
 * Optimized with React.memo for 60fps performance:
 * - Prevents re-renders when isTraining state hasn't changed
 * - Callbacks expected to be stable (parent should use useCallback)
 * 
 * @example
 * ```tsx
 * <TrainingControlsOverlayHtml
 *   isTraining={true}
 *   onStartTraining={() => console.log('start')}
 *   onStopTraining={() => console.log('stop')}
 *   isMobile={false}
 * />
 * ```
 * 
 * @korean 훈련제어오버레이컴포넌트
 */
export const TrainingControlsOverlayHtml = React.memo<TrainingControlsOverlayHtmlProps>(
  ({
    isTraining,
    onStartTraining,
    onStopTraining,
    isMobile,
    variant = "panel",
  }) => {
  const isCompact = variant === "compact";
  const panelWidth = isCompact ? (isMobile ? 180 : 210) : isMobile ? 200 : 220;
  const panelHeight = isCompact ? (isMobile ? 40 : 44) : isMobile ? 90 : 100;
  const padding = isCompact ? getResponsiveSpacing("xs", isMobile) : getResponsiveSpacing("sm", isMobile);
 
  const stateColor = isTraining ? KOREAN_COLORS.ACCENT_GREEN : KOREAN_COLORS.ACCENT_RED;
  const borderColor = hexToRgbaString(stateColor, 0.9);
 
  const panelStyle: React.CSSProperties = {
    ...getEnhancedKoreanOverlayStyles({
      opacity: 0.88,
      glowIntensity: isTraining ? "medium" : "subtle",
      includeGradient: false,
      includeBackdropBlur: true,
      depthLayers: 2,
    }),
    width: `${panelWidth}px`,
    height: `${panelHeight}px`,
    padding: `${padding}px`,
    border: `2px solid ${borderColor}`,
    position: "relative",
    display: "flex",
    flexDirection: isCompact ? "row" : "column",
    alignItems: isCompact ? "center" : "stretch",
    justifyContent: isCompact ? "space-between" : "flex-start",
    gap: `${padding}px`,
    boxSizing: "border-box",
    fontFamily: FONT_FAMILY.KOREAN,
  };
 
  const buttonStyles = React.useMemo(
    () =>
      getKoreanButtonWithGlow({
        variant: isTraining ? "danger" : "success",
        glowIntensity: "strong",
        hoverAnimation: "combined",
      }),
    [isTraining]
  );
 
  const titleFontSize = isCompact ? (isMobile ? 11 : 12) : isMobile ? 13 : 14;
  const infoFontSize = isMobile ? 9 : 10;
 
  return (
    <div style={panelStyle} data-testid="training-controls-html">
      {/* Header with bilingual status */}
      <div style={{ marginBottom: isCompact ? 0 : `${SPACING.SM}px`, minWidth: 0 }}>
        <div
          style={{
            fontSize: `${titleFontSize}px`,
            fontWeight: "bold",
            color: hexToRgbaString(stateColor),
            textShadow: getNeonTextShadow(stateColor, isTraining ? "medium" : "subtle"),
            transition: getSmoothTransition("all", "normal"),
            overflow: "hidden",
            textOverflow: "ellipsis",
            whiteSpace: "nowrap",
          }}
        >
          {formatBilingualText(
            isTraining ? "훈련 진행중" : "훈련 대기",
            isTraining ? "Training Active" : "Training Stopped",
            "pipe"
          )}
        </div>
      </div>
 
      {/* Status Indicator with CSS animation */}
      <div
        className={`status-indicator ${isTraining ? "active" : "inactive"}`}
        style={{
          position: "absolute",
          top: isCompact ? "6px" : "12px",
          right: isCompact ? "6px" : "12px",
        }}
      />
 
      {/* Start/Stop Button with Korean theming */}
      <button
        onClick={isTraining ? onStopTraining : onStartTraining}
        className={`training-button ${isTraining ? "training-button-stop" : "training-button-start"}`}
        style={{
          ...buttonStyles,
          fontSize: `${titleFontSize}px`,
          height: isCompact ? "30px" : "35px",
          minWidth: isCompact ? "72px" : undefined,
          padding: isCompact ? "4px 8px" : buttonStyles.padding,
          flexShrink: 0,
        }}
        data-testid="training-toggle-button"
        data-training-state={isTraining ? "active" : "inactive"}
      >
        <span>{isTraining ? "⏹" : "▶"}</span>
        <span>
          {formatBilingualText(
            isTraining ? "중지" : "시작",
            isTraining ? "Stop" : "Start",
            "pipe"
          )}
        </span>
      </button>
 
      {/* Info text about auto-restart with Korean colors */}
      {!isCompact && !isTraining && (
        <div
          style={{
            fontSize: `${infoFontSize}px`,
            color: hexToRgbaString(KOREAN_COLORS.TEXT_TERTIARY),
            textAlign: "center",
            marginTop: `${SPACING.XS}px`,
            fontFamily: FONT_FAMILY.KOREAN,
            lineHeight: "1.4",
          }}
        >
          <div>모드 변경시 자동 재시작</div>
          <div>Auto-restarts on mode change</div>
        </div>
      )}
    </div>
  );
  },
  (prevProps, nextProps) => {
    return (
      prevProps.isTraining === nextProps.isTraining &&
      prevProps.isMobile === nextProps.isMobile &&
      prevProps.variant === nextProps.variant &&
      prevProps.onStartTraining === nextProps.onStartTraining &&
      prevProps.onStopTraining === nextProps.onStopTraining
    );
  },
);
 
TrainingControlsOverlayHtml.displayName = "TrainingControlsOverlayHtml";
 
export default TrainingControlsOverlayHtml;