#!/bin/bash
# tikzphysics-help — quick reference for the tikzphysics TikZ library
# Usage: tikzphysics-help [shape]
# Examples:
#   tikzphysics-help          — list everything
#   tikzphysics-help wedge    — show wedge details
#   tikzphysics-help platform — show platform details

BOLD="\033[1m"
DIM="\033[2m"
RESET="\033[0m"
CYAN="\033[36m"
GREEN="\033[32m"
YELLOW="\033[33m"

print_header() {
  echo -e "\n${BOLD}${CYAN}tikzphysics v1.0.0${RESET} — TikZ-native physics diagram library"
  echo -e "${DIM}Load: \\\\usepackage{tikzphysics}  or  \\\\usetikzlibrary{tikzphysics.surface, tikzphysics.mechanics, tikzphysics.optics}${RESET}\n"
}

print_all() {
  print_header

  echo -e "${BOLD}SUBMODULES${RESET}"
  echo "  tikzphysics.surface     platforms, wedges, flat strips"
  echo "  tikzphysics.mechanics   blocks, pulleys, tangent strings"
  echo "  tikzphysics.optics      lenses"
  echo "  tikzphysics.core        shared utilities (auto-loaded)"

  echo -e "\n${BOLD}STYLES (use as \\\\node[style, ...])${RESET}"
  echo -e "  ${GREEN}physicsplatform-left${RESET}    L-shaped platform, wall on left"
  echo -e "  ${GREEN}physicsplatform-right${RESET}   L-shaped platform, wall on right"
  echo -e "  ${GREEN}physicsplatform-both${RESET}    U-shaped platform, walls on both sides"
  echo -e "  ${GREEN}physicswedge${RESET}            right triangle (inclined plane)"
  echo -e "  ${GREEN}physicsground${RESET}           flat strip, surface on top"
  echo -e "  ${GREEN}physicsceiling${RESET}          flat strip, surface on bottom"
  echo -e "  ${GREEN}physicswall-left${RESET}        vertical strip, surface on right"
  echo -e "  ${GREEN}physicswall-right${RESET}       vertical strip, surface on left"
  echo -e "  ${GREEN}physicsblock${RESET}            rectangular block"
  echo -e "  ${GREEN}physicspulley${RESET}           circle with axle dot"
  echo -e "  ${GREEN}physicslens${RESET}             thin curved optical element"

  echo -e "\n${BOLD}KEYS${RESET}"
  echo -e "  ${YELLOW}Platforms:${RESET}  physics platform width, physics platform depth, physics strip width,"
  echo "              physics wall angle, physics left wall angle, physics right wall angle"
  echo -e "  ${YELLOW}Wedge:${RESET}     physics wedge width, physics wedge height, physics wedge angle,"
  echo "              physics wedge right angle at (br|bl|top)"
  echo -e "  ${YELLOW}Flat:${RESET}      physics ground width/depth, physics ceiling width/depth,"
  echo "              physics wall thickness/height"
  echo -e "  ${YELLOW}Block:${RESET}     physics block width, physics block height"
  echo -e "  ${YELLOW}Pulley:${RESET}    physics pulley diameter, physics pulley axle radius,"
  echo "              physics pulley axle color, physics string start/end solution, physics string wrap"
  echo -e "  ${YELLOW}Lens:${RESET}      physics lens radius, physics lens thickness,"
  echo "              physics lens aperture angle"

  echo -e "\n${BOLD}DEBUG${RESET}"
  echo "  physics debug/anchors=true   numbered dots + legend"
  echo "  physics debug/keys=true      keys box with defaults"
  echo "  physics debug/all=true       both"

  echo -e "\n${BOLD}NUMERIC ANCHORS${RESET}"
  echo "  <edge>-0 through <edge>-100 on straight edges"
  echo "  front-T / back-T arc anchors on physicslens"

  echo -e "\n${DIM}Run: tikzphysics-help platform|wedge|block|pulley|flat|lens for details${RESET}"
}

print_platform() {
  print_header
  echo -e "${BOLD}PLATFORMS${RESET}  physicsplatform-left / -right / -both"
  echo -e "\n${YELLOW}Keys (defaults):${RESET}"
  echo "  physics platform width    = 5cm"
  echo "  physics platform depth    = 2cm"
  echo "  physics strip width       = 0.3cm"
  echo "  physics wall angle        = -90°"
  echo "  physics left wall angle   = -90°   (both only)"
  echo "  physics right wall angle  = -90°   (both only)"
  echo -e "\n${YELLOW}Anchors:${RESET}"
  echo "  Floor:  floor-tl, floor-tr, floor-br, floor-bl"
  echo "          floor-top-mid, floor-bottom-mid, floor-left-mid,"
  echo "          floor-right-mid, floor-center"
  echo "  Wall:   wall-A (outer-near), wall-B (inner-miter),"
  echo "          wall-C (inner-far), wall-D (outer-far)"
  echo "          wall-outer-mid, wall-inner-mid, wall-near-mid,"
  echo "          wall-far-mid, wall-center"
  echo "  Corner: corner (fixed point on the continuous contact line)"
  echo "          left-corner, right-corner (both-wall platform)"
  echo "  Both:   prefix wall anchors with left- or right-"
  echo -e "\n${YELLOW}Numeric edges:${RESET}"
  echo "  floor-top-T, floor-bottom-T, floor-left-T, floor-right-T"
  echo "  wall-outer-T, wall-inner-T, wall-near-T, wall-far-T"
  echo "  (T = 0..100)"
}

