@extends('layouts.layout-2')

@section('content')

    @if ($errors->any())
        <div class="row">
            <div class="col-sm-12">
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            </div>
        </div>
    @endif

    <h4 class="font-weight-bold py-2 mb-2">
        {{ __('Create/Edit Rolle') }}
    </h4>

    <div class="text-left mt-0 mb-2">
        <a href="{{ route('admin_levels') }}" class="btn btn-default">{{ __('back') }}</a>
    </div>

    <div class="card mb-2">
        {!! Form::open(['url' => route('admin_level_store',), 'class' => 'form-horizontal', 'id'=>'']) !!}
        <input type="hidden" name="id" value="@if($value->id>0){{$value->id}}@else new @endif">
        <h5 class="card-header">
            {{ __('Rolle') }}
        </h5>
        <div class="card-body">

            <div class="form-row">
                <div class="form-group col">
                    <label for="name" class="form-label">{{__('Name')}}*</label>
                    {{ Form::text('name', $value->name,  array('placeholder'=>__('Bezeichnung'), 'class'=>'form-control', 'required')) }}
                </div>
            </div>

            <div class="form-row">
                <div class="form-group col">
                    <label for="content" class="form-label">{{__('Beschreibung')}}</label>
                    {{ Form::textarea('content', $value->content,  array('placeholder'=>__('Beschreibung'), 'class'=>'form-control summernote-small')) }}
                    <p> <i>Platzhalter ##mehr lesen## </i></p>
                </div>


            </div>

            <div class="form-row">
                <div class="form-group col-12">
                    <label class="custom-control custom-checkbox m-2">
                        {!! Form::checkbox('partner_provision', 1, $value->partner_provision, ['class'=>'custom-control-input']) !!}
                        <span class="custom-control-label">Vertriebspartner Provision berechnen</span>
                    </label>
                </div>

            </div>

            <div class="form-row">
                <div class="form-group col-6">
                    <label class="custom-control custom-checkbox m-2">
                        {!! Form::checkbox('active', 1, $value->active, ['class'=>'custom-control-input']) !!}
                        <span class="custom-control-label">{{__('active')}}</span>
                    </label>
                </div>
                <div class="form-group col-6">
                    {{ Form::text('pos', $value->pos,  array('placeholder'=>__('Number to move the position if necessary'), 'class'=>'form-control')) }}
                </div>
            </div>
            @if(isset($trans))
                <hr>
                @foreach($trans as $tran)
                    @if($tran != 'de')
                        <div class="form-row">
                            <div class="form-group col">
                                <label for="name" class="form-label">{{__('Translate')}} <strong style="text-transform: uppercase">{{$tran}}</strong></label>
                                <input type="text" class="form-control" name="trans[{{$tran}}]" id="trans_{{$tran}}" placeholder="">
                            </div>
                        </div>
                    @endif
                @endforeach
            @endif
            <div class="text-left mt-0 mb-2">
                <button type="submit" class="btn btn-secondary" name="action" value="user_level">{{ __('save') }}</button>&nbsp;
            </div>
        </div>
        {!! Form::close() !!}
    </div>

    @if($value->id>0)
        <div class="card mb-2">
        <h6 class="card-header">
            {{__('Staffelpreise')}}
        </h6>
        <div class="card-datatable table-responsive">
            <table class="datatables-style table table-striped table-bordered">
                <thead>
                <tr>
                    <th style="max-width: 60px;">&nbsp;</th>
                    <th>{{__('Preis ab')}} &euro;</th>
                    <th>{{__('Handelsspanne')}} %</th>
                    <th>{{__('Provision')}} %</th>

                    <th></th>
                </tr>
                </thead>
                <tbody>
                @foreach($value->user_level_margins as $user_level_margin)
                    <tr>
                        <td>
                            <button type="button" class="btn icon-btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-user-level-margin"
                                    data-id="{{ $user_level_margin->id }}"
                                    data-price_from="{{ $user_level_margin->getFormattedPriceFrom() }}"
                                    data-trading_margin="{{ $user_level_margin->getFormattedTradingMargin() }}"
                                    data-commission="{{ $user_level_margin->getFormattedCommission() }}">
                                <span class="far fa-edit"></span>
                            </button>
                        </td>
                        <td>{{ $user_level_margin->getFormattedPriceFrom() }}</td>
                        <td>{{ $user_level_margin->getFormattedTradingMargin() }}</td>
                        <td>{{ $user_level_margin->getFormattedCommission() }}</td>
                        <td><a class="text-danger" href="{{ route('admin_level_delete', ['user_level_margin', $user_level_margin->id]) }}"  onclick="return confirm('{{__('Really delete entry?')}}');"><i class="far fa-trash-alt"></i></a></td>

                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="mt-4 ml-4">
                <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-user-level-margin"
                        data-id="new"
                        data-price_from=""
                        data-trading_margin=""
                        data-commission=""
                >{{__('Neuen Staffelpreis erstellen')}}</button>
            </div>
        </div>
    </div>

    <!-- Modal template price -->
    <div class="modal fade" id="modals-user-level-margin">
        <div class="modal-dialog">
            <form class="modal-content" action="{{ route('admin_level_store') }}" method="post">
                @csrf
                <input type="hidden" name="id">
                <input type="hidden" name="user_level_id" value="@if($value->id>0){{$value->id}}@else new @endif">

                <div class="modal-header">
                    <h5 class="modal-title"> {{__('Staffelpreis')}} <span class="font-weight-light">{{__('create/edit')}}</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-6">
                            <label for="price_from" class="form-label">{{__('ab Preis')}}*</label>
                            <input type="text" class="form-control" name="price_from" placeholder="{{__('Preis in Euro')}}" required>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-6">
                            <label for="trading_margin" class="form-label">{{__('Handelspanne')}}</label>
                            <input type="text" class="form-control" name="trading_margin" placeholder="{{__('in %')}}">
                        </div>
                        <div class="form-group col-6">
                            <label for="commission" class="form-label">{{__('Provision')}}</label>
                            <input type="text" class="form-control" name="commission" placeholder="{{__('in %')}}">
                        </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="user_level_margin">{{__('save')}}</button>
                </div>
            </form>
        </div>
    </div>




    <script>
        $( document ).ready(function() {

            $('#modals-user-level-margin').on('show.bs.modal', function (event) {
                var button = $(event.relatedTarget);
                $(this).find(".modal-content input[name='id']").val(button.data('id'));
                $(this).find(".modal-body input[name='price_from']").val(button.data('price_from'));
                $(this).find(".modal-body input[name='trading_margin']").val(button.data('trading_margin'));
                $(this).find(".modal-body input[name='commission']").val(button.data('commission'));
            });

        });
    </script>

    @endif
    <div class="text-left mt-2 mb-2">
        <a href="{{ route('admin_levels') }}" class="btn btn-default">{{ __('back') }}</a>
    </div>




@endsection
