@extends('layouts.layout-2')

@section('content')
    <h4 class="font-weight-bold py-2 mb-2 d-flex justify-content-between align-items-center w-100 ">
        <div>{{ __('navigation.my_promotions') }} / {{ __('navigation.overview') }}</div>
        <button type="button" class="btn btn-secondary rounded-pill d-block float-right" data-toggle="modal" data-target="#modals-new-user-promotion">
            <span class="ion ion-md-add"></span>&nbsp; Neue Promotion anlegen
        </button>
    </h4>

    <p> Text ...</p>

    <div class="card mb-3">
    <h5 class="card-header bg-white">
        <a href="#" class=""  data-toggle="collapse" data-target="#collapsePromotionFaq" aria-expanded="false" aria-controls="collapsePromotionFaq">
            <i class="fa fa-caret-expand"></i>  {{ __('Und so geht\'s / FAQs') }}
        </a>
    </h5>
    <div class="collapse" id="collapsePromotionFaq">
        <div class="px-4 py-3">
        <p>Text ...</p>
        </div>
    </div>
    </div>
 

    <div class="row">
        <div class="col-12">

            @foreach($values as $value)

            <div class="card mb-4">
                <div class="card-body d-flex justify-content-between align-items-start pb-2">
                    <div>
                        <a href="{{route('user_promotion_detail', [$value->id])}}" class="text-body text-big font-weight-semibold">{{$value->name}}</a>
                    </div>
                    @if($value->canDelete())
                    <div class="btn-group project-actions">
                        <a href="{{ route('user_promotion_delete', [$value->id, 'user_promotion']) }}"
                            class=" dropdown-item" onclick="return confirm('Promotion wirklich löschen?');">
                             <span class="ion ion-md-trash text-danger"></span>
                         </a>
                    </div>
                     @endif
                 </div>
                 <div class="progress rounded-0" style="height: 2px;">
                     <div class="progress-bar" style="width: 100%;"></div>
                 </div>
                <div class="card-body pt-3 pb-1">
                    {{$value->description}}
                    <hr>
                </div>
                <div class="card-body pt-0">
                    <div class="row">
                        <div class="col">
                            <div class="text-muted small">Promotion Produkte</div>
                            <div class="font-weight-bold">{{$value->promotion_admin->promotion_admin_products_active->count()}}
                                {{ formatPlural($value->promotion_admin->promotion_admin_products_active->count(), 'Sorte', 'n') }}
                            </div>
                        </div>
                     
                        <div class="col">
                            <div class="text-muted small">aktive Produkte</div>
                            <div class="font-weight-bold">{{$value->promotion_user_products_active->count()}} 
                                {{ formatPlural($value->promotion_user_products_active->count(), 'Sorte', 'n') }}
                            </div>
                        </div>

                        <div class="col">
                            <div class="text-muted small">geplant Produkte</div>
                            <div class="font-weight-bold">{{$value->getCountOpenItems()}} Stk.</div>
                        </div>
                     
                        <div class="col">
                            <div class="text-muted small">geordert Produkte</div>
                            <div class="font-weight-bold">{{$value->getCountSellItems()}} Stk.</div>
                        </div>

                       
                    </div>
                    <div class="row mt-3">
                        <div class="col">
                            <div class="text-muted small">Promotion aktiv</div>
                            <div class="font-weight-bold">{!! get_active_badge($value->active) !!}</div>
                        </div>

                        <div class="col">
                            <div class="text-muted small">persönliche Abholung</div>
                            <div class="font-weight-bold">{!! get_active_badge($value->pick_up) !!}</div>

                        </div>
                        <div class="col">
                            <div class="text-muted small">Potentielle Kosten</div>
                            @php($user_promotion_cart = $value->calculateCart())
                            <div class="font-weight-bold">{{ formatNumber($user_promotion_cart['price']) }} € brutto</div>
                        </div>
                        <div class="col">
                            <div class="text-muted small">Kosten bisher</div>
                            @php($user_promotion_sell = $value->calculateSell())
                            <div class="font-weight-bold">{{ formatNumber($user_promotion_sell['price']) }} € brutto</div>
                        </div>

                    </div>
                </div>
                <hr class="m-0">
                <div class="card-body py-3">
                    <div class="form-row">
                        <div class="form-group col-10 mb-0">
                            <label  class="form-label">Domain / URL für Deine Promotion</label>
                            <div class="input-group">
                                <span class="input-group-prepend">
                                <button class="btn btn-sm btn-secondary" type="button" title="Kopiert!" data-clipboard-demo data-clipboard-target="#promotion_link_{{$value->id}}"><i class="ion ion-ios-copy"></i> Domain kopieren</button>
                                </span>
                                <input type="text" class="form-control" name="promotion_link_{{$value->id}}" value="{{ $value->getUrlPreview() }}" id="promotion_link_{{$value->id}}" placeholder="">
                            </div>
                        </div>
                        <div class="form-group col-2 mb-0">
                            <label class="form-label">&nbsp;</label>
                            <div>
                                <a class="btn btn-sm btn-outline-primary mt-1"  href="{{ $value->getUrlPreview() }}" target="_blank"><i class="ion ion-ios-share-alt"></i></a>
                            </div>
                        </div>
                    </div>
                        @php($checkPaymentCredit = $value->checkPaymentCredit())
                        @if($checkPaymentCredit === 'empty')
                            <h6 class="alert badge-danger mt-3 py-2">Du hast kein Guthaben aus Deinem Konto auf, lade Dein Konto auf, bis dahin ist die Promotion gestoppt.</h6>
                        @endif
                        @if($checkPaymentCredit === 'okay')
                            <h6 class="alert badge-success mt-3 py-2">Dein Guthaben ist für diese Promotion</h6>
                        @endif
                        @if($checkPaymentCredit === 'not')
                            <h6 class="alert badge-danger mt-3 py-2">Dein Guthaben ist nicht ausreichend für diese Promotion, lade Dein Konto auf, bis dahin ist die Promotion gestoppt.</h6>
                        @endif
                </div>
              
                <hr class="m-0">
                <div class="card-body py-3">
                    <div class="d-flex flex-wrap">
                            <a href="{{route('user_promotion_detail', [$value->id])}}" class="btn btn-secondary mr-2 mb-2"><i class="ion ion-ios-cog"></i> Bearbeiten</a>
                         {{--    
                            <a href="#" class="btn btn-secondary mr-2 mb-2"><i class="ion ion-md-basket"></i> Promotions ansehen (n.b!)</a>
                            <a href="#" class="btn btn-secondary mr-2 mb-2"><i class="ion ion-md-basket"></i> Bestellung ansehen (n.b!)</a>
                             --}}
                    </div>
                </div>
            </div>
            @endforeach
        </div>
    </div>



    <!-- Modal template -->
    <div class="modal fade" id="modals-new-user-promotion">
        <div class="modal-dialog">
            <form class="modal-content" action="{{route('user_promotion_detail', ['new'])}}" method="post">
                @csrf
                <div class="modal-header">
                    <h5 class="modal-title">Neue Promotion anlegen</span></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
                </div>
                <div class="modal-body">
                    <div class="form-row">
                        <div class="form-group col-md-12">
                            <label for="country_ids" class="form-label">Wähle die Art deiner Promotion</label>
                            <select class="selectpicker" name="promotion_admin_id" id="promotion_admin_id"  data-style="btn-light" data-live-search="true" required>                          
                              {!! HTMLHelper::getAnyOptions(null, \App\Models\PromotionAdmin::getActiveAdminPromotionsAsArray(), true) !!}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">{{__('close')}}</button>
                    <button type="submit" class="btn btn-primary" name="action" value="new-user-promotion">{{__('anlegen')}}</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        $( document ).ready(function() {
            $( document ).ready(function() {
                var clipboardDemos = new ClipboardJS('[data-clipboard-demo]');
                clipboardDemos.on('success', function (e) {
                    e.clearSelection();
                    $(e.trigger).tooltip('enable').tooltip('show');
                });
                clipboardDemos.on('error', function (e) {
                    console.error('Action:', e.action);
                    console.error('Trigger:', e.trigger);
                });
    
                $('button[data-clipboard-demo]').on('mouseout', function () {
                    $(this).tooltip('disable');
                })
            });
        });
    </script>
@endsection