#!/usr/bin/env bash
winezgui-template()
{
  HEADER="$(basename ${0}): ${FUNCNAME[0]}"
    
  SOURCE "script-check-variables-loaded-or-not"
  script-check-variables-loaded-or-not
  dbug "I: $(basename ${0}): Launched ${FUNCNAME[0]}"
  echo "I: ${HEADER}: WINEARCH=$WINEARCH"
  unset TEMPLATE_OPTION

  # For Zenity 4
  ZENITY_VERSION=$(${ZENITY_CMD} --version|cut -f1 -d ".")
  if [ "${ZENITY_VERSION}" -eq 4 ]; then
       WINDOW_HEIGHT=640
       WINDOW_WIDTH=500
  else
       WINDOW_HEIGHT=400
       WINDOW_WIDTH=360
  fi
  TEMPLATE_OPTION=$(${ZENITY_CMD}                          \
                  --title "${APP_WITH_VER} - Template"     \
                  --list --hide-header                     \
                  --width=${WINDOW_WIDTH}                  \
                  --height=${WINDOW_HEIGHT}                \
                  --radiolist --column " "                 \
                  --column "Action"                        \
                      TRUE "Configure ${TEMPLATE_NAME}..." \
                         0 "Backup    ${TEMPLATE_NAME}..." \
                         0 "Download  Template..."         \
                         0 "Create New..."                 \
                         0 "Clone..."                      \
                         0 "Change..."                     \
                         0 "Backup..."                     \
                         0 "Restore..."                    \
                         0 "Delete..."                     \
                         0 "Help..."                       \
                  --text   "Template..."                   )
                        
    # Exit if Cancel is clicked
  if [ -z "${TEMPLATE_OPTION}" ]; then
       dbug "I: ${HEADER}: Cancel Selected!"
       return 1
  fi

  # Show What is selected     
  dbug "I: ${HEADER}: ${TEMPLATE_OPTION} Selected!"

  if   [ "${TEMPLATE_OPTION}" = "Configure ${TEMPLATE_NAME}..." ]; then
          SOURCE "winezgui-template-configure"
          winezgui-template-configure
  elif [ "${TEMPLATE_OPTION}" = "Backup    ${TEMPLATE_NAME}..." ]; then
          SOURCE "winezgui-template-backup"
          winezgui-template-backup "${TEMPLATE}"
  elif [ "${TEMPLATE_OPTION}" = "Download  Template..." ]; then
          SOURCE "winezgui-template-download"
          winezgui-template-download
  elif [ "${TEMPLATE_OPTION}" = "Create New..." ]; then
          SOURCE "winezgui-template-create-new"
          winezgui-template-create-new
  elif [ "${TEMPLATE_OPTION}" = "Clone..." ]; then
          SOURCE "winezgui-template-clone"
          winezgui-template-clone
  elif [ "${TEMPLATE_OPTION}" = "Change..." ]; then
          SOURCE "winezgui-template-change"
          winezgui-template-change
  elif [ "${TEMPLATE_OPTION}" = "Backup..." ]; then
          SOURCE "winezgui-template-backup"
          winezgui-template-backup
  elif [ "${TEMPLATE_OPTION}" = "Restore..." ]; then
          SOURCE "winezgui-template-restore"
          winezgui-template-restore
  elif [ "${TEMPLATE_OPTION}" = "Delete..." ]; then
          SOURCE "winezgui-template-delete"
          winezgui-template-delete
  elif [ "${TEMPLATE_OPTION}" = "Help..." ]; then
          SOURCE "winezgui-template-help"
          winezgui-template-help
  else
       echo "E: Unknown Configure Option = ${TEMPLATE_OPTION}"
       exit 1
  fi
  
  return 0
} 
