// 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;

using Glade;
using Hiperscan.ApoIdentCore.GuiControl;
using Hiperscan.Extensions.ApoIdent.Widgets;

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

        [Widget] Gtk.Toolbar protocol_toolbar = null;
        [Obsolete("Do not use this field")]
        [Widget] Gtk.ToolButton protocol_save_toolbutton = null;
        [Obsolete("Do not use this field")]
        [Widget] Gtk.ToolButton protocol_pdf_toolbutton = null;
        [Obsolete("Do not use this field")]
        [Widget] Gtk.ToolButton protocol_print_toolbutton = null;
        [Obsolete("Do not use this field")]
        [Widget] Gtk.ToolButton protocol_label_print_toolbutton = null;

        [Widget] Gtk.Label protocol_test_id_label = null;

        private void UpdateProtocolSection(UpdateArgs update_arg)
        {
            if (update_arg.Protocol.HasFlag(UpdateCategory.Sensitives))
                this.SetProtocSensitives();

            if (update_arg.Protocol.HasFlag(UpdateCategory.SetValues))
                this.SetProtocolTestId();
        }

        private void SetProtocSensitives()
        {
            bool sensitive = this.Control.GlobalStates.QuitRequested == false &&
                              this.Control.GlobalStates.Busy == false &&
                              this.Control.ProtocolManager.IsComplete &&
                              this.Control.MeasuringManager.IsReferencing == false;

            this.protocol_section_label.Sensitive = sensitive;
            this.ProtocolSaveToolButton.Sensitive = sensitive  && this.Control.ProtocolManager.IsProtocolSaved == false;
            this.ProtocolPdfToolButton.Sensitive = sensitive;
            this.ProtocolPrintToolButton.Sensitive = sensitive;
            this.ProtocolLabelPrintToolButton.Sensitive = sensitive && this.Control.ProtocolManager.PrinterSettings.HasPrinter;
            this.protocol_test_id_label.Sensitive = sensitive;

        }

        private void SetProtocolTestId()
        {
            this.protocol_test_id_label.Markup = " <b>" + this.Control.MeasuringManager.GetMeasurmentId() + "</b>";
        }

        private ApoIdentToolButton ProtocolSaveToolButton { get; set; }
        private ApoIdentToolButton ProtocolPdfToolButton { get; set; }
        private ApoIdentToolButton ProtocolPrintToolButton { get; set; }
        private ApoIdentToolButton ProtocolLabelPrintToolButton { get; set; }
    }
}
