@extends('layouts.app')

@section('title', $quotation->quotation_number)

@section('content')
    <x-breadcrumbs :items="[
        ['label' => 'Dashboard', 'url' => route('dashboard')],
        ['label' => 'Quotations', 'url' => route('quotations.index')],
        ['label' => $quotation->quotation_number],
    ]" />

    <x-page-header :title="$quotation->quotation_number" subtitle="Quotation v{{ $quotation->version }}">
        <div class="d-flex flex-wrap gap-2">
            @can('issue', $quotation)
                @if (in_array($quotation->status, [\App\Enums\QuotationStatus::Draft, \App\Enums\QuotationStatus::Sent]))
                    <form method="POST" action="{{ route('quotations.issue', $quotation) }}" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-primary btn-sm">Issue</button>
                    </form>
                @endif
            @endcan
            @can('accept', $quotation)
                @if (in_array($quotation->status, [\App\Enums\QuotationStatus::Draft, \App\Enums\QuotationStatus::Sent]))
                    <form method="POST" action="{{ route('quotations.accept', $quotation) }}" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-success btn-sm">Accept</button>
                    </form>
                @endif
            @endcan
            @can('convert', $quotation)
                @if ($quotation->status === \App\Enums\QuotationStatus::Accepted)
                    <form method="POST" action="{{ route('quotations.convert', $quotation) }}" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-success btn-sm">Convert to Invoice</button>
                    </form>
                @endif
            @endcan
            @can('update', $quotation)
                @if ($quotation->isEditable())
                    <a href="{{ route('quotations.edit', $quotation) }}" class="btn btn-outline-primary btn-sm">Edit Draft</a>
                @endif
            @endcan
            @can('delete', $quotation)
                @if ($quotation->isEditable())
                    <form method="POST" action="{{ route('quotations.destroy', $quotation) }}" class="d-inline" onsubmit="return confirm('Delete this draft quotation?');">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn btn-outline-danger btn-sm">Delete Draft</button>
                    </form>
                @endif
            @endcan
            <a href="{{ route('quotations.pdf', $quotation) }}" class="btn btn-primary btn-sm">
                <i class="bi bi-download me-1"></i> Download PDF
            </a>
            <a href="{{ route('quotations.print', $quotation) }}" class="btn btn-outline-secondary btn-sm" target="_blank">Print</a>
        </div>
    </x-page-header>

    <div class="row g-3">
        <div class="col-lg-8">
            @include('partials.document-show-sections', ['document' => $quotation])
        </div>
        <div class="col-lg-4">
            <x-attachments-panel :attachable="$quotation" />
        </div>
    </div>
@endsection
