@extends('layouts.app')

@section('title', __('renewals.history.title'))

@section('content')
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-1">
                    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">{{ __('dashboard') }}</a></li>
                    <li class="breadcrumb-item"><a href="{{ route('renewals') }}">{{ __('renewals.title') }}</a></li>
                    <li class="breadcrumb-item active" aria-current="page">{{ __('renewal_history') }}</li>
                </ol>
            </nav>
            <h4 class="fw-bold mb-0">{{ __('renewals.history.title') }}</h4>
        </div>
        <a href="{{ url()->previous() }}" class="btn btn-outline-secondary btn-sm">
            <i class="bi bi-arrow-left"></i>
            <span class="ms-1">{{ __('back') }}</span>
        </a>
    </div>

    <div class="card border-0 shadow-sm mb-4">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-lg-4">
                    <div class="text-muted small">{{ __('subscriptions.customer_name') }}</div>
                    <div class="fw-bold">{{ $subscription->customer_name }}</div>
                    <div class="text-muted small">{{ $subscription->phone }}</div>
                </div>
                <div class="col-lg-4">
                    <div class="text-muted small">{{ __('service_type') }}</div>
                    <div class="fw-bold">{{ $subscription->service ? $subscription->service->name : '-' }}</div>
                    <div class="text-muted small">{{ __('invoice_number') }}: {{ $subscription->invoice_number }}</div>
                </div>
                <div class="col-lg-4">
                    <div class="text-muted small">{{ __('renewal_date') }}</div>
                    <div class="fw-bold">
                        {{ $subscription->renewal_due_date ? \Carbon\Carbon::parse($subscription->renewal_due_date)->format('Y-m-d') : '-' }}
                    </div>
                    <div class="text-muted small">{{ __('subscriptions.renewal_amount') }}: {{ number_format((float) ($subscription->renewal_amount ?? 0), 0) }}</div>
                </div>
            </div>
        </div>
    </div>

    <div class="card border-0 shadow-sm">
        <div class="card-header bg-white border-bottom-0 py-3">
            <h6 class="fw-bold m-0">{{ __('renewals.history.title') }}</h6>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="py-3 ps-4">{{ __('invoice_number') }}</th>
                            <th class="py-3">{{ __('renewal_date') }}</th>
                            <th class="py-3">{{ __('amount') }}</th>
                            <th class="py-3">{{ __('subscriptions.payment_method') }}</th>
                            <th class="py-3">{{ __('renewals.renewed_at') }}</th>
                            <th class="py-3">{{ __('renewals.renewed_by') }}</th>
                            <th class="py-3">{{ __('note') }}</th>
                            <th class="py-3 text-end pe-4">{{ __('subscriptions.actions') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($renewals as $renewal)
                            <tr>
                                <td class="ps-4 fw-bold">{{ $renewal->invoice_number }}</td>
                                <td>{{ \Carbon\Carbon::parse($renewal->renewal_date)->format('Y-m-d') }}</td>
                                <td>{{ number_format((float) $renewal->amount, 0) }}</td>
                                <td>
                                    {{ $renewal->payment_method ? __('subscriptions.payment_methods.' . $renewal->payment_method) : '-' }}
                                </td>
                                <td>{{ $renewal->created_at ? $renewal->created_at->format('Y-m-d H:i') : '-' }}</td>
                                <td>{{ $renewal->creator?->name ?? '-' }}</td>
                                <td class="text-muted">{{ $renewal->note ?: '-' }}</td>
                                <td class="text-end pe-4">
                                    <a href="{{ route('customers.renewals.print', $renewal->id) }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="{{ __('print') }}">
                                        <i class="bi bi-printer"></i>
                                    </a>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="8" class="text-center text-muted py-4">{{ __('no_renewals_found') }}</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@endsection
