@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row justify-content-center">
            <div class="user-details">
                <div class="d-flex justify-content-between mb-2">
                    <h3>{{ $artist->user->name }} | Details</h3>

                    @auth
                        @if(Auth::user()->type === \App\Enum\UserType::ORGANIZER->value)
                            <button class="btn btn-primary d-inline-flex">
                                <a href="/offers/create/{{ $artist->user->username }}" style="color: white">Send
                                    Proposal</a>
                            </button>
                        @endif

                        @if(Auth::user()->type === \App\Enum\UserType::ARTIST->value && Auth::id() === $artist->user->id)
                            <button class="btn btn-primary d-inline-flex">
                                <a href="/{{ Auth::user()->username }}/manager" style="color: white">Manager</a>
                            </button>
                        @endif
                    @endauth
                </div>
                <table class="table">
                    <thead>
                    <tr>
                        <th scope="col">Property</th>
                        <th scope="col">Value</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><strong>Name</strong></td>
                        <td>{{ $artist->user->name }}</td>
                    </tr>
                    <tr>
                        <td><strong>Home City & Country</strong></td>
                        <td>{{ $artist->city }}, {{ $artist->country }}</td>
                    </tr>
                    <tr>
                        <td><strong>Birthdate</strong></td>
                        <td>{{ $artist->birth_date ? $artist->birth_date->isoFormat('Do MMMM Y') : ''}}</td>
                    </tr>
                    <tr>
                        <td><strong>Price Per Hour (USD)</strong></td>
                        <td>
                            @if($artist->price_per_hour != null)
                                @currency($artist->price_per_hour)
                            @else
                                Not yet defined
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <td><strong>Artist Type</strong></td>
                        <td>{{ $artist->artist_type ? $artist->artist_type->name : ''}}</td>
                    </tr>
                    @if(!(is_null($artist->instagram_link) ||
                                is_null($artist->spotify_link) ||
                                is_null($artist->apple_music_link) ||
                                is_null($artist->youtube_link) ||
                                is_null($artist->soundcloud_link)))
                        <tr>
                            <td><strong>Artist is available on</strong></td>
                            <td class="d-flex">
                                @if(!is_null($artist->instagram_link))
                                    <a href="{{ $artist->instagram_link }}" class="badge bg-light text-dark m-1">
                                        Instagram
                                    </a>
                                    <br>
                                @endif

                                @if(!is_null($artist->spotify_link))
                                    <a href="{{ $artist->spotify_link }}" class="badge bg-light text-dark m-1">
                                        Spotify
                                    </a>
                                    <br>
                                @endif

                                @if(!is_null($artist->apple_music_link))
                                    <a href="{{ $artist->apple_music_link }}" class="badge bg-light text-dark m-1">
                                        Apple Music
                                    </a>
                                    <br>
                                @endif

                                @if(!is_null($artist->youtube_link))
                                    <a href="{{ $artist->youtube_link }}" class="badge bg-light text-dark m-1">
                                        YouTube
                                    </a>
                                    <br>
                                @endif

                                @if(!is_null($artist->soundcloud_link))
                                    <a href="{{ $artist->soundcloud_link }}" class="badge bg-light text-dark m-1">
                                        Soundcloud
                                    </a>
                                    <br>
                                @endif
                            </td>
                        </tr>
                    @endif
                    <tr>
                        <td><strong>Genres</strong></td>
                        <td>
                            @foreach($artist->genres as $genre)
                                <p class="badge bg-light text-dark">{{ $genre->name }}</p>
                            @endforeach
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="reviews row justify-content-center mt-5">
            <div class="reviews mb-4">
                <h4 class="mb-2">Reviews</h4>
                <table class="table">
                    <thead>
                    <tr>
                        <th scope="col">Review</th>
                        <th scope="col">Rating</th>
                        <th scope="col">By</th>
                        <th scope="col">Date & Time</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($artist->reviews as $review)
                        <tr>
                            <td>{{ $review->content }}</td>
                            <td><span class="badge bg-info text-dark">{{ $review->rating }}</span></td>
                            <td>{{ $review->organizer->user->name }}</td>
                            <td>{{ $review->created_at->isoFormat('DD-MMM-Y') }}</td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>

            @if ($abilityToPostReview)
                <div class="post-review">
                    <form action="/artists/review" method="POST">
                        @csrf
                        <input type="hidden" name="artist_id" value="{{ $artist->user_id }}">
                        <textarea name="comment" id="" cols="30" rows="5" placeholder="Type your comment..."
                                  class="form-control mb-3 w-100" required></textarea>
                        <input type="radio" name="rating" value="1" class="form-check-input" required>1
                        <input type="radio" name="rating" value="2" class="form-check-input">2
                        <input type="radio" name="rating" value="3" class="form-check-input">3
                        <input type="radio" name="rating" value="4" class="form-check-input">4
                        <input type="radio" name="rating" value="5" class="form-check-input">5
                        <br><br>
                        <button type="submit" class="btn btn-success">Submit</button>
                    </form>
                </div>
            @endif
        </div>

        @if($abilityToSeeAndManageOffers)
            <div class="offers row justify-content-center mt-5">
                <div class="offers mb-4">
                    <h4 class="mb-2">Offers</h4>
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th scope="col">#</th>
                            <th scope="col">From</th>
                            <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>
                                <td>{{ $offer->event->organizer->user->name }}</td>
                                <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>
        @endif
    </div>
@endsection
