using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Metadata;
using System;
using System.Collections.Generic;
using VeloeMinecraftLauncher.Models.Entity;

namespace VeloeMinecraftLauncher.Utils
{
    internal class ChangelogDataTemplate : IDataTemplate
    {
        [Content]
        public Dictionary<bool, IDataTemplate> AvailableTemplates { get; } = new Dictionary<bool, IDataTemplate>();

        public Control? Build(object? param)
        {
            ArgumentNullException.ThrowIfNull(param);
            return AvailableTemplates[string.IsNullOrEmpty(((Changelog)param).Title)].Build(param);
        }

        public bool Match(object? data) => data is Changelog changelog && AvailableTemplates.ContainsKey(string.IsNullOrEmpty(changelog.Title));
    }
}
