// 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 Gtk;
using Hiperscan.Extensions.ApoIdent.Widgets;
using Hiperscan.GtkExtensions;

namespace Hiperscan.Extensions.ApoIdent
{
    public partial class ApoIdentApplication
    {
        private void OnPharmacyConfigComboChanged(object sender, EventArgs e)
        {
            this.Control.ChangeProfile(this.pharmacy_profile_combobox.ActiveText);
        }

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



        [GLib.ConnectBefore]
        private void OnSubstanceMatchSelected(object sender, MatchSelectedArgs e)
        { 
            string text = (string)e.Model.GetValue(e.Iter, (sender as Gtk.EntryCompletion).TextColumn);
            this.Control.SelectNewSubstance(text, true);
        }

        private void OnSubstanceSearchEntryFocusOut(object sender, Gtk.FocusOutEventArgs e)
        {
            string text = this.SubstanceSearchEntry.GtkEntry.Text;
            this.Control.SelectNewSubstance(text, false);
        }

        private void OnSubstanceSearchEntryActivated(object sender, EventArgs e)
        {
            string text = this.SubstanceSearchEntry.GtkEntry.Text;
            this.Control.SelectNewSubstance(text, false);
        }

        private void OnReadExchangeDataButtonClicked(object sender, EventArgs e)
        {
            this.Control.ImportExchangeData();
        }

        private void OnClearSubstanceInputClicked(object sender, EventArgs e)
        {
            this.Control.ClearSubstanceSelection();
            if (this.SubstanceClearButton.Sensitive == false)
                this.SubstanceSearchEntry.GtkEntry.GrabFocus();
        }

        private void OnModelClassButtonClicked(object sender, EventArgs e)
        {
            this.Control.ChangeModelClass();
        }

        private void OnSubstanceInfoButtonClicked(object sender, EventArgs e)
        {
            this.Control.ShowSubstanceClassificationInfo();
        }

        private void OnValidationReportButtonClicked(object sender, EventArgs e)
        {
            this.Control.ShowSubstanceValidation();
        }

        private void OnBakMarkingChanged(object sender, EventArgs e)
        {
            this.Control.SetBakMarking((sender as BAKMarkingWidget).State);
        }



        private void OnPpnEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetPpn(this.SpecimenPpnEntry.GtkEntry.Text);
        }

