@extends('layouts.master')

@section('title', $title )


@section('main')
<div class="main-content">
    <section class="section">

        <x-backend.breadcrumb :title=$title :url="route('admin.city.create')" button-label="Create New" />

        <div class="section-body">
            <div class="row">
                <div class="col-12 col-md-12 col-lg-12">

                    <x-backend.card>

                        <table class="table table-bordered city">
                            <thead>
                                <tr>
                                    <th scope="col">#</th>
                                    <th>Country</th>
                                    <th>State</th>
                                    <th>City Name</th>
                                    <th scope="col">Status</th>
                                    <th scope="col">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($lists as $key => $list)
                                <tr id="row_{{ $list->id}}">
                                    <td scope="row">{{ ++$key }}</td>
                                    <td>{{ $list->country->country_name }}</td>
                                    <td>{{ $list->state->state_name }}</td>
                                    <td>{{$list->name }}</td>
                                    <td>{!! $list->status ==  1 ? '<span class="badge badge-success">Active</span>' : '<span class="badge badge-danger">Inactive</span>' !!}</td>
                                    <td>

                                        <a href="{{ route('admin.city.edit',$list->id)}}">
                                            <x-icons.pencil />
                                        </a>

                                        <a href="javascript:void(0)"  class="delete text-danger" data-id={{ $list->id }}>
                                            <x-icons.trash />
                                        </a>
                                    </td>
                                </tr>
                                @endforeach


                            </tbody>
                        </table>
                        {{ $lists->links() }}
                    </x-backend.card>
                </div>

            </div>
        </div>
    </section>
</div>
@endsection('pageContent')

@push('scripts')
<script type="text/javascript">

    $(".city").on("click", ".delete", function() {
        var row_id = $(this).attr("data-id");
        var token = $("meta[name='csrf-token']").attr("content");

        return deleteRecord("{{ route('admin.city.destroy','' ) }}" + "/" + row_id, {
            _token: token,
             id: row_id
		})

    });

</script>
@endpush