@extends('shop::layouts.master')

@section('page_title')
    {{ __('shop::app.customer.account.wishlist.page-title') }}
@endsection

@push('css')
    <link rel="stylesheet" href="{{bagisto_asset('styles/categories-tv.css')}}" />
    <link rel="stylesheet" href="{{bagisto_asset('styles/favourites.css')}}" />
@endpush

@section('content-wrapper')

    @inject ('toolbarHelper', 'Webkul\Product\Helpers\Toolbar')

    <svg display="none">
        <symbol id="rows" viewBox="0 0 23 20">
            <g id="View_2_" data-name="View (2)" transform="translate(0 -61)">
                <g id="Сгруппировать_39" data-name="Сгруппировать 39" transform="translate(5.192 61)">
                    <g id="Сгруппировать_38" data-name="Сгруппировать 38" transform="translate(0 0)">
                        <path id="Контур_72" data-name="Контур 72"
                              d="M135.764,61h-13.72a1.8,1.8,0,1,0,0,3.562h13.72a1.8,1.8,0,1,0,0-3.562Z"
                              transform="translate(-120 -61)" />
                    </g>
                </g>
                <g id="Сгруппировать_41" data-name="Сгруппировать 41" transform="translate(5.192 69.219)">
                    <g id="Сгруппировать_40" data-name="Сгруппировать 40" transform="translate(0 0)">
                        <path id="Контур_73" data-name="Контур 73"
                              d="M135.764,211h-13.72a1.8,1.8,0,1,0,0,3.562h13.72a1.8,1.8,0,1,0,0-3.562Z"
                              transform="translate(-120 -211)" />
                    </g>
                </g>
                <g id="Сгруппировать_43" data-name="Сгруппировать 43" transform="translate(5.192 77.438)">
                    <g id="Сгруппировать_42" data-name="Сгруппировать 42">
                        <path id="Контур_74" data-name="Контур 74"
                              d="M135.764,361h-13.72a1.8,1.8,0,1,0,0,3.562h13.72a1.8,1.8,0,1,0,0-3.562Z"
                              transform="translate(-120 -361)" />
                    </g>
                </g>
                <g id="Сгруппировать_45" data-name="Сгруппировать 45" transform="translate(0 61)">
                    <g id="Сгруппировать_44" data-name="Сгруппировать 44" transform="translate(0 0)">
                        <path id="Контур_75" data-name="Контур 75"
                              d="M1.781,61a1.781,1.781,0,1,0,1.781,1.781A1.783,1.783,0,0,0,1.781,61Z"
                              transform="translate(0 -61)" />
                    </g>
                </g>
                <g id="Сгруппировать_47" data-name="Сгруппировать 47" transform="translate(0 69.219)">
                    <g id="Сгруппировать_46" data-name="Сгруппировать 46" transform="translate(0 0)">
                        <path id="Контур_76" data-name="Контур 76"
                              d="M1.781,211a1.781,1.781,0,1,0,1.781,1.781A1.783,1.783,0,0,0,1.781,211Z"
                              transform="translate(0 -211)" />
                    </g>
                </g>
                <g id="Сгруппировать_49" data-name="Сгруппировать 49" transform="translate(0 77.438)">
                    <g id="Сгруппировать_48" data-name="Сгруппировать 48">
                        <path id="Контур_77" data-name="Контур 77"
                              d="M1.781,361a1.781,1.781,0,1,0,1.781,1.781A1.783,1.783,0,0,0,1.781,361Z"
                              transform="translate(0 -361)" />
                    </g>
                </g>
            </g>
        </symbol>
        <symbol id="cubes" viewBox="0 0 20 20">
            <g id="View_1_" data-name="View (1)" transform="translate(-1542 -408)">
                <path id="Контур_68" data-name="Контур 68"
                      d="M5.222-1H1.667A2.666,2.666,0,0,0-1,1.667V5.222A2.666,2.666,0,0,0,1.667,7.889H5.222A2.666,2.666,0,0,0,7.889,5.222V1.667A2.666,2.666,0,0,0,5.222-1Zm.889,6.222a.888.888,0,0,1-.889.889H1.667a.888.888,0,0,1-.889-.889V1.667A.888.888,0,0,1,1.667.778H5.222a.888.888,0,0,1,.889.889V5.222Z"
                      transform="translate(1543 409)" />
                <path id="Контур_69" data-name="Контур 69"
                      d="M5.222-1H1.667A2.666,2.666,0,0,0-1,1.667V5.222A2.666,2.666,0,0,0,1.667,7.889H5.222A2.666,2.666,0,0,0,7.889,5.222V1.667A2.666,2.666,0,0,0,5.222-1Zm.889,6.222a.888.888,0,0,1-.889.889H1.667a.888.888,0,0,1-.889-.889V1.667A.888.888,0,0,1,1.667.778H5.222a.888.888,0,0,1,.889.889V5.222Z"
                      transform="translate(1554.111 409)" />
                <path id="Контур_70" data-name="Контур 70"
                      d="M5.222-1H1.667A2.666,2.666,0,0,0-1,1.667V5.222A2.666,2.666,0,0,0,1.667,7.889H5.222A2.666,2.666,0,0,0,7.889,5.222V1.667A2.666,2.666,0,0,0,5.222-1Zm.889,6.222a.888.888,0,0,1-.889.889H1.667a.888.888,0,0,1-.889-.889V1.667A.888.888,0,0,1,1.667.778H5.222a.888.888,0,0,1,.889.889V5.222Z"
                      transform="translate(1554.111 420.111)" />
                <path id="Контур_71" data-name="Контур 71"
                      d="M5.222-1H1.667A2.666,2.666,0,0,0-1,1.667V5.222A2.666,2.666,0,0,0,1.667,7.889H5.222A2.666,2.666,0,0,0,7.889,5.222V1.667A2.666,2.666,0,0,0,5.222-1Zm.889,6.222a.888.888,0,0,1-.889.889H1.667a.888.888,0,0,1-.889-.889V1.667A.888.888,0,0,1,1.667.778H5.222a.888.888,0,0,1,.889.889V5.222Z"
                      transform="translate(1543 420.111)" />
            </g>
        </symbol>
    </svg>

    <main class="item-section container @if ($items->count()==0) empty @endif ">
        @if ($items->count())
        @include ('shop::products.list.wishlist-toolbar')

        <div class="item-section-wrapper">
            <div class="item-section-products">

                <div class="product-block-wrapper @if ($toolbarHelper->isModeActive('grid')) gridded-view @endif" >
                    @inject ('reviewHelper', 'Webkul\Product\Helpers\Review')
                    @foreach ($items as $item)

                    @php
                        $product = $item->product;
                        $productBaseImage = productimage()->getProductBaseImage($product);
                    @endphp

                        <div class="product-block @if ($toolbarHelper->isModeActive('grid')) cube-view @endif">
                            <div class="product-block-img">
                                <img src="{{ $productBaseImage['medium_image_url'] }}"
                                    onerror="this.src='{{ asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png') }}'"
                                    alt="{{$product->name}}">

                                    <!-- Remove from wishlist -->
                                    <form id="wishlist-{{ $item->id }}" action="{{ route('customer.wishlist.remove', $item->id) }}" method="POST">
                                        @method('DELETE')

                                        @csrf
                                    </form>

                                    <a
                                        class="mb-50"
                                        href="javascript:void(0);"
                                        onclick="document.getElementById('wishlist-{{ $item->id }}').submit();">
                                        <img src="{{bagisto_asset('icons/trash.svg') }}" alt="remove" style="width: 23px; position: absolute;">
                                    </a>
                                    <!-- Remove from wishlist End -->
                            </div>
                            <div class="product-description">
                                <a href="{{ route('shop.productOrCategory.index', $product->url_key) }}" title="{{ $product->name }}" class="product-name">
                                    {{$product->name}}
                                </a>
                                <div class="product-rating">
                                    <div class="product-rating-img">
                                        <img src="{{ bagisto_asset('icons/star.svg') }}" alt="star">
                                    </div>
                                    <span class="product-rating-text">{{ $reviewHelper->getAverageRating($product) }}</span>
                                    <span class="product-rating-feed">{{ $reviewHelper->getTotalReviews($product) }} отзывов</span>
                                </div>

                                @include ('shop::products.list.attributes')
                            </div>
                            <div class="product-buy">
                                <form class='product-buttons-wrapper' action="{{ route('cart.add', $product->product_id) }}" method="POST">
                                    @csrf
                                    <input type="hidden" name="product_id" value="{{ $product->product_id }}">
                                    <input type="hidden" name="quantity" value="1">

                                    <button class="to-cart" {{ $product->isSaleable() ? '' : 'disabled' }}>
                                        <div class="to-cart-img">
                                            <img src="{{ bagisto_asset('icons/icon (cart) 2.svg') }}" alt="cart" />
                                        </div>

                                        <span class="to-cart-text">
                                            {{ ($product->type == 'booking') ?  __('shop::app.products.book-now') :  __('shop::app.products.add-to-cart') }}
                                        </span>
                                    </button>
                                    <button class="one-click">
                                        <span class="one-click-text">Купить в один клик</span>
                                    </button>
                                </form>

                                @include ('shop::products.price', ['product' => $product])
                            </div>
                        </div>
                    @endforeach
                </div>
                @if($items->hasPages())
                    <div class="product-section-pagination">
                        <div class="pagination-buttons">
                            @php
                                //array
                                $requestInputs = request()->input();

                                if(!isset($requestInputs['mode'])) {
                                    $requestInputs['mode'] = $toolbarHelper->isModeActive('list') ? 'list' : 'grid';
                                }

                                //examples
                                //http://.../wishlist?mode=grid
                                //http://.../wishlist?mode=list&page=2
                                //http://.../wishlist?mode=grid&page=1
                            @endphp
                            <form method="get">
                                <a class="pagination-button pagination-button-left" href="{{ $items->appends($requestInputs)->previousPageUrl() }}">
                                    <img src="{{bagisto_asset('icons/arrow-down-sign-to-navigate.svg')}}" alt="left">
                                </a>
                                <span class="mid-button-text">{{ $items->appends($requestInputs)->currentPage() }}</span>
                                <a class="pagination-button pagination-button-right" href="{{ $items->appends($requestInputs)->nextPageUrl() }}">
                                    <div><img src="{{bagisto_asset('icons/arrow-down-sign-to-navigate.svg')}}" alt="right"></div>
                                </a>
                            </form>
                        </div>
                        <span class="page-count">{{__('shop::app.products.total-pages',['total'=>$products->lastPage()])}}</span>
                    </div>
                @endif
            </div>
        </div>
        @else
            <div class="empty_icon">
                <img src="{{bagisto_asset('icons/bookmark.svg')}}" alt="empty">
            </div>
            <h2 class="empty_text">{{ __('shop::app.customer.account.wishlist.empty') }}</h2>


        @endif
    </main>


    <!-- Old wishlist -->
    {{--
    <div class="account-content">
         @include('shop::customers.account.partials.sidemenu')

         @inject ('reviewHelper', 'Webkul\Product\Helpers\Review')

        <div class="account-layout">

            <div class="account-head mb-15">
                <span class="account-heading">{{ __('shop::app.customer.account.wishlist.title') }}</span>



                <div class="horizontal-rule"></div>
            </div>

            {!! view_render_event('bagisto.shop.customers.account.wishlist.list.before', ['wishlist' => $items]) !!}

            <div class="account-items-list">

                @if ($items->count())
                    @foreach ($items as $item)
                        <div class="account-item-card mt-15 mb-15">
                            <div class="media-info">
                                @php
                                    $image = $item->product->getTypeInstance()->getBaseImage($item);
                                @endphp

                                <img class="media" src="{{ $image['small_image_url'] }}" alt="" />

                                <div class="info">
                                    <div class="product-name">
                                        {{ $item->product->name }}

                                        @if (isset($item->additional['attributes']))
                                            <div class="item-options">

                                                @foreach ($item->additional['attributes'] as $attribute)
                                                    <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
                                                @endforeach

                                            </div>
                                        @endif
                                    </div>


                                    <span class="stars" style="display: inline">
                                        @for ($i = 1; $i <= $reviewHelper->getAverageRating($item->product); $i++)
                                            <span class="icon star-icon"></span>
                                        @endfor
                                    </span>

                                </div>
                            </div>

                            <div class="operations">


                                <a href="{{ route('customer.wishlist.move', $item->id) }}" class="btn btn-primary btn-md">
                                    {{ __('shop::app.customer.account.wishlist.move-to-cart') }}
                                </a>
                            </div>
                        </div>

                        <div class="horizontal-rule mb-10 mt-10"></div>
                    @endforeach

                    <div class="bottom-toolbar">
                        {{ $items->links()  }}
                    </div>
                @else
                    <div class="empty">
                        {{ __('customer::app.wishlist.empty') }}
                    </div>
                @endif
            </div>

            {!! view_render_event('bagisto.shop.customers.account.wishlist.list.after', ['wishlist' => $items]) !!}

        </div>
    </div>
    --}}
    <!-- Old wishlist End -->
@endsection