@extends('layouts.site')

@section('meta_title', $item->name . ' | ' . $item->catalog->name)

@section('content')
    @include('partials._catalog.toolbar.toolbar')
    <section class="container mt-2">
        @include('partials._catalog.toolbar.breadcrumbs', [
            'breadcrumbClass' => 'col-xs-12',
            'crumbs' => [
                ['url' => '', 'title' => $item->name]
            ],
            'linkCatalog' => true
        ])
        <div class="row catalog-item-detail-layout">
            <div class="col-xs-12 col-md-3 catalog-filters catalog-layout__sidebar" id="catalog-filters">
                @include('partials._catalog.sidebar')
            </div>
            <div class="col-xs-12 col-sm-12 col-md-9 catalog-layout__content">

                    <div class="panel mb-4 catalog-item-detail-card">
                        <div class="panel-body">
                            <div class="row catalog-item-detail-grid">
                                <div class="col-xs-12 col-sm-8 catalog-item-detail-main">
                                    <div class="mb-2">
                                        <h3 class="m-0">{{ $item->name }}</h3>

                                    @if ($item->isConfigurable())
                                        <h6 class="item__price-container"><strong class="item__price">{{ $item->getTypeInstance()->getPointsRange() }}</strong> {{ __('Catalog::theme.general.points') }}</h6>
                                    @else
                                        <h6 class="item__price-container"><strong class="item__price">{{ $item->getPoints() }}</strong> {{ __('Catalog::theme.general.points') }}</h6>
                                    @endif
                                    </div>
                                    <div class="item__image-container mt-2 mb-2">
                                        <img class="img-responsive item__image--rounded" src="{{ $item->getImageUrl() }}" />
                                        @if ($item->isCardType() && trim($item->class))
                                        <span class="item__image-ribbon">{{ $item->present()->getClass() }}</span>
                                        @endif
                                    </div>
                                    <div class="lead">
                                        {!! $item->getDescription() !!}
                                    </div>
                                    @if ('' !== trim($item->terms))
                                    <div class="catalog-item-terms">
                                        <div class="panel panel-transparent p-0 m-0">
                                            <div class="panel-heading" role="heading">
                                                <h4 class="panel-title">
                                                    <span class="fa-solid fa-circle-info"></span> {{ __('Catalog::theme.general.terms') }}
                                                </h4>
                                            </div>
                                            <div class="panel-body">
                                                <div class="text-block">{!! $item->getTerms() !!}</div>
                                            </div>
                                            @if ('' !== trim($item->disclaimer))
                                                <div class="panel-body">
                                                    <div class="text-block">{!! $item->getDisclaimer() !!}</div>
                                                </div>
                                            @endif
                                        </div>
                                    </div>
                                    @elseif ('' !== trim($item->disclaimer))
                                        <div class="catalog-item-terms">
                                            <div class="panel panel-transparent p-0 m-0">
                                                <div class="panel-body">
                                                    <div class="text-block">{!! $item->getDisclaimer() !!}</div>
                                                </div>
                                            </div>
                                        </div>
                                    @endif
                                </div>
                                <div class="col-xs-12 col-sm-4 catalog-item-detail-purchase">
                                    <form method="post" action="{{ route('catalog.cart.store') }}">
                                        {{ csrf_field() }}
                                        <input type="hidden" id="itemId" name="item_id" value="{{ $item->getKey() }}" />

                                        @if ($item->isConfigurable() && $item->getTypeInstance()->hasOptions())
                                            @foreach ($item->getTypeInstance()->getOptions() as $option)
                                                @php $attribute = $option->first()->attribute; @endphp
                                                <div class="form-group" id="option-{{ $attribute->code }}">
                                                    <label for="option-{{ $attribute->code }}" class="control">{{ $attribute->label }}</label>
                                                    @include("partials._catalog.options." . $attribute->type, [
                                                        'attribute' => $attribute,
                                                        'options' => $option
                                                    ])
                                                </div>
                                            @endforeach
                                        @endif

                                        <div class="form-group">
                                            <label for="quantity" class="control">{{ __('Catalog::theme.general.quantity') }}</label>
                                            <select id="quantity" class="form-control" name="quantity">
                                                @foreach(range(1, 10) as $num)
                                                    <option value="{{ $num }}">{{ $num }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="form-group catalog-item-detail-actions">
                                            @if ($item->isSimple() || ($item->isConfigurable() && $item->getTypeInstance()->hasOptions()))
                                            <button type="submit" class="btn btn-primary btn-block" name="cartType" value="cart">
                                                <span class="fa-solid fa-shopping-cart"></span>
                                                {{ __('Catalog::theme.cart.item.add.label') }}
                                            </button>
                                            @endif
                                            <a href="{{ $item->getFavoriteUrl() }}" class="btn btn-default btn-block">
                                                <span class="text-danger {{ $item->isFavorited() ? 'fa-solid' : 'fa-regular' }} fa-heart"></span>
                                                <small>
                                                @if ($item->isFavorited())
                                                    {{ __('Catalog::theme.favorite.item.remove.label') }}
                                                @else
                                                    {{ __('Catalog::theme.favorite.item.add.label') }}
                                                @endif
                                                </small>
                                            </a>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
            </div>
        </div>
    </section>
@endsection

@section('js')
    @parent
    <script src="{{ asset('/vendor/ignite/js/catalog/catalog.js') }}"></script>
@endsection
