<div class="btn-group" role="group">
    @if($row->status === 'paid')
        <button class="btn btn-sm btn-success" onclick="printPaidInvoice({{ $row->id }})">Print Paid Invoice</button>
    @elseif($row->status === 'pending' || $row->status === 'partial')
        <button class="btn btn-sm btn-warning" onclick="printUnpaidInvoice({{ $row->id }})">Print Unpaid Invoice</button>
    @endif
    <button class="btn btn-sm btn-primary" onclick="editBilling({{ $row->id }})">Edit</button>
    <button class="btn btn-sm btn-danger" onclick="deleteBilling({{ $row->id }})">Delete</button>
</div>

<script>
function printPaidInvoice(id){
    window.location.href = "{{ url('admin/billings/print-paid') }}?ids=" + id;
}
function printUnpaidInvoice(id){
    window.location.href = "{{ url('admin/billings/print-unpaid') }}?ids=" + id;
}
function generateInvoice(id){
    fetch("{{ url('admin/billings') }}/"+id+"/generate",{method:'POST',headers:{'X-CSRF-TOKEN':'{{ csrf_token() }}'}})
    .then(r=>r.json()).then(()=>location.reload());
}
function editBilling(id){
    // open modal via AJAX - left for client implementation
    alert('Open edit modal for '+id);
}
function deleteBilling(id){
    if(!confirm('Delete billing?')) return;
    fetch("{{ url('admin/billings') }}/"+id,{method:'DELETE',headers:{'X-CSRF-TOKEN':'{{ csrf_token() }}'}})
    .then(r=>r.json()).then(()=>location.reload());
}
</script>