@extends('layouts.app')

@section('content')
<div class="container">
    <h2>Customers</h2>
    <a href="{{ route('customers.create') }}" class="btn btn-success mb-3">Add Customer</a>
    
    {{-- Flash Messages --}}

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif

    @if(session('error'))
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>CNIC</th>
                <th>Phone</th>
                <th>Address</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($customers as $customer)
                <tr>
                    <td>{{ $customer->id }}</td>
                    <td>{{ $customer->name }}</td>
                    <td>{{ $customer->email }}</td>
                    <td>{{ $customer->phone }}</td>
                    <td>{{ $customer->address }}</td>
                    <td class="action-buttons">
                    <!-- <a href="{{ route('customers.updateUnique', $customer->id) }}" class="btn btn-success" style="height: 32px;"><i class="bi bi-pencil"></i></a> -->
                    <a href="{{ route('customers.editUnique', $customer->id) }}" class="btn btn-success" style="height: 32px;"><i class="bi bi-pencil"></i></a>
                    <form action="{{ route('customers.destroy', $customer->id) }}" method="POST">
                            @csrf
                            @method('DELETE')
                            <button class="btn btn-danger btn-" onclick="return confirm('Are you sure?')"><i class="bi bi-trash"></i></button>
                        </form>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</div>
@endsection


<style>
        .action-buttons {
        white-space: nowrap;
        display: flex;
        gap: 5px;
    }
</style>