@extends('layouts.dashboard')

@section('title', 'Data Ibu Hamil')

@section('content')

    <div class="pagetitle mb-4">
        <h1 style="color: #FF782D; font-weight: 700;">Data Ibu Hamil</h1>
        <p class="text-muted">Manajemen data ibu hamil PosSehat.</p>
    </div>

    <div class="card shadow-sm border-0" style="border-radius: 20px;">
        <div class="card-body p-4">

            <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-4">
                <div>
                    <h5 class="card-title mb-0" style="color: #2c3e50; font-weight: 600;">Daftar Ibu Hamil</h5>
                </div>

                <div class="mt-3 mt-md-0">
                    <a href="{{ route('ibu_hamil.create') }}" class="btn btn-orange px-4 py-2 shadow-sm" style="background-color: #FF782D; color: white; border-radius: 10px; font-weight: 500;">
                        <i class="bi bi-plus-circle me-2"></i> Tambah Ibu Hamil
                    </a>
                </div>
            </div>

            <form method="GET" action="{{ route('ibu_hamil.index') }}" class="mb-4">
                <div class="input-group search-bar" style="max-width: 400px;">
                    <span class="input-group-text bg-white border-end-0" style="border-radius: 10px 0 0 10px;">
                        <i class="bi bi-search" style="color: #FF782D;"></i>
                    </span>
                    <input type="text" name="search" class="form-control border-start-0" id="search"
                        placeholder="Cari nama ibu hamil..."
                        value="{{ request('search') }}" style="border-radius: 0 10px 10px 0;">
                </div>
            </form>

            <div class="table-responsive">
                <table class="table table-hover align-middle custom-table">
                    <thead>
                        <tr>
                            <th style="width: 5%">No</th>
                            <th>Nama</th>
                            <th>Tanggal Lahir</th>
                            <th>Alamat</th>
                            <th>No HP</th>
                            <th style="width: 15%" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody id="ibu-hamil-table">
                        @forelse ($ibu_hamil as $index => $ibu_hamils)
                            <tr>
                                <td class="fw-bold">{{ $ibu_hamil->firstItem() + $index }}</td>
                                <td>{{ $ibu_hamils->nik }}</td>
                                <td>
                                    <div class="d-flex align-items-center">
                                        <div class="avatar-sm me-3">
                                            <img src="https://ui-avatars.com/api/?name={{ urlencode($ibu_hamils->nama) }}&background=fff5f0&color=FF782D" class="rounded-circle" width="35">
                                        </div>
                                        <span class="fw-semibold text-dark">{{ $ibu_hamils->nama }}</span>
                                    </div>
                                </td>
                                <td>{{ $ibu_hamils->tgl_lahir }}</td>
                                <td>{{ $ibu_hamils->alamat }}</td>
                                <td>{{ $ibu_hamils->no_hp }}</td>
                                <td class="text-center">
                                    <div class="d-flex justify-content-center gap-2">
                                        <a href="{{ route('ibu_hamil.edit', $ibu_hamils->id) }}"
                                        class="btn btn-sm btn-edit-custom" title="Edit">
                                            <i class="bi bi-pencil-square"></i>
                                        </a>

                                        <form action="{{ route('ibu_hamil.destroy', $ibu_hamils->id) }}" method="POST" style="display:inline;">
                                            @csrf
                                            @method('DELETE')
                                            <button class="btn btn-sm btn-delete-custom"
                                                    onclick="return confirm('Yakin ingin menghapus data ibu hamil ini?')"
                                                    title="Hapus">
                                                <i class="bi bi-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center py-5 text-muted">
                                    <i class="bi bi-person-x d-block mb-2" style="font-size: 3rem; color: #dee2e6;"></i>
                                    Belum ada data ibu hamil yang ditemukan
                                </td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            <div class="d-flex justify-content-between align-items-center mt-4">
                <small class="text-muted">Menampilkan {{ $ibu_hamil->firstItem() ?? 0 }} sampai {{ $ibu_hamil->lastItem() ?? 0 }} dari {{ $ibu_hamil->total() }} data</small>
                <div>
                    {{ $ibu_hamil->withQueryString()->links() }}
                </div>
            </div>

        </div>
    </div>

<style>
    /* Table Styling */
    .custom-table thead {
        background-color: #f8f9fa;
    }
    .custom-table th {
        color: #7a7a7a;
        font-weight: 600;
        text-transform: uppercase;
        font-size: 12px;
        letter-spacing: 0.5px;
        border-top: none;
        padding: 15px;
    }
    .custom-table td {
        padding: 15px;
        color: #555;
    }

    /* Badge Styling */
    .bg-orange-light {
        background-color: #fff5f0;
        color: #FF782D;
        border: 1px solid #ffccbc;
    }
    .bg-blue-light {
        background-color: #e3f2fd;
        color: #1976d2;
        border: 1px solid #bbdefb;
    }

    /* Action Buttons */
    .btn-edit-custom {
        background-color: #fff9db;
        color: #f59f00;
        border: none;
    }
    .btn-edit-custom:hover {
        background-color: #f59f00;
        color: white;
    }
    .btn-delete-custom {
        background-color: #fff5f5;
        color: #fa5252;
        border: none;
    }
    .btn-delete-custom:hover {
        background-color: #fa5252;
        color: white;
    }

    /* Form Control Focus */
    .form-control:focus {
        border-color: #FF782D;
        box-shadow: 0 0 0 0.2rem rgba(255, 120, 45, 0.25);
    }
    /* Badge Laki-laki (Biru Lembut) */
    .bg-blue-light {
        background-color: #e7f3ff; /* Biru sangat muda */
        color: #007bff;            /* Teks biru */
        border: 1px solid #cfe2ff;
        padding: 6px 12px;
        border-radius: 8px;
        font-weight: 600;
    }

    /* Badge Perempuan (Merah Muda Lembut) */
    .bg-pink-light {
        background-color: #fff0f3; /* Pink sangat muda */
        color: #ff4d6d;            /* Teks pink/merah muda */
        border: 1px solid #ffccd5;
        padding: 6px 12px;
        border-radius: 8px;
        font-weight: 600;
    }

    /* Efek hover agar interaktif */
    .badge:hover {
        opacity: 0.8;
        cursor: default;
    }
</style>

<script>
let delayTimer;

document.getElementById('search').addEventListener('keyup', function () {
    clearTimeout(delayTimer);

    let query = this.value;

    delayTimer = setTimeout(() => {
        fetch(`{{ route('ibu_hamil.index') }}?search=` + query)
        .then(response => response.text())
        .then(html => {
            let parser = new DOMParser();
            let doc = parser.parseFromString(html, 'text/html');

            let newTable = doc.querySelector('#ibu-hamil-table').innerHTML;
            document.getElementById('ibu-hamil-table').innerHTML = newTable;
        });
    }, 300);
});
</script>

@endsection



