<?php

namespace App\Http\Controllers\Web\Seller;

use App\Http\Controllers\Controller;
use App\Models\Ecommerce\Channel\Channel;
use App\Repositories\Ecommerce\Product\ProductRepository;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class EntrepreneurController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        return view('web.themes.shella.pages.entrepreneurs.home.index', [
            'channels' => Channel::where('is_visible', true)->get(),
        ]);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show(Request $request, $entrepreneur)
    {
        $channel = Channel::where('slug', $entrepreneur)->where('is_visible', true)->firstOrFail();

        $products = ProductRepository::make($request)
            ->queryAsFromResource($channel)
            ->applyBasicQueries()
            ->applyFilters()
            ->applySorting()
            ->simplePaginate();

        return $request->ajax()
                    ? ProductRepository::ajaxPaginate($products)
                    : view('web.themes.shella.pages.entrepreneurs.home.products', [
                        'resource' => $channel,
                        'products' => $products,
                    ]);
    }
}
