# Mainline bash completion script
#
# To install:
#   source /path/to/completion/mainline-completion.bash
#
# Or add to ~/.bashrc:
#   source /path/to/completion/mainline-completion.bash

_mainline_completion() {
    local cur prev words cword
    _init_completion || return

    # Get current word and previous word
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Completion options based on previous word
    case "${prev}" in
        --display)
            # Display backends
            COMPREPLY=($(compgen -W "terminal null replay websocket pygame moderngl" -- "${cur}"))
            return
            ;;

        --pipeline-source)
            # Available sources
            COMPREPLY=($(compgen -W "headlines poetry empty fixture pipeline-inspect" -- "${cur}"))
            return
            ;;

        --pipeline-effects)
            # Available effects (comma-separated)
            local effects="afterimage border crop fade firehose glitch hud motionblur noise tint"
            COMPREPLY=($(compgen -W "${effects}" -- "${cur}"))
            return
            ;;

        --pipeline-camera)
            # Camera modes
            COMPREPLY=($(compgen -W "feed scroll horizontal omni floating bounce radial" -- "${cur}"))
            return
            ;;

        --pipeline-border)
            # Border modes
            COMPREPLY=($(compgen -W "off simple ui" -- "${cur}"))
            return
            ;;

        --pipeline-display)
            # Display backends (same as --display)
            COMPREPLY=($(compgen -W "terminal null replay websocket pygame moderngl" -- "${cur}"))
            return
            ;;

        --theme)
            # Theme colors
            COMPREPLY=($(compgen -W "green orange purple blue red" -- "${cur}"))
            return
            ;;

        --viewport)
            # Viewport size suggestions
            COMPREPLY=($(compgen -W "80x24 100x30 120x40 60x20" -- "${cur}"))
            return
            ;;

        --preset)
            # Presets (would need to query available presets)
            COMPREPLY=($(compgen -W "demo demo-base demo-pygame demo-camera-showcase poetry headlines empty test-basic test-border test-scroll-camera" -- "${cur}"))
            return
            ;;

        --positioning)
            # Positioning modes
            COMPREPLY=($(compgen -W "absolute relative mixed" -- "${cur}"))
            return
            ;;
    esac

    # Flag completion (start with --)
    if [[ "${cur}" == -* ]]; then
        COMPREPLY=($(compgen -W "
            --display
            --pipeline-source
            --pipeline-effects
            --pipeline-camera
            --pipeline-display
            --pipeline-ui
            --pipeline-border
            --viewport
            --preset
            --theme
            --positioning
            --websocket
            --websocket-port
            --allow-unsafe
            --help
        " -- "${cur}"))
        return
    fi
}

complete -F _mainline_completion mainline.py
complete -F _mainline_completion python\ -m\ engine.app
complete -F _mainline_completion python\ -m\ mainline
