UI/SpawnMenu/Mounts/MountContent.razor
@using Sandbox;
@using Sandbox.UI;
@using Sandbox.Mounting;
@namespace Sandbox
@inherits Panel

@if ( mount is null )
{
    <root>
        #spawnmenu.mounts.error
    </root>
    return;
}


<SpawnMenuContent>

    <Header>
        <SpawnMenuToolbar>
			<Left>
				@*
				<Button Icon="home" @onclick="@GoHome"></Button>
				<Button Icon="arrow_upward" Disabled=@( currentDir?.Parent == null ) @onclick="@GoUp"></Button>
				*@
			</left>
			<Body>
				@*
				<SpawnMenuPath Path=@CurrentPath></SpawnMenuPath>
				*@

				<label>@( $"{mount.Title}, {GetData().Count()}" ) </label><label>#spawnmenu.common.items</label>
			</Body>
			<Right>
				<SpawnMenuFilter Query:bind="@Filter"></SpawnMenuFilter>
				<SpawnMenuIconOptions Size:bind="@ItemSize"></SpawnMenuIconOptions>
			</Right>
		</SpawnMenuToolbar>
    </Header>

    <Body>
		
        <VirtualGrid Items=@( GetData() ) ItemSize=@ItemSize>
            <Item Context="item">

				@if (item is ResourceFolder dir)
                {
                    <div class="folder" @onclick=@( () => currentDir = dir )>
						<div><i>folder</i></div>
						<div class="name">@dir.Name</div>
					</div>
                }

                @if (item is ResourceLoader loader)
                {
                    var nameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(loader.Name);
                    <SpawnMenuIcon HideText=@(ItemSize <= 60) Ident=@($"mount:{loader.Path}") Title="@nameWithoutExt" [email protected]( mount.Title )></SpawnMenuIcon>
                }

            </Item>
        </VirtualGrid>
    </Body>

</SpawnMenuContent>

@code
{
    public string Ident { get; set; }
    public string Filter { get; set; }

    public static int ItemSize { get; set; } = 120;

	ResourceFolder currentDir;

    BaseGameMount mount;

	protected override int BuildHash() => HashCode.Combine(Ident, ItemSize, Filter);

    protected override async Task OnParametersSetAsync()
    {
        mount = await Sandbox.Mounting.Directory.Mount( Ident );
    }

	void GoHome()
	{
		currentDir = mount.RootFolder;
	}

	void GoUp()
	{
		if ( currentDir.Parent != null )
		{
			currentDir = currentDir.Parent;
		}
	}

	string CurrentPath
	{
		get => currentDir?.Path ?? "/";
	}

    IEnumerable<object> GetData()
    {
		var q = mount.Resources
						.Where( x => x.Type == ResourceType.Model )
						.Where( x => !x.Flags.Contains( Sandbox.Mounting.ResourceFlags.DeveloperOnly ) ); // Hide dev-only junk models

		if ( !string.IsNullOrWhiteSpace( Filter ) )
		{
			q = q.Where( x => x.Path.Contains( Filter, StringComparison.OrdinalIgnoreCase ) );
		}

		return q;
    }

}