@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>Character attribute events</span>
                <strong>@Model.CharacterAttributeEvents.Count</strong>
            </div>

            @if (!Model.CharacterAttributeEvents.Any())
            {
                <p class="muted">No character attribute events are recorded for this scene yet.</p>
            }
            else
            {
                <div class="scene-structure-editor-list">
                    @foreach (var item in Model.CharacterAttributeEvents)
                    {
                        <article class="scene-structure-editor-card">
                            <div class="scene-structure-card-header">
                                <div>
                                    <h4>@item.CharacterName</h4>
                                    <p>@item.AttributeName</p>
                                </div>
                                <span class="scene-structure-marker">@item.AttributeValue</span>
                            </div>

                            @if (!string.IsNullOrWhiteSpace(item.Description))
                            {
                                <p>@item.Description</p>
                            }

                            <form asp-controller="Scenes" asp-action="UpdateCharacterAttributeEvent" method="post" class="scene-structure-editor-form" data-scene-editor-form>
                                @Html.AntiForgeryToken()
                                <input type="hidden" name="CharacterAttributeEventID" value="@item.CharacterAttributeEventID" />
                                <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="AttributeEvent_@(item.CharacterAttributeEventID)__CharacterID">Character</label>
                                    <select class="form-control form-control-sm" id="AttributeEvent_@(item.CharacterAttributeEventID)__CharacterID" name="CharacterID">
                                        @foreach (var option in Model.CharacterOptions)
                                        {
                                            <option value="@option.Value" selected="@(option.Value == item.CharacterID.ToString())">@option.Text</option>
                                        }
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label for="AttributeEvent_@(item.CharacterAttributeEventID)__CharacterAttributeTypeID">Attribute type</label>
                                    <select class="form-control form-control-sm" id="AttributeEvent_@(item.CharacterAttributeEventID)__CharacterAttributeTypeID" name="CharacterAttributeTypeID">
                                        @foreach (var option in Model.CharacterAttributeTypeOptions)
                                        {
                                            <option value="@option.Value" selected="@(option.Value == item.CharacterAttributeTypeID.ToString())">@option.Text</option>
                                        }
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label for="AttributeEvent_@(item.CharacterAttributeEventID)__AttributeValue">Attribute value</label>
                                    <input class="form-control form-control-sm" id="AttributeEvent_@(item.CharacterAttributeEventID)__AttributeValue" name="AttributeValue" value="@item.AttributeValue" maxlength="500" />
                                </div>

                                <div class="form-group">
                                    <label for="AttributeEvent_@(item.CharacterAttributeEventID)__Description">Description</label>
                                    <textarea class="form-control form-control-sm" id="AttributeEvent_@(item.CharacterAttributeEventID)__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 attribute</button>
                                </div>
                            </form>
                        </article>
                    }
                </div>
            }
        </section>

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

            <form asp-controller="Scenes" asp-action="AddCharacterAttributeEvent" 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="AttributeCharacterID">Character</label>
                    <select class="form-control form-control-sm" id="AttributeCharacterID" name="CharacterID" asp-items="Model.CharacterOptions"></select>
                </div>

                <div class="form-group">
                    <label for="AttributeTypeID">Attribute type</label>
                    <select class="form-control form-control-sm" id="AttributeTypeID" name="CharacterAttributeTypeID" asp-items="Model.CharacterAttributeTypeOptions"></select>
                </div>

                <div class="form-group">
                    <label for="AttributeValue">Attribute value</label>
                    <input class="form-control form-control-sm" id="AttributeValue" name="AttributeValue" maxlength="500" placeholder="Value, e.g. Bruised ribs" />
                </div>

                <div class="form-group">
                    <label for="AttributeDescription">Description</label>
                    <textarea class="form-control form-control-sm" id="AttributeDescription" name="Description" rows="3" placeholder="Scene-specific context"></textarea>
                </div>

                <div class="scene-structure-action-row">
                    <button class="btn btn-sm btn-primary" type="submit" data-scene-editor-save>Add attribute</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>
