@extends('layouts.app')

@section('title', 'Customer Statement')

@section('content')
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-md-12">
            <div class="d-flex justify-content-between align-items-center">
                <h2 class="h3 mb-0">Customer Statement</h2>
                <div>
                    <a href="{{ route('customers.show', $customer) }}" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> Back to Customer
                    </a>
                    <button onclick="window.print()" class="btn btn-info">
                        <i class="fas fa-print"></i> Print
                    </button>
                </div>
            </div>
            <p class="text-muted">{{ $customer->name }} ({{ $customer->customer_code }})</p>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Account Statement</h5>
                </div>
                <div class="card-body">
                    <!-- Summary -->
                    <div class="row mb-4">
                        <div class="col-md-3">
                            <div class="card bg-light">
                                <div class="card-body text-center">
                                    <h6 class="text-muted">Outstanding Balance</h6>
                                    <h3 class="text-danger">৳{{ number_format($customer->outstanding_balance, 2) }}</h3>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card bg-light">
                                <div class="card-body text-center">
                                    <h6 class="text-muted">Credit Limit</h6>
                                    <h3 class="text-info">৳{{ number_format($customer->credit_limit, 2) }}</h3>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card bg-light">
                                <div class="card-body text-center">
                                    <h6 class="text-muted">Available Credit</h6>
                                    <h3 class="text-success">
                                        ৳{{ number_format(max(0, $customer->credit_limit - $customer->outstanding_balance), 2) }}
                                    </h3>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card bg-light">
                                <div class="card-body text-center">
                                    <h6 class="text-muted">Customer Type</h6>
                                    <h3>
                                        <span class="badge badge-{{ $customer->customer_type == 'installment' ? 'warning' : 'success' }}">
                                            {{ ucfirst($customer->customer_type) }}
                                        </span>
                                    </h3>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Transaction History (Placeholder) -->
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle"></i>
                        Transaction history will be displayed here once sales and payment modules are integrated.
                    </div>
                    
                    <!-- Placeholder Table -->
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Description</th>
                                    <th>Invoice No</th>
                                    <th class="text-right">Debit (৳)</th>
                                    <th class="text-right">Credit (৳)</th>
                                    <th class="text-right">Balance (৳)</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>{{ date('d M, Y') }}</td>
                                    <td>Opening Balance</td>
                                    <td>-</td>
                                    <td class="text-right">৳{{ number_format($customer->outstanding_balance, 2) }}</td>
                                    <td class="text-right">৳0.00</td>
                                    <td class="text-right">৳{{ number_format($customer->outstanding_balance, 2) }}</td>
                                </tr>
                                <!-- More rows will be added dynamically -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection