@extends('desktop.layouts.app')

@section('content')
<div id="movieView" class="container-fluid" data-mid="{{ $movieCd }}">

    <div class="row g-2 align-items-center">
        <div class="col-auto">
            <span class="badge text-bg-warning fs-6">
                {{ $stats->Rank }}위
            </span>
        </div>
        <div class="col-auto">
            <h5 class="mb-0 fw-bold">
                {{ $info->MovieNm }} @if($info->MovieNmEn) ({{ $info->MovieNmEn }}) @endif
            </h5>
        </div>
        <div class="col-auto">
            {{ $stats->RankInten }}
            @if($stats->RankInten > 0)
                <span class="text-danger">▲</span>
            @else
                <span class="text-primary">▼</span>
            @endif
        </div>
        <div class="col text-end">
            <a href="{{ $listURL }}" class="btn btn-sm btn-default" target="_self">목록으로</a>
        </div>
    </div>
    <hr/>

    <div class="row">
        <div class="col-auto">
            <img src="{{ $detail->MainImg }}" class="img-fluid rounded d-block" width="220px" alt="{{ $info->MovieNm }}" onerror="this.src='/images/default/no_image.png'"/>
            <div class="p-3 text-center">
                <button type="button" id="btnMainImgEnlargement" class="btn btn-default" title="{{ $info->MovieNm }}" value="{{ $detail->MainImg }}">
                    <i class="fa-solid fa-magnifying-glass"></i>
                </button>
            </div>
        </div>
        <div class="col">
            <label class="form-label">주요 정보</label>
            <table class="table table-borderless">
                <colgroup>
                    <col width="100px"/>
                    <col width="*"/>
                </colgroup>
                <tr>
                    <th>감독</th>
                    <td>
                        @if($info->Directors)
                            @foreach(json_decode($info->Directors) as $director)
                                {{ $director->peopleNm }}
                                @if($director->peopleNmEn) ({{ $director->peopleNmEn }}) @endif
                                @if(!$loop->last), @endif
                            @endforeach
                        @else
                            -
                        @endif
                    </td>
                </tr>
                <tr>
                    <th>평점</th>
                    <td class="ps-0">
                        <div class="float-start">
                            <span id="movieAvgRate" data-rate="{{ $avgRate }}"></span>
                        </div>
                        <div class="float-start">
                            <strong>{{ sprintf("%.1f", $avgRate) }}</strong>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>제작연도</th>
                    <td>{{ $info->PrdtYear ?? '-' }}</td>
                </tr>
                <tr>
                    <th>상영시간</th>
                    <td>
                        @if($info->ShowTm)
                            {{ $info->ShowTm }}분
                        @else
                            -
                        @endif
                    </td>
                </tr>
                <tr>
                    <th>개봉일</th>
                    <td>
                        @if($info->OpenDt)
                            {{ (new DateTime($info->OpenDt))->format('Y.m.d') }}
                        @else
                            -
                        @endif
                    </td>
                </tr>
                <tr>
                    <th>유형</th>
                    <td>{{ $info->TypeNm ?? '-' }}</td>
                </tr>
                <tr>
                    <th>장르</th>
                    <td>
                        @if($info->Genres)
                            @foreach(json_decode($info->Genres) as $genre)
                                {{ $genre->genreNm }} @if(!$loop->last), @endif
                            @endforeach
                        @else
                            -
                        @endif
                    </td>
                </tr>
                <tr>
                    <th>심의등급</th>
                    <td>
                        @if($info->Audits)
                            @foreach(json_decode($info->Audits) as $audit)
                               <p class="mb-0">{{ $audit->auditNo }} / {{ $audit->watchGradeNm }}</p>
                            @endforeach
                        @else
                            -
                        @endif
                    </td>
                </tr>
                <tr>
                    <th>누적 관객수</th>
                    <td>
                        {{ number_format($stats->AudiAcc) ?? '0' }}명
                        <small>
                        ({{ $stats->AudiChange }}%)
                        @if($stats->AudiChange > 0)
                            <span class="text-danger">▲</span>
                        @else
                            <span class="text-primary">▼</span>
                        @endif
                        </small>
                    </td>
                </tr>
                <tr>
                    <th>누적 매출액</th>
                    <td>
                        {{ number_format($stats->SalesAcc) ?? '0' }}원
                        <small>
                            ({{ $stats->SalesChange }}%)
                            @if($stats->SalesChange > 0)
                                <span class="text-danger">▲</span>
                            @else
                                <span class="text-primary">▼</span>
                            @endif
                        </small>
                    </td>
                </tr>
            </table>
        </div>
        <div id="movieReviewLatest" class="col-sm-12 col-xl-4 col-xxl-6 border-start">
            <div class="row align-items-center">
                <div class="col-auto">
                    <label class="mb-2">
                        평점·후기 <span class="text-danger">(<span id="movieReviewTotal">0</span>)</span>
                    </label>
                </div>
                <div class="col text-end">
                    <a href="#" id="btnMovieReviewWrite" @auth data-bs-toggle="modal" data-bs-target="#movieReviewWriteModal" @endauth>내 평점 등록</a>
                    <span class="divider"></span>
                    <a href="{{ route('movie.review.show', $movieCd) }}" target="_self">전체보기</a>
                </div>
            </div>

            <!-- 평점/후기 목록 -->
            <div id="movieReviewList"></div>

            <!-- 평점/후기 등록/수정 -->
            @include('desktop.movie.review.write')
        </div>
    </div>
    <hr/>

    @if($detail->Poster)
    <section>
        <h5>포스터</h5>
        <div id="posters" class="swiper">
            <div class="swiper-wrapper">
                @foreach(json_decode($detail->Poster) as $poster)
                <div class="swiper-slide">
                    <a href="{{ $poster->Origin }}" class="d-block" target="_self">
                        <img src="{{ $poster->Thumb }}" alt="Poster_{{ $loop->index }}"/>
                    </a>
                </div>
                @endforeach
            </div>
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
        </div>
    </section>
    <hr/>
    @endif

    @if($detail->StillCut)
    <section>
        <h5>스틸컷</h5>
        <div id="stillCut" class="swiper">
            <div class="swiper-wrapper">
                @foreach(json_decode($detail->StillCut) as $stillCut)
                <div class="swiper-slide">
                    <a href="{{ $stillCut->Origin }}" class="d-block" target="_self">
                        <img src="{{ $stillCut->Thumb }}" alt="StillCut_{{ $loop->index }}"/>
                    </a>
                </div>
                @endforeach
            </div>
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
        </div>
    </section>
    <hr/>
    @endif

    <br/>

    <section class="synopsis">
        <h5>줄거리</h5>
        <blockquote>
            {{ $detail->Synopsis ?? '-' }}
        </blockquote>
    </section>

    <br/>

    <section class="actor">
        <h5>배우</h5>
        <blockquote>
            @if($info->Actors)
                @foreach(json_decode($info->Actors) as $actor)
                    {{ $actor->peopleNm }}@if($actor->peopleNmEn)({{ $actor->peopleNmEn }})@endif
                    @if(!$loop->last), @endif
                @endforeach

            @else
                -
            @endif
        </blockquote>
        <input type="checkbox" class="btn-more-info" hidden/>
    </section>

    <br/>

    <section class="staff">
        <h5>제작진</h5>
        <blockquote>
            @if($info->Staffs)
                @foreach(json_decode($info->Staffs) as $staffs)
                    <dl class="d-inline-block">
                        <dd class="mb-0">{{ $staffs->peopleNm }}@if($staffs->peopleNmEn)({{ $staffs->peopleNmEn }})@endif</dd>
                        <dd>
                            @if($staffs->staffRoleNm)
                                <small class="text-secondary">[{{ $staffs->staffRoleNm }}]</small>
                            @endif
                        </dd>
                    </dl>
                    @if(!$loop->last), @endif
                @endforeach
            @else
                -
            @endif
        </blockquote>
        <input type="checkbox" class="btn-more-info" hidden/>
    </section>

    <br/>

    <section class="company">
        <h5>제작/수입/배급사</h5>
        <blockquote>
            @if($info->Companys)
                @foreach(json_decode($info->Companys) as $company)
                    <p>
                        @if($company->companyPartNm)
                            <strong class="text-muted form-text">[{{ $company->companyPartNm }}]</strong>
                        @endif
                        {{ $company->companyNm }}@if($company->companyNmEn)({{ $company->companyNmEn }})@endif
                    </p>
                @endforeach
            @else
                -
            @endif
        </blockquote>
    </section>

    <br/>

    <section class="nation">
        <h5>제작국가</h5>
        <blockquote>
            @if($info->Nations)
                @foreach(json_decode($info->Nations) as $nation)
                    {{ $nation->nationNm }}
                    @if(!$loop->last), @endif
                @endforeach
            @else
                -
            @endif
        </blockquote>
    </section>
</div>
@endsection

@push('styles')
    <link rel="stylesheet" href="{{ asset('css/desktop/movie/view.css') }}"/>
@endpush

@push('scripts')
    <script src="{{ asset('js/movie/view.js') }}" defer></script>
    <script src="{{ asset('js/movie/review.js') }}" defer></script>
    <script>
        window.addEventListener('DOMContentLoaded', function () {
            Review.init();
            Review.latest();
        });
    </script>
@endpush
