@extends('dashboard.layouts.app')
@section('title', trans('admin.users.title') . ' - ')
@section('speedbar')
    <div class="content-header row">
        <div class="content-header-left col-md-9 col-12 mb-2">
            <div class="row breadcrumbs-top">
                <div class="col-12">
                    <h2 class="content-header-title float-left mb-0">@lang('admin.statuses.title')</h2>
                    <div class="breadcrumb-wrapper col-12">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item "><a href="{{ route('dashboard') }}">@lang('admin.home')</a>
                            </li>
                            <li class="breadcrumb-item active">
                                @lang('admin.statuses.title')
                            </li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@push('css')
    <link rel="stylesheet" type="text/css" href="/vendor/dashboard/app-assets/vendors/css/pickers/pickadate/pickadate.css">
@endpush

@section('content')
    <div class="row" id="table-head">
        <div class="col-md-12 mb-1">
            <a href="{{ route('dashboard.statuses.create') }}" class="btn btn-icon btn-success float-right">
                <i class="feather icon-plus"></i> @lang('admin.add')
            </a>
        </div>

        <div class="col-12">
            <div class="card">
                <div class="card-content">
                    <div class="table-responsive">
                        <table class="table mb-0">
                            <thead class="thead-dark">
                                <tr>
                                    <th scope="col" width="50">ID</th>
                                    <th scope="col" class="text-center">slug</th>
                                    <th scope="col" class="text-center">@lang('admin.statuses.font_color')</th>
                                    <th scope="col" class="text-center">@lang('admin.statuses.background_color')</th>
                                    <th scope="col" class="text-center">@lang('admin.statuses.example')</th>
                                    <th scope="col" class="text-right">@lang('admin.actions')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($statuses as $status)
                                    <tr>
                                        <th scope="row">{{ $status->id }}</th>
                                        <td class="text-center">{{ $status->slug }}</td>
                                        <td class="text-center">
                                            {{ $status->font_color }}
                                        </td>
                                        <td class="text-center">
                                            {{ $status->bg_color }}
                                        </td>
                                        <td class="text-center">
                                            <div
                                                style="background: {{ $status->bg_color }}; color: {{ $status->font_color }}; padding: 5px 0 5px 0;">
                                                Text
                                            </div>
                                        </td>
                                        <td class="text-right">
                                            <a href="{{ route('dashboard.statuses.edit', $status->id) }}"
                                                class="btn btn-sm btn-success btn-icon" data-toggle="tooltip"
                                                data-original-title="@lang('admin.edit')">
                                                <i class="feather icon-edit"></i>
                                            </a>
                                            <form class="delete-form d-inline"
                                                action="{{ route('dashboard.statuses.destroy', $status->id) }}"
                                                method="post" data-original-title="@lang('admin.delete')"
                                                data-toggle="tooltip">
                                                @csrf
                                                @method('DELETE')
                                                <button class="btn btn-sm btn-danger btn-icon" type="submit">
                                                    <i class="feather icon-trash"></i>
                                                </button>
                                            </form>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-center" colspan="6">
                                            @lang('admin.no_data')
                                        </td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            {{ $statuses->links('pagination::bootstrap-4') }}
        </div>
    </div>
@endsection

<!-- Add this JavaScript for delete confirmation -->
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const deleteForms = document.querySelectorAll('.delete-form');

        deleteForms.forEach(form => {
            form.addEventListener('submit', function(event) {
                event.preventDefault(); // Prevent default form submission
                const confirmation = confirm("Are you sure you want to delete this status?");

                if (confirmation) {
                    form.submit(); // Submit form if confirmed
                }
            });
        });
    });
</script>
