@extends('admin.layouts.app')
@section('title','Dealers / Wholesale')
@section('content')
<div class="page-head"><div><h1 class="page-title">Dealers / Wholesale</h1><div class="page-subtitle">Dealer account, reseller pricing and commission</div></div></div>

<form method="POST" action="{{ route('admin.dealers.store') }}" class="card panel-tight grid-4">@csrf<div><label>Name</label><input name="name" required></div><div><label>Code</label><input name="code" required></div><div><label>Phone</label><input name="phone"></div><div><label>Email</label><input name="email"></div><div><label>Address</label><input name="address"></div><div><label>Area</label><input name="area_name"></div><div><label>Type</label><select name="dealer_type"><option>Dealer</option><option>Reseller</option><option>Wholesale</option></select></div><div><label>Status</label><select name="status"><option>Active</option><option>Inactive</option></select></div><div><label>Commission %</label><input type="number" step="0.01" name="commission_percent"></div><div><label>Credit Limit</label><input type="number" step="0.01" name="credit_limit"></div><div><label>Rating</label><input type="number" min="1" max="5" name="rating"></div><div><label>Notes</label><input name="notes"></div><div class="form-actions" style="grid-column:1/-1"><button class="btn primary">Save Dealer</button></div></form>
<div class="card panel-tight table-wrap"><table class="table"><thead><tr><th>Name</th><th>Type</th><th>Area</th><th>Commission</th><th>Status</th><th>Action</th></tr></thead><tbody>@forelse($dealers as $dealer)<tr><td>{{ $dealer->name }}</td><td>{{ $dealer->dealer_type }}</td><td>{{ $dealer->area_name ?: '—' }}</td><td>{{ $dealer->commission_percent }}%</td><td>{{ $dealer->status }}</td><td><a class="btn" href="{{ route('admin.dealers.ledger',$dealer) }}">Ledger</a><details><summary class="btn">Edit</summary><form method="POST" action="{{ route('admin.dealers.update',$dealer) }}" class="grid-3" style="margin-top:10px">@csrf @method('PUT')<div><label>Name</label><input name="name" value="{{ $dealer->name }}"></div><div><label>Code</label><input name="code" value="{{ $dealer->code }}"></div><div><label>Phone</label><input name="phone" value="{{ $dealer->phone }}"></div><div><label>Email</label><input name="email" value="{{ $dealer->email }}"></div><div><label>Address</label><input name="address" value="{{ $dealer->address }}"></div><div><label>Area</label><input name="area_name" value="{{ $dealer->area_name }}"></div><div><label>Type</label><select name="dealer_type">@foreach(['Dealer','Reseller','Wholesale'] as $type)<option value="{{ $type }}" @selected($dealer->dealer_type==$type)>{{ $type }}</option>@endforeach</select></div><div><label>Status</label><select name="status"><option value="Active" @selected($dealer->status=='Active')>Active</option><option value="Inactive" @selected($dealer->status=='Inactive')>Inactive</option></select></div><div><label>Commission</label><input type="number" step="0.01" name="commission_percent" value="{{ $dealer->commission_percent }}"></div><div><label>Credit Limit</label><input type="number" step="0.01" name="credit_limit" value="{{ $dealer->credit_limit }}"></div><div><label>Rating</label><input type="number" min="1" max="5" name="rating" value="{{ $dealer->rating }}"></div><div><label>Notes</label><input name="notes" value="{{ $dealer->notes }}"></div><div class="form-actions" style="grid-column:1/-1"><button class="btn primary">Update</button></div></form></details></td></tr>@empty<tr><td colspan="6">No dealers found.</td></tr>@endforelse</tbody></table>{{ $dealers->links() }}</div>

@endsection
