@include('layouts.header')
<link rel="stylesheet" type="text/css" href="{{ url('/') }}/app-assets/vendors/css/tables/datatable/dataTables.bootstrap5.min.css">

<!-- BEGIN: Content-->
<div class="app-content content ">
    <div class="content-overlay"></div>
    <div class="header-navbar-shadow"></div>
    <div class="content-wrapper">
        <div class="content-header row">
            <h4>{{ __('License activation status') }}</h4>
            @if ($authed)
            <div class="col-2">
                <a class="btn btn-sm btn-danger float-start" href="{{route('setting.deleteKey')}}">{{__('Delete Key')}}</a>
            </div>
            @endif
        </div>
        <div class="content-body">
            <section class="app-activation-status">
                <div class="card">
                    <div class="card-body border-bottom">
                        @if ($authed)
                        <h4>{{ __('Activated') }} <i stroke="green" data-feather="check-circle" style="width:36px;height:36px;"></i></h4>
                        <!-- <span class="badge rounded-pill badge-light-success me-1">{{ __('Activated') }}</span> -->
                        @else
                        <form action="{{route('setting.license')}}" method="POST">
                            @csrf
                            <div class="mb-3 form-password-toggle">
                                <h5>Key</h5>
                                <div class="input-group input-group-merge">
                                    <input type="password" id="key" class="form-control" name="key" value="{{$key}}" placeholder="&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;" aria-describedby="password" />
                                    <span class="input-group-text cursor-pointer"><i data-feather="eye-off"></i></span>
                                    <button class="btn btn-primary" type="submit">{{ __('Activate now!') }}</button>
                                </div>
                            </div>
                            <div>
                                <h5>Go to <a href="{{config('app.URL_MY_ACCOUNT')}}" target="_blank">{{config('app.URL_MY_ACCOUNT')}}</a> to get key or de-activate key.</h5>
                            </div>
                        </form>
                        @endif
                    </div>
                </div>
            </section>
        </div>

        <div class="card-body">
            <button type="button" class="btn btn-sm btn-primary float-end" data-bs-toggle="modal" data-bs-target="#addNew">{{ __('Add new setting') }}</button>
            <a href="{{ route('setting.clearCache') }}" class="btn btn-sm btn-danger float-end" >{{ __('Clear app cache') }}</a>
        </div>

        <div class="content-header row">
            <h4>{{ __('Settings list') }}<span class="badge rounded-pill badge-light-secondary">{{DB::table('settings')->count()}}</span></h4>
        </div>
        <div class="content-body">
            <!-- settings list start -->
            <section class="app-setting-list">
                <!-- list and filter start -->
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive table-responsive">
                            <table id="tbl-bootstr" class="table table-hover">
                                <thead class="table-light">
                                    <tr>
                                        <th>{{ __('Setting key') }}</th>
                                        <th>{{ __('Setting value') }}</th>
                                        <th>{{ __('Actions') }}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($settings as $setting)
                                    <tr>
                                        <td><a href="javascript:;" data-bs-target="#edit-{{$setting->id}}" data-bs-toggle="modal">
                                        {{ $setting->key }}</a>
                                        </td>
                                        <td><a href="javascript:;" data-bs-target="#edit-{{$setting->id}}" data-bs-toggle="modal">
                                        {{ $setting->value }}</a>
                                        </td>
                                        <td>
                                            <button class="btn btn-warning dropdown-toggle" type="button" id="actionButton-{{$setting->id}}" data-bs-toggle="dropdown" aria-expanded="false">
                                                <i data-feather="command" class="me-0"></i>
                                            </button>
                                            <div class="dropdown-menu" aria-labelledby="actionButton-{{$setting->id}}">
                                                <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#edit-{{$setting->id}}"><i data-feather="edit" class="me-0"></i> {{__('Edit')}}</a>
                                                <div class="dropdown-divider"></div>
                                                <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#destroy-{{$setting->id}}"><i data-feather="trash" class="me-0"></i> {{__('Delete')}}</a>
                                            </div>
                                        </td>
                                    </tr>
                                    <!-- Delete Modal -->
                                    <div class="modal fade modal-danger text-start" id="destroy-{{$setting->id}}" tabindex="-1" aria-labelledby="myModalLabel120" aria-hidden="true">
                                        <div class="modal-dialog modal-dialog-centered">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="myModalLabel120">{{ __('Delete confirmation') }}</h5>
                                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                </div>
                                                <div class="modal-body">
                                                    {{ __('Are you sure you want to delete?') }} <br><br>
                                                    <span class="text text-danger"> <b>{{ $setting->key }}</b> </span><br><br>
                                                    {{ __('This process is irreversible') }} <br>
                                                    {{ __('The record(s) will be deleted from the database permanently') }}
                                                </div>
                                                <div class="modal-footer">
                                                    <a class="btn btn-sm btn-danger" href="{{ route('setting.destroy', ['setting_id' => $setting->id]) }}">{{ __('Delete') }}</a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- Edit Setting Modal -->
                                    <div class="modal fade" id="edit-{{$setting->id}}" tabindex="-1" aria-hidden="true">
                                        <div class="modal-dialog modal-xl modal-dialog-centered modal-edit-setting">
                                            <div class="modal-content">
                                                <div class="modal-header bg-transparent">
                                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                </div>
                                                <div class="modal-body pb-5 px-sm-5 pt-50">
                                                    <div class="text-center mb-2">
                                                        <h1 class="mb-1">{{ __('Edit setting') }}</h1>
                                                    </div>
                                                    <form action="{{ route('setting.update') }}" method="POST" class="row gy-1 pt-75">
                                                        @csrf
                                                        <div class="row">
                                                        <div class="col-12 col-md-6">
                                                            <input type="hidden"  name="setting_id" value="{{ $setting->id }}" />
                                                            <label class="form-label" for="key">{{ __('Setting key') }}</label>
                                                            <input type="text" name="key" class="form-control" value="{{ $setting->key }}" />
                                                        </div>
                                                        <div class="col-12 col-md-6">
                                                            <label class="form-label" for="value">{{ __('Setting value') }}</label>
                                                            <input type="text" name="value" class="form-control" value="{{ $setting->value }}" />
                                                        </div>
                                                        <div class="col-12 text-center mt-2 pt-50">
                                                            <button type="submit" class="btn btn-primary me-1">{{ __('Submit') }}</button>
                                                            <button type="reset" class="btn btn-outline-secondary" data-bs-dismiss="modal" aria-label="Close">{{ __('Cancel') }}</button>
                                                        </div>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--/ Edit Setting Modal -->
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- Modal to add new setting starts-->
                    <div class="modal modal-slide-in new-setting-modal fade" id="addNew">
                        <div class="modal-dialog">
                            <form action="{{ route('setting.store') }}" method="POST" class="add-new-setting modal-content pt-0">
                            @csrf
                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">×</button>
                                <div class="modal-header mb-1">
                                    <h5 class="modal-title" id="exampleModalLabel">{{ __('Add new setting') }}</h5>
                                </div>
                                <div class="modal-body flex-grow-1">
                                    <div class="mb-1">
                                        <label class="form-label" for="key">{{ __('Setting key') }}</label>
                                        <input type="text" name="key" class="form-control" required />
                                    </div>
                                    <div class="mb-1">
                                        <label class="form-label" for="value">{{ __('Setting value') }}</label>
                                        <input type="text" name="value" class="form-control" required />
                                    </div>
                                    <button type="submit" class="btn btn-primary me-1 data-submit">{{ __('Submit') }}</button>
                                    <button type="reset" class="btn btn-outline-secondary" data-bs-dismiss="modal">{{ __('Cancel') }}</button>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- Modal to add new setting Ends-->
                </div>
                <!-- list and filter end -->
            </section>
            <!-- settings list ends -->
            <!-- <div class="row">
                <div class="col-md-12">
                    {{--{{ $settings->links() }}--}}
                </div>
            </div> -->
        </div>
    </div>
</div>
<!-- END: Content-->

<!-- BEGIN: Vendor JS-->
<script src="{{ url('/') }}/app-assets/vendors/js/vendors.min.js"></script>
<script src="{{ url('/') }}/app-assets/vendors/js/tables/datatable/jquery.dataTables.min.js"></script>
<script src="{{ url('/') }}/app-assets/vendors/js/tables/datatable/dataTables.bootstrap5.min.js"></script>
<!-- BEGIN Vendor JS-->
<script>
    $(document).ready(function () {
        $('#tbl-bootstr').DataTable();
    });        
</script>

@include('layouts.footer')
