// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2018 Thomas Klose & 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.Spectroscopy;
using Hiperscan.Unix;

namespace Hiperscan.Extensions.ApoIdent
{
    public partial class FinderWindow
    {
        [Widget] Gtk.Alignment empty_align1         = null;
        [Widget] Gtk.Alignment empty_align2         = null;
        [Widget] Gtk.Alignment start_align1         = null;
        [Widget] Gtk.Alignment start_align2         = null;

        [Widget] Gtk.Button start_button            = null;

        [Widget] Gtk.Label start_label              = null;
        [Widget] Gtk.Label empty_die_label          = null;
        [Widget] Gtk.CheckButton insert_checkbutton = null;

        [Widget] Gtk.Image empty_image = null;
        [Widget] Gtk.Image start_image = null;


        private void UpdateMeasurementSection()
        {
            bool active = 
                this.InitState == ServerDeviceState.Success             && 
                this.Finder.IsDeviceReady                               &&
                this.SubstanceManagement.CurrentSubstance != null       &&
                this.SubstanceManagement.CurrentClassification.IsNirMeasurable;

            this.SetTransflexionSection(active);
            this.SetMeasurementStartSection(active);
        }

        private void SetTransflexionSection(bool active)
        {
            bool active_transflexion = active               && 
                this.Finder.Current.RecalibrationIsPending  && 
                        this.SubstanceManagement.CurrentModelClass.IsFluid;

            this.empty_align1.Sensitive     = active_transflexion;
            this.empty_align2.Sensitive     = active_transflexion;
            this.empty_die_label.Visible    = active_transflexion;
        }


        private void SetMeasurementStartSection(bool active)
        {
            bool active_start_button = active &&
                this.PollFinderButton;

            this.start_align1.Sensitive     = active_start_button;
            this.start_align2.Sensitive     = active_start_button;

            this.start_label.Visible        = false;
            this.insert_checkbutton.Visible = false;

            if (active == true)
            {
                if (this.SubstanceManagement.CurrentModelClass.IsFluid == true)
                {
                    this.start_label.Text = Catalog.GetString("Please use the same transflectance insert and sample container for the " +
                                                              "transflectance reference measurement and your substance measurement.");
                    this.start_label.Visible = this.Finder.Current.RecalibrationIsPending == false;
                }
                else
                {
                    if (this.SubstanceManagement.CurrentSubstance.CanInsert == true && 
                        this.SubstanceManagement.CurrentModelClass.IsInsertModelClass == false)
                        this.insert_checkbutton.Visible     = true;

                    if (this.Finder != null && this.Finder.Current != null &&
                        (this.Finder.Current.ProbeType == ProbeType.FinderInsert ||
                         this.Finder.Current.ProbeType == ProbeType.FinderSDInsert))
                        this.insert_checkbutton.Active = true;
                    else
                        this.insert_checkbutton.Active = false;

                    this.start_label.Text = Catalog.GetString("Place the sample container with your selected substance on the device.");
                    this.start_label.Visible = true;
                }
            }
        }
    }
}
