using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DocumentFormat.OpenXml.Office.CoverPageProps;
using eOMS_Standard.Common.Constants;
using Telerik.Reporting.Expressions;
using Telerik.Reporting.Processing;

namespace eOMS_Standard.WebApp.ReportViewer
{
    public class BaseTelerikReport: Telerik.Reporting.Report
    {
        public void hideTextBoxIfEmpty(object sender, EventArgs e)
        {
            var textbox = (Telerik.Reporting.Processing.TextBox)sender;
            textbox.Visible = !string.IsNullOrWhiteSpace((string)textbox.Value);
        }

        [Function(Category = "My Function", Namespace = "Cus")]
        public static string NumberFormat(object number, string currencySymbol = null)
        {
            if (number == null) return string.Empty;
            return (currencySymbol??string.Empty) + ((decimal)number).ToString(FormatConst.LongDoubleFormat);
        }

        [Function(Category = "My Function", Namespace = "Cus")]
        public static string GetFooterInfoString(string Address, string PhoneNumber, string FaxNumber, string EmailAddress)
        {
            var redColor = "#800000";
            var result = string.Empty;

            if (!string.IsNullOrWhiteSpace(Address))
            {
                result += string.Format("<span>{0}</span>", HttpUtility.HtmlEncode(Address));
            }

            if (!string.IsNullOrWhiteSpace(PhoneNumber))
            {
                result += string.Format("<span>/<strong style='color: {1}'>T </strong>{0}</span>", HttpUtility.HtmlEncode(PhoneNumber), redColor);
            }

            if (!string.IsNullOrWhiteSpace(FaxNumber))
            {
                result += string.Format("<span>/<strong style='color: {1}'>F </strong>{0}</span>", HttpUtility.HtmlEncode(FaxNumber), redColor);
            }

            if (!string.IsNullOrWhiteSpace(EmailAddress) && EmailAddress.Contains("@"))
            {
                var tmp = EmailAddress.Split('@');
                result += string.Format("<span>/<strong style='color:{2}'>{0}</strong>{1}</span>", HttpUtility.HtmlEncode(tmp[0]), HttpUtility.HtmlEncode("@" + tmp[1]), redColor);
            }

            return string.Format("<p style='font-size: 8pt; font-family: calibri light;'>{0}</p>", result);
        }
    }
}