using NexusShell.Models;

namespace NexusShell.Services;

public sealed class NexusSearchService
{
    public IReadOnlyList<FileSystemItem> SearchLocal(string query, IReadOnlyList<FileSystemItem> sourceItems)
    {
        if (string.IsNullOrWhiteSpace(query))
        {
            return sourceItems;
        }

        var term = query.Trim();
        return sourceItems
            .Where(item => item.Name.Contains(term, StringComparison.OrdinalIgnoreCase) ||
                           item.KindLabel.Contains(term, StringComparison.OrdinalIgnoreCase))
            .OrderByDescending(static item => item.IsDirectory)
            .ThenBy(static item => item.Name, StringComparer.OrdinalIgnoreCase)
            .ToList();
    }
}
