using System;
using System.Collections.Generic;
namespace Mods.ModManager
{
///
/// Presentation helpers for catalog provenance. The manager shows where a mod
/// comes from without cluttering the tile: a short host label plus the full
/// URL list in the tooltip, and a "+N" marker when several catalogs publish
/// the same build.
///
public static class ModCatalogSource
{
/// First source URL, or null when there are none.
public static string FirstUrl(IReadOnlyList urls)
=> urls != null && urls.Count > 0 ? urls[0] : null;
/// Host of a URL (fallback: the raw string when it does not parse).
public static string Host(string url)
{
if (string.IsNullOrWhiteSpace(url))
return null;
if (Uri.TryCreate(url, UriKind.Absolute, out var uri) && !string.IsNullOrEmpty(uri.Host))
return uri.Host;
return url;
}
/// Short label: host plus "+N" for extra catalogs, or null when unknown.
public static string Label(IReadOnlyList urls)
{
var first = FirstUrl(urls);
if (first == null)
return null;
var host = Host(first);
var extra = urls.Count - 1;
return extra > 0 ? $"{host} +{extra}" : host;
}
/// Newline-joined full URL list for tooltips.
public static string Tooltip(IReadOnlyList urls)
=> urls == null || urls.Count == 0 ? null : string.Join("\n", urls);
}
}