print_wedge() {
  print_header
  echo -e "${BOLD}WEDGE${RESET}  physicswedge"
  echo -e "\n${YELLOW}Keys (defaults):${RESET}"
  echo "  physics wedge width          = 4cm"
  echo "  physics wedge height         = (derived)"
  echo "  physics wedge angle          = (mode default: 30° or 45°)"
  echo "  physics wedge right angle at   = br  (br|bl|top)"
  echo -e "\n${YELLOW}Precedence:${RESET} physics wedge angle > physics wedge height > mode default"
  echo -e "\n${YELLOW}Anchors:${RESET}"
  echo "  bl, br, top, base-mid, right-mid, slope-mid,"
  echo "  slope-right-mid (top mode), centroid, mid"
  echo "  + compass: center, north, south, east, west, etc."
  echo -e "\n${YELLOW}Numeric edges:${RESET}  base-T, right-T, slope-T  (T = 0..100)"
}

print_block() {
  print_header
  echo -e "${BOLD}BLOCK${RESET}  physicsblock"
  echo -e "\n${YELLOW}Keys (defaults):${RESET}"
  echo "  physics block width   = 1cm"
  echo "  physics block height  = 1cm"
  echo -e "\n${YELLOW}Anchors:${RESET}  center, north, south, east, west, + corners"
}

print_pulley() {
  print_header
  echo -e "${BOLD}PULLEY${RESET}  physicspulley"
  echo -e "\n${YELLOW}Keys (defaults):${RESET}"
  echo "  physics pulley diameter     = 1cm"
  echo "  physics pulley axle radius  = 2pt  (set 'none' to hide)"
  echo "  physics pulley axle color   = black"
  echo -e "\n${YELLOW}Tangent string:${RESET}"
  echo "  \\physicsstringoverpulley{start}{pulley}{end}"
  echo "  physics string start solution = 2"
  echo "  physics string end solution   = 1"
  echo "  physics string route          = surface-right  (surface-right|over|under|shortest)"
  echo "  physics string wrap           = clockwise  (clockwise|counterclockwise|shortest)"
  echo -e "\n${YELLOW}Complete examples:${RESET}"
  echo "  mechanics-pulley-flat-plane.tex"
  echo "  mechanics-block-pulley.tex"
  echo "  mechanics-pulley-bent-platform.tex"
  echo "  mechanics-pulley-two-masses.tex"
  echo -e "\n${YELLOW}Anchors:${RESET}  center, north, south, east, west, + corners"
}

print_flat() {
  print_header
  echo -e "${BOLD}FLAT STRIPS${RESET}  physicsground / physicsceiling / physicswall-left / physicswall-right"
  echo -e "\n${YELLOW}Keys (defaults):${RESET}"
  echo "  physics ground width/depth      = 6cm / 0.3cm"
  echo "  physics ceiling width/depth     = 2cm / 0.3cm"
  echo "  physics wall thickness/height   = 0.3cm / 3cm"
  echo -e "\n${YELLOW}Anchors:${RESET}"
  echo "  top-left, top-right, top-mid, bottom-left, bottom-right,"
  echo "  bottom-mid, left-mid, right-mid, surface, center"
  echo -e "\n${YELLOW}Numeric edges:${RESET}  top-T, bottom-T, left-T, right-T  (T = 0..100)"
}

print_lens() {
  print_header
  echo -e "${BOLD}LENS${RESET}  physicslens"
  echo -e "\n${YELLOW}Keys (defaults):${RESET}"
  echo "  physics lens radius          = 5cm"
  echo "  physics lens thickness       = 0.25cm"
  echo "  physics lens aperture angle = 30°"
  echo -e "\n${YELLOW}Anchors:${RESET}"
  echo "  center, vertex, arc-mid, front-mid, back-mid,"
  echo "  front-top, front-bottom, back-top, back-bottom,"
  echo "  top, bottom, east, west"
  echo -e "\n${YELLOW}Numeric arcs:${RESET}  front-T, back-T  (T = 0..100, bottom to top)"
}

case "${1:-all}" in
  all|-h|--help) print_all ;;
  platform*) print_platform ;;
  wedge)     print_wedge ;;
  block)     print_block ;;
  pulley)    print_pulley ;;
  flat|ground|ceiling|wall) print_flat ;;
  lens|optics) print_lens ;;
  *)
    echo "Unknown: $1. Try: platform, wedge, block, pulley, flat, lens" >&2
    exit 2
    ;;
esac
