using System.Windows.Forms;
using System.Globalization;

namespace NotepadEnhanced.Helpers
{
    public static class MsgBox
    {
        private static bool IsRightToLeft(IWin32Window owner)
        {
            Control control = owner as Control;

            if (control != null)
            {
                return control.RightToLeft == RightToLeft.Yes;
            }

            // If no parent control is available, ask the CurrentUICulture
            // if we are running under right-to-left.
            return CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
        }

        /// <summary>
        /// Shows the a message box with the default error setup. 
        /// </summary>
        public static DialogResult Show(string text)
        {
            MessageBoxOptions options = 0;

            if (IsRightToLeft(null))
            {
                options |= MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign;
            }

            return MessageBox.Show(null, text, Application.ProductName,
                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, options);
        }

        public static DialogResult Show(string text, MessageBoxIcon icon)
        {
            MessageBoxOptions options = 0;

            if (IsRightToLeft(null))
            {
                options |= MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign;
            }

            return MessageBox.Show(null, text, Application.ProductName,
                MessageBoxButtons.OK, icon, MessageBoxDefaultButton.Button1, options);
        }

        public static DialogResult Show(string text, MessageBoxIcon icon, MessageBoxButtons buttons)
        {
            MessageBoxOptions options = 0;

            if (IsRightToLeft(null))
            {
                options |= MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign;
            }

            return MessageBox.Show(null, text, Application.ProductName,
                buttons, icon, MessageBoxDefaultButton.Button1, options);
        }
    }
}