@extends('admin.layouts.app')
@section('title','Branches & Franchise')
@section('content')
<div class="page-head"><div><h1 class="page-title">Branches & Franchise</h1><div class="page-subtitle">Multiple branch setup, HO control and branch users</div></div></div>

<form method="POST" action="{{ route('admin.branches.store') }}" class="card panel-tight grid-3">@csrf
<div><label>Name</label><input name="name" required></div><div><label>Code</label><input name="code" required></div><div><label>Type</label><select name="type"><option>Head Office</option><option>Branch</option><option>Franchise</option><option>Central Warehouse</option></select></div>
<div><label>Address</label><input name="address"></div><div><label>Phone</label><input name="phone"></div><div><label>Email</label><input name="email"></div>
<div><label>Manager</label><input name="manager_name"></div><div><label>Invoice Prefix</label><input name="invoice_prefix"></div><div><label>Status</label><select name="status"><option>Active</option><option>Inactive</option></select></div>
<div><label><input type="checkbox" name="is_head_office" value="1"> Head Office Control</label></div><div><label><input type="checkbox" name="is_central_warehouse" value="1"> Central Warehouse</label></div>
<div class="form-actions" style="grid-column:1/-1"><button class="btn primary">Save Branch</button><a href="{{ route('admin.branches.stocks') }}" class="btn">Branch Stock</a><a href="{{ route('admin.branches.performance') }}" class="btn">Branch Performance</a></div>
</form>
<div class="card panel-tight table-wrap"><table class="table"><thead><tr><th>Name</th><th>Code</th><th>Type</th><th>Invoice Prefix</th><th>Status</th><th>Action</th></tr></thead><tbody>@forelse($branches as $branch)<tr><td>{{ $branch->name }}</td><td>{{ $branch->code }}</td><td>{{ $branch->type }}</td><td>{{ $branch->invoice_prefix ?: '—' }}</td><td>{{ $branch->status }}</td><td><details><summary class="btn">Edit</summary><form method="POST" action="{{ route('admin.branches.update',$branch) }}" class="grid-3" style="margin-top:10px">@csrf @method('PUT')<div><label>Name</label><input name="name" value="{{ $branch->name }}"></div><div><label>Code</label><input name="code" value="{{ $branch->code }}"></div><div><label>Type</label><input name="type" value="{{ $branch->type }}"></div><div><label>Address</label><input name="address" value="{{ $branch->address }}"></div><div><label>Phone</label><input name="phone" value="{{ $branch->phone }}"></div><div><label>Email</label><input name="email" value="{{ $branch->email }}"></div><div><label>Manager</label><input name="manager_name" value="{{ $branch->manager_name }}"></div><div><label>Invoice Prefix</label><input name="invoice_prefix" value="{{ $branch->invoice_prefix }}"></div><div><label>Status</label><select name="status"><option value="Active" @selected($branch->status==='Active')>Active</option><option value="Inactive" @selected($branch->status==='Inactive')>Inactive</option></select></div><div><label><input type="checkbox" name="is_head_office" value="1" @checked($branch->is_head_office)> Head Office</label></div><div><label><input type="checkbox" name="is_central_warehouse" value="1" @checked($branch->is_central_warehouse)> Central Warehouse</label></div><div class="form-actions" style="grid-column:1/-1"><button class="btn primary">Update</button></div></form><form method="POST" action="{{ route('admin.branches.destroy',$branch) }}" style="margin-top:8px">@csrf @method('DELETE')<button class="btn btn-danger" onclick="return confirm('Delete this branch?')">Delete</button></form></details></td></tr>@empty<tr><td colspan="6">No branches found.</td></tr>@endforelse</tbody></table>{{ $branches->links() }}</div>

@endsection
