{% extends '__layout__.html' %}
{% block title %}Admin{% endblock %}
{% block head %}
<link href="/static/css/admin.css" rel="stylesheet"/> <!-- Its just easier to resuse this-->
{% endblock %}
{% block content %}
<div id="main">
    <div class="container">
        <a href="/admin" class="btn border-primary btn-sm mb-2">Back to Admin Panel</a>
        <h1>Asset Manager</h1>
        {% with messages = get_flashed_messages() %}
        {% if messages %}
        <div>
        {% for message in messages %}
            <div class="alert border border-danger p-2 text-center messagealerts">
                {{ message }}
            </div>
        {% endfor %}
        </div>
        {% endif %}
        {% endwith %}
        <form method="post" class="d-flex" action="/admin/manage-assets">
            <input type="text" name="assetid" class="form-control" placeholder="AssetId" {% if asset: %}value="{{asset.id}}"{%endif%}>
            <input type="hidden" name="csrf_token" value="{{csrf_token()}}">
            <input type="submit" class="btn btn-primary ms-3" value="Search">
        </form>
        {% if asset %}
        <div class="linebreak"></div>
        <form method="post">
            <div class="d-flex align-items-center">
                <a href="/catalog/{{asset.id}}/">< View asset on catalog</a>
                {% if IsItemEligibleForItemReleasePool and CanManageItemReleasePool: %}
                <a href="/admin/manage-assets/{{asset.id}}/insert-item-pool" class="ms-auto text-primary">Insert Item into Item Release Pool</a>
                {% endif %}
            </div>
            <label for="assetnameinput" class="form-label m-0">Asset Name</label>
            <input type="text" name="assetname" id="assetnameinput" class="form-control" placeholder="Name" value="{{asset.name}}">
            <label for="assetdescriptioninput" class="form-label m-0">Asset Description</label>
            <textarea type="text" name="assetdescription" id="assetdescriptioninput" class="form-control" placeholder="Description">{{asset.description}}</textarea>
            <div class="row">
                <div class="col">
                    <label for="assetpricerobuxinput" class="form-label m-0">Robux Price</label>
                    <input type="number" name="assetpricerobux" id="assetpricerobuxinput" class="form-control" placeholder="Robux Price" value="{{asset.price_robux}}">
                </div>
                <div class="col">
                    <label for="assetpricetixinput" class="form-label m-0">Tickets Price</label>
                    <input type="number" name="assetpricetix" id="assetpricetixinput" class="form-control" placeholder="Tix Price" value="{{asset.price_tix}}">
                </div>
            </div>
            <p class="m-0 text-secondary" style="font-size: small;">note: if you want an item to be free both robux and tix prices have to be set to 0</p>
            <div class="linebreak"></div>
            <div class="mt-2">
                <div class="row">
                    <div class="col-6 ms-auto">
                        <div class="form-floating">
                            <input type="datetime-local" name="offsale-at" id="offsale-at" class="form-control" placeholder="Offsale At">
                            <label for="offsale-at" class="form-label m-0">Offsale At</label>
                        </div>
                    </div>
                    <div class="col-2 me-auto">
                        <div class="form-floating">
                            <select name="offsale-timezone" class="form-control">
                                <option value="0">UTC</option>
                                <option value="1">UTC+1</option>
                                <option value="2">UTC+2</option>
                                <option value="3">UTC+3</option>
                                <option value="4">UTC+4</option>
                                <option value="5">UTC+5</option>
                                <option value="6">UTC+6</option>
                                <option value="7">UTC+7</option>
                                <option value="8">UTC+8</option>
                                <option value="9">UTC+9</option>
                                <option value="10">UTC+10</option>
                                <option value="11">UTC+11</option>
                                <option value="12">UTC+12</option>
                                <option value="-1">UTC-1</option>
                                <option value="-2">UTC-2</option>
                                <option value="-3">UTC-3</option>
                                <option value="-4">UTC-4</option>
                                <option value="-5">UTC-5</option>
                                <option value="-6">UTC-6</option>
                                <option value="-7">UTC-7</option>
                                <option value="-8">UTC-8</option>
                                <option value="-9">UTC-9</option>
                                <option value="-10">UTC-10</option>
                                <option value="-11">UTC-11</option>
                                <option value="-12">UTC-12</option>
                            </select>
                            <label for="timezone">Timezone</label>
                        </div>
                    </div>
                </div>
                <p class="text-secondary text-center" style="font-size: 13px;">(UTC) Current offsale time: <span class="text-body">{{asset.offsale_at}}</span> | Note: To remove a offsale date you need to set the item offsale manually</p>
            </div>
            <div class="linebreak"></div>
            <label for="assetserialamount" class="form-label m-0">Serial Amount</label>
            <input type="number" name="assetserialamount" id="assetserialamount" class="form-control" placeholder="Serial Amount" value="{{asset.serial_count}}">
            <div class="row mt-3">
                <div class="col">
                    <input class="form-check-input" name="isForsale" type="checkbox" id="isForsaleCheckbox" {% if asset.is_for_sale: %}checked{% endif %}>
                    <label class="form-check-label" for="isForsaleCheckbox">
                        <p>For Sale</p>
                    </label>
                </div>
                <div class="col">
                    <input class="form-check-input" name="isLimited" type="checkbox" id="isLimitedCheckbox" {% if asset.is_limited: %}checked{% endif %}>
                    <label class="form-check-label" for="isLimitedCheckbox">
                        <p>Limited</p>
                    </label>
                </div>
                <div class="col">
                    <input class="form-check-input" name="isLimitedUnique" type="checkbox" id="isLimitedUniqueCheckbox" {% if asset.is_limited_unique: %}checked{% endif %}>
                    <label class="form-check-label" for="isLimitedUniqueCheckbox">
                        <p>Limited Unique</p>
                    </label>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <p clas="m-0 text-secondary">Created: <span class="text-body">{{asset.created_at}}</span></p>
                </div>
                <div class="col">
                    <p clas="m-0 text-secondary">Updated: <span class="text-body">{{asset.updated_at}}</span></p>
                </div>
                <div class="col">
                    <p clas="m-0 text-secondary">Original Roblox AssetId: <a href="https://www.roblox.com/catalog/{{asset.roblox_asset_id}}/--" target="_blank">{{asset.roblox_asset_id}}</a></p>
                </div>
                <div class="col">
                    <p clas="m-0 text-secondary">AssetType: <span class="text-body">{{asset.asset_type.name}}</span></p>
                </div>
            </div>
            <input type="hidden" name="csrf_token" value="{{csrf_token()}}">
            <input type="submit" class="btn btn-primary mt-1 w-100 btn-sm fw-bold" value="Save">
        </form>
        <form action="/admin/manage-assets/{{asset.id}}/rerender" method="post">
            <input type="hidden" name="csrf_token" value="{{csrf_token()}}">
            <input type="submit" class="btn btn-success mt-4 w-100 btn-sm fw-bold" value="Rerender Asset">
        </form>
        {% endif %}
    </div>
</div>
{% endblock %}