@model SceneEditViewModel
@{
    var primaryLocation = Model.LocationOptions.FirstOrDefault(x => x.Value == Model.PrimaryLocationID?.ToString())?.Text?.Trim();
    var locationNames = new[] { primaryLocation }.Where(x => !string.IsNullOrWhiteSpace(x))
        .Select(x => x!)
        .Concat(Model.SceneCharacters.Where(x => !string.IsNullOrWhiteSpace(x.LocationName)).Select(x => x.LocationName!))
        .Concat(Model.SceneAssetLocations.Where(x => !string.IsNullOrWhiteSpace(x.LocationName)).Select(x => x.LocationName!))
        .Distinct(StringComparer.OrdinalIgnoreCase)
        .ToList();
    var assetNames = Model.AssetEvents.Select(x => x.AssetName).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
}

<article class="scene-inspector-v2-card" data-scene-summary-part="world">
    <div class="scene-inspector-v2-card-header">
        <div>
            <p class="eyebrow">World</p>
            <div class="scene-inspector-v2-heading">
                <h3>Locations and assets</h3>
                <help-icon key="sceneInspector.locations" mode="inline" />
            </div>
        </div>
        <div class="scene-inspector-v2-actions">
            <div class="btn-group scene-inspector-v2-action-menu">
                <button type="button" class="btn btn-sm btn-outline-primary" data-scene-editor="locations" data-scene-id="@Model.SceneID" data-scene-editor-url="@Url.Action("SceneLocationsEditor", "Scenes", new { sceneId = Model.SceneID })">Edit World</button>
                <button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
                    <span class="visually-hidden">Show world editor actions</span>
                </button>
                <div class="dropdown-menu dropdown-menu-end">
                    <button type="button" class="dropdown-item" data-scene-editor="locations" data-scene-id="@Model.SceneID" data-scene-editor-url="@Url.Action("SceneLocationsEditor", "Scenes", new { sceneId = Model.SceneID })">Locations</button>
                    <button type="button" class="dropdown-item" data-scene-editor="assets" data-scene-id="@Model.SceneID" data-scene-editor-url="@Url.Action("SceneAssetsEditor", "Scenes", new { sceneId = Model.SceneID })">Assets</button>
                    <button type="button" class="dropdown-item" data-scene-editor="custody" data-scene-id="@Model.SceneID">Custody</button>
                </div>
            </div>
        </div>
    </div>

    <div class="scene-inspector-v2-section">
        <span>Locations</span>
        @if (!locationNames.Any())
        {
            <p class="muted">No scene locations have been assigned yet.</p>
        }
        else
        {
            <div class="scene-inspector-v2-chip-row">
                @foreach (var location in locationNames.Take(8))
                {
                    <span>@location</span>
                }
            </div>
        }
    </div>

    <div class="scene-inspector-v2-section">
        <span>Assets</span>
        @if (!assetNames.Any())
        {
            <p class="muted">No story assets appear in this scene yet.</p>
        }
        else
        {
            <ul class="scene-inspector-v2-list">
                @foreach (var asset in assetNames.Take(6))
                {
                    <li><strong>@asset</strong></li>
                }
            </ul>
        }
    </div>

    @if (Model.AssetEvents.Any() || Model.AssetCustodyEvents.Any() || Model.SceneAssetLocations.Any())
    {
        <p class="muted">
            @Model.AssetEvents.Count asset event@(Model.AssetEvents.Count == 1 ? "" : "s"),
            @Model.AssetCustodyEvents.Count custody entr@(Model.AssetCustodyEvents.Count == 1 ? "y" : "ies"),
            @Model.SceneAssetLocations.Count placed asset@(Model.SceneAssetLocations.Count == 1 ? "" : "s").
        </p>
    }
</article>
