@model bitforum.Models.Account.MemberGrade
@{
    ViewData["Title"] = "회원등급 수정";
}

<div class="container">
    <h3>@ViewData["Title"]</h3>
    <hr />

    <partial name="_StatusMessage" />

    <form name="f_admin_write" id="fAdminWrite" method="post" accept-charset="utf-8" autocomplete="off" action="/Member/Grade/Update" enctype="multipart/form-data">
        <input type="hidden" asp-for="ID" />

        <div class="row mb-2">
            <label for="Image" class="col-sm-2 col-form-label">이미지</label>
            <div class="col-sm-10">
                @if (Model.Image is not null && Model.Image != string.Empty)
                {
                    <img src="@Url.Content(Model.Image)" class="img-fluid img-thumbnail" alt="@Model.KorName" />
                    <div class="form-check-inline">
                        <input type="checkbox" name="IsImageRemove" id="IsImageRemove" class="form-check-input" value="true" />
                        <label for="IsImageRemove" class="form-check-label">삭제</label>
                    </div>

                    <input type="hidden" asp-for="Image" class="form-control" value="" />
                }
                else
                {
                    <div id="gradePrev" hidden><img class="img-fluid img-thumbnail" alt="이미지 미리보기" /></div>
                    <input type="file" asp-for="Image" class="form-control" accept="image/*" />
                    <span asp-validation-for="Image" class="text-danger"></span>
                }
            </div>
        </div>
        <div class="row mb-2">
            <label for="KorName" class="col-sm-2 col-form-label"><span>*</span> 한글 명</label>
            <div class="col-sm-10">
                <input type="text" asp-for="KorName" class="form-control" required />
                <span asp-validation-for="KorName" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="EngName" class="col-sm-2 col-form-label"><span>*</span> 영문 명</label>
            <div class="col-sm-10">
                <input type="text" asp-for="EngName" class="form-control" required />
                <span asp-validation-for="EngName" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="Description" class="col-sm-2 col-form-label">내용</label>
            <div class="col-sm-10">
                <textarea asp-for="Description" class="form-control" placeholder="최대 1000자" rows="2" maxlength="1000"></textarea>
                <span asp-validation-for="Description" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="Order" class="col-sm-2 col-form-label"><span>*</span> 순서</label>
            <div class="col-sm-10">
                <input type="number" asp-for="Order" class="form-control d-inline w-auto" min="-999" max="999" required />
                <span asp-validation-for="Order" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="RequiredExp" class="col-sm-2"><span>*</span> 최소 요구 경험치<br />(Exp)</label>
            <div class="col-sm-10">
                <input type="number" asp-for="RequiredExp" class="form-control d-inline w-auto" min="0" required />
                <span asp-validation-for="RequiredExp" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="RequiredCoin" class="col-sm-2"><span>*</span> 최소 요구 코인<br />(Coin)</label>
            <div class="col-sm-10">
                <input type="number" asp-for="RequiredCoin" class="form-control d-inline w-auto" min="0" required />
                <span asp-validation-for="RequiredCoin" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="IsActive" class="col-sm-2 col-form-label">사용 여부</label>
            <div class="col-sm-10 align-content-center">
                <div class="form-check-inline">
                    <input type="checkbox" asp-for="IsActive" class="form-check-input" />
                    <label class="form-check-label" for="IsActive">
                        사용합니다.
                    </label>
                    <span asp-validation-for="IsActive" class="text-danger"></span>
                </div>
            </div>
        </div>
        @if (Model.UpdatedAt is not null)
        {
            <div class="row mb-2">
                <label class="col-sm-2 col-form-label">수정일시</label>
                <div class="col-sm-10">
                    <input asp-for="UpdatedAt" class="form-control-plaintext" type="text" readonly />
                </div>
            </div>
        }
        @if (Model.CreatedAt != DateTime.MinValue)
        {
            <div class="row mb-2">
                <label class="col-sm-2 col-form-label">등록일시</label>
                <div class="col-sm-10">
                    <input asp-for="CreatedAt" class="form-control-plaintext" type="text" readonly />
                </div>
            </div>
        }
        <hr />
        <div class="d-grid gap-2 text-center d-md-block">
            <button type="submit" class="btn btn-sm btn-success">저장</button>
            <a asp-action="Index" class="btn btn-sm btn-secondary">취소</a>
        </div>
        <br />
    </form>
</div>

@section Scripts {
    <script>
        setupImagePreview("Image", "gradePrev");

        // 이미지 삭제
        let oldImageSrc = "";
        document.getElementById("isImageRemove").addEventListener("change", function (e) {
            let image = document.getElementById("Image");
            if (e.target.checked) {
                oldImageSrc = image.src;
                image.src = "";
            } else {
                image.src = oldImageSrc;
            }
        });
    </script>
}