<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{
    /**
     * @Route("/", name="homepage")
     */
    public function index(Request $request)
    {

        $locale = $request->getLocale();

        $curl = curl_init();
        curl_setopt_array($curl, array(

            CURLOPT_URL => "https://admin.telheirodoinfante.com/api/getContentArticle/our_story/$locale",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => array(
                "cache-control: no-cache"
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        $first_article = json_decode($response);


        $curl2 = curl_init();
        curl_setopt_array($curl2, array(

            CURLOPT_URL => "https://admin.telheirodoinfante.com/api/getContentArticle/our_restorante/$locale",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => array(
                "cache-control: no-cache"
            ),
        ));

        $response2 = curl_exec($curl2);
        $err = curl_error($curl2);

        curl_close($curl2);

        $second_article = json_decode($response2);



        return $this->render('default/index.html.twig', [
            'controller_name' => 'Telheiro do Infante',
            'first_article' => $first_article,
            'second_article' => $second_article,
        ]);
    }
}
