<?php

namespace App\Http\Controllers\nn_site;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\nn_menu_item;
use App\Models\nn_menu_item_lang;
use App\Models\nn_info;
use App\Models\nn_collection_lang;

class SiteInfosPage extends SiteController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data['items'] = nn_info::getInfoItemsForSite(23);

        $data['infoList'] = \DB::table('nn_info')->where([
            ['nn_info.collection_id', 14],
            ['nn_info_lang.lang', getCurrentLocale()]
        ])
        ->join('nn_info_lang', 'nn_info_lang.info_id', '=', 'nn_info.id')
        ->select(
            'nn_info.id',
            'nn_info.created_at',
            'nn_info_lang.name',
            'nn_info_lang.description'
            )
        ->orderBy('nn_info.position', 'ASC')
        ->orderBy('nn_info.created_at')
        ->get();

        $data['infoBlocks'] = \DB::table('nn_info')->where([
            ['nn_info.collection_id', 15],
            ['nn_info_lang.lang', getCurrentLocale()]
        ])
        ->join('nn_info_lang', 'nn_info_lang.info_id', '=', 'nn_info.id')
        ->select(
            'nn_info.id',
            'nn_info.created_at',
            'nn_info_lang.name',
            'nn_info_lang.imgurl',
            'nn_info_lang.description'
            )
        ->orderBy('nn_info.created_at')
        ->get();

        return view('nn_site.pages.infos', $data);
    }

    /**
     * Display Inner Page.
     *
     * @return \Illuminate\Http\Response
     */
    // public function details($slug, $itemSlug)
    // {
    //     $data['slug'] = $slug;

    //     $nn_menu_item = nn_menu_item::where(['slug' => $data['slug']])->firstOrFail();

    //     $data['pageContent'] = nn_menu_item_lang::where(['nn_menu_item_id' => $nn_menu_item->id, 'lang' => getCurrentLocale()])->firstOrFail();

    //     $data['item'] = nn_info::getInfoItem($itemSlug);

    //     $data['collection'] = nn_collection_lang::where('collection_id', $data['item'][0]->collection_id)
    //                                 ->where('lang', getCurrentLocale())->firstOrFail();

    //     return view('nn_site.pages.info', $data);
    // }
}