<?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_article;
use App\Models\nn_collection_lang;

class SiteArticlesPage extends SiteController
{
    public function index()
    {
        $data['menuItem'] = nn_menu_item::where(['slug' => 'news'])->firstOrFail();

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

        $data['items'] = nn_article::getArticleItemsForSite($data['menuItem']->id);

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

    public function show($slug)
    {
        $data['menuItem'] = nn_menu_item::where(
            [
                ['nn_menu_item.slug', 'news'],
                ['nn_menu_item_lang.lang', getCurrentLocale()]
            ]
        )
        ->leftJoin('nn_menu_item_lang', 'nn_menu_item_lang.nn_menu_item_id', '=', 'nn_menu_item.id')
        ->select('nn_menu_item.slug', 'nn_menu_item_lang.name')->first();

        $data['item'] = nn_article::getArticleItem($slug);

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

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