using DeepDrftModels.DTOs;
using DeepDrftPublic.Client.Services;
using Models.Common;

namespace DeepDrftPublic.Client.ViewModels;

public class TracksViewModel
{
    public ITrackDataService TrackData { get; }

    public int PageNumber { get; set; } = 1;

    public int PageSize
    {
        get => Page?.PageSize ?? 15;
        set
        {
            if (Page == null) return;
            if (value != Page.PageSize)
            {
                Page.PageSize = value;
            }
        }
    }
    public string SortBy { get; set; } = string.Empty;
    public bool IsDescending { get; set; } = false;
    public PagedResult<TrackDto>? Page { get; set; } = null;

    // Active gallery filters. Null/empty means "no filter on this dimension". SearchText is the
    // free-text query; FilterAlbum/FilterGenre are exact-match pills driven by the /albums and
    // /genres pages via query-string navigation.
    public string? SearchText { get; set; }
    public string? FilterAlbum { get; set; }
    public string? FilterGenre { get; set; }

    public bool HasActiveFilter =>
        !string.IsNullOrWhiteSpace(SearchText)
        || !string.IsNullOrWhiteSpace(FilterAlbum)
        || !string.IsNullOrWhiteSpace(FilterGenre);

    public TracksViewModel(ITrackDataService trackData)
    {
        TrackData = trackData;
    }
}
