# Fish completion script for Mainline
#
# To install:
#   source /path/to/completion/mainline-completion.fish
#
# Or copy to ~/.config/fish/completions/mainline.fish

# Define display backends
set -l display_backends terminal null replay websocket pygame moderngl

# Define sources
set -l sources headlines poetry empty fixture pipeline-inspect

# Define effects
set -l effects afterimage border crop fade firehose glitch hud motionblur noise tint

# Define camera modes
set -l cameras feed scroll horizontal omni floating bounce radial

# Define border modes
set -l borders off simple ui

# Define themes
set -l themes green orange purple blue red

# Define presets
set -l presets demo demo-base demo-pygame demo-camera-showcase poetry headlines empty test-basic test-border test-scroll-camera test-figment test-message-overlay

# Main completion function
function __mainline_complete
    set -l cmd (commandline -po)
    set -l token (commandline -t)

    # Complete display backends
    complete -c mainline.py -n '__fish_seen_argument --display' -a "$display_backends" -d 'Display backend'

    # Complete sources
    complete -c mainline.py -n '__fish_seen_argument --pipeline-source' -a "$sources" -d 'Data source'

    # Complete effects
    complete -c mainline.py -n '__fish_seen_argument --pipeline-effects' -a "$effects" -d 'Effect plugin'

    # Complete camera modes
    complete -c mainline.py -n '__fish_seen_argument --pipeline-camera' -a "$cameras" -d 'Camera mode'

    # Complete display backends (pipeline)
    complete -c mainline.py -n '__fish_seen_argument --pipeline-display' -a "$display_backends" -d 'Display backend'

    # Complete border modes
    complete -c mainline.py -n '__fish_seen_argument --pipeline-border' -a "$borders" -d 'Border mode'

    # Complete themes
    complete -c mainline.py -n '__fish_seen_argument --theme' -a "$themes" -d 'Color theme'

    # Complete presets
    complete -c mainline.py -n '__fish_seen_argument --preset' -a "$presets" -d 'Preset name'

    # Complete viewport sizes
    complete -c mainline.py -n '__fish_seen_argument --viewport' -a '80x24 100x30 120x40 60x20' -d 'Viewport size (WxH)'

    # Complete flag options
    complete -c mainline.py -n 'not __fish_seen_argument --display' -l display -d 'Display backend' -a "$display_backends"
    complete -c mainline.py -n 'not __fish_seen_argument --preset' -l preset -d 'Preset to use' -a "$presets"
    complete -c mainline.py -n 'not __fish_seen_argument --viewport' -l viewport -d 'Viewport size (WxH)' -a '80x24 100x30 120x40 60x20'
    complete -c mainline.py -n 'not __fish_seen_argument --theme' -l theme -d 'Color theme' -a "$themes"
    complete -c mainline.py -l websocket -d 'Enable WebSocket server'
    complete -c mainline.py -n 'not __fish_seen_argument --websocket-port' -l websocket-port -d 'WebSocket port' -a '8765'
    complete -c mainline.py -l allow-unsafe -d 'Allow unsafe pipeline configuration'
    complete -c mainline.py -n 'not __fish_seen_argument --help' -l help -d 'Show help'

    # Pipeline-specific flags
    complete -c mainline.py -n 'not __fish_seen_argument --pipeline-source' -l pipeline-source -d 'Data source' -a "$sources"
    complete -c mainline.py -n 'not __fish_seen_argument --pipeline-effects' -l pipeline-effects -d 'Effect plugins (comma-separated)' -a "$effects"
    complete -c mainline.py -n 'not __fish_seen_argument --pipeline-camera' -l pipeline-camera -d 'Camera mode' -a "$cameras"
    complete -c mainline.py -n 'not __fish_seen_argument --pipeline-display' -l pipeline-display -d 'Display backend' -a "$display_backends"
    complete -c mainline.py -l pipeline-ui -d 'Enable UI panel'
    complete -c mainline.py -n 'not __fish_seen_argument --pipeline-border' -l pipeline-border -d 'Border mode' -a "$borders"
end

# Register the completion function
__mainline_complete
