@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row justify-content-center">
            <div class="offer-container">
                <h3 class="mb-3">My Offers</h3>
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th scope="col">#</th>
                        @if(Auth::user()->type === \App\Enum\UserType::ORGANIZER->value)
                            <th scope="col">To</th>
                        @else
                            <th scope="col">From</th>
                        @endif
                        <th scope="col">Event Name</th>
                        <th scope="col">Status</th>
                        <th scope="col">Price (USD)</th>
                        <th scope="col">Event Date & Start Time</th>
                        <th scope="col">City & Country</th>
                        <th scope="col">Event Type</th>
                        <th scope="col">Options</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($offers as $offer)
                        <tr>
                            <td>{{ $loop->index+1 }}</td>
                            @if(Auth::user()->type === \App\Enum\UserType::ORGANIZER->value)
                                <td>
                                    <a href="/{{ $offer->artist->user->username }}">
                                        {{ $offer->artist->user->name }}
                                    </a>
                                </td>
                            @else
                                <td>{{ $offer->event->organizer->user->name }}</td>
                            @endif
                            <td>{{ $offer->event->title }}</td>
                            @if($offer->status === \App\Enum\OfferStatus::IN_PROGRESS->value)
                                <td><p class="badge bg-warning">In Progress</p></td>
                            @elseif($offer->status === \App\Enum\OfferStatus::COMPLETED->value)
                                <td><p class="badge bg-success">Completed</p></td>
                            @elseif($offer->status === \App\Enum\OfferStatus::DECLINED->value)
                                <td><p class="badge bg-danger">Declined</p></td>
                            @elseif($offer->status === \App\Enum\OfferStatus::WAITING_FOR_PAYMENT->value)
                                <td><p class="badge bg-warning">Waiting for payment</p></td>
                            @endif
                            <td>
                                @if($offer->price != null)
                                    @currency($offer->price)
                                @else
                                    Not yet defined
                                @endif
                            </td>
                            <td>{{ $offer->event->event_date->isoFormat('DD-MMM-Y') . ", " . $offer->event->start_time->isoFormat('H:mm') }}</td>
                            <td>{{ $offer->event->city }}, {{ $offer->event->country }}</td>
                            <td><span class="badge bg-info text-dark">{{ $offer->event->event_type->name }}</span>
                            <td>
                                <a href="/offers/{{ $offer->slug }}">
                                    <button type="button" class="btn btn-primary">Details</button>
                                </a>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>

                <div class="d-flex justify-content-center">
                    {!! $offers->links() !!}
                </div>
            </div>
        </div>
    </div>
@endsection
