@php
    $bodyClass = 'blog-detail';
    $layout_path = 'frontend.layouts.content-sidebar';
    if($post->layout_type == 'blocks') {
        $bodyClass .= ' blog-detail--blocks';
        $layout_path = 'frontend.layouts.main';

        if($post->header_overlap) {
            $bodyClass .= ' header-over';
        }
    }
@endphp

@extends($layout_path, [
    'body_class' => $bodyClass
])

@if($post->layout_type == 'blocks')

    @section('content')
        <div class="blog-detail__content-blocks">
            @include('frontend.templates.components.blocks_section', ['blocks' => $post->blocks])
        </div>
    @stop

@else

    @section('content-top')
        <div class="blog-detail__header" data-controller="pages/blog-detail">
            <div class="blog__control">
                <a href="{{ $backUrl }}" data-action="goBack">@lang('frontend.blog_detail_label')</a>
            </div>
            <h1>@title($post->title)</h1>
            <div class="blog-detail__date-cats">
                <span class="blog-detail__date">{{ format_date($post->date) }}</span>
                @foreach($post->categories as $i => $category)
                    @if($i > 0)
                    |
                    @endif
                    <a href="{{ $redirectPath . '?c=' . $category->id }}">{{ $category->title }}</a>
                @endforeach
            </div>
            <div class="blog-detail__authors">
                @foreach($post->authors as $author)
                <a href="{{ lang_url($author->lang_uri) }}" class="blog-detail__author">
                    <div class="blog-detail__author-image">
                        {!! getMediaImg($author->media, '200x200') !!}
                    </div>
                    <div class="blog-detail__author-info">
                        <div class="blog-detail__author-name">{{ $author->title }}</div>
                        <div class="blog-detail__author-position">{{ $author->position_company }}</div>
                    </div>
                </a>
                @endforeach
            </div>
        </div>
    @stop

    @section('content-toolbar')
        @include('frontend.templates.components.share_buttons')
    @stop

    @section('content-left')
        {!! getMediaImg($post->media, '800w', htmlspecialchars($post->title), 'blog-detail__main-image') !!}
        <div class="blog-detail__content rich-content">
            {!! wpautop($post->content) !!}
            @if($post->type == 'interview')
                <div class="blog-detail__interview">
                    <?php $firstAnswer = [null, true, true, true]; ?>
                    @foreach($post->questions as $question)
                        <div class="blog-detail__question">
                            {{ empty(trim($question->question)) ? $question->title : $question->question  }}
                        </div>
                        <div class="blog-detail__answer">
                            <span class="blog-detail__interviewed">
                                <?php
                                    $abbreviation = abbreviate($question->getInterviewed());
                                    if ($firstAnswer[$question->person * 1]) {
                                        $person = $question->getInterviewed() . " ($abbreviation)";
                                        $firstAnswer[$question->person * 1] = false;
                                    } else {
                                        $person = $abbreviation;
                                    }
                                ?>
                                {{ $person  }}:
                            </span>
                            {!! $question->answer !!}
                        </div>
                    @endforeach
                </div>
            @endif
        </div>
        @if($post->cta_bar_type === 'contact' && $post->ctaBarContact)
            <div class="blog-detail__testimonials-section">
                <div class="blog-detail__testimonials-image">
                    {!! getMediaImg($post->ctaBarContact->image, '200x200') !!}
                </div>
                <div class="blog-detail__testimonials-info">
                    <h2>{{ $post->ctaBarContact->name }}</h2>
                    <span>{{ $post->ctaBarContact->job_position }}</span>
                    <p>“{{ $post->cta_bar_text }}”</p>
                </div>
                <a
                    href="#"
                    class="std-button blog-detail__contact-button std-button--large contact-open"
                    data-name="{{ $post->ctaBarContact->name }}"
                    data-contact="{{ base64_encode(json_encode(["Contact_person" => $post->ctaBarContact->name ])) }}"
                    data-controller="components/form-modal"
                    data-popupid="contact-us-modal">
                    Contact us
                </a>
            </div>
        @endif
        @if($post->cta_bar_type === 'regular')
            <div class="blog-detail__cta-section">
                <div class="blog-detail__cta-info">
                    <h2>{{ $post->cta_bar_title }}</h2>
                    <p>{{ $post->cta_bar_text }}</p>
                </div>
                {!! generateLink($post->cta_bar_cta, 'std-button std-button--large blog-detail__cta-button') !!}
            </div>
        @endif
    @stop

    @section('sidebar-top')
        @if(!isset($post->hide_newsletter) || $post->hide_newsletter == 0)
            <div class="default-sidebar blog-detail__top-sidebar">
                @include('frontend.templates.components.sidebar-widgets.subscribe')
            </div>
        @endif
    @stop

    @section('sidebar-bottom')
        <div class="default-sidebar blog-detail__bottom-sidebar">
            @include('frontend.templates.components.sidebar-widgets.related-posts', ['relatedPosts' => $relatedPosts])
        </div>
    @stop
@endif
