@extends('admin.layouts.app')

@section('panel')

<div class="col-lg-12">
    <div class="show-filter mb-3 text-end">
        <button type="button" class="btn btn-outline--primary showFilterBtn btn-sm"><i class="las la-filter"></i>
            @lang('Filter')</button>
    </div>
    <div class="card responsive-filter-card mb-4">
        <div class="card-body">
            <form action="">
                <div class="d-flex flex-wrap gap-4">
                    <div class="flex-grow-1">
                        <label>@lang('Name')</label>
                        <input type="text" name="search" value="{{ request()->search }}" class="form-control">
                    </div>
                    <div class="flex-grow-1">
                        <label>@lang('Status')</label>
                        <select name="status" class="form-control">
                            <option value="">@lang('All')</option>
                            <option value="{{ Status::ENABLE }}" @selected(request()->status == Status::ENABLE)>@lang('Active')
                            </option>
                            <option value="{{ Status::DISABLE }}" @selected(request()->status == Status::DISABLE)>@lang('Deactive')
                            </option>
                        </select>
                    </div>
                    <div class="flex-grow-1">
                        <label>@lang('Date')</label>
                        <input name="date" type="text" data-range="true" data-multiple-dates-separator=" - "
                            data-language="en" class="datepicker-here form-control" data-position='bottom right'
                            placeholder="@lang('Start date - End date')" autocomplete="off" value="{{ request()->date }}">
                    </div>
                    <div class="flex-grow-1 align-self-end">
                        <button class="btn btn--primary w-100 h-45"><i class="fas fa-filter"></i>
                            @lang('Filter')</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card b-radius--10">
                <div class="card-body p-0">
                    <div class="table-responsive--sm table-responsive">
                        <table class="table table--light style--two ">
                            <thead>
                                <tr>
                                    <th>@lang('Sl No')</th>
                                    <th>@lang('Name Of File')</th>
                                    <th>@lang('Description')</th>
                                    <th>@lang('Status')</th>
                                    <th>@lang('Created at')</th>
                                    <th>@lang('Action')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($notelist as $media)
                                    <tr>
                                        <td>
                                            <span class="fw-bold">{{ $loop->iteration }}</span>
                                        </td>
                                        <td>
                                            <span class="fw-bold">{{ $media->name }}</span>
                                        </td>
                                        <td >
                                            <span class="fw-bold d-block" >
                                                {{ Str::limit($media->desc, 100) }}
                                                @if (Str::length($media->desc) > 100)
                                                    <a class="read-more"  data-bs-toggle="modal" data-bs-target="#readMoreModal{{ $media->id }}">
                                                        @lang('Read More')
                                                    </a>

                                                    <!-- Read More Modal -->
                                                    <div class="modal fade" id="readMoreModal{{ $media->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                                        <div class="modal-dialog">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h5 class="modal-title" id="myModalLabel">@lang('Description')</h5>
                                                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                                </div>
                                                                <div class="modal-body">
                                                                    <p style="word-break: break-word; white-space: pre-line;" >{{ $media->desc }}</p>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                @endif
                                            </span>
                                        </td>

                                        <td>@php echo $media->statusBadge @endphp</td>
                                        <td>
                                            <span class="fw-bold">{{ $media->created_at->format('d M Y') }}</span>
                                        </td>
                                        <td>
                                            @haspermission('manage_user:user_edit', 'admin')
                                                <button type="button" class="btn btn-sm btn-outline--primary editBtn"
                                                    data-bs-route="{{ route('admin.noteList.editCreatelist', $media->id) }}"
                                                    data-bs-title="@lang('Update Pdf List : ') {{ $media->name }}"
                                                    data-bs-toggle="modal" data-bs-target="#couponModal">
                                                    <i class="la la-pen"></i> @lang('Edit')
                                                </button>
                                                <button type="button" class="btn btn-sm btn-outline--danger" data-bs-toggle="modal" data-bs-target="#deleteConfirmModal{{ $media->id }}">
                                                    <i class="la la-trash"></i> @lang('Delete')
                                                </button>

                                                <!-- Delete Confirmation Modal -->
                                                <div class="modal fade" id="deleteConfirmModal{{ $media->id }}" tabindex="-1" aria-labelledby="deleteConfirmModalLabel{{ $media->id }}" aria-hidden="true">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h5 class="modal-title" id="deleteConfirmModalLabel{{ $media->id }}">@lang('Confirm Delete')</h5>
                                                                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">&times;</span>
                                                                </button>
                                                            </div>
                                                            <div class="modal-body">
                                                                @lang('Are you sure you want to delete this item?')
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@lang('Cancel')</button>
                                                                <a href="{{ route('admin.noteList.deleteNoteList', $media->id) }}" class="btn btn-danger">@lang('Delete')</a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                            @endhaspermission
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%">{{ __($emptyMessage) }}</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table><!-- table end -->
                    </div>
                </div>
                @if ($notelist->hasPages())
                    <div class="card-footer py-4">
                        @php echo paginateLinks($notelist) @endphp
                    </div>
                @endif
            </div><!-- card end -->
        </div>
    </div>

    <div class="modal fade" id="couponModal" tabindex="-1" role="dialog" aria-labelledby="couponModalLabel"
        aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="couponModalLabel"></h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                        <i class="las la-times"></i>
                    </button>
                </div>
                <div class="modal-body">
                </div>
            </div>
        </div>
    </div>
@endsection



@push('breadcrumb-plugins')

    @haspermission('manage_user:user_edit', 'admin')
        <button type="button" class="btn btn-sm btn-outline--primary editBtn" data-bs-route="{{ route('admin.noteList.editCreatelist') }}"
            data-bs-title="@lang('Create list')" data-bs-toggle="modal" data-bs-target="#couponModal">
            <i class="la la-plus"></i> @lang('Create')
        </button>
    @endhaspermission

    <x-search-form dateSearch='no' />
@endpush


@push('script')
    <script>
        (function($) {
            $('.editBtn').on('click', function() {
                var modal = $('#couponModal');
                modal.find('#couponModalLabel').text($(this).data('bs-title'));
                var url = $(this).data('bs-route');
                $.ajax({
                    url: url,
                    method: 'GET',
                    success: function(response) {
                        modal.find('.modal-title').text($(this).data('bs-title'));
                        modal.find('.modal-body').html(response);
                        modal.modal('show');
                    }
                });
            });
        })(jQuery);
    </script>
@endpush
@push('style-lib')
    <link rel="stylesheet" href="{{ asset('assets/admin/css/vendor/datepicker.min.css') }}">
@endpush
@push('script-lib')
    <script src="{{ asset('assets/admin/js/vendor/datepicker.min.js') }}"></script>
    <script src="{{ asset('assets/admin/js/vendor/datepicker.en.js') }}"></script>
@endpush
@push('script')
    <script>
        (function($) {
            "use strict";
            if (!$('.datepicker-here').val()) {
                $('.datepicker-here').datepicker();
            }
        })(jQuery)
    </script>
@endpush
