@model RelationshipEvolutionViewModel
@{
    ViewData["Title"] = "Relationship Evolution";
    var maxIndex = Math.Max(Model.Events.Any() ? Model.Events.Max(x => x.GlobalSceneIndex) : 1, 1);
}

<div class="page-heading">
    <div>
        <p class="eyebrow">Relationship Evolution</p>
        <h1>@Model.Relationship.CharacterAName -> @Model.Relationship.CharacterBName</h1>
        <p class="lead-text">@Model.Relationship.RelationshipTypeName</p>
    </div>
    <a class="btn btn-outline-secondary" asp-controller="Timeline" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID" asp-route-FocusType="relationship" asp-route-FocusID="@Model.Relationship.CharacterRelationshipID">Show on timeline</a>
</div>

<section class="story-bible-section">
    <div class="dynamics-timeline relationship">
        @foreach (var item in Model.Events)
        {
            var left = (item.GlobalSceneIndex - 1) * 100m / maxIndex;
            <a class="dynamics-marker" style="left:@left%" title="@item.RelationshipStateName @item.Intensity" asp-controller="Scenes" asp-action="Edit" asp-route-id="@item.SceneID">
                <span style="height:@Math.Max(item.Intensity ?? 3, 1)0%"></span>
            </a>
        }
    </div>
</section>

<partial name="_DynamicsIssues" model="Model.Issues" />

<section class="story-bible-section">
    <h2>Relationship History</h2>
    <div class="writer-queue-list">
        @foreach (var item in Model.Events)
        {
            <article class="writer-queue-card">
                <div class="writer-queue-title">
                    <h3>@item.BookTitle / Ch @item.ChapterNumber / Scene @item.SceneNumber: @item.SceneTitle</h3>
                    <span class="status-pill">@item.RelationshipStateName</span>
                </div>
                <div class="story-bible-meta">
                    <span>Intensity @DisplayValue(item.Intensity)</span>
                    <span>@(item.IsKnownToOtherCharacter ? "Known to other character" : "Private/uncertain")</span>
                </div>
                <p>@item.Description</p>
            </article>
        }
    </div>
</section>

@functions {
    private static string DisplayValue(int? value) => value?.ToString() ?? "-";
}
