@extends('layouts.app')
@section('title', 'Quotations — HIGHRA CRM')
@section('header', 'Quotations')

@section('content')
<div class="row" style="margin-bottom: 20px;">
    <div>
        <h1 style="margin: 0 0 4px 0;">Quotations</h1>
        <p style="color: #8e9ab4; margin: 0;">Create, send and track customer quotations and estimates.</p>
    </div>
    @if(auth()->user()?->hasPermission('quotations.create'))
        <a class="btn" href="{{ route('quotations.create') }}">
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
            + New Quotation
        </a>
    @endif
</div>

<div class="panel" style="margin-top: 0;">
    <div style="overflow-x: auto;">
        <table style="width: 100%;">
            <thead>
                <tr>
                    <th>Quote No.</th>
                    <th>Customer</th>
                    <th>Total (INR)</th>
                    <th>Status</th>
                    <th style="text-align: right;">Action</th>
                </tr>
            </thead>
            <tbody>
                @forelse($quotations as $q)
                    <tr>
                        <td>
                            <strong style="color: #ffffff; font-family: monospace;">{{ $q->quote_no }}</strong>
                        </td>
                        <td>
                            <span style="color: #e2e8f0; font-weight: 600;">{{ $q->customer?->name ?? '—' }}</span>
                            @if($q->customer?->phone)
                                <small style="display: block; color: #8e9ab4;">{{ $q->customer->phone }}</small>
                            @endif
                        </td>
                        <td>
                            <strong style="color: #34d399; font-size: 13.5px;">{{ format_inr($q->total) }}</strong>
                        </td>
                        <td>
                            @php
                                $stClass = match(strtolower($q->status)) {
                                    'accepted', 'won' => 'badge-sales',
                                    'draft' => 'badge-inactive',
                                    'sent' => 'badge-support',
                                    'rejected', 'lost' => 'btn-danger',
                                    default => 'badge-manager'
                                };
                            @endphp
                            <span class="badge {{ $stClass }}">{{ ucfirst($q->status) }}</span>
                        </td>
                        <td style="text-align: right;">
                            <a href="{{ route('quotations.show', $q) }}" class="btn btn-secondary btn-sm">View</a>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="5" style="padding: 40px; text-align: center; color: #64748b;">
                            No quotations found. Click <strong>+ New Quotation</strong> to create one.
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div style="margin-top: 14px;">
        {{ $quotations->links() }}
    </div>
</div>
@endsection
