@extends('layouts.app')
@section('title', 'Back Office - SIM Jaga RSUD')
@section('caption', 'Back Office Admin')
@section('content')
<div class="page-heading">
    <div><p class="eyebrow">BACK OFFICE RSUD</p><h1>Dashboard Admin</h1><p>Kelola pegawai, hari libur, cuti, dan libur pengganti.</p></div>
    <a class="public-link" href="{{ route('schedule') }}">Lihat halaman depan</a>
</div>
<section class="stats-grid">
    <article class="stat-card"><div class="stat-icon teal">P</div><div><p>Total Pegawai</p><strong>{{ $employees->count() }}</strong><span>{{ $employees->where('status', 'Aktif')->count() }} pegawai aktif</span></div></article>
    <article class="stat-card"><div class="stat-icon blue">PJ</div><div><p>Penanggung Jawab</p><strong>{{ $employees->where('role', 'PJ')->count() }}</strong><span>Tersedia dalam rotasi</span></div></article>
    <article class="stat-card"><div class="stat-icon orange">L</div><div><p>Hari Libur</p><strong>{{ $holidays->count() }}</strong><span>Terdaftar di kalender</span></div></article>
    <article class="stat-card"><div class="stat-icon purple">C</div><div><p>Perlu Persetujuan</p><strong>{{ $leaves->where('status', 'Menunggu')->count() }}</strong><span>Cuti / libur pengganti</span></div></article>
</section>
<section class="admin-panel card">
    <div class="admin-tabs">
        <button class="admin-tab active" data-tab="employees">Data Pegawai</button>
        <button class="admin-tab" data-tab="holidays">Hari Libur</button>
        <button class="admin-tab" data-tab="leaves">Cuti / Libur Pengganti</button>
    </div>
    <div class="admin-view active" id="tab-employees">
        <div class="crud-head"><div><p class="eyebrow">MASTER DATA</p><h3>Daftar Pegawai</h3></div><button class="primary-btn" data-open="employee-modal" data-reset>+ Tambah Pegawai</button></div>
        <div class="data-table">
            <div class="admin-row employee-grid head"><span>Pegawai</span><span>Jabatan</span><span>Unit</span><span>Status</span><span>Aksi</span></div>
            @foreach($employees as $employee)
            <div class="admin-row employee-grid">
                <div><strong>{{ $employee->name }}</strong><small>{{ $employee->nip }}</small></div>
                <span class="role-badge {{ strtolower($employee->role) }}">{{ $employee->role }}</span><span>{{ $employee->unit }}</span><span class="simple-badge {{ strtolower($employee->status) }}">{{ $employee->status }}</span>
                <div class="actions">
                    <button class="action-btn" data-open="employee-modal" data-edit='@json($employee)'>Edit</button>
                    <form method="POST" action="{{ route('admin.employees.destroy', $employee) }}" data-confirm>@csrf @method('DELETE')<button class="action-btn delete">Hapus</button></form>
                </div>
            </div>
            @endforeach
        </div>
    </div>
    <div class="admin-view" id="tab-holidays">
        <div class="crud-head"><div><p class="eyebrow">KALENDER RSUD</p><h3>Daftar Hari Libur</h3></div><button class="primary-btn" data-open="holiday-modal" data-reset>+ Tambah Hari Libur</button></div>
        <div class="data-table">
            <div class="admin-row holiday-grid head"><span>Tanggal</span><span>Nama Hari Libur</span><span>Jenis</span><span>Aksi</span></div>
            @foreach($holidays as $holiday)
            <div class="admin-row holiday-grid"><strong>{{ $holiday->date->translatedFormat('d M Y') }}</strong><span>{{ $holiday->name }}</span><span class="simple-badge">{{ $holiday->type }}</span>
                <div class="actions"><button class="action-btn" data-open="holiday-modal" data-edit='@json($holiday)'>Edit</button><form method="POST" action="{{ route('admin.holidays.destroy', $holiday) }}" data-confirm>@csrf @method('DELETE')<button class="action-btn delete">Hapus</button></form></div>
            </div>
            @endforeach
        </div>
    </div>
    <div class="admin-view" id="tab-leaves">
        <div class="crud-head"><div><p class="eyebrow">KETIDAKHADIRAN</p><h3>Cuti & Libur Pengganti</h3></div><button class="primary-btn" data-open="leave-modal" data-reset>+ Tambah Pengajuan</button></div>
        <div class="data-table">
            <div class="admin-row leave-grid head"><span>Pegawai</span><span>Jenis</span><span>Periode</span><span>Status</span><span>Aksi</span></div>
            @foreach($leaves as $leave)
            <div class="admin-row leave-grid"><strong>{{ $leave->employee->name }}</strong><span class="simple-badge">{{ $leave->type }}</span><span>{{ $leave->start_date->translatedFormat('d M Y') }} - {{ $leave->end_date->translatedFormat('d M Y') }}</span><span class="simple-badge {{ strtolower($leave->status) }}">{{ $leave->status }}</span>
                <div class="actions"><button class="action-btn" data-open="leave-modal" data-edit='@json($leave)'>Edit</button><form method="POST" action="{{ route('admin.leaves.destroy', $leave) }}" data-confirm>@csrf @method('DELETE')<button class="action-btn delete">Hapus</button></form></div>
            </div>
            @endforeach
        </div>
    </div>
