All files / web/src/app/create/worksheets/components ConfigSidebar.stories.tsx

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

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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
import type { Meta, StoryObj } from '@storybook/react'
import { useState } from 'react'
import { ConfigSidebar } from './ConfigSidebar'
import { WorksheetConfigProvider } from './WorksheetConfigContext'
import type { WorksheetFormState } from '../types'

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

export default meta
type Story = StoryObj<typeof meta>

const mockFormState: WorksheetFormState = {
  operator: 'addition',
  mode: 'manual',
  digitRange: { min: 2, max: 3 },
  problemsPerPage: 20,
  pages: 5,
  cols: 4,
  orientation: 'portrait',
  name: 'Student Name',
  displayRules: {
    tenFrames: 'whenRegrouping',
    carryBoxes: 'whenRegrouping',
    placeValueColors: 'whenRegrouping',
    answerBoxes: 'always',
    problemNumbers: 'always',
    cellBorders: 'always',
    borrowNotation: 'never',
    borrowingHints: 'never',
  },
  pAnyStart: 0.3,
  pAllStart: 0.1,
  interpolate: false,
  seed: 12345,
}

// Wrapper to provide context
function SidebarWrapper({
  initialState,
  isSaving = false,
  lastSaved = null,
  isReadOnly = false,
}: {
  initialState?: Partial<WorksheetFormState>
  isSaving?: boolean
  lastSaved?: Date | null
  isReadOnly?: boolean
}) {
  const [formState, setFormState] = useState<WorksheetFormState>({
    ...mockFormState,
    ...initialState,
  })

  const updateFormState = (updates: Partial<WorksheetFormState>) => {
    setFormState((prev) => ({ ...prev, ...updates }))
  }

  return (
    <div
      style={{
        height: '100vh',
        width: '400px',
        display: 'flex',
        flexDirection: 'column',
      }}
    >
      <WorksheetConfigProvider formState={formState} updateFormState={updateFormState}>
        <ConfigSidebar isSaving={isSaving} lastSaved={lastSaved} isReadOnly={isReadOnly} />
      </WorksheetConfigProvider>
    </div>
  )
}

export const DefaultState: Story = {
  render: () => <SidebarWrapper />,
}

export const Saving: Story = {
  render: () => <SidebarWrapper isSaving={true} />,
}

export const Saved: Story = {
  render: () => <SidebarWrapper lastSaved={new Date()} />,
}

export const ReadOnly: Story = {
  render: () => <SidebarWrapper isReadOnly={true} />,
}

export const AdditionMode: Story = {
  render: () => <SidebarWrapper initialState={{ operator: 'addition' }} />,
}

export const SubtractionMode: Story = {
  render: () => <SidebarWrapper initialState={{ operator: 'subtraction' }} />,
}

export const MixedMode: Story = {
  render: () => <SidebarWrapper initialState={{ operator: 'mixed' }} />,
}

export const SmartMode: Story = {
  render: () => (
    <SidebarWrapper
      initialState={{
        mode: 'custom',
        difficultyProfile: 'earlyLearner',
      }}
    />
  ),
}

export const MasteryMode: Story = {
  render: () => (
    <SidebarWrapper
      initialState={{
        mode: 'mastery',
        currentAdditionSkillId: 'add-2digit-no-regroup',
      }}
    />
  ),
}

export const LandscapeLayout: Story = {
  render: () => (
    <SidebarWrapper
      initialState={{
        orientation: 'landscape',
        cols: 5,
        problemsPerPage: 25,
      }}
    />
  ),
}

