@extends('layouts.app')
@section('title','Parties')
@section('page_title','Parties')
@section('content')
<div class="page-head"><div><h1>Customers, Vendors & Parties</h1><p>One legal entity can carry separate customer and vendor roles and ledgers.</p></div>@if(auth()->user()->hasPermission('parties.create'))<a class="btn btn-primary" href="{{ route('parties.create') }}">+ Add Party</a>@endif</div>
<div class="card"><div class="toolbar"><form class="search"><input class="control" name="search" value="{{ request('search') }}" placeholder="Search name, TRN, phone or email"><select class="control" name="role" style="max-width:180px"><option value="">All roles</option>@foreach(\App\Enums\PartyRoleType::cases() as $role)<option value="{{ $role->value }}" @selected(request('role')===$role->value)>{{ ucwords(str_replace('_',' ',$role->value)) }}</option>@endforeach</select><button class="btn btn-secondary">Filter</button></form><span class="muted">{{ $parties->total() }} parties</span></div>
<div class="table-wrap"><table class="table"><thead><tr><th>Party</th><th>Roles</th><th>TRN</th><th>Contact</th><th>Credit Terms</th><th>Status</th><th>Actions</th></tr></thead><tbody>
@forelse($parties as $party)<tr><td><strong>{{ $party->legal_name }}</strong>@if($party->trade_name)<div class="muted">{{ $party->trade_name }}</div>@endif</td><td>@foreach($party->roles as $role)<span class="badge badge-blue">{{ ucwords(str_replace('_',' ',$role->role->value ?? $role->role)) }}</span> @endforeach</td><td>{{ $party->trn ?: '—' }}</td><td>{{ $party->phone ?: '—' }}<div class="muted">{{ $party->email }}</div></td><td>{{ number_format((float)$party->credit_limit,2) }} / {{ $party->credit_period_days }} days</td><td><span class="badge {{ $party->is_active?'badge-green':'badge-red' }}">{{ $party->is_active?'Active':'Inactive' }}</span></td><td><div class="actions"><a class="btn btn-secondary btn-sm" href="{{ route('parties.show',$party) }}">View</a>@if(auth()->user()->hasPermission('parties.edit_draft'))<a class="btn btn-secondary btn-sm" href="{{ route('parties.edit',$party) }}">Edit</a>@endif</div></td></tr>@empty<tr><td colspan="7" class="empty">No parties found.</td></tr>@endforelse
</tbody></table></div>{{ $parties->links() }}</div>
@endsection
