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

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

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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
import type { Meta, StoryObj } from '@storybook/react'
import { useState } from 'react'
import { OverallDifficultySlider } from './OverallDifficultySlider'
import { DIFFICULTY_PROFILES } from '../../difficultyProfiles'
import type { DisplayRules } from '../../displayRules'

const meta = {
  title: 'Worksheets/Config Panel/OverallDifficultySlider',
  component: OverallDifficultySlider,
  parameters: {
    layout: 'padded',
  },
  tags: ['autodocs'],
} satisfies Meta<typeof OverallDifficultySlider>

export default meta
type Story = StoryObj<typeof meta>

// Wrapper to handle state
function SliderWrapper(args: React.ComponentProps<typeof OverallDifficultySlider>) {
  const [difficulty, setDifficulty] = useState(args.currentDifficulty)
  const [config, setConfig] = useState({ pAnyStart: 0, pAllStart: 0 })

  return (
    <div style={{ maxWidth: '500px' }}>
      <OverallDifficultySlider
        {...args}
        currentDifficulty={difficulty}
        onChange={(updates) => {
          const newDifficulty =
            (updates.pAnyStart + updates.pAllStart * 2) / 3 +
            (1 - Object.values(updates.displayRules).filter((v) => v === 'always').length / 10)
          setDifficulty(newDifficulty)
          setConfig({
            pAnyStart: updates.pAnyStart,
            pAllStart: updates.pAllStart,
          })
        }}
      />
      <div
        style={{
          marginTop: '16px',
          padding: '12px',
          background: '#f3f4f6',
          borderRadius: '6px',
          fontSize: '12px',
        }}
      >
        <strong>Current Configuration:</strong>
        <div
          style={{
            marginTop: '8px',
            fontSize: '11px',
            fontFamily: 'monospace',
          }}
        >
          pAnyStart: {config.pAnyStart.toFixed(2)}
          <br />
          pAllStart: {config.pAllStart.toFixed(2)}
        </div>
      </div>
    </div>
  )
}

export const EarlyLearner: Story = {
  render: (args) => <SliderWrapper {...args} />,
  args: {
    currentDifficulty: 2.0,
  },
}

export const Intermediate: Story = {
  render: (args) => <SliderWrapper {...args} />,
  args: {
    currentDifficulty: 5.0,
  },
}

export const Expert: Story = {
  render: (args) => <SliderWrapper {...args} />,
  args: {
    currentDifficulty: 8.5,
  },
}

export const MinimumDifficulty: Story = {
  render: (args) => <SliderWrapper {...args} />,
  args: {
    currentDifficulty: 0,
  },
}

export const MaximumDifficulty: Story = {
  render: (args) => <SliderWrapper {...args} />,
  args: {
    currentDifficulty: 10,
  },
}