        private void OnProducerEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetProducer(this.SpecimenProducerEnntry.GtkEntry.Text);
        }

        private void OnBatchEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetBatch(this.SpecimenBatchEntry.GtkEntry.Text);
        }

        private void OnReferenceQuantityValueChanged(object sender, EventArgs e)
        {
            this.Control.SetReferenceQuantityValue(this.SpecimenQuantityEntry.GtkEntry.Text);
        }

        private void OnReferenceQuantityUnitChanged(object sender, EventArgs e)
        {
            this.Control.SetReferenceQuantityUnit(this.SpecimenQuantityComboBox.EnumComboBox.CurrentItem);
        }

        private void OnDistributorEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetDistributor(this.SpecimenDistributorEntry.GtkEntry.Text);
        }

        private void OnPriceEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetPrice(this.SpecimenPriceEntry.GtkEntry.Text);
        }

        private void OnExpiryDateChanged(object sender, EventArgs e)
        {
            this.Control.SetExpiryDate(this.SpecimenExpiryDateEntry.GtkEntry.Text);
        }

        private void OnGracePeriodValueChanged(object sender, EventArgs e)
        {
            this.Control.SetGracePeriodValue(this.SpecimenGracePeriodEntry.GtkEntry.Text);
        }

        private void OnGracePeriodUnitChanged(object sender, EventArgs e)
        {
            this.Control.SetGracePeriodUnit(this.SpecimenGracePeriodComboBox.EnumComboBox.CurrentItem);
        }

        private void OnCorrectionFactorEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetCorrectionFactor(this.SpecimenWeighingCorrEntry.GtkEntry.Text);
        }

        private void OnDeliveryDateChanged(object sender, EventArgs e)
        {
            this.Control.SetDeliveryDate(this.SpecimenDeliveryDateEntry.GtkEntry.Text);
        }

        private void OnTHCEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetTHC(this.SpecimenTHCEntry.GtkEntry.Text);
        }
       
        private void OnCBDEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetCBD(this.SpecimenCBDEntry.GtkEntry.Text);
        }

        private void OnVarietyEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetVariety(this.SpecimenVarietyEntry.GtkEntry.Text);
        }



        private void OnUseSampleInsertToogled(object sender, EventArgs e)
        {
            this.Control.ChangeFinder((sender as ToggleButton).Active);
        }

        private void OnMeasuringButtonActivated(object sender, EventArgs e)
        {
            this.Control.StartMeasuringCycleByGuiButton();
        }

        private void OnMeasuringButtonClicked(object sender, EventArgs e)
        {
            this.Control.StartMeasuringCycleByGuiButton();
        }

        private void OnMeasuringAbortButtonActivated(object sender, EventArgs e)
        {
            this.Control.AbortReferencing();
        }

        private void OnMeasuringAbortButtonClicked(object sender, EventArgs e)
        {
            this.Control.AbortReferencing();
        }



        private void OnResultSuggestionButtonClicked(object sender, EventArgs e)
        {
            this.Control.ShowSuggestion();
        }

        private void OnResultAdditionalTestsClicked(object sender, EventArgs e)
        {
            this.Control.EditAdditionalTest();
        }

        private void OnResultCommentEntryChanged(object sender, EventArgs e)
        {
            this.Control.SetComment(this.ResultCommentEntry.GtkEntry.Text);
        }

        private void OnResultNirButtonClicked(object sender, EventArgs e)
        {
            this.Control.ShowNirResultPlot();
        }

        private void OnResultRatingButtonClicked(object sender, EventArgs e)
        {
            this.Control.ShowResultRatingList();
        }




        private void OnSaveReportButtonClicked(object o, EventArgs e)
        {
            this.Control.SaveProtocol();
        }

        private void OnShowReportButtonClicked(object o, EventArgs e)
        {
            this.Control.ShowProtocol();
        }

        private void OnPrintReportButtonClicked(object o, EventArgs e)
        {
            this.Control.PrintProtocol();
        }

        private void OnPrintLabelButtonClicked(object o, EventArgs e)
        {
            this.Control.LabelPrintProtocol();
        }



        private void OnQuickStepMenuButtonClicked(object o, EventArgs e)
        {
            if (this.Host.MainWindow == null || this.Host.MainWindow.Visible == true)
                return;

            if (this.Control.OpenQuickStepWindow())
            {
                this.Host.MainWindow.ShowAll();
                this.Host.MainWindow.Present();
            }
        }

        private void OnExitMenuButtonClicked(object o, EventArgs e)
        {
            this.Control.ExitApplicationByUser();
        }

        private void OnArchiveMenuButtonClicked(object sender, EventArgs e)
        {
            this.ShowPreSelectionArchive(sender as Widget);
        }

        private void OnQueryMenuButtonClicked(object o, EventArgs e)
        {
            this.Control.ShowQueryDialog();
        }

        private void OnResetReferenceMenuButtonClicked(object o, EventArgs e)
        {
            this.Control.ResetReferences();
        }

        private void OnSettingsMenuButtonClicked(object o, EventArgs e)
        {
            this.Control.ShowPreferencesDialog();
        }

        private void OnConnectMenuButtonClicked(object o, EventArgs e)
        {
            this.Control.Reconnect();
        }

        private void OnSubstanceManagementMenuButtonClicked(object sender, EventArgs e)
        {
            this.Control.ShowSubstanceExtensionDialog();
        }

        private void OnValidationDocuMenuButtonClicked(object sender, EventArgs e)
        {
            this.ShowValidationMenu(sender as Widget);
        }

        private void OnHelpMenuButtonClicked(object sender, EventArgs e)
        {
            this.ShowHelpMenu(sender as Widget);
        }

        private void OnHCannabisMenuButtonClicked(object sender, EventArgs e)
        {
            this.ShowCannabisMenu(sender as Widget);
        }

        internal void OnInfoMenuButtonClicked(object o, EventArgs e)
        {
            this.Control.ShowAboutDialog();
        }
    }
}
