#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Mk Base Image
# 
# Copyright (C) 2026 Arnaud G. GIBERT
# mailto:arnaud@rx3.net
# 
# This is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; If not, see
# <https://www.gnu.org/licenses/>.
# 
#-----------------------------------------------------------------------------------------------------------------------------------
# -*- mode: shell; sh-basic-offset: 4; indent-tabs-mode: nil; -*-



_mk_base_image() {
    local cur prev opts distrib_opts lang_opts timezone_opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Supported distributions (customize as needed)
    distrib_opts="9 10 cauldron"
    
    # Supported languages (customize as needed)
    lang_opts="en_US.UTF-8 fr_FR.UTF-8 de_DE.UTF-8"

    # Supported timezones (customize as needed)
    timezone_opts="Europe/Paris America/New_York Asia/Tokyo UTC"

    # Check if mutually exclusive options are already used
    local has_mutually_exclusive=false

    for arg in "${COMP_WORDS[@]}"; do
        case "$arg" in
            --help|-h|--version|-V|--pre|-p|--post|-P|--strip|-s|--unstrip|-u)
                has_mutually_exclusive=true
            ;;
        esac
    done

    # If a mutually exclusive option is used, only suggest non-mutually exclusive options
    if $has_mutually_exclusive; then
        opts="--direct -D --distrib -d --lang -l --language -L --localtime -m --root -r --tmp -t --test -T --verbose -v"
    # Otherwise, show all options
    else
        opts="--help -h --version -V --pre -p --post -P --strip -s --unstrip -u --direct -D --distrib -d --lang -l --language -L --localtime -m --root -r --tmp -t --test -T --verbose -v"
    fi

    case "${prev}" in
        --distrib|-d)
            COMPREPLY=( $(compgen -W "${distrib_opts}" -- "${cur}") )
            return 0
        ;;
        
        --lang|-l|--language|-L)
            COMPREPLY=( $(compgen -W "${lang_opts}" -- "${cur}") )
            return 0
        ;;
        
        --localtime|-m)
            COMPREPLY=( $(compgen -W "${timezone_opts}" -- "${cur}") )
            return 0
        ;;
        
        --root|-r|--tmp|-t)
            COMPREPLY=( $(compgen -d -- "${cur}") )  # Complete with directories
            return 0
        ;;
        
        *)
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
        ;;
    esac
}



complete -F _mk_base_image mk_base_image
