All files / components/shared/ui/shared ConfirmDialog.tsx

100% Statements 26/26
95.45% Branches 21/22
100% Functions 9/9
100% Lines 23/23

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                                                                  4x                   19x     19x 14x   13x 2x 1x 1x 1x 1x 1x       13x 13x     19x   18x                                     3x 1x                                                                                                                       1x 1x   1x                     1x 1x   1x                            
/**
 * ConfirmDialog Component - Modal confirmation dialog
 * 
 * Features:
 * - Korean/English bilingual text
 * - Cyberpunk Korean theming
 * - Backdrop blur effect
 * - Responsive sizing
 * - Keyboard shortcuts (Enter = confirm, Esc = cancel)
 * 
 * Now uses BaseButtonHTML for consistent styling
 */
 
import React, { useEffect } from "react";
import { useAudio } from "../../../../audio/AudioProvider";
import { KOREAN_COLORS, FONT_FAMILY } from "../../../../types/constants";
import { hexToRgbaString } from "../../../../utils/colorUtils";
import { BaseButtonHTML } from "../../base";
 
export interface ConfirmDialogProps {
  readonly isOpen: boolean;
  readonly title: string;
  readonly titleKorean: string;
  readonly message: string;
  readonly messageKorean: string;
  readonly onConfirm: () => void;
  readonly onCancel: () => void;
  readonly isMobile: boolean;
}
 
/**
 * ConfirmDialog - Modal confirmation dialog with Korean theming
 */
export const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
  isOpen,
  title,
  titleKorean,
  message,
  messageKorean,
  onConfirm,
  onCancel,
  isMobile,
}) => {
  const audio = useAudio();
 
  // Handle keyboard shortcuts
  useEffect(() => {
    if (!isOpen) return;
 
    const handleKeyDown = (e: KeyboardEvent) => {
      if (e.key === "Enter") {
        e.preventDefault();
        onConfirm();
      E} else if (e.key === "Escape") {
        e.preventDefault();
        onCancel();
      }
    };
 
    window.addEventListener("keydown", handleKeyDown);
    return () => window.removeEventListener("keydown", handleKeyDown);
  }, [isOpen, onConfirm, onCancel]);
 
  if (!isOpen) return null;
 
  return (
    <div
      data-testid="confirm-dialog"
      style={{
        position: "fixed",
        top: 0,
        left: 0,
        width: "100%",
        height: "100%",
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        backgroundColor: hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.8),
        backdropFilter: "blur(8px)",
        zIndex: 1001,
        pointerEvents: "auto",
      }}
      onClick={(e) => {
        // Close on backdrop click
        if (e.target === e.currentTarget) {
          onCancel();
        }
      }}
    >
      <div
        style={{
          padding: isMobile ? "24px" : "32px",
          backgroundColor: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_DARK, 1),
          border: `2px solid ${hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.8)}`,
          borderRadius: "12px",
          maxWidth: isMobile ? "320px" : "400px",
          boxShadow: `0 0 30px ${hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.3)}`,
        }}
      >
        {/* Title */}
        <h2
          data-testid="dialog-title"
          style={{
            fontSize: isMobile ? "20px" : "24px",
            color: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 1),
            fontFamily: FONT_FAMILY.KOREAN,
            fontWeight: "bold",
            margin: "0 0 16px 0",
            textAlign: "center",
            textShadow: `0 0 10px ${hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.4)}`,
          }}
        >
          {titleKorean}
          <br />
          {title}
        </h2>
 
        {/* Message */}
        <p
          data-testid="dialog-message"
          style={{
            fontSize: isMobile ? "14px" : "16px",
            color: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 1),
            fontFamily: FONT_FAMILY.KOREAN,
            margin: "0 0 24px 0",
            lineHeight: "1.5",
            textAlign: "center",
          }}
        >
          {messageKorean}
          <br />
          {message}
        </p>
 
        {/* Buttons - Now using BaseButtonHTML */}
        <div
          style={{
            display: "flex",
            gap: "12px",
          }}
        >
          <BaseButtonHTML
            korean="취소"
            english="Cancel"
            onClick={() => {
              audio.playSFX("menu_back");
              onCancel();
            }}
            onMouseEnter={() => audio.playSFX("menu_hover")}
            variant="secondary"
            size={isMobile ? "sm" : "md"}
            isMobile={isMobile}
            testId="cancel-button"
            style={{ flex: 1 }}
          />
          <BaseButtonHTML
            korean="확인"
            english="Confirm"
            onClick={() => {
              audio.playSFX("menu_select");
              onConfirm();
            }}
            onMouseEnter={() => audio.playSFX("menu_hover")}
            variant="primary"
            size={isMobile ? "sm" : "md"}
            isMobile={isMobile}
            testId="confirm-button"
            style={{ flex: 1 }}
          />
        </div>
      </div>
    </div>
  );
};
 
export default ConfirmDialog;