<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Modules\Blog\Entities\BlogPosts;

class RenderArquivo extends Controller
{
    public static function estetica()
    {
        setlocale(LC_TIME, 'pt_br');

        $posts = BlogPosts::where('status', true)->orderBy('id', 'desc')->get();
        
        if(count($posts)>0){
        foreach ($posts as $post) {
            $array[$post->created_at->formatLocalized("%Y")][$post->created_at->formatLocalized("%m")][] = $post;
            ksort($array[$post->created_at->formatLocalized("%Y")]);
        }


        $keys = array_keys($array);

        for ($i = 0; $i < count($keys); $i++) {
            $array_final[$i] = $array[$keys[$i]];
            $array_ano[$i] = $keys[$i];
        }

        $array = $array_final;

        $mes_txt = RenderArquivo::meses();
    }else{
        $array=NULL;
        $mes_txt=NULL;
        $array_ano=[];
    }

        return view('paginas.render.arquivo-estetica', ['mes_txt' => $mes_txt, 'posts' => $posts, 'array' => $array, 'array_ano' => $array_ano]);
    }

    public static function atendimento()
    {
        setlocale(LC_TIME, 'pt_br');

        $posts = BlogPosts::where('status', true)->orderBy('id', 'desc')->get();
        
        if(count($posts)>0){
        foreach ($posts as $post) {
            $array[$post->created_at->formatLocalized("%Y")][$post->created_at->formatLocalized("%m")][] = $post;
            ksort($array[$post->created_at->formatLocalized("%Y")]);
        }


        $keys = array_keys($array);

        for ($i = 0; $i < count($keys); $i++) {
            $array_final[$i] = $array[$keys[$i]];
            $array_ano[$i] = $keys[$i];
        }

        $array = $array_final;

        $mes_txt = RenderArquivo::meses();
    }else{
        $array=NULL;
        $mes_txt=NULL;
        $array_ano=[];
    }

        return view('paginas.render.arquivo-atendimento', ['mes_txt' => $mes_txt, 'posts' => $posts, 'array' => $array, 'array_ano' => $array_ano]);
    }

    public static function meses()
    {
        $mes_txt["01"] = "Janeiro";
        $mes_txt["02"] = "Fevereiro";
        $mes_txt["03"] = "Março";
        $mes_txt["04"] = "Abril";
        $mes_txt["05"] = "Maio";
        $mes_txt["06"] = "Junho";
        $mes_txt["07"] = "Julho";
        $mes_txt["08"] = "Agosto";
        $mes_txt["09"] = "Setembro";
        $mes_txt["10"] = "Outubro";
        $mes_txt["11"] = "Novembro";
        $mes_txt["12"] = "Dezembro";

        return $mes_txt;
    }
}
