<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Request;

class ResourcesController extends Controller
{
    public function resources()
    {
        $resouece = Http::post('https://wip.tezcommerce.com:3304/api/v1/module/module-list', [
            "data" => [
                "storeId" => 69,
                "slug" => "resource"
            ]
        ]);
        $resoueceDetails = $resouece->json();

        if (isset($resoueceDetails['errorNode']['errorCode']) && $resoueceDetails['errorNode']['errorCode'] == 0) {
            $headerDetails = $resoueceDetails['data']['details'][0]['moduleItems'][0];
        }
        if (isset($resoueceDetails['errorNode']['errorCode']) && $resoueceDetails['errorNode']['errorCode'] == 0) {
            $knowledgeDetails = $resoueceDetails['data']['details'][0]['moduleItems'][1];
        }
        if (isset($resoueceDetails['errorNode']['errorCode']) && $resoueceDetails['errorNode']['errorCode'] == 0) {
            $veteranDetails = $resoueceDetails['data']['details'][0]['moduleItems'][2];
        }
        if (isset($resoueceDetails['errorNode']['errorCode']) && $resoueceDetails['errorNode']['errorCode'] == 0) {
            $ourExpertDetails = $resoueceDetails['data']['details'][0]['moduleItems'][3];
        }

        $blogList = Http::post('https://wip.tezcommerce.com:3304/api/v1/blogList', [
            "data" => [
                "storeId" => 69,
                "limit" => 3
            ]
        ]);     
        $blogListDetails = $blogList->json();
        
        if (isset($blogListDetails['errorNode']['errorCode']) && $blogListDetails['errorNode']['errorCode'] == 0) {
            $blog_details = $blogListDetails['data']['details'];
        }
        // dd($veteranDetails);
        return view('resource')->with('headerDetails', $headerDetails)->with('knowledgeDetails', $knowledgeDetails)
        ->with('veteranDetails',$veteranDetails)->with('ourExpertDetails', $ourExpertDetails)->with('blog_details',$blog_details);
    }
}
