@extends('layouts.nova')

@section('content')
@php
    $sanitizeHtml = fn (?string $value) => \App\Services\ContentSanitizer::sanitizeRenderedHtml($value ?? '');
@endphp
<div class="container-fluid legacy-page">
    <div class="effect2 page-header-wrap">
        <header class="page-heading">
            <h1 class="page-header">Interview</h1>
            <p>{{ $ar->headline ?? '' }}</p>
            <div style="location_bar">
                <a href="/interviews" class="btn btn-xs btn-default" title="List of all Interviews"><i class="fa fa-list fa-fw"></i> Interviews List</a>
            </div>
        </header>
    </div>

    <div class="row">
        <div class="col-md-9">
            <div class="panel panel-default">
                <div class="panel-body">
                    <h1 class="skinTitle">{{ $ar->headline }}</h1>
                    <div>{!! $sanitizeHtml($ar->tekst) !!}</div>
                </div>
            </div>

            <h2 class="skinTitle">User Comments</h2>

            @foreach($comments as $comment)
                @php
                    $local_date = date('j.F.y @ H:i:s', strtotime($comment->datum));
                    $user_id = $comment->user_id ?? null;
                @endphp
                <table width="100%" cellspacing="1" cellpadding="1" class="MojText" border="0" style="background:#eee;">
                    <tr>
                        <td rowspan="3" valign="top" width="100" style="background:#fff">
                            @if(!empty($comment->user_id) && !empty($comment->icon))
                                <div align="center"><a href="/profile/{{ $comment->user_id }}"><img src="{{ \App\Support\AvatarUrl::forUser((int) $comment->user_id, null, 50) }}" width="50" height="50" border="0" alt="" /></a></div>
                            @endif
                            <br/>Posted by: <b><a href="/profile/{{ $comment->user_id ?? '' }}">{{ $comment->author }}</a></b><br/>
                            Posts: {{ $postCounts[$comment->author] ?? 0 }}
                            <div align="center"><img src="/gfx/member_stars/{{ $comment->user_type ?? 0 }}.jpg" title="" /></div>
                        </td>
                        <td valign="top" height="10" style="background:#eee">&nbsp;{{ $local_date }}</td>
                    </tr>
                    <tr>
                        <td height="50" style="background:#fff;padding-left:13px; padding-right:3px;">{!! $sanitizeHtml($comment->tekst) !!}</td>
                    </tr>
                    <tr>
                        <td valign="bottom" align="center" height="10" style="background:#fff;">
                            @if(!empty($comment->signature))
                                {!! nl2br(e($comment->signature)) !!}
                            @endif
                        </td>
                    </tr>
                </table>
                <br />
            @endforeach

            @php
                $status = $_SESSION['web_login']['status'] ?? false;
                $user_type = $_SESSION['web_login']['user_type'] ?? 0;
            @endphp

            @if(!$status || $user_type < 2)
                <h1>Please login first</h1>
            @else
                <h2 class="skinTitle">Write comment</h2>
                <form action="{{ url()->current() }}" method="post">
                    @csrf
                    <textarea name="comment" style="width:98%; height:215px;" class="textarea"></textarea><br />
                    <input type="hidden" name="interview_id" value="{{ $ar->id }}">
                    <input type="hidden" name="action" value="store">
                    <button type="submit" class="btn btn-success">Submit</button>
                </form>
            @endif
        </div>

        <div class="col-md-3">
            <div style="margin-left:4px; float:right;width:300px;border-left :dotted 1px #eee; padding-left:10px;">
                <br/><br/>
                @php \App\Banner::ShowBanner300x250(); @endphp
                <br/><br/>

                @if(!empty($ar->username))
                    @php $username = DB::table('users')->where('uname', $ar->username)->value('uname'); @endphp
                    <div class="interviewGuy">{{ $username }} Gallery (random order):</div><br/>
                    @foreach($artworks as $artwork)
                        @php $nid = (int)($artwork->id / 100); @endphp
                        <a href="/art/{{ $artwork->id }}/{{ \Illuminate\Support\Str::slug($artwork->name ?? '') }}">
                            <img src="/files/archive/shots/{{ $nid }}/{{ $artwork->picture }}" alt="" style="max-width:100%;" />
                        </a>
                        <br/><br/>
                    @endforeach
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
