# fabprint full workflow demo
# Usage: cd ~/repos/fabprint && vhs docs/recordings/demo.tape
#
# BEFORE RECORDING:
#   1. Have your Bambu Cloud password ready to type live (masked prompt)
#   2. Have email open to grab the verification code (also typed live)
#   3. Ensure OrcaSlicer is installed locally (or Docker available)
#
# Everything is scripted EXCEPT password and verification code entry.
# Adjust profile search terms below if your printer isn't a P1S.
#
# The interactive picker uses simple-term-menu:
#   Single-select: type to filter, Enter to select highlighted item
#   Multi-select:  / to search, Space to toggle, Enter to confirm

Output docs/recordings/demo.gif

Require fabprint

Set Shell "bash"
Set FontSize 16
Set Width 1400
Set Height 1200
Set Padding 20
Set Theme "Catppuccin Mocha"
Set WindowBar Colorful
Set BorderRadius 8
Set TypingSpeed 50ms
Set CursorBlink false
Set WaitTimeout 120s

# =====================================================================
# Preparation (hidden)
# =====================================================================
Hide


Type "rm -f ~/repos/decoy-case/fabprint.toml"
Enter
Sleep 500ms

Type "cd ~/repos/decoy-case"
Enter
Sleep 1s

Type "export PATH=$PATH:/usr/local/bin"
Enter
Type "export FABPRINT_SKIP_SLICER_DETECT=1"
Enter
Sleep 500ms


# Pre-warm Docker bridge so AMS query completes during init
# Pre-warm Docker bridge — must complete before init starts
Type "fabprint status > /tmp/vhs-status-debug.txt 2>&1 && echo WARM"
Enter
Wait+Screen /WARM/
Sleep 500ms

Type "clear"
Enter
Sleep 500ms

Show


# =====================================================================
# PART 2: fabprint init — interactive config wizard
# =====================================================================

Type "# Step 2: Create a fabprint.toml config"
Enter
Sleep 1s

Type "fabprint init"
Sleep 1s
Enter

Wait+Screen /fabprint init/
Sleep 500ms

# --- Printer Profile (simple-term-menu, single-select) ---
# Printer already configured, skips to profile picker
Wait+Screen /Printer Profile/
Sleep 500ms

# Type to filter, Enter selects highlighted match
Type@100ms "P1S 0.4"
Sleep 500ms
Enter
Sleep 1s

# --- Process Profile (simple-term-menu, single-select) ---
Wait+Screen /Process Profile/
Sleep 500ms

# Type to filter, Enter selects highlighted match
Type "0.20mm Standard @BBL X1C"
Sleep 200ms
Enter
Sleep 5s

# --- Filament (AMS connected — accept matched suggestions) ---
# Accept AMS-matched filaments
Wait+Screen /Use these filaments/
Sleep 1s
Type "y"
Enter

# --- CAD Files (simple-term-menu, multi-select) ---
Wait+Screen /CAD Files/
Sleep 500ms

# Multi-select: Space toggles items, Enter confirms
# Toggle first item, move down, toggle second, confirm
Space
Down
Space
Enter
Sleep 500ms

# First file — copies (accept default 1)
Wait+Screen /copies/
Enter

# First file — orient (accept default "flat")
Wait+Screen /orient/
Enter

# First file — filament slot (pick slot 3)
Wait+Screen /filament slot/
Type "3"
Enter

# Second file — copies (accept default 1)
Wait+Screen /copies/
Enter

# Second file — orient (accept default "flat")
Wait+Screen /orient/
Enter

# Second file — filament slot (pick slot 3)
Wait+Screen /filament slot/
Type "3"
Enter

# --- Slicer Overrides (now after CAD files) ---
Wait+Screen /slicer overrides/
Sleep 300ms

# Yes, add overrides
Type "y"
Enter
Sleep 2s

# Pick infill density (option 1)
Type "1"
Enter
Sleep 1s

# Enter infill value (percent type — "30" auto-becomes "30%")
Type "30"
Enter
Sleep 1s

# Don't add another override
Wait+Screen /Add another override/
Enter

# --- Build Plate ---
Wait+Screen /Build Plate/
Sleep 300ms

# Accept detected plate width
Wait+Screen /Plate width/
Enter

# Accept detected plate depth
Wait+Screen /Plate depth/
Sleep 500ms
Enter
Sleep 3s

# --- Slicer Version ---
# Pick first version (list loaded from bundled JSON, no network call)
Type "1"
Enter
Sleep 2s

# --- Printer Connection (simple-term-menu, single-select) ---
# Select "workshop" (first option)
Enter
Sleep 2s

# --- Project Name ---
# Accept default "decoy-case"
Enter
Sleep 2s

# --- Preview and write ---
Type "w"
Enter

Sleep 5s

Type "clear"
Enter
Sleep 500ms

# =====================================================================
# PART 3: fabprint validate
# =====================================================================

Type "# Step 3: Validate the config"
Enter
Sleep 1s

Type "fabprint validate"
Enter

Wait+Screen /Validating/
Sleep 500ms

Wait+Screen /checks passed|warning/
Sleep 3s

Type "clear"
Enter
Sleep 500ms

# =====================================================================
# PART 4: fabprint run — full pipeline including print
# =====================================================================

Type "# Step 4: Run the full pipeline"
Enter
Sleep 1s

Type "fabprint run"
Enter

Wait+Screen /Loaded.*part/
Sleep 500ms

Wait+Screen /Arranged.*part/
Sleep 500ms

Wait+Screen /Plate exported/
Sleep 500ms

# Slicing can take 30-60s
Wait+Screen /Sliced/
Sleep 1s

Wait+Screen /Print time|filament/
Sleep 1s

Wait+Screen /Sent to printer/
Sleep 3s

# Hold final frame
Sleep 3s