export const InteractiveTabs: Story = {
  render: () => {
    return (
      <div
        style={{
          height: '100vh',
          display: 'flex',
          gap: '20px',
          padding: '20px',
        }}
      >
        <div style={{ width: '400px' }}>
          <SidebarWrapper />
        </div>
        <div
          style={{
            flex: 1,
            background: '#f3f4f6',
            borderRadius: '12px',
            padding: '20px',
            overflow: 'auto',
          }}
        >
          <h2 style={{ margin: '0 0 16px 0', fontSize: '18px', fontWeight: 600 }}>
            Tab Navigation
          </h2>
          <div
            style={{
              display: 'flex',
              flexDirection: 'column',
              gap: '12px',
              fontSize: '14px',
            }}
          >
            <div>
              <strong>📝 Content Tab:</strong>
              <p style={{ margin: '4px 0 0 0', color: '#6b7280' }}>
                Choose operator (Addition, Subtraction, or Mixed) and select mode (Manual, Smart, or
                Mastery).
              </p>
            </div>
            <div>
              <strong>📐 Layout Tab:</strong>
              <p style={{ margin: '4px 0 0 0', color: '#6b7280' }}>
                Configure page orientation, problems per page, number of pages, and column layout.
              </p>
            </div>
            <div>
              <strong>🎯 Scaffolding Tab:</strong>
              <p style={{ margin: '4px 0 0 0', color: '#6b7280' }}>
                Control when visual aids appear (ten-frames, carry boxes, place value colors, etc.).
                Set rules like "always", "never", or "when regrouping".
              </p>
            </div>
            <div>
              <strong>⚡ Difficulty Tab:</strong>
              <p style={{ margin: '4px 0 0 0', color: '#6b7280' }}>
                Adjust regrouping frequency, difficulty presets, and progressive difficulty
                settings.
              </p>
            </div>
            <div
              style={{
                marginTop: '16px',
                padding: '12px',
                background: '#eff6ff',
                borderRadius: '6px',
              }}
            >
              <strong>💡 Pro Tip:</strong>
              <p
                style={{
                  margin: '4px 0 0 0',
                  color: '#3b82f6',
                  fontSize: '13px',
                }}
              >
                Active tab is saved to sessionStorage. When you return, the same tab will be
                selected.
              </p>
            </div>
          </div>
        </div>
      </div>
    )
  },
}

export const AllTabsShowcase: Story = {
  render: () => {
    return (
      <div
        style={{
          height: '100vh',
          display: 'grid',
          gridTemplateColumns: 'repeat(2, 1fr)',
          gap: '20px',
          padding: '20px',
        }}
      >
        {['operator', 'layout', 'scaffolding', 'difficulty'].map((tab) => {
          // Force tab by manipulating sessionStorage before mount
          if (typeof window !== 'undefined') {
            sessionStorage.setItem('worksheet-config-active-tab', tab)
          }

          return (
            <div key={tab} style={{ display: 'flex', flexDirection: 'column' }}>
              <div
                style={{
                  background: '#1f2937',
                  color: 'white',
                  padding: '8px 12px',
                  borderRadius: '6px 6px 0 0',
                  fontSize: '13px',
                  fontWeight: 600,
                  textTransform: 'capitalize',
                }}
              >
                {tab} Tab
              </div>
              <div
                style={{
                  flex: 1,
                  border: '2px solid #1f2937',
                  borderTop: 'none',
                }}
              >
                <SidebarWrapper />
              </div>
            </div>
          )
        })}
      </div>
    )
  },
}

export const ComparisonReadOnlyVsEditable: Story = {
  render: () => {
    return (
      <div
        style={{
          height: '100vh',
          display: 'flex',
          gap: '20px',
          padding: '20px',
        }}
      >
        <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
          <div
            style={{
              background: '#3b82f6',
              color: 'white',
              padding: '8px 16px',
              borderRadius: '8px 8px 0 0',
              fontSize: '14px',
              fontWeight: 600,
            }}
          >
            ✏️ Editable
          </div>
          <div style={{ flex: 1, border: '2px solid #3b82f6', borderTop: 'none' }}>
            <SidebarWrapper isReadOnly={false} />
          </div>
        </div>
        <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
          <div
            style={{
              background: '#6b7280',
              color: 'white',
              padding: '8px 16px',
              borderRadius: '8px 8px 0 0',
              fontSize: '14px',
              fontWeight: 600,
            }}
          >
            👁️ Read-Only
          </div>
          <div style={{ flex: 1, border: '2px solid #6b7280', borderTop: 'none' }}>
            <SidebarWrapper isReadOnly={true} />
          </div>
        </div>
      </div>
    )
  },
}

export const DenseProblemsLayout: Story = {
  render: () => (
    <SidebarWrapper
      initialState={{
        problemsPerPage: 40,
        cols: 5,
        orientation: 'landscape',
      }}
    />
  ),
}

export const MinimalProblems: Story = {
  render: () => (
    <SidebarWrapper
      initialState={{
        problemsPerPage: 6,
        cols: 2,
        pages: 1,
      }}
    />
  ),
}

export const WithStudentName: Story = {
  render: () => <SidebarWrapper initialState={{ name: 'Alex Martinez' }} />,
}

export const EmptyStudentName: Story = {
  render: () => <SidebarWrapper initialState={{ name: '' }} />,
}