// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2024 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 Hiperscan.AnalysisModule;
using Hiperscan.Common;
using Hiperscan.PdfLib;
using Hiperscan.Unix;

namespace Hiperscan.ApoIdentCore.Reporting.Protocol.Footer
{
    public class CommonFooter : IDraw
    {
        public bool Draw(PdfArgs args)
        {
            args.Layout.SetFont(PdfFontTypes.HELVETICA_BOLD, 5, PdfColors.Black);

            args.Layout.YPosition = args.Layout.InnerPageHeight + 10;
            args.Layout.XPosition = 0;

            string text = String.Format(Catalog.GetString("Page {0} of {1}"), 
                                        args.State.CurrentPage,
                                        args.State.TotalPages);

            args.Layout.AddFooter(text, PdfTextAlignments.Right);

            args.Layout.SetFont(PdfFontTypes.HELVETICA, 5, PdfColors.Black);
            args.Layout.Feed(args.Layout.ParagraphBoundingBox.Height + 2);

            args.Layout.XPosition = 0;
            text = String.Format("{0}\n{1}",
                                      ApoIdentInfo.COPYRIGHT,
                                 Catalog.GetString("www.hiperscan.com"));
            args.Layout.AddFooter(text);

            args.Layout.XPosition = 120;
            text = String.Format("QuickStep Apo-Ident {0}", ApoIdentInfo.FullVersion);
            if (args.Info.IsMeasurable == false)
            {
                args.Layout.AddFooter(text);
                return true;
            }

            string module = args.Info.AnalysisType == AnalysisType.Identification ?
                                DefaultNames.IdentServer.PRODUCTNAME :
                                DefaultNames.QuantifierServer.PRODUCTNAME;

            text += String.Format("\n{0} {1}",
                                  module,
                                  args.Info.AnalysisModuleVersion ?? String.Empty);

            args.Layout.AddFooter(text);

            args.Layout.XPosition = 240;
            text = String.Format("SGS: {0}\n{1}: {2}\n{3}",
                                      args.Info.Serial,
                                      Catalog.GetString("White Reference"),
                                      args.Info.WhiteReference,
                                      args.Info.AnalysisMethodVersion);

            args.Layout.AddFooter(text);
            return true;
        }
    }
}