</section>
@endsection
@section('modals')
<div class="modal-backdrop" id="employee-modal"><form class="modal-card crud-form" method="POST" action="{{ route('admin.employees.store') }}" data-store="{{ route('admin.employees.store') }}" data-update="{{ url('/admin/employees') }}">@csrf<div class="method-slot"></div><button type="button" class="modal-close" data-close>x</button><p class="eyebrow">DATA PEGAWAI</p><h3>Tambah / Edit Pegawai</h3><label>Nama<input name="name" required></label><label>NIP<input name="nip" required></label><div class="form-row"><label>Jabatan<select name="role">@foreach(['Pimpinan','PJ','Perawat'] as $item)<option>{{ $item }}</option>@endforeach</select></label><label>Status<select name="status">@foreach(['Aktif','Cuti','Nonaktif'] as $item)<option>{{ $item }}</option>@endforeach</select></label></div><label>Unit<input name="unit" value="Rawat Inap" required></label><button class="primary-btn form-submit">Simpan Pegawai</button></form></div>
<div class="modal-backdrop" id="holiday-modal"><form class="modal-card crud-form" method="POST" action="{{ route('admin.holidays.store') }}" data-store="{{ route('admin.holidays.store') }}" data-update="{{ url('/admin/holidays') }}">@csrf<div class="method-slot"></div><button type="button" class="modal-close" data-close>x</button><p class="eyebrow">HARI LIBUR</p><h3>Tambah / Edit Hari Libur</h3><label>Tanggal<input type="date" name="date" required></label><label>Nama<input name="name" required></label><label>Jenis<select name="type"><option>Nasional</option><option>Internal</option></select></label><button class="primary-btn form-submit">Simpan Hari Libur</button></form></div>
<div class="modal-backdrop" id="leave-modal"><form class="modal-card crud-form" method="POST" action="{{ route('admin.leaves.store') }}" data-store="{{ route('admin.leaves.store') }}" data-update="{{ url('/admin/leaves') }}">@csrf<div class="method-slot"></div><button type="button" class="modal-close" data-close>x</button><p class="eyebrow">PENGAJUAN</p><h3>Tambah / Edit Pengajuan</h3><label>Pegawai<select name="employee_id">@foreach($employees as $employee)<option value="{{ $employee->id }}">{{ $employee->name }}</option>@endforeach</select></label><label>Jenis<select name="type">@foreach(['Cuti','Izin','Sakit','Libur Pengganti'] as $item)<option>{{ $item }}</option>@endforeach</select></label><div class="form-row"><label>Mulai<input type="date" name="start_date" required></label><label>Selesai<input type="date" name="end_date" required></label></div><label>Status<select name="status">@foreach(['Menunggu','Disetujui','Ditolak'] as $item)<option>{{ $item }}</option>@endforeach</select></label><label>Catatan<textarea name="notes"></textarea></label><button class="primary-btn form-submit">Simpan Pengajuan</button></form></div>
@endsection
