@extends('admin.layouts.app')
@section('container', 'dashboard-container-lg')
@section('section', d_trans('Countries'))
@section('title', d_trans('States'))
@section('header_title', d_trans('States'))
@section('create', route('admin.settings.countries.states.create'))
@section('back', route('admin.settings.index'))
@section('content')
    @include('admin.settings.countries.includes.tabs', ['active' => 'states'])
    <div class="card">
        <div class="card-header border-bottom">
            <form action="{{ url()->current() }}" method="GET">
                <div class="row g-3">
                    <div class="col-12 col-lg-7">
                        <input type="text" name="search" class="form-control" placeholder="{{ d_trans('Search...') }}"
                            value="{{ request('search') }}">
                    </div>
                    <div class="col-12 col-lg-3">
                        <select name="country" class="selectpicker" title="{{ d_trans('Country') }}"
                            data-live-search="true">
                            @foreach ($countries as $country)
                                <option value="{{ $country->id }}" @selected($country->id == request('country'))>
                                    {{ $country->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col">
                        <button class="btn btn-primary w-100"><i class="fa fa-search"></i></button>
                    </div>
                    <div class="col">
                        <a href="{{ url()->current() }}" class="btn btn-soft w-100">{{ d_trans('Reset') }}</a>
                    </div>
                </div>
            </form>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table data-table">
                    <thead>
                        <tr>
                            <th><i class="fa-solid fa-hashtag"></i></th>
                            <th>{{ d_trans('Name') }}</th>
                            <th class="text-center">{{ d_trans('Country') }}</th>
                            <th class="text-center">{{ d_trans('Created date') }}</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($states as $state)
                            <tr>
                                <td>
                                    <a href="{{ route('admin.settings.countries.states.edit', $state->id) }}">
                                        <i class="fa-solid fa-hashtag me-1"></i>{{ $state->id }}
                                    </a>
                                </td>
                                <td>
                                    <a href="{{ route('admin.settings.countries.states.edit', $state->id) }}"
                                        class="text-dark">
                                        {{ $state->name }}
                                    </a>
                                </td>
                                <td class="text-center">
                                    <a href="{{ route('admin.settings.countries.edit', $state->country->id) }}"
                                        class="text-dark">
                                        {{ $state->country->name }}
                                    </a>
                                </td>
                                <td class="text-center">{{ dateFormat($state->created_at) }}</td>
                                <td class="text-end">
                                    <div class="dropdown">
                                        <button class="dropdown-btn" type="button" id="dropdownMenuButton"
                                            data-bs-toggle="dropdown" aria-expanded="false">
                                            <i class="fa fa-ellipsis-v"></i>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-lg dropdown-menu-end"
                                            aria-labelledby="dropdownMenuButton">
                                            <li>
                                                <a class="dropdown-item"
                                                    href="{{ route('admin.settings.countries.states.edit', $state->id) }}">
                                                    <i class="fa-regular fa-pen-to-square"></i>{{ d_trans('Edit') }}
                                                </a>
                                            </li>
                                            <li>
                                                <a class="dropdown-item"
                                                    href="{{ route('admin.settings.countries.cities.index', ['state' => $state->id]) }}"><i
                                                        class="bi bi-globe-americas"></i>{{ d_trans('Cities') }}</a>
                                            </li>
                                            <li>
                                                <hr class="dropdown-divider" />
                                            </li>
                                            <li>
                                                <form
                                                    action="{{ route('admin.settings.countries.states.destroy', $state->id) }}"
                                                    method="POST">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button class="action-confirm dropdown-item text-danger"><i
                                                            class="far fa-trash-alt"></i>{{ d_trans('Delete') }}</button>
                                                </form>
                                            </li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            @include('admin.partials.empty-table', ['colspan' => 5])
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    {{ $states->links() }}
    @push('styles_libs')
        <link rel="stylesheet" href="{{ asset('vendor/libs/bootstrap/select/bootstrap-select.min.css') }}">
    @endpush
    @push('scripts_libs')
        <script src="{{ asset('vendor/libs/bootstrap/select/bootstrap-select.min.js') }}"></script>
    @endpush
@endsection
