203 lines
11 KiB
Plaintext
203 lines
11 KiB
Plaintext
@page "/admin/npcs/shops/edit"
|
|
@model Npcs.ShopEditModel
|
|
@using System.Text.Json
|
|
@{
|
|
ViewData["Title"] = Model.IsNew ? "Create NPC Shop" : $"Edit Shop: {Model.Shop.Name}";
|
|
var itemCatalog = JsonSerializer.Serialize(Model.ItemDefinitions.Select(i => new
|
|
{
|
|
id = i.Id,
|
|
name = i.Name,
|
|
rarity = i.Rarity.ToString(),
|
|
type = i.Type.ToString(),
|
|
search = ($"{i.Name} {i.Rarity} {i.Type} {i.Id}").ToLowerInvariant()
|
|
}));
|
|
}
|
|
|
|
<div class="space-y-6 max-w-6xl">
|
|
<div class="flex items-center gap-4">
|
|
<a href="/admin/npcs/shops" class="p-2 hover:bg-gray-800 rounded-lg">
|
|
<svg class="w-6 h-6 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
|
|
</svg>
|
|
</a>
|
|
<div>
|
|
<h1 class="text-3xl font-bold text-white">@(Model.IsNew ? "Create NPC Shop" : "Edit NPC Shop")</h1>
|
|
<p class="text-gray-400 mt-1">@(Model.IsNew ? "Create a slot-based shop inventory" : $"ID: {Model.Shop.Id}")</p>
|
|
</div>
|
|
</div>
|
|
|
|
@if (!string.IsNullOrEmpty(Model.Message))
|
|
{
|
|
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-200" : "bg-green-900/50 border border-green-700 text-green-200")">
|
|
@Model.Message
|
|
</div>
|
|
}
|
|
|
|
<form method="post" class="card p-6 space-y-4">
|
|
@Html.AntiForgeryToken()
|
|
<input type="hidden" name="Shop.Id" value="@Model.Shop.Id" />
|
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
<div class="md:col-span-2">
|
|
<label class="label">Shop Name *</label>
|
|
<input type="text" name="Shop.Name" value="@Model.Shop.Name" class="input" maxlength="64" required />
|
|
</div>
|
|
<div class="flex items-center pt-6">
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input type="checkbox" name="Shop.IsEnabled" value="true" checked="@Model.Shop.IsEnabled" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
|
|
<span class="text-gray-300">Enabled</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<div class="flex items-center gap-3">
|
|
<button type="submit" class="btn btn-primary">@(Model.IsNew ? "Create Shop" : "Save Shop")</button>
|
|
<a href="/admin/npcs/shops" class="btn btn-secondary">Back</a>
|
|
</div>
|
|
</form>
|
|
|
|
@if (!Model.IsNew)
|
|
{
|
|
<div class="card overflow-hidden">
|
|
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
|
<h2 class="text-lg font-semibold text-white">Shop Slots (@Model.Items.Count)</h2>
|
|
<button type="button" class="btn btn-primary btn-sm" onclick="openItemModal()">+ Add Slot</button>
|
|
</div>
|
|
<table class="w-full">
|
|
<thead class="bg-gray-900/50">
|
|
<tr>
|
|
<th class="table-header w-20">Slot</th>
|
|
<th class="table-header">Item</th>
|
|
<th class="table-header w-20">Qty</th>
|
|
<th class="table-header w-24">Price</th>
|
|
<th class="table-header w-20">Restock</th>
|
|
<th class="table-header w-24">Interval</th>
|
|
<th class="table-header w-24">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-700">
|
|
@foreach (var i in Model.Items)
|
|
{
|
|
<tr class="hover:bg-gray-700/30">
|
|
<td class="table-cell font-mono text-gray-300">@i.SlotIndex</td>
|
|
<td class="table-cell">
|
|
<div class="text-white">@i.ItemDefinition?.Name</div>
|
|
<div class="text-xs text-gray-500">ID: @i.ItemDefinitionId</div>
|
|
</td>
|
|
<td class="table-cell text-gray-300">@i.Quantity</td>
|
|
<td class="table-cell text-yellow-300">@i.PriceGold</td>
|
|
<td class="table-cell text-gray-300">@(i.Restocks ? "Yes" : "No")</td>
|
|
<td class="table-cell text-gray-300">@i.RestockIntervalSeconds s</td>
|
|
<td class="table-cell">
|
|
<div class="flex gap-2">
|
|
<button type="button" class="btn btn-secondary btn-sm" onclick="openItemModal(@i.SlotIndex, @i.ItemDefinitionId, @i.Quantity, @i.PriceGold, @i.Restocks.ToString().ToLower(), @i.RestockIntervalSeconds)">Edit</button>
|
|
<form method="post" asp-page-handler="DeleteItem" class="inline" onsubmit="return confirm('Delete this slot item?');">
|
|
@Html.AntiForgeryToken()
|
|
<input type="hidden" name="shopId" value="@Model.Shop.Id" />
|
|
<input type="hidden" name="itemId" value="@i.Id" />
|
|
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
}
|
|
@if (!Model.Items.Any())
|
|
{
|
|
<tr>
|
|
<td colspan="7" class="table-cell text-center text-gray-500 py-8">No slot items yet.</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div id="itemModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
|
|
<div class="bg-gray-800 rounded-xl p-6 max-w-2xl w-full mx-4 border border-gray-700">
|
|
<h3 class="text-lg font-semibold text-white mb-4">Upsert Shop Slot</h3>
|
|
<form method="post" asp-page-handler="UpsertItem" class="space-y-4">
|
|
@Html.AntiForgeryToken()
|
|
<input type="hidden" name="shopId" value="@Model.Shop.Id" />
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="label">Slot Index *</label>
|
|
<input id="slotIndex" type="number" name="slotIndex" class="input" min="0" required />
|
|
</div>
|
|
<div>
|
|
<label class="label">Filter Items</label>
|
|
<input id="itemSearch" type="text" class="input" placeholder="Type to filter items..." oninput="filterItems()" />
|
|
</div>
|
|
<div class="md:col-span-2">
|
|
<label class="label">Item *</label>
|
|
<select id="itemDefinitionId" name="itemDefinitionId" class="input" size="10" style="height:auto;" required>
|
|
@foreach (var item in Model.ItemDefinitions)
|
|
{
|
|
<option value="@item.Id" data-search="@($"{item.Name} {item.Rarity} {item.Type} {item.Id}".ToLowerInvariant())">@item.Name (@item.Rarity / @item.Type)</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label class="label">Quantity *</label>
|
|
<input id="quantity" type="number" name="quantity" class="input" min="1" value="1" required />
|
|
</div>
|
|
<div>
|
|
<label class="label">Price (Gold) *</label>
|
|
<input id="priceGold" type="number" name="priceGold" class="input" min="0" value="1" required />
|
|
</div>
|
|
<div>
|
|
<label class="label">Restock Interval (seconds)</label>
|
|
<input id="restockIntervalSeconds" type="number" name="restockIntervalSeconds" class="input" min="1" value="300" />
|
|
</div>
|
|
<div class="flex items-center pt-6">
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input id="restocks" type="checkbox" name="restocks" value="true" checked class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
|
|
<span class="text-gray-300">Restocks</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<div class="flex justify-end gap-3 pt-2">
|
|
<button type="button" class="btn btn-secondary" onclick="closeItemModal()">Cancel</button>
|
|
<button type="submit" class="btn btn-primary">Save Slot</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@section Scripts {
|
|
<script>
|
|
const itemCatalog = @Html.Raw(itemCatalog);
|
|
|
|
function openItemModal(slotIndex, itemId, qty, price, restocks, interval) {
|
|
document.getElementById('slotIndex').value = slotIndex ?? '';
|
|
document.getElementById('itemDefinitionId').value = itemId ?? '';
|
|
document.getElementById('quantity').value = qty ?? 1;
|
|
document.getElementById('priceGold').value = price ?? 1;
|
|
document.getElementById('restocks').checked = (restocks ?? true) === true;
|
|
document.getElementById('restockIntervalSeconds').value = interval ?? 300;
|
|
document.getElementById('itemSearch').value = '';
|
|
filterItems();
|
|
document.getElementById('itemModal').classList.remove('hidden');
|
|
document.getElementById('itemModal').classList.add('flex');
|
|
}
|
|
|
|
function closeItemModal() {
|
|
document.getElementById('itemModal').classList.add('hidden');
|
|
document.getElementById('itemModal').classList.remove('flex');
|
|
}
|
|
|
|
function filterItems() {
|
|
const term = (document.getElementById('itemSearch').value || '').toLowerCase();
|
|
const select = document.getElementById('itemDefinitionId');
|
|
for (let i = 0; i < select.options.length; i++) {
|
|
const opt = select.options[i];
|
|
const text = (opt.dataset.search || opt.text || '').toLowerCase();
|
|
opt.style.display = term === '' || text.includes(term) ? '' : 'none';
|
|
}
|
|
}
|
|
|
|
document.addEventListener('keydown', e => {
|
|
if (e.key === 'Escape') closeItemModal();
|
|
});
|
|
</script>
|
|
}
|
|
|