export const InteractiveWithPresets: Story = {
  args: {
    currentDifficulty: 5.0,
    onChange: () => {},
  },
  render: () => {
    const [difficulty, setDifficulty] = useState(5.0)
    const [pAnyStart, setPAnyStart] = useState(0.5)
    const [pAllStart, setPAllStart] = useState(0.1)
    const [displayRules, setDisplayRules] = useState<DisplayRules>({
      tenFrames: 'whenRegrouping',
      carryBoxes: 'whenRegrouping',
      placeValueColors: 'whenRegrouping',
      answerBoxes: 'always',
      problemNumbers: 'always',
      cellBorders: 'always',
      borrowNotation: 'never',
      borrowingHints: 'never',
    })

    return (
      <div style={{ maxWidth: '600px' }}>
        <div style={{ marginBottom: '24px' }}>
          <h3 style={{ margin: '0 0 8px 0', fontSize: '14px', fontWeight: 600 }}>
            Difficulty Presets
          </h3>
          <div style={{ display: 'flex', gap: '8px', flexWrap: 'wrap' }}>
            {Object.entries(DIFFICULTY_PROFILES).map(([key, profile]) => (
              <button
                key={key}
                type="button"
                onClick={() => {
                  const calcDiff =
                    (profile.regrouping.pAnyStart + profile.regrouping.pAllStart * 2) / 3 +
                    (1 -
                      Object.values(profile.displayRules).filter((v) => v === 'always').length / 10)
                  setDifficulty(calcDiff)
                  setPAnyStart(profile.regrouping.pAnyStart)
                  setPAllStart(profile.regrouping.pAllStart)
                  setDisplayRules(profile.displayRules)
                }}
                style={{
                  padding: '8px 12px',
                  background: '#fff',
                  border: '1px solid #d1d5db',
                  borderRadius: '6px',
                  cursor: 'pointer',
                  fontSize: '12px',
                }}
              >
                {profile.label}
              </button>
            ))}
          </div>
        </div>

        <OverallDifficultySlider
          currentDifficulty={difficulty}
          onChange={(updates) => {
            const newDiff =
              (updates.pAnyStart + updates.pAllStart * 2) / 3 +
              (1 - Object.values(updates.displayRules).filter((v) => v === 'always').length / 10)
            setDifficulty(newDiff)
            setPAnyStart(updates.pAnyStart)
            setPAllStart(updates.pAllStart)
            setDisplayRules(updates.displayRules)
          }}
        />

        <div
          style={{
            marginTop: '16px',
            padding: '12px',
            background: '#f3f4f6',
            borderRadius: '6px',
            fontSize: '12px',
          }}
        >
          <strong>Current State:</strong>
          <div
            style={{
              marginTop: '8px',
              fontSize: '11px',
              fontFamily: 'monospace',
            }}
          >
            <div>Difficulty: {difficulty.toFixed(2)} / 10</div>
            <div>pAnyStart: {pAnyStart.toFixed(2)}</div>
            <div>pAllStart: {pAllStart.toFixed(2)}</div>
            <div style={{ marginTop: '8px' }}>
              <strong>Display Rules:</strong>
              <ul style={{ margin: '4px 0 0 16px', padding: 0 }}>
                {Object.entries(displayRules).map(([key, value]) => (
                  <li key={key}>
                    {key}: {value}
                  </li>
                ))}
              </ul>
            </div>
          </div>
        </div>
      </div>
    )
  },
}

export const SnappingBehavior: Story = {
  args: {
    currentDifficulty: 5.0,
    onChange: () => {},
  },
  render: () => {
    const [difficulty, setDifficulty] = useState(5.0)
    const [snappedTo, setSnappedTo] = useState<string>('')

    return (
      <div style={{ maxWidth: '500px' }}>
        <div
          style={{
            marginBottom: '16px',
            padding: '12px',
            background: '#eff6ff',
            borderRadius: '6px',
            fontSize: '12px',
          }}
        >
          <strong>ℹ️ Snapping Behavior:</strong>
          <p style={{ margin: '8px 0 0 0' }}>
            As you drag the slider, it will snap to the nearest valid configuration along the
            pedagogical difficulty path. Watch how it snaps to combinations of regrouping intensity
            and scaffolding level.
          </p>
        </div>

        <OverallDifficultySlider
          currentDifficulty={difficulty}
          onChange={(updates) => {
            const newDiff =
              (updates.pAnyStart + updates.pAllStart * 2) / 3 +
              (1 - Object.values(updates.displayRules).filter((v) => v === 'always').length / 10)
            setDifficulty(newDiff)
            setSnappedTo(
              updates.difficultyProfile
                ? DIFFICULTY_PROFILES[updates.difficultyProfile].label
                : 'Custom'
            )
          }}
        />

        {snappedTo && (
          <div
            style={{
              marginTop: '16px',
              padding: '12px',
              background: '#f3f4f6',
              borderRadius: '6px',
              fontSize: '12px',
            }}
          >
            <strong>Snapped to:</strong> {snappedTo}
          </div>
        )}
      </div>
    )
  },
}