@model SceneEditViewModel

<div class="scene-inspector-editor-form">
    <div class="scene-inspector-editor-fields">
        <section class="scene-structure-editor-section">
            <div class="scene-structure-editor-heading">
                <span>Relationship events</span>
                <strong>@Model.RelationshipEvents.Count</strong>
            </div>

            @if (!Model.RelationshipEvents.Any())
            {
                <p class="muted">No relationship events are recorded for this scene yet.</p>
            }
            else
            {
                <div class="scene-structure-editor-list">
                    @foreach (var item in Model.RelationshipEvents)
                    {
                        <article class="scene-structure-editor-card">
                            <div class="scene-structure-card-header">
                                <div>
                                    <h4>@item.CharacterAName -> @item.CharacterBName</h4>
                                    <p>@item.RelationshipTypeName</p>
                                </div>
                                <span class="scene-structure-marker">@item.RelationshipStateName</span>
                            </div>

                            <p class="muted">Intensity @(item.Intensity?.ToString() ?? "not set")@(item.IsKnownToOtherCharacter ? " / known to other character" : "")</p>
                            @if (!string.IsNullOrWhiteSpace(item.Description))
                            {
                                <p>@item.Description</p>
                            }

                            <form asp-controller="Scenes" asp-action="UpdateRelationshipEvent" method="post" class="scene-structure-editor-form" data-scene-editor-form>
                                @Html.AntiForgeryToken()
                                <input type="hidden" name="RelationshipEventID" value="@item.RelationshipEventID" />
                                <input type="hidden" name="SceneID" value="@Model.SceneID" />
                                <input type="hidden" name="ReturnProjectID" value="@Model.ReturnProjectID" />
                                <input type="hidden" name="ReturnBookID" value="@Model.ReturnBookID" />

                                <div class="scene-inspector-editor-error" data-scene-editor-error hidden></div>

                                <div class="form-group">
                                    <label for="RelationshipEvent_@(item.RelationshipEventID)__CharacterRelationshipID">Relationship</label>
                                    <select class="form-control form-control-sm" id="RelationshipEvent_@(item.RelationshipEventID)__CharacterRelationshipID" name="CharacterRelationshipID">
                                        @foreach (var option in Model.RelationshipOptions)
                                        {
                                            <option value="@option.Value" selected="@(option.Value == item.CharacterRelationshipID.ToString())">@option.Text</option>
                                        }
                                    </select>
                                </div>

                                <div class="scene-inspector-editor-grid">
                                    <div class="form-group">
                                        <label for="RelationshipEvent_@(item.RelationshipEventID)__RelationshipStateID">Relationship state</label>
                                        <select class="form-control form-control-sm" id="RelationshipEvent_@(item.RelationshipEventID)__RelationshipStateID" name="RelationshipStateID">
                                            @foreach (var option in Model.RelationshipStateOptions)
                                            {
                                                <option value="@option.Value" selected="@(option.Value == item.RelationshipStateID.ToString())">@option.Text</option>
                                            }
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <label for="RelationshipEvent_@(item.RelationshipEventID)__Intensity">Intensity <output>@(item.Intensity ?? 5)</output></label>
                                        <input class="form-range" id="RelationshipEvent_@(item.RelationshipEventID)__Intensity" name="Intensity" type="range" min="1" max="10" step="1" value="@(item.Intensity ?? 5)" data-scene-metric-range />
                                    </div>
                                </div>

                                <label class="scene-structure-inline-check">
                                    <input type="checkbox" name="IsKnownToOtherCharacter" value="true" checked="@item.IsKnownToOtherCharacter" />
                                    <input type="hidden" name="IsKnownToOtherCharacter" value="false" />
                                    <span>Other character knows</span>
                                </label>

                                <div class="form-group">
                                    <label for="RelationshipEvent_@(item.RelationshipEventID)__Description">Notes</label>
                                    <textarea class="form-control form-control-sm" id="RelationshipEvent_@(item.RelationshipEventID)__Description" name="Description" rows="3">@item.Description</textarea>
                                </div>

                                <div class="scene-structure-action-row">
                                    <button class="btn btn-sm btn-primary" type="submit" data-scene-editor-save>Save relationship</button>
                                </div>
                            </form>

                            <form asp-controller="Scenes" asp-action="DeleteRelationshipEvent" method="post" class="scene-structure-delete-form" data-scene-editor-form>
                                @Html.AntiForgeryToken()
                                <input type="hidden" name="id" value="@item.RelationshipEventID" />
                                <input type="hidden" name="sceneId" value="@Model.SceneID" />
                                <input type="hidden" name="projectId" value="@Model.ReturnProjectID" />
                                <input type="hidden" name="bookId" value="@Model.ReturnBookID" />
                                <div class="scene-inspector-editor-error" data-scene-editor-error hidden></div>
                                <button class="btn btn-sm btn-outline-danger" type="submit" data-scene-editor-save>Remove relationship</button>
                            </form>
                        </article>
                    }
                </div>
            }
        </section>

        <section class="scene-structure-editor-section">
            <div class="scene-structure-editor-heading">
                <span>Add relationship event</span>
            </div>

            <form asp-controller="Scenes" asp-action="AddRelationshipEvent" method="post" class="scene-structure-editor-card scene-structure-editor-form" data-scene-editor-form>
                @Html.AntiForgeryToken()
                <input type="hidden" name="SceneID" value="@Model.SceneID" />
                <input type="hidden" name="ReturnProjectID" value="@Model.ReturnProjectID" />
                <input type="hidden" name="ReturnBookID" value="@Model.ReturnBookID" />

                <div class="scene-inspector-editor-error" data-scene-editor-error hidden></div>

                <div class="form-group">
                    <label for="RelationshipCharacterRelationshipID">Relationship</label>
                    <select class="form-control form-control-sm" id="RelationshipCharacterRelationshipID" name="CharacterRelationshipID" asp-items="Model.RelationshipOptions">
                        <option value="">Create or choose relationship</option>
                    </select>
                </div>

                <div class="scene-inspector-editor-grid">
                    <div class="form-group">
                        <label for="RelationshipCharacterAID">Character A</label>
                        <select class="form-control form-control-sm" id="RelationshipCharacterAID" name="CharacterAID" asp-items="Model.CharacterOptions">
                            <option value="">Character A</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="RelationshipCharacterBID">Character B</label>
                        <select class="form-control form-control-sm" id="RelationshipCharacterBID" name="CharacterBID" asp-items="Model.CharacterOptions">
                            <option value="">Character B</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label for="RelationshipTypeID">Relationship type</label>
                    <select class="form-control form-control-sm" id="RelationshipTypeID" name="RelationshipTypeID" asp-items="Model.RelationshipTypeOptions">
                        <option value="">Relationship type</option>
                    </select>
                </div>

                <div class="scene-inspector-editor-grid">
                    <div class="form-group">
                        <label for="RelationshipStateID">Relationship state</label>
                        <select class="form-control form-control-sm" id="RelationshipStateID" name="RelationshipStateID" asp-items="Model.RelationshipStateOptions"></select>
                    </div>
                    <div class="form-group">
                        <label for="RelationshipIntensity">Intensity <output>5</output></label>
                        <input class="form-range" id="RelationshipIntensity" name="Intensity" type="range" min="1" max="10" step="1" value="5" data-scene-metric-range />
                    </div>
                </div>

                <label class="scene-structure-inline-check">
                    <input type="checkbox" name="IsKnownToOtherCharacter" value="true" />
                    <input type="hidden" name="IsKnownToOtherCharacter" value="false" />
                    <span>Other character knows</span>
                </label>

                <div class="form-group">
                    <label for="RelationshipDescription">Notes</label>
                    <textarea class="form-control form-control-sm" id="RelationshipDescription" name="Description" rows="3" placeholder="Relationship event description"></textarea>
                </div>

                <div class="scene-structure-action-row">
                    <button class="btn btn-sm btn-primary" type="submit" data-scene-editor-save>Add relationship event</button>
                </div>
            </form>
        </section>
    </div>

    <div class="scene-inspector-editor-footer">
        <button type="button" class="btn btn-sm btn-outline-secondary" data-scene-editor-close>Close</button>
    </div>
</div>
