// 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
    {
        private ImageMenuItem help_available_substances_menuitem = null;
        private ImageMenuItem help_available_insert_substances_menuitem = null;
        private ImageMenuItem help_substance_update_info_menuitem = null;
        private ImageMenuItem help_validation_doc_menuitem = null;
        private ImageMenuItem help_additional_tests_item = null;

        private void UpdateHelpSection()
        {
            if (this.Control.QuitRequested == false)
            {
                this.SetAvailableSubstanceMenueItem();
                this.SetAvailableInsertSubstanceMenuItem();
                this.SetChangedSubstanceMenueItem();

                this.SetValidationDocuMenueItem();
                this.SetAdditionalTestsDocuMenuItem();
            }
        }

        private void SetAvailableSubstanceMenueItem()
        {
            this.help_available_substances_menuitem.Sensitive = this.SubstanceManagement.Pdfs.IsUpdatingSubstancePdfs == false;
        }

        private void SetAvailableInsertSubstanceMenuItem()
        {
            this.help_available_insert_substances_menuitem.Sensitive = this.SubstanceManagement.Pdfs.IsUpdatingSubstancePdfs == false;
        }

        private void SetChangedSubstanceMenueItem()
        {
            this.help_substance_update_info_menuitem.Sensitive = this.SubstanceManagement.Pdfs.IsUpdatingSubstancePdfs == false;
        }

        private void SetValidationDocuMenueItem()
        {
            if (this.SubstanceManagement.Pdfs.IsUpdatingValdationPdfs == true || this.Config.IdentModuleSettings.TestVersion == true)
            {
                this.help_validation_doc_menuitem.Sensitive = false;
            }
            else
            {
                List<string> classifier_names = new List<string>(this.SubstanceManagement.Config.IdentModuleSettings.ValidatedClassifiers);

                if (classifier_names.Count == 0)
                {
                    this.help_validation_doc_menuitem.Sensitive = false;
                }
                else
                {
                    classifier_names.Sort();
                    Menu validation_menues = new Menu();
                    this.help_validation_doc_menuitem.Submenu = validation_menues;

                    foreach (string classifier_name in classifier_names)
                    {
                        ImageMenuItem item = new ImageMenuItem(classifier_name);
                        item.Data["class_name"] = classifier_name;
                        item.Image = new Gtk.Image(Stock.File, IconSize.LargeToolbar);
                        item.Activated += this.OnShowValidationDocumentActivated;
                        item.ButtonReleaseEvent += this.OnShowValidationDocumentActivated;
                        item.ShowAll();
                        validation_menues.Append(item);
                    }

                    this.help_validation_doc_menuitem.Sensitive = true;
                }
            }
        }

        private void SetAdditionalTestsDocuMenuItem()
        {
            Locale.LocaleType locale = this.Config.IdentModuleSettings.Locale;

            this.help_additional_tests_item.Visible = locale == Locale.LocaleType.de_DE;
            this.help_additional_tests_item.NoShowAll = locale != Locale.LocaleType.de_DE;
            this.help_additional_tests_item.Sensitive = this.SubstanceManagement.Pdfs.IsUpdatingAdditionalPdfs == false;
        }
    }
}
                                                                   