@extends('layouts.app')

@section('page-title', 'Sales Proposals')

@section('content')
<div class="container-fluid">
    <div class="row mb-3">
        <div class="col-md-6">
            <h3>Sales Proposals</h3>
        </div>
        <div class="col-md-6 text-end">
            <a href="{{ route('quotations.index') }}" class="btn btn-secondary">Back to All</a>
        </div>
    </div>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    <div class="card">
        <div class="card-body">
            <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Date</th>
                        <th>Client</th>
                        <th>Company</th>
                        <th>Total</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($quotations as $quotation)
                        <tr>
                            <td>{{ $quotation->quotation_number }}</td>
                            <td>{{ $quotation->date ? \Illuminate\Support\Carbon::parse($quotation->date)->format('Y-m-d') : '' }}</td>
                            <td>{{ $quotation->bill_to }}</td>
                            <td>{{ $quotation->company_name }}</td>
                            <td>{{ number_format($quotation->total,2) }}</td>
                            <td>
                                <a href="{{ route('quotations.show', $quotation) }}" class="btn btn-sm btn-secondary" target="_blank">Print</a>
                                <a href="{{ route('quotations.edit', $quotation) }}" class="btn btn-sm btn-info">Edit</a>
                                <form action="{{ route('quotations.destroy', $quotation) }}" method="POST" style="display:inline-block;" onsubmit="return confirm('Delete this quotation?');">
                                    @csrf
                                    @method('DELETE')
                                    <button class="btn btn-sm btn-danger">Delete</button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="text-center">No sales proposals found.</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
