All files / web/src/app/create/worksheets/components/config-panel MakeEasierHarderButtons.tsx

0% Statements 0/335
0% Branches 0/1
0% Functions 0/1
0% Lines 0/335

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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
'use client'

import type React from 'react'
import * as Tooltip from '@radix-ui/react-tooltip'
import { css } from '@styled/css'
import type { DifficultyMode } from '../../difficultyProfiles'
import { useTheme } from '@/contexts/ThemeContext'

export interface DifficultyChangeResult {
  changeDescription: string
  pAnyStart: number
  pAllStart: number
  displayRules: any
  difficultyProfile?: string
}

export interface MakeEasierHarderButtonsProps {
  easierResultBoth: DifficultyChangeResult
  easierResultChallenge: DifficultyChangeResult
  easierResultSupport: DifficultyChangeResult
  harderResultBoth: DifficultyChangeResult
  harderResultChallenge: DifficultyChangeResult
  harderResultSupport: DifficultyChangeResult
  canMakeEasierBoth: boolean
  canMakeEasierChallenge: boolean
  canMakeEasierSupport: boolean
  canMakeHarderBoth: boolean
  canMakeHarderChallenge: boolean
  canMakeHarderSupport: boolean
  onEasier: (mode: DifficultyMode) => void
  onHarder: (mode: DifficultyMode) => void
}

