@extends('layouts.layout-2')

@section('content')
    <div class="card">
        <h6 class="card-header">
            {{__('Systemeinstellungen')}}
        </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>{{__('Name')}}</th>
                    <th>{{__('slug') }}</th>
                    <th>{{__('Info') }}</th>
                    <th>{{__('Action') }}</th>
                    <th>{{__('Status')}}</th>
                    <th>{{__('Aktiv')}}</th>
                </tr>
                </thead>
                <tbody>
                @foreach($values as $value)
                    <tr>
                        <td>
                            <button type="button" class="btn icon-btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-default"
                                    data-id="{{ $value->id }}"
                                    data-name="{{ $value->name }}"
                                    data-slug="{{ $value->slug }}"
                                    data-message="{{ $value->message }}"
                                    data-action="{{ $value->action }}"
                                    data-status="{{ $value->status }}"
                                    data-active="{{ $value->active }}">
                                <span class="far fa-edit"></span>
                            </button>
                        </td>
                        <td>{{ $value->name }}</td>
                        <td>{{ $value->slug }}</td>
                        <td>{{ $value->message }}</td>
                        <td>{{ $value->action }}</td>
                        <td>{{ $value->status }}</td>
                        <td data-sort="{{ $value->active }}">{!! get_active_badge($value->active) !!}</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-default"
                        data-id="new"
                        data-name=""
                        data-slug=""
                        data-message=""
                        data-action=""
                        data-status=""
                        data-active="1"
                >{{__('Neue Einstellung hinzufügen')}}</button>
            </div>
        </div>

    </div>



    <!-- Modal template -->
    <div class="modal fade" id="modals-default">
        <div class="modal-dialog">
            <form class="modal-content" action="{{ route('sysadmin_setting_store') }}" method="post">
                @csrf
                <input type="hidden" class="form-control" name="id">

                <div class="modal-header">
                    <h5 class="modal-title"> {{__('Systemeinstellung')}} <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">
                            <label for="name" class="form-label">{{__('Name')}}</label>
                            <input type="text" class="form-control" name="name">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col">
                            <label for="slug" class="form-label">{{__('Slug')}}</label>
                            <input type="text" class="form-control" name="slug">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col">
                            <label for="message" class="form-label">{{__('Info')}}</label>
                            <input type="text" class="form-control" name="message">
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col">
                            <label for="action" class="form-label">{{__('Action')}}</label>
                            <input type="text" class="form-control" name="action">
                        </div>
                    </div>

                    <div class="form-group col-sm-5">
                        <label class="form-label" for="status">{{ __('Produkt anzeigen') }}</label>
                        {{ Form::select('status', \App\Models\SySetting::$statusTypes, 1, array('data-live-search'=>'false', 'class'=>'selectpicker') ) }}
                    </div>

                    <div class="form-row">
                        <div class="form-group col">
                            <label class="custom-control custom-checkbox m-2">
                                <input type="checkbox" class="custom-control-input" name="active" checked>
                                <span class="custom-control-label">{{__('Aktiv')}}</span>
                            </label>
                        </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">{{__('save')}}</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        $( document ).ready(function() {
            $('#modals-default').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='name']").val(button.data('name'));
                $(this).find(".modal-body input[name='slug']").val(button.data('slug'));
                $(this).find(".modal-body input[name='message']").val(button.data('message'));
                $(this).find(".modal-body input[name='action']").val(button.data('action'));

                $(this).find(".modal-body input[name='active']").prop( "checked", button.data('active'));
                $(this).find(".modal-body select[name='status']").val(button.data('status'));

                $('.selectpicker').selectpicker('refresh');
            });

            $('.datatables-style').dataTable({
                "bLengthChange": false,
                "iDisplayLength": 50,

                "language": {
                    "url": "/js/German.json"
                }
            });
        });
    </script>
@endsection
