#region << Using Directives >>
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Volpe.Cafe.Resources;
using Volpe.Cafe.UI;
#endregion

namespace Volpe.Cafe.EspressoUI.Utils
{
    /// <summary>
    /// Provides helper methods for displaying text-based application resources as modal dialogs or windows.
    /// </summary>
    static class ResourceViewer
    {
        /// <summary>
        /// Displays the Warnings dialog box.
        /// </summary>
        /// <param name="showCancelButton">true, to display the OK and Cancel buttons; false, to display the OK button only.</param>
        /// <returns>The result value of a dialog box.</returns>
        public static DialogResult ShowWarningsDialog(bool showCancelButton)
        {
            PromptOption promptOption = (showCancelButton) ? PromptOption.OkCancel : PromptOption.Ok;
            return ShowScreenHelper(EmbeddedResources.WarningsRtf, "CAFE Model Warnings", promptOption, false, false);
        }
        /// <summary>
        /// Displays the Notice dialog box.
        /// </summary>
        /// <returns>The result value of a dialog box.</returns>
        public static DialogResult ShowNoticeDialog()
        {
            return ShowScreenHelper(EmbeddedResources.NoticeRtf, "CAFE Model Notice", PromptOption.Ok, false, true);
        }
        /// <summary>
        /// Displays the About dialog box.
        /// </summary>
        /// <returns>The result value of a dialog box.</returns>
        public static DialogResult ShowAboutDialog()
        {
            return ShowScreenHelper(EmbeddedResources.AboutRtf, "About CAFE Model", PromptOption.Ok, true, false);
        }
        static DialogResult ShowScreenHelper(EmbeddedResources resource,
            string caption, PromptOption promptOption, bool showBuildInfo, bool showLicenseButton)
        {
            DialogResult dr = DialogResult.OK;
            using (Stream stream = AppResources.GetResourceStream(resource))
            {
                dr = RtfDialog.ShowDialogFromStream(caption, stream, promptOption, showBuildInfo, showLicenseButton);
            }
            return dr;
        }

        /// <summary>
        /// Displays the GNU Lesser General Public License in a new window.
        /// </summary>
        public static void ShowGNULGPLWindow()
        {
            using (Stream stream = AppResources.GetResourceStream(EmbeddedResources.GNU_LGPL))
            {
                RtfViewer.Show("GNU LESSER GENERAL PUBLIC LICENSE", stream);
            }
        }

        /// <summary>
        /// Displays the MIT License for the ExcelDataReader library in a new window.
        /// </summary>
        public static void ShowExcelDataReaderLicenseWindow()
        {
            using (Stream stream = AppResources.GetResourceStream(EmbeddedResources.ExcelDataReaderLicense))
            {
                RtfViewer.Show("The MIT License for the ExcelDataReader Library", stream);
            }
        }
    }
}
