using System.Text;
using SharepointToolbox.Core.Models;

namespace SharepointToolbox.Services.Export;

/// <summary>
/// Generates the branding header HTML fragment for HTML reports.
/// Called by each HTML export service between &lt;body&gt; and &lt;h1&gt;.
/// Returns empty string when no logos are configured (no broken images).
/// </summary>
internal static class BrandingHtmlHelper
{
    public static string BuildBrandingHeader(ReportBranding? branding)
    {
        if (branding is null) return string.Empty;

        var msp = branding.MspLogo;
        var client = branding.ClientLogo;

        if (msp is null && client is null) return string.Empty;

        var sb = new StringBuilder();
        sb.AppendLine("<div style=\"display:flex;gap:16px;align-items:center;padding:12px 24px 0;\">");

        if (msp is not null)
            sb.AppendLine($"  <img src=\"data:{msp.MimeType};base64,{msp.Base64}\" alt=\"\" style=\"max-height:60px;max-width:200px;object-fit:contain;\">");

        if (msp is not null && client is not null)
            sb.AppendLine("  <div style=\"flex:1\"></div>");

        if (client is not null)
            sb.AppendLine($"  <img src=\"data:{client.MimeType};base64,{client.Base64}\" alt=\"\" style=\"max-height:60px;max-width:200px;object-fit:contain;\">");

        sb.AppendLine("</div>");
        return sb.ToString();
    }
}
