using System.Xml;

namespace aeqw89.tools.Publish;

internal class ItemGroup {
    private readonly XmlElement _element;
    public List<Item> Items { get; }

    public void Remove() {
        _element.ParentNode!.RemoveChild(_element);
    }
    
    public ItemGroup(XmlElement element) {
        _element = element;
        Items = element.ChildNodes
            .OfType<XmlElement>()
            .Select(Item.FromElement)
            .ToList();
    }

    public void Add(Item item) {
        var imported = _element.OwnerDocument!.ImportNode(item.Node, true);
        _element.AppendChild(imported);
        Items.Add(Item.FromElement((XmlElement)imported));
    }
}