@extends('layouts.layout-2')

@section('content')

    <style>
        .table-small {
            font-size: 0.9em;
            width: auto;
        }

        .table-small td {
            padding: 0.225rem 1rem 0.225rem 0;
        }

        .btn-md-extra {
            padding: 0.3rem 0.6rem;
            font-size: 0.8rem;
            line-height: 1.5;
            border-radius: 0.25rem;
        }
        .md-btn-extra {
            width: calc(1.7rem + 2px) !important;
            line-height: 1.5rem;
        }
        .form-control.input-extra {
            padding: 0.28rem 0.6rem;
            font-size: 0.8rem;
            font-weight: 500;
            min-height: calc(1.8rem + 2px);
            height: calc(1.8rem + 2px);
            width: 44px;
        }
        .input-group-min-w {
            min-width: 102px;
        }
        .img-extra {
            min-width:55px;
            max-height: 120px;
        }

        .table td.border-top {
            border: none;
            border-top: 1px solid #ccccdb;
        }

        .table td {
            border: none;
        }

        .table th {
            border: none;
            border-bottom: 1px solid #c3c3d2;
        }

        @media (max-width: 767px) {
            .default-style:not([dir=rtl]) div.card-datatable table.dataTable thead th:first-child,
            .default-style:not([dir=rtl]) div.card-datatable table.dataTable tbody td:first-child,
            .default-style:not([dir=rtl]) div.card-datatable table.dataTable tfoot th:first-child {
                padding-left: 0.6rem !important;

            }
            .img-extra {
                min-width:35px;
                max-height: 160px;
            }
        }
        .table .foot-small td {
            padding: 0.225rem 0.625rem;
        }
        .table .text-body {
            font-size: 0.9em;
        }
        .table .options a.auto-delete-product {
            font-size: 0.7em;
            font-weight: bold;
            text-transform: uppercase;
        }
        .table .min-width-80 {
            min-width: 160px;
        }
    </style>
    <h4 class="font-weight-bold py-2 mb-2 d-flex justify-content-between align-items-center w-100 ">
        <div>{{ __('navigation.my_homeparty') }} / {{ $homeparty->name }} - {{ $homeparty->date }}</div>
        <a href="{{route('user_homepartys')}}" class="btn btn-sm btn-default float-right">zurück</a>
    </h4>

    @if($userHistoryPaymentOrder && $userHistoryPaymentOrder->status > 2)
        <h6 class="alert badge-{{$userHistoryPaymentOrder->getStatusColor()}}">Eine Zahlung wurde ausgeführt. Status: {{ trans('payment.status.'.$userHistoryPaymentOrder->getStatusType())}}</h6>
    @endif

    {!! Form::open(['url' => route('user_homeparty_order', [$homeparty->id]), 'class' => 'form-horizontal', 'id'=>'homeparty-order-form']) !!}

    <div class="card mb-4">
        <h5 class="card-header">
            <div class="row">
                <div class="col-12">
                    <div class="d-flex justify-content-between align-items-center w-100">
                        <div>Bestellung anlegen</div>
                        @if(!$homeparty->completed)
                        <div class="float-right">
                            <a href="{{route('user_homeparty_detail', [$homeparty->id])}}" class="btn btn-sm btn-secondary mr-2 mb-1"><i class="ion ion-ios-cog"></i> Verwalten</a>
                            <a href="{{route('user_homeparty_guests', [$homeparty->id])}}" class="btn btn-sm btn-secondary mr-2 mb-1"><i class="ion ion-md-person-add"></i> Gäste anlegen</a>
                        </div>
                        @endif
                    </div>
                </div>
            </div>
        </h5>
        <div class="card-body">
            <div class="row">
                <div class="col-md-6">
                    <h6>Lieferadresse Gastgeber/in
                        @if(!$homeparty->completed)
                            <a href="{{route('user_homeparty_guest_detail', [$homeparty->id, $homeparty->homeparty_host->id])}}"><i class="fa fa-edit"></i> </a>
                        @endif
                    </h6>
                    @include('user.homeparty._address', ['homeparty_user' => $homeparty->homeparty_host])
                </div>

                {{-- TODO Berechnung Bonus --}}
                <div class="col-md-6">
                    <h6>Aktuelle Bonusansicht</h6>

                    <div id="insert_show_bonus">
                        @include('user.homeparty.show_bonus', ['homeparty' => $homeparty])
                    </div>
                </div>
            </div>
        </div>
    </div>

    @if($homeparty->homeparty_host)
    <div class="card mb-3">
        <h5 class="card-header">
            <div class="row">
                <div class="col-12">
                    <div class="d-flex justify-content-between align-items-center w-100">
                        <div>Bestellung Gastgeber/in {{$homeparty->homeparty_host->billing_firstname}} {{$homeparty->homeparty_host->billing_lastname}}</div>
                    </div>
                </div>
                @if(!$homeparty->completed)
                <div class="col-12">
                    <button type="button" class="btn btn-sm btn-secondary btn-block mt-2" data-toggle="modal" data-target="#modals-load-content"
                            data-id="{{ $homeparty->id }}"
                            data-action="homeparty-add-product"
                            data-user_id="{{$homeparty->homeparty_host->id}}"
                            data-route="{{ route('modal_load') }}"><i class="fa fa-plus-circle"></i> Produkt hinzufügen</button>
                </div>
                @endif
            </div>
        </h5>
        <div class="card-body">
            <div class="insert_show_products_order" id="insert_show_products_order_{{$homeparty->homeparty_host->id}}" data-homeparty-id="{{ $homeparty->id }}" data-homeparty-user-id="{{$homeparty->homeparty_host->id}}">
                @include('user.homeparty.show_products_order', ['homeparty_guest' => $homeparty->homeparty_host])
            </div>
        </div>
    </div>
    @endif

    @if($homeparty->homeparty_guests)
        @php($g_count = 1)
        @foreach($homeparty->homeparty_guests as $homeparty_guest)
        <div class="card mb-3">
            <h5 class="card-header">
                <div class="row">
                    <div class="col-12">
                        <div class="d-flex justify-content-between align-items-center w-100">
                            <div>Bestellung {!! $g_count++ !!}. Gast {{$homeparty_guest->billing_firstname}} {{$homeparty_guest->billing_lastname}}</div>
                        </div>
                    </div>
                    @if(!$homeparty->completed)
                    <div class="col-12">
                        <button type="button" class="btn btn-sm btn-secondary btn-block mt-2" data-toggle="modal" data-target="#modals-load-content"
                                data-id="{{ $homeparty->id }}"
                                data-action="homeparty-add-product"
                                data-user_id="{{$homeparty_guest->id}}"
                                data-route="{{ route('modal_load') }}"><i class="fa fa-plus-circle"></i> Produkt hinzufügen</button>
                    </div>
                    @endif
                </div>
            </h5>
            <div class="card-body">
                <div class="insert_show_products_order" id="insert_show_products_order_{{$homeparty_guest->id}}" data-homeparty-id="{{ $homeparty->id }}" data-homeparty-user-id="{{$homeparty_guest->id}}">
                    @include('user.homeparty.show_products_order', ['homeparty_guest' => $homeparty_guest])
                </div>
            </div>
        </div>
        @endforeach
    @endif
    <hr>

    <div class="card mb-4">
        <h5 class="card-header">
            <div class="row">
                <div class="col-12">
                    <div class="d-flex justify-content-between align-items-center w-100">
                        <div>Gesamtübersicht</div>
                    </div>
                </div>
            </div>
        </h5>

        <div class="card-body">
            <div id="insert_show_total_order">
                @include('user.homeparty.show_total_order', ['homeparty' => $homeparty])
            </div>
            @if(!$homeparty->completed)
                <hr>
                @if($homeparty->homeparty_host && $homeparty->homeparty_host->isAddress())
                <div class="float-right">
                    <button type="submit" class="btn btn-secondary"><i class="ion ion-ios-redo"></i> bestätigen und weiter zur Kasse</button>
                </div>
                <br><br>
                <em class="small text-center"> <i class="fa fa-lock"></i> Du wirst auf unseren checkout weitergeletet, die Verbindung ist SSL verschlüsselt.</em>
                @else
                    <div class="alert alert-warning">
                        Die Bestellung kann erst abgesendet werden, wenn die Lieferadresse Gastgeber/in angelegt ist. <a href="{{route('user_homeparty_guest_detail', [$homeparty->id, $homeparty->homeparty_host->id])}}"><i class="fa fa-edit"></i> </a></h6>
                    </div>

                @endif
            @endif
        </div>
    </div>

    <div class="text-left mt-3">
        @if(!$homeparty->completed)
        <a href="{{route('user_homeparty_detail', [$homeparty->id])}}" class="btn btn-sm btn-secondary mr-2 mb-2"><i class="ion ion-ios-cog"></i> Homparty verwalten</a>
        @endif
        <a href="{{route('user_homepartys')}}" class="btn btn-sm btn-default mb-2">zurück zur Übersicht</a>
    </div>
    {!! Form::close() !!}




@endsection
@section('scripts')
    <script src="{{ asset('/js/iq-homeparty-cart.js') }}?v=1{{ get_file_last_time('/js/iq-homeparty-cart.js') }}"></script>
    <script type="application/javascript">
        var iqHomepartyCart = IqHomepartyCart.init();


        $( document ).ready(function() {


        });


    </script>
@endsection