@using atakanozbancom.Models.classes
@model List<affiliatelink>

@{
    ViewBag.Title = "affiliatelinks";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

<h2 class="text-white mt-3 mb-3">Affiliate Links</h2>
@if (TempData["ok"] != null)
{<div class="alert alert-success">@TempData["ok"]</div>}

<table class="table table-bordered mt-3">
    <tr class="bg-dark text-white">
        <th class="bg-dark text-white">Logo</th>
        <th class="bg-dark text-white">Title</th>
        <th class="bg-dark text-white">Description</th>
        <th class="bg-dark text-white">URL</th>
        <th class="bg-dark text-white">Order</th>
        <th class="bg-dark text-white">Edit</th>
        <th class="bg-dark text-white">Delete</th>
    </tr>
    @foreach (var x in Model)
    {
        <tr>
            <td class="bg-dark text-white"><img src="@x.image" alt="@x.title" style="width:40px;height:40px;object-fit:contain;background:#fff;border-radius:4px;padding:2px;" /></td>
            <td class="bg-dark text-white">@x.title</td>
            <td class="bg-dark text-white">@x.description</td>
            <td class="bg-dark text-white" style="word-break:break-all;">@x.url</td>
            <td class="bg-dark text-white">@x.sort_order</td>
            <td class="bg-dark text-white"><a href="/admin/affiliatelinkget/@x.id" class="btn btn-primary">Edit</a></td>
            <td class="bg-dark text-white">
                @using (Html.BeginForm("affiliatelinkdelete", "admin", new { id = x.id }, FormMethod.Post, new { onsubmit = "return confirm('Delete this affiliate link?');" }))
                {
                    @Html.AntiForgeryToken()
                    <button type="submit" class="btn btn-danger">Delete</button>
                }
            </td>
        </tr>
    }
    @if (!Model.Any())
    {
        <tr>
            <td class="bg-dark text-white-50" colspan="7">No affiliate links yet.</td>
        </tr>
    }
</table>
<a href="/admin/newaffiliatepost" class="btn btn-primary">Create New Affiliate Link</a>
