@extends('layouts.app')

@section('title', 'Areas')

@section('content')

<div class="row">

    {{-- Page Header --}}
    <div class="col-sm-12">
        <div class="card card-transparent card-block card-stretch card-height border-none mb-4">
            <div class="card-body p-0 d-flex justify-content-between align-items-center">

                <div>
                    <h3 class="mb-2">Areas</h3>
                    <p class="mb-0 text-muted">
                        Manage customer areas
                    </p>
                </div>

                <div>
                    <a href="{{ route('area.add') }}" class="btn btn-primary">
                        <i class="ri-add-line mr-1"></i>
                        Add Area
                    </a>
                </div>

            </div>
        </div>
    </div>


    {{-- Success Message --}}
    @if(session('success'))
        <div class="col-sm-12">
            <div class="alert alert-success">
                {{ session('success') }}
            </div>
        </div>
    @endif


    {{-- Area List --}}
    <div class="col-lg-12">

        <div class="card card-block card-stretch card-height">

            <div class="card-header d-flex justify-content-between">

                <div class="header-title">
                    <h4 class="card-title">
                        Area List
                    </h4>
                </div>

            </div>


            <div class="card-body">

                <div class="table-responsive">

                    <table class="table mb-0">

                        <thead class="thead-light">
                            <tr>
                                <th>#</th>
                                <th>Area Name</th>
                                <th>Actions</th>
                            </tr>
                        </thead>


                        <tbody>

                            @forelse($areas as $area)

                                <tr>

                                    <td>
                                        {{ $loop->iteration }}
                                    </td>

                                    <td>
                                        <strong>
                                            {{ $area->area_name }}
                                        </strong>
                                    </td>

                                    <td>

                                        {{-- Edit --}}
                                        <a
                                            href="{{ route('area.edit', $area->area_id) }}"
                                            class="badge bg-success mr-2"
                                            title="Edit"
                                            data-toggle="tooltip"
                                        >
                                            <i class="ri-pencil-line"></i>
                                        </a>


                                        {{-- Delete --}}
                                        <form
                                            action="{{ route('area.delete', $area->area_id) }}"
                                            method="POST"
                                            style="display:inline-block;"
                                            onsubmit="return confirm('Are you sure you want to delete this area?');"
                                        >

                                            @csrf
                                            @method('DELETE')

                                            <button
                                                type="submit"
                                                class="badge badge-danger border-0"
                                                title="Delete"
                                                data-toggle="tooltip"
                                            >
                                                <i class="ri-delete-bin-line"></i>
                                            </button>

                                        </form>

                                    </td>

                                </tr>

                            @empty

                                <tr>

                                    <td
                                        colspan="3"
                                        class="text-center text-muted"
                                    >
                                        No areas found.
                                    </td>

                                </tr>

                            @endforelse

                        </tbody>

                    </table>

                </div>

            </div>

        </div>

    </div>

</div>

@endsection