@extends('themes::layout')

@php
    $menu = \VsMov\Core\Models\Menu::getTree();

    $tops = Cache::remember('site.movies.tops', setting('site_cache_ttl', 5 * 60), function () {
        $lists = preg_split('/[\n\r]+/', get_theme_option('hotest'));
        $data = [];
        foreach ($lists as $list) {
            if (trim($list)) {
                $list = explode('|', $list);
                [$label, $relation, $field, $val, $sortKey, $alg, $limit, $template] = array_merge($list, ['Phim hot', '', 'type', 'series', 'view_total', 'desc', 4, 'top_thumb']);
                try {
                    $data[] = [
                        'label' => $label,
                        'template' => $template,
                        'data' => \VsMov\Core\Models\Movie::when($relation, function ($query) use ($relation, $field, $val) {
                            $query->whereHas($relation, function ($rel) use ($field, $val) {
                                $rel->where($field, $val);
                            });
                        })
                            ->when(!$relation, function ($query) use ($field, $val) {
                                $query->where($field, $val);
                            })
                            ->orderBy($sortKey, $alg)
                            ->limit($limit)
                            ->get(),
                    ];
                } catch (\Exception $e) {
                    # code
                }
            }
        }

        return $data;
    });
@endphp

@push('header')

    <link href="{{ asset('/themes/dy/templets/css/style.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('/themes/dy/templets/css/aliicon.css') }}" rel="stylesheet" type="text/css">
    <link type="text/css" rel="stylesheet" href="{{ asset('/themes/dy/templets/css/mxhtmlblack.css') }}">
    <link disabled="" class="theme_white" type="text/css" rel="stylesheet" href="{{ asset('/themes/dy/templets/css/white.css') }}">
    <script src="{{ asset('/themes/dy/templets/js/jquery.js') }}"></script>
    <script type="text/javascript" src="{{ asset('/themes/dy/templets/js/jquery.lazyload.js') }}"></script>
    <script src="{{ asset('/themes/dy/templets/js/jquery.autocomplete.js') }}"></script>
    <script src="{{ asset('/themes/dy/templets/js/jquery.cookie.js') }}"></script>
    <script src="{{ asset('/themes/dy/templets/js/home.js') }}"></script>
    <script type="text/javascript" src="{{ asset('/themes/dy/templets/js/jquery.clipboard.js') }}"></script>
    <script type="text/javascript" src="{{ asset('/themes/dy/templets/js/swiper.min.js') }}"></script>
    <script src="{{ asset('/themes/dy/templets/js/script.js') }}"></script>
@endpush

@section('body')
    @include('themes::themedy.inc.nav')
    @if (get_theme_option('ads_header'))
        {!! get_theme_option('ads_header') !!}
    @endif
    @yield('slider_recommended')
    @yield('content')
@endsection

@section('footer')
    {!! get_theme_option('footer') !!}
    @if (get_theme_option('ads_catfish'))
        {!! get_theme_option('ads_catfish') !!}
    @endif
    {!! setting('site_scripts_google_analytics') !!}
@endsection
