# Task 12 Context: Restructure CraftingTab
## Task Description
Restructure CraftingTab (remove 1-4 progress bar, split Fabricate/Enchant, top sub-tabs) (PRIORITY 3a)
## Source Files
### 1. `/src/components/game/tabs/CraftingTab.tsx` (268 lines)
**Imports and Dependencies:**
```typescript
'use client';
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { Progress } from '@/components/ui/progress';
import { GameCard } from '@/components/ui/game-card';
import { SectionHeader } from '@/components/ui/section-header';
import { ActionButton } from '@/components/ui/action-button';
import { Stepper } from '@/components/ui/stepper';
import { Scroll, Hammer, Sparkles, Anvil } from 'lucide-react';
import type { EquipmentInstance, EnchantmentDesign, DesignEffect, AppliedEnchantment, LootInventory, EquipmentCraftingProgress } from '@/lib/game/types';
import { fmt, type GameStore } from '@/lib/game/store';
import {
EnchantmentDesigner,
EnchantmentPreparer,
EnchantmentApplier,
EquipmentCrafter,
} from '@/components/game/crafting';
import { useGameToast } from '@/components/game/GameToast';
```
**Crafting Phases Constant:**
```typescript
// Crafting phases for the stepper
const CRAFTING_PHASES = ['Design', 'Prepare', 'Apply', 'Craft'];
```
**Component Props:**
```typescript
export interface CraftingTabProps {
store: GameStore;
}
```
**State and Stepper Mapping:**
```typescript
export function CraftingTab({ store }: CraftingTabProps) {
const showToast = useGameToast();
const currentAction = store.currentAction;
const designProgress = store.designProgress;
const preparationProgress = store.preparationProgress;
const applicationProgress = store.applicationProgress;
const equipmentCraftingProgress = store.equipmentCraftingProgress;
const pauseApplication = store.pauseApplication;
const resumeApplication = store.resumeApplication;
const [craftingStage, setCraftingStage] = useState<'design' | 'prepare' | 'apply' | 'craft'>('craft');
// Map crafting stage to stepper index
const getStepperIndex = (stage: string): number => {
switch (stage) {
case 'design': return 0;
case 'prepare': return 1;
case 'apply': return 2;
case 'craft': return 3;
default: return 0;
}
};
```
**Stepper Component (lines 58-68):**
```tsx
{/* Visual Stepper - Requirement: show Design, Prepare, Apply phases as visual stepper */}
```
**Stage Content Conditional Rendering (lines 71-97):**
```tsx
{/* Stage Content - Without unlabeled Tabs, using conditional rendering instead */}
{craftingStage === 'craft' && (
)}
{craftingStage === 'design' && (
{}}
selectedEffects={[]}
setSelectedEffects={() => {}}
designName={''}
setDesignName={() => {}}
selectedDesign={null}
setSelectedDesign={() => {}}
/>
)}
{craftingStage === 'prepare' && (
{}}
/>
)}
{craftingStage === 'apply' && (
{}}
selectedDesign={null}
setSelectedDesign={() => {}}
onEnchantmentApplied={handleEnchantmentApplied}
onCapacityExceeded={handleCapacityExceeded}
/>
)}
```
**Stage Navigation Buttons (lines 99-131):**
```tsx
{/* Stage Navigation Buttons */}
setCraftingStage('craft')}
className={craftingStage === 'craft' ? 'ring-2 ring-[var(--interactive-primary)]' : ''}
>
Craft
setCraftingStage('design')}
className={craftingStage === 'design' ? 'ring-2 ring-[var(--interactive-primary)]' : ''}
>
Design
setCraftingStage('prepare')}
className={craftingStage === 'prepare' ? 'ring-2 ring-[var(--interactive-primary)]' : ''}
>
Prepare
setCraftingStage('apply')}
className={craftingStage === 'apply' ? 'ring-2 ring-[var(--interactive-primary)]' : ''}
>
Apply
```
**Current Activity Indicators (Progress Bars to be removed - lines 133-236):**
```tsx
{/* Current Activity Indicator */}
{currentAction === 'craft' && equipmentCraftingProgress && (
{safeToFixed(calcPercent(equipmentCraftingProgress.progress, equipmentCraftingProgress.required), 0)}%
}
/>
{/* ... more content ... */}
)}
{currentAction === 'design' && designProgress && (
{/* ... Progress bar and content ... */}
)}
{currentAction === 'prepare' && preparationProgress && (
{/* ... Progress bar and content ... */}
)}
{currentAction === 'enchant' && applicationProgress && (
{/* ... Progress bar and content ... */}
)}
```
---
### 2. Files in `/src/components/game/crafting/` Directory
| File | Size | Last Modified |
|------|------|---------------|
| `EnchantmentApplier.tsx` | 12,206 bytes | 1777364523 |
| `EnchantmentDesigner.tsx` | 19,568 bytes | 1777361558 |
| `EnchantmentPreparer.tsx` | 14,816 bytes | 1777365343 |
| `EquipmentCrafter.tsx` | 9,121 bytes | 1777205526 |
| `index.tsx` | 396 bytes | 1777028644 |
**Barrel File (`index.tsx`):**
```typescript
// Barrel file for crafting components
export { EnchantmentDesigner, type EnchantmentDesignerProps } from './EnchantmentDesigner';
export { EnchantmentPreparer, type EnchantmentPreparerProps } from './EnchantmentPreparer';
export { EnchantmentApplier, type EnchantmentApplierProps } from './EnchantmentApplier';
export { EquipmentCrafter, type EquipmentCrafterProps } from './EquipmentCrafter';
```
---
### 3. Stepper Component (`/src/components/ui/stepper.tsx`)
**Interface:**
```typescript
interface StepperProps extends React.HTMLAttributes {
steps: string[];
currentStep: number; // 0-indexed
orientation?: "horizontal" | "vertical";
}
```
**Full Implementation (100 lines):**
```typescript
import * as React from "react";
import { cn } from "@/lib/utils";
import { Check, Circle, ArrowRight } from "lucide-react";
interface StepperProps extends React.HTMLAttributes {
steps: string[];
currentStep: number; // 0-indexed
orientation?: "horizontal" | "vertical";
}
interface StepProps {
label: string;
stepNumber: number;
isActive: boolean;
isCompleted: boolean;
isLast: boolean;
orientation?: "horizontal" | "vertical";
}
const Step = ({ label, stepNumber, isActive, isCompleted, isLast, orientation = "horizontal" }: StepProps) => {
return (
{isCompleted ? (
) : (
{stepNumber}
)}
{label}
{!isLast && (
)}
);
};
export function Stepper({ steps, currentStep, orientation = "horizontal", className, ...props }: StepperProps) {
return (
{steps.map((step, index) => (
))}
);
}
```
---
### 4. Current Sub-Tab/Navigation Implementation Details
**Current Structure:**
The CraftingTab currently uses a **4-stage linear workflow** with:
1. A visual Stepper component showing phases: Design → Prepare → Apply → Craft
2. Navigation buttons at the bottom to switch between stages
3. Conditional rendering of content based on `craftingStage` state
**Current Stages:**
- `design` - EnchantmentDesigner component (Design enchantments)
- `prepare` - EnchantmentPreparer component (Prepare equipment)
- `apply` - EnchantmentApplier component (Apply enchantments)
- `craft` - EquipmentCrafter component (Craft equipment)
**Issues to Address (Task Requirements):**
1. **Remove 1-4 progress bar** - The Stepper component (lines 58-68) needs to be removed
2. **Split Fabricate/Enchant** - Currently "Craft" (EquipmentCrafter) is mixed in with enchantment workflow. Need to split into:
- "Fabricate" tab - for EquipmentCrafter (crafting equipment)
- "Enchant" tab - for the Design → Prepare → Apply workflow
3. **Top sub-tabs** - Replace the bottom navigation buttons with proper top-level sub-tabs
**Current Navigation Pattern:**
- State: `craftingStage` (useState with 4 possible values)
- Navigation: 4 ActionButtons at the bottom of the tab
- Visual indicator: Stepper at the top showing progress through phases
**Suggested New Structure (for implementation):**
```
CraftingTab
├── Top Sub-Tabs: [Fabricate] [Enchant]
├── Fabricate Content: EquipmentCrafter
└── Enchant Content:
├── Sub-Navigation: [Design] [Prepare] [Apply]
├── Design: EnchantmentDesigner
├── Prepare: EnchantmentPreparer
└── Apply: EnchantmentApplier
```
---
### 5. Component Props Signatures
**EquipmentCrafterProps:**
```typescript
export interface EquipmentCrafterProps {
store: GameStore;
}
```
**EnchantmentDesignerProps:**
```typescript
export interface EnchantmentDesignerProps {
store: GameStore;
selectedEquipmentType: string | null;
setSelectedEquipmentType: (type: string | null) => void;
selectedEffects: DesignEffect[];
setSelectedEffects: (effects: DesignEffect[]) => void;
designName: string;
setDesignName: (name: string) => void;
selectedDesign: string | null;
setSelectedDesign: (id: string | null) => void;
}
```
**EnchantmentPreparerProps:**
```typescript
export interface EnchantmentPreparerProps {
store: GameStore;
selectedEquipmentInstance: string | null;
setSelectedEquipmentInstance: (id: string | null) => void;
}
```
**EnchantmentApplierProps:**
```typescript
export interface EnchantmentApplierProps {
store: GameStore;
selectedEquipmentInstance: string | null;
setSelectedEquipmentInstance: (id: string | null) => void;
selectedDesign: string | null;
setSelectedDesign: (id: string | null) => void;
onEnchantmentApplied?: () => void;
onCapacityExceeded?: (itemName: string, used: number, total: number) => void;
}
```
---
### 6. Key Observations for Restructuring
1. **Stepper Removal**: The `CRAFTING_PHASES` constant and `Stepper` component usage must be removed from CraftingTab
2. **State Management**: The `craftingStage` state will need to be replaced with:
- A top-level tab state (`fabricate` | `enchant`)
- An enchant sub-stage state (`design` | `prepare` | `apply`) when in enchant mode
3. **Progress Bars**: The activity indicators with Progress components (lines 133-236) should potentially be moved into their respective components (EquipmentCrafter, EnchantmentDesigner, etc.) rather than being in CraftingTab
4. **No Tab Component**: Currently, the app doesn't use a Tab component - it uses conditional rendering with ActionButtons. The restructured version should implement proper tabs at the top level
5. **Helper Functions**: The `safeToFixed` and `calcPercent` helpers are used for progress bars - these may no longer be needed in CraftingTab after restructuring