// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2023. 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 System.Collections.Generic;

using Glade;

using Hiperscan.Extensions.ReferenceCheck.Control.GuiUpdate;
using Hiperscan.GtkExtensions.Widgets;

namespace Hiperscan.Extensions.ReferenceCheck.View
{
    public partial class GUI
    {
        [Widget] Gtk.Alignment protocol_alignment = null;
        [Widget] Gtk.Label protocol_date_label = null;
        [Widget] Gtk.Label protocol_date_out_label = null;
        [Widget] Gtk.Label protocol_operator_label = null;
        [Widget] Gtk.Entry protocol_operator_entry = null;
        [Widget] Gtk.Button protocol_create_button = null;
        [Widget] Gtk.Button protocol_show_button = null;
        [Widget] Gtk.Button protocol_save_button = null;


        private void InitProtocolSection()
        {
            this.protocol_create_button.Clicked += this.OnProtocolCreateButtonClicked;
            this.protocol_show_button.Clicked += this.OnProtocolShowButtonClicked;
            this.protocol_save_button.Clicked += this.OnProtocolSaveButtonClicked;

            this.ProtocolOperatorEntry = new OutLinedEntry(this.protocol_operator_entry);
            this.ProtocolOperatorEntry.IsValid = false;
            this.ProtocolOperatorEntry.ValueChanged += this.OnProtocolOperatorEntryChanged;
        }

        private void OnProtocolOperatorEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetOperatorName(this.ProtocolOperatorEntry.GtkEntry.Text);
        }

        private void OnProtocolCreateButtonClicked(object sender, EventArgs e)
        {
            this.Control.CreateProtocol();
        }

        private void OnProtocolShowButtonClicked(object sender, EventArgs e)
        {
            this.Control.ShowProtocol();
        }

        private void OnProtocolSaveButtonClicked(object sender, EventArgs e)
        {
            this.Control.SaveProtocol();
        }


        private void UpdateProtocolSection(UpdateCategory category, List<string> pharmacy_profiles)
        {
            if (category.HasFlag(UpdateCategory.Sensitives))
            {
                this.protocol_date_label.Sensitive = this.Control.ProtocolIsBusy == false;
                this.protocol_date_out_label.Sensitive = this.Control.ProtocolIsBusy == false;
                this.protocol_operator_label.Sensitive = this.Control.ProtocolIsBusy == false;
                this.ProtocolOperatorEntry.Sensitive = this.Control.ProtocolIsBusy == false;

                this.protocol_create_button.Sensitive = this.Control.CanCreateProtocol;
                this.protocol_show_button.Sensitive = this.Control.CanShowProtocol;
                this.protocol_save_button.Sensitive = this.Control.CanSaveProtocol;
                bool can_next = this.Control.CanNext();
                this.next_button.Sensitive = can_next;
                this.next_button_eventbox.ModifyBg(Gtk.StateType.Normal,
                    can_next ? new Gdk.Color(50, 205, 50) : new Gdk.Color(232, 232, 232));
            }

            if (category.HasFlag(UpdateCategory.QuickDataChange))
            {
                this.ProtocolOperatorEntry.GtkEntry.Text = this.Control.ProtocolOperatorName;
                this.ProtocolOperatorEntry.IsValid = this.Control.IsProtocolOperatorValid;
            }

            if (category.HasFlag(UpdateCategory.SlowDataChange))
            {
                this.ProtocolOperatorEntry.GtkEntry.IsEditable = this.Control.CanEnterOperator;
                this.protocol_date_out_label.Text = this.Control.ProtocolDate;
            }
        }

        private OutLinedEntry ProtocolOperatorEntry { get; set; }
    }
}
