<?php

namespace TPS\Shop\Http\Controllers;


use TPS\Shop\Repositories\WishlistRepository;
use Webkul\Customer\Http\Controllers\WishlistController as WController;
use Webkul\Product\Repositories\ProductRepository;

class WishlistController extends WController
{
    public function __construct(
        WishlistRepository $wishlistRepository,
        protected ProductRepository $productRepository
    )
    {
        $this->_config = request('_config');

        $this->currentCustomer = auth()->guard('customer')->user();

        $this->wishlistRepository = $wishlistRepository;
    }

    /**
     * Displays the listing resources if the customer having items in wishlist.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        if (! core()->getConfigData('general.content.shop.wishlist_option')) {
            abort(404);
        }

        return view($this->_config['view'], [
            'items' => $this->wishlistRepository->getCustomerWishlist(),
            'isSharingEnabled' => $this->isSharingEnabled(),
            'isWishlistShared' => $this->currentCustomer->isWishlistShared(),
            'wishlistSharedLink' => $this->currentCustomer->getWishlistSharedLink()
        ]);
    }
}