<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SupportEcosystemPartnersController extends Controller
{
    public function index(Request $request)
    {
        $catalogId = $request->get('cid');
        $catalogId = (!$catalogId || $catalogId < 1) ? 0 : $catalogId;
        $appclitionId = $request->get('aid');
        $appclitionId = (!$appclitionId || $appclitionId < 1) ? 0 : $appclitionId;
        $perPageItems = 20;
        $page = $request->get("p");
        $page = (!$page || $page < 1) ? 1 : $page;
        $pageOffset = $perPageItems * ($page - 1);

        $catalogRows = \App\Models\SupportEcosystemPartnerCatalog::where('is_front_show', '=', true)
            ->orderBy('lft', 'asc')
            ->orderBy('id', 'desc')
            ->select('id', 'name');

        $dataRows = \App\Models\SupportEcosystemPartner::where('support_ecosystem_partner_catalog_id', '=', $catalogId)
            ->where('is_front_show', '=', true)
            ->orderBy('title', 'desc')
            ->select('id', 'title', 'description', 'photos', 'website');

        return view('support-ecosystem-partners', [
            'catalogRows' => $catalogRows->get(),
            'catalogCurrentId' => $catalogId,
            'dataRows' => $dataRows->skip($pageOffset)->take($perPageItems)->get(),
            'dataCurrentPage' => $page,
            'dataPerPageItems' => $perPageItems,
            'dataTotalCount' => $dataRows->count()
        ]);

    }
}
