@page
@model MyPage.ChargeCash.IndexModel
@using Microsoft.AspNetCore.Http
@using JtkMainServer.Managers
@{
    ViewData["Title"] = "충전";
    var loggedInUserId = HttpContext.Session.GetString("LoggedInUserId");
    ViewData["LoggedIn"] = loggedInUserId != null;
    ViewData["ActivatedTabIndex"] = 1;

    var userChargeLogs = DbManager.GetUserChargeLogs(loggedInUserId);
}


<div class="row" style="margin-top:20px">
    <div class="col-md-6">
        @Html.Partial("~/Views/MyPageTabs.cshtml")
        <h3>현재 잔액</h3>
        <h2 style="text-align:right">￦@((ViewData["UserTotalCash"] as double?).Value.ToString("N0"))</h2>
        <hr />
        <h3 style="margin-bottom:20px">충전</h3>
        <form method="post" id="form">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="ChargeCash.Amount" class="control-label"></label>
                <input asp-for="ChargeCash.Amount" class="form-control" min="1000" max="100000" step="1000" value="1000" type="number" />
                <span asp-validation-for="ChargeCash.Amount" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="ChargeCash.CardNumber" class="control-label"></label>
                <input asp-for="ChargeCash.CardNumber" class="form-control" type="text" />
                <span asp-validation-for="ChargeCash.CardNumber" class="text-danger"></span>
            </div>
            <div class="form-group" style="width:50%; margin-bottom:0px; display:inline-block">
                <label asp-for="ChargeCash.ValidMonth" class="control-label"></label>
                <input asp-for="ChargeCash.ValidMonth" class="form-control" type="month" />
            </div>
            <div class="form-group" style="width:20%; margin-bottom:0px; display:inline-block">
                <label asp-for="ChargeCash.SecurityNumber" class="control-label"></label><abbr title="카드 뒷면의 숫자 중 오른쪽 끝의 세 자리 입니다.">ⓘ</abbr>
                <input asp-for="ChargeCash.SecurityNumber" class="form-control" type="text" />
            </div>
            <br />
            <span asp-validation-for="ChargeCash.ValidMonth" class="text-danger"></span>
            <span asp-validation-for="ChargeCash.SecurityNumber" class="text-danger"></span>

            <br />
            <div class="form-group">
                <span class="text-success">@Model.Message</span>
            </div>
            <div class="form-group" style="text-align:right">
                <a href="javascript:document.getElementById('form').reset()" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> 다시 입력</a>
                <a href="javascript:document.getElementById('form').submit()" class="btn btn-warning"><span class="glyphicon glyphicon-shopping-cart"></span> 결제</a>
                <input type="submit" hidden="hidden" />
                @*<input type="reset" value="다시 입력" class="btn btn-default" />
        <input type="submit" value="결제" class="btn btn-warning" />*@
            </div>
        </form>

        <hr />
        <h3>충전 내역</h3>
        <table class="table">
            <thead>
                <tr>
                    <th>일시</th>
                    <th>충전금액</th>
                    <th>잔액</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var tuple in userChargeLogs) {
                    <tr>
                        <td>@tuple.chargedTime.ToString("yyyy-MM-dd HH:mm")</td>
                        <td>￦@tuple.chargedCash.ToString("N0")</td>
                        <td>￦@tuple.totalCash.ToString("N0")</td>
                    </tr>
                }
            </tbody>
        </table>
        @if (userChargeLogs?.Length == 0) {
            <center>이용 내역이 없습니다.</center>
        }
        <hr />
    </div>
</div>
<div>
    <a asp-page="Index">홈으로 이동</a>
</div>
@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
