// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2021 Torsten Schache, Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU 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 <http://www.gnu.org/licenses/>.

using System.Collections.Generic;

using Glade;

using Gtk;

using Hiperscan.Common.I18n;

namespace Hiperscan.Extensions.ApoIdent
{
    public partial class ApoIdentApplication
    {
        [Widget] Gtk.Toolbar menu_toolbar = null;

        [Widget] Gtk.ToolButton menu_quickstep_toolbutton = null;
        [Widget] Gtk.ToolButton menu_exit_toolbutton = null;
        [Widget] Gtk.ToolButton menu_archive_toolbutton = null;
        [Widget] Gtk.ToolButton menu_query_toolbutton = null;
        [Widget] Gtk.ToolButton menu_reset_toolbutton = null;
        [Widget] Gtk.ToolButton menu_settings_toolbutton = null;
        [Widget] Gtk.ToolButton menu_connect_toolbutton = null;
        [Widget] Gtk.ToolButton menu_substance_toolbutton = null;
        [Widget] Gtk.ToolButton menu_help_toolbutton = null;
        [Widget] Gtk.ToolButton menu_info_toolbutton = null;

        [Widget] Gtk.ToolItem menu_archive_spacer = null;

        private void UpdateMenueSection()
        {
            this.UpdateMenuButtons();
            this.SetMenuButtonStates();
        }

        private void UpdateMenuButtons()
        {
            bool active = this.Control.QuitRequested == false && 
                              this.Control.MeasuringProgressState.IsReferencing == false &&
                              this.Control.Busy == false;

            this.menu_quickstep_toolbutton.Sensitive = active;
            this.menu_exit_toolbutton.Sensitive = active;

            this.menu_archive_spacer.Visible = this.Control.ProfileChangedMode == false;
            this.menu_archive_toolbutton.Visible = this.Control.ProfileChangedMode == false;
            this.menu_archive_toolbutton.Sensitive = active;

            this.menu_query_toolbutton.Sensitive = active;
            this.menu_help_toolbutton.Sensitive = active;
            this.menu_info_toolbutton.Sensitive = active;

            this.menu_settings_toolbutton.Sensitive = active; //TODO see below

            this.menu_connect_toolbutton.Sensitive = active && 
                this.Control.ConnectionSuccess == false;

            this.menu_substance_toolbutton.Sensitive = active && 
                this.Control.ConnectionSuccess;

            this.menu_reset_toolbutton.Sensitive = active &&
                this.Control.ConnectionSuccess == true &&
                this.Finder?.ExternalReferencingIsPending == false;
        }

        private void SetMenuButtonStates()
        {
            this.SetToolButtonActiveState(this.menu_quickstep_toolbutton);
            this.SetToolButtonActiveState(this.menu_exit_toolbutton);
            this.SetToolButtonActiveState(this.menu_archive_toolbutton);
            this.SetToolButtonActiveState(this.menu_query_toolbutton);
            this.SetToolButtonActiveState(this.menu_reset_toolbutton);
            this.SetToolButtonActiveState(this.menu_connect_toolbutton);
            this.SetToolButtonActiveState(this.menu_settings_toolbutton);
            this.SetToolButtonActiveState(this.menu_substance_toolbutton);
            this.SetToolButtonActiveState(this.menu_help_toolbutton);
            this.SetToolButtonActiveState(this.menu_info_toolbutton);
        }
    }
}