export function MakeEasierHarderButtons({
  easierResultBoth,
  easierResultChallenge,
  easierResultSupport,
  harderResultBoth,
  harderResultChallenge,
  harderResultSupport,
  canMakeEasierBoth,
  canMakeEasierChallenge,
  canMakeEasierSupport,
  canMakeHarderBoth,
  canMakeHarderChallenge,
  canMakeHarderSupport,
  onEasier,
  onHarder,
}: MakeEasierHarderButtonsProps) {
  const { resolvedTheme } = useTheme()
  const isDark = resolvedTheme === 'dark'
  // Determine which mode is alternative for easier
  const easierAlternativeMode =
    easierResultBoth.changeDescription === easierResultChallenge.changeDescription
      ? 'support'
      : 'challenge'
  const easierAlternativeResult =
    easierAlternativeMode === 'support' ? easierResultSupport : easierResultChallenge
  const easierAlternativeLabel =
    easierAlternativeMode === 'support' ? '↑ More support' : '← Less challenge'
  const canEasierAlternative =
    easierAlternativeMode === 'support' ? canMakeEasierSupport : canMakeEasierChallenge

  // Determine which mode is alternative for harder
  const harderAlternativeMode =
    harderResultBoth.changeDescription === harderResultChallenge.changeDescription
      ? 'support'
      : 'challenge'
  const harderAlternativeResult =
    harderAlternativeMode === 'support' ? harderResultSupport : harderResultChallenge
  const harderAlternativeLabel =
    harderAlternativeMode === 'support' ? '↓ Less support' : '→ More challenge'
  const canHarderAlternative =
    harderAlternativeMode === 'support' ? canMakeHarderSupport : canMakeHarderChallenge

  return (
    <div
      className={css({
        display: 'flex',
        flexDirection: 'column',
        gap: '2',
        pt: '1',
        borderTop: '1px solid',
        borderColor: isDark ? 'gray.700' : 'gray.200',
      })}
    >
      {/* Four-Button Layout: [Alt-35%][Rec-65%][Rec-65%][Alt-35%] */}
      <Tooltip.Provider delayDuration={300}>
        <div className={css({ display: 'flex', gap: '2' })}>
          {/* EASIER SECTION */}
          <div className={css({ display: 'flex', flex: '1' })}>
            {/* Alternative Easier Button - Hidden if disabled and main is enabled */}
            {canEasierAlternative && (
              <Tooltip.Root>
                <Tooltip.Trigger asChild>
                  <button
                    onClick={() => onEasier(easierAlternativeMode)}
                    disabled={!canEasierAlternative}
                    data-action={`easier-${easierAlternativeMode}`}
                    className={css({
                      flexShrink: 0,
                      width: '10',
                      h: '16',
                      display: 'flex',
                      alignItems: 'center',
                      justifyContent: 'center',
                      fontSize: '2xs',
                      fontWeight: 'medium',
                      color: isDark ? 'gray.300' : 'gray.700',
                      bg: isDark ? 'gray.700' : 'gray.100',
                      border: '1.5px solid',
                      borderColor: isDark ? 'gray.600' : 'gray.300',
                      borderRight: 'none',
                      borderTopLeftRadius: 'lg',
                      borderBottomLeftRadius: 'lg',
                      cursor: 'pointer',
                      _hover: {
                        bg: isDark ? 'gray.600' : 'gray.200',
                      },
                    })}
                  >
                    {easierAlternativeLabel}
                  </button>
                </Tooltip.Trigger>
                <Tooltip.Portal>
                  <Tooltip.Content
                    side="top"
                    className={css({
                      bg: 'gray.800',
                      color: 'white',
                      px: '3',
                      py: '2',
                      rounded: 'md',
                      fontSize: 'xs',
                      maxW: '250px',
                      shadow: 'lg',
                      zIndex: 1000,
                    })}
                  >
                    {easierAlternativeResult.changeDescription}
                    <Tooltip.Arrow className={css({ fill: 'gray.800' })} />
                  </Tooltip.Content>
                </Tooltip.Portal>
              </Tooltip.Root>
            )}

            {/* Recommended Easier Button - Expands to full width if alternative is hidden */}
            <button
              onClick={() => onEasier('both')}
              disabled={!canMakeEasierBoth}
              data-action="easier-both"
              className={css({
                flex: '1',
                h: '16',
                px: '3',
                py: '2',
                display: 'flex',
                flexDirection: 'column',
                alignItems: 'flex-start',
                gap: '0.5',
                color: canMakeEasierBoth ? 'brand.700' : isDark ? 'gray.500' : 'gray.400',
                bg: isDark ? 'gray.800' : 'white',
                border: '1.5px solid',
                borderColor: canMakeEasierBoth ? 'brand.500' : isDark ? 'gray.600' : 'gray.300',
                borderTopLeftRadius: canEasierAlternative ? 'none' : 'lg',
                borderBottomLeftRadius: canEasierAlternative ? 'none' : 'lg',
                borderTopRightRadius: 'lg',
                borderBottomRightRadius: 'lg',
                cursor: canMakeEasierBoth ? 'pointer' : 'not-allowed',
                opacity: canMakeEasierBoth ? 1 : 0.5,
                _hover: canMakeEasierBoth
                  ? {
                      bg: isDark ? 'gray.700' : 'brand.50',
                    }
                  : {},
              })}
            >
              <div
                className={css({
                  fontSize: 'xs',
                  fontWeight: 'semibold',
                  flexShrink: 0,
                })}
              >
                ← Make Easier
              </div>
              {canMakeEasierBoth && (
                <div
                  className={css({
                    fontSize: '2xs',
                    fontWeight: 'normal',
                    lineHeight: '1.3',
                    textAlign: 'left',
                    overflow: 'hidden',
                    display: '-webkit-box',
                    WebkitLineClamp: 2,
                  })}
                  style={
                    {
                      WebkitBoxOrient: 'vertical',
                    } as React.CSSProperties
                  }
                >
                  {easierResultBoth.changeDescription}
                </div>
              )}
            </button>
          </div>

          {/* HARDER SECTION */}
          <div className={css({ display: 'flex', flex: '1' })}>
            {/* Recommended Harder Button - Expands to full width if alternative is hidden */}
            <button
              onClick={() => onHarder('both')}
              disabled={!canMakeHarderBoth}
              data-action="harder-both"
              className={css({
                flex: '1',
                h: '16',
                px: '3',
                py: '2',
                display: 'flex',
                flexDirection: 'column',
                alignItems: 'flex-start',
                gap: '0.5',
                color: canMakeHarderBoth ? 'brand.700' : isDark ? 'gray.500' : 'gray.400',
                bg: isDark ? 'gray.800' : 'white',
                border: '1.5px solid',
                borderColor: canMakeHarderBoth ? 'brand.500' : isDark ? 'gray.600' : 'gray.300',
                borderTopLeftRadius: 'lg',
                borderBottomLeftRadius: 'lg',
                borderTopRightRadius: canHarderAlternative ? 'none' : 'lg',
                borderBottomRightRadius: canHarderAlternative ? 'none' : 'lg',
                cursor: canMakeHarderBoth ? 'pointer' : 'not-allowed',
                opacity: canMakeHarderBoth ? 1 : 0.5,
                _hover: canMakeHarderBoth
                  ? {
                      bg: isDark ? 'gray.700' : 'brand.50',
                    }
                  : {},
              })}
            >
              <div
                className={css({
                  fontSize: 'xs',
                  fontWeight: 'semibold',
                  flexShrink: 0,
                })}
              >
                Make Harder →
              </div>
              {canMakeHarderBoth && (
                <div
                  className={css({
                    fontSize: '2xs',
                    fontWeight: 'normal',
                    lineHeight: '1.3',
                    textAlign: 'left',
                    overflow: 'hidden',
                    display: '-webkit-box',
                    WebkitLineClamp: 2,
                  })}
                  style={
                    {
                      WebkitBoxOrient: 'vertical',
                    } as React.CSSProperties
                  }
                >
                  {harderResultBoth.changeDescription}
                </div>
              )}
            </button>

            {/* Alternative Harder Button - Hidden if disabled and main is enabled */}
            {canHarderAlternative && (
              <Tooltip.Root>
                <Tooltip.Trigger asChild>
                  <button
                    onClick={() => onHarder(harderAlternativeMode)}
                    disabled={!canHarderAlternative}
                    data-action={`harder-${harderAlternativeMode}`}
                    className={css({
                      flexShrink: 0,
                      width: '10',
                      h: '16',
                      display: 'flex',
                      alignItems: 'center',
                      justifyContent: 'center',
                      fontSize: '2xs',
                      fontWeight: 'medium',
                      color: isDark ? 'gray.300' : 'gray.700',
                      bg: isDark ? 'gray.700' : 'gray.100',
                      border: '1.5px solid',
                      borderColor: isDark ? 'gray.600' : 'gray.300',
                      borderLeft: 'none',
                      borderTopRightRadius: 'lg',
                      borderBottomRightRadius: 'lg',
                      cursor: 'pointer',
                      _hover: {
                        bg: isDark ? 'gray.600' : 'gray.200',
                      },
                    })}
                  >
                    {harderAlternativeLabel}
                  </button>
                </Tooltip.Trigger>
                {canHarderAlternative && (
                  <Tooltip.Portal>
                    <Tooltip.Content
                      side="top"
                      className={css({
                        bg: 'gray.800',
                        color: 'white',
                        px: '3',
                        py: '2',
                        rounded: 'md',
                        fontSize: 'xs',
                        maxW: '250px',
                        shadow: 'lg',
                        zIndex: 1000,
                      })}
                    >
                      {harderAlternativeResult.changeDescription}
                      <Tooltip.Arrow className={css({ fill: 'gray.800' })} />
                    </Tooltip.Content>
                  </Tooltip.Portal>
                )}
              </Tooltip.Root>
            )}
          </div>
        </div>
      </Tooltip.Provider>
    </div>
  )
}