<?php
/**
 * NEPHRO ERP - LABORATUVAR TEST TANIMLARI (Cihaz Tasarımı Uyumlu)
 * işlem.php'ye uygun şekilde güncellendi
 */
global $pdo;
if (!function_exists('h')) { 
    function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, "UTF-8"); } 
}

// Filtreleme değişkenleri
$kategori = $_GET['kategori'] ?? 'all';
$arama = trim($_GET['arama'] ?? '');

// SQL sorgusu için hazırlık
$where = [];
$params = [];

if ($kategori !== 'all') {
    $where[] = "kategori = ?";
    $params[] = $kategori;
}

if ($arama !== '') {
    $where[] = "(test_adi LIKE ? OR test_kodu LIKE ?)";
    $like = "%{$arama}%";
    $params[] = $like;
    $params[] = $like;
}

$sqlWhere = $where ? " WHERE " . implode(" AND ", $where) : "";

// Testleri getir
$sql = "SELECT * FROM test_tanimlari $sqlWhere ORDER BY kategori ASC, test_adi ASC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$testler = $stmt->fetchAll(PDO::FETCH_ASSOC);

// İstatistikler
$istatistikler = [
    'toplam' => count($testler),
    'biyokimya' => 0,
    'hemogram' => 0,
    'hormon' => 0,
    'seroloji' => 0,
    'digery' => 0
];

foreach ($testler as $test) {
    $kategoriLower = strtolower($test['kategori']);
    if (isset($istatistikler[$kategoriLower])) {
        $istatistikler[$kategoriLower]++;
    } else {
        $istatistikler['digery']++;
    }
}

// Kategoriler (veritabanından benzersiz kategorileri al)
$kategoriler = ['all' => 'Tüm Kategoriler'];
try {
    $kategoriSorgu = $pdo->query("SELECT DISTINCT kategori FROM test_tanimlari ORDER BY kategori");
    $dbKategoriler = $kategoriSorgu->fetchAll(PDO::FETCH_COLUMN);
    foreach ($dbKategoriler as $kat) {
        $kategoriler[$kat] = $kat;
    }
} catch (Exception $e) {
    $kategoriler['Biyokimya'] = 'Biyokimya';
    $kategoriler['Hemogram'] = 'Hemogram';
    $kategoriler['Hormon'] = 'Hormon';
    $kategoriler['Seroloji'] = 'Seroloji';
}
?>

<style>
/* === Cihaz Yönetimi Stilinde Değişkenler === */
:root {
    --primary: #3b82f6;
    --primary-light: #eff6ff;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #1e293b;
    --light: #f8fafc;
    --border: #e2e8f0;
    --card: #ffffff;
    --muted: #64748b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background: var(--light);
    padding: 20px;
    color: var(--dark);
}

/* === Container === */
.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* === Header === */
.header {
    margin-bottom: 30px;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 5px;
}

.header p {
    color: var(--muted);
    font-size: 14px;
}

/* === Stats Grid (Cihazdaki gibi) === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 30px;
}

.stat-item {
    background: var(--card);
    padding: 20px;
    border-radius: 16px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.stat-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.stat-number {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* === Search Bar (Cihazdaki gibi) === */
.search-container {
    background: var(--card);
    border-radius: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.search-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.search-box {
    flex: 1;
    min-width: 300px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 12px 45px 12px 15px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-box i {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

/* === Filter Chips (Cihazdaki badge'ler gibi) === */
.filter-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip {
    padding: 8px 16px;
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chip:hover {
    background: #e2e8f0;
}

.chip.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* === Test Grid === */
.test-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.test-card {
    background: var(--card);
    border-radius: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    position: relative;
    transition: all 0.25s ease;
}

.test-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.08);
}

/* === Status Badge === */
.kategori-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
}

.kategori-biyokimya { background: rgba(59, 130, 246, 0.1); color: var(--primary); }
.kategori-hemogram { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.kategori-hormon { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.kategori-seroloji { background: rgba(168, 85, 247, 0.1); color: #8b5cf6; }

/* === Card Content === */
.test-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 8px;
    line-height: 1.4;
}

.test-code {
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.code-item {
    background: var(--light);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
}

.code-item i {
    margin-right: 4px;
}

/* === Range Info === */
.range-info {
    background: var(--light);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
}

.range-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    text-align: center;
}

.range-item {
    padding: 8px;
}

.range-label {
    font-size: 10px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.range-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--dark);
}

.range-divider {
    width: 1px;
    background: var(--border);
    margin: 0 5px;
}

/* === Meta Info === */
.meta-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: 15px;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.meta-item i {
    color: var(--primary);
}

/* === Action Bar (Cihazdaki gibi) === */
.action-bar {
    display: flex;
    gap: 8px;
}

.btn {
    flex: 1;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-edit {
    background: var(--primary-light);
    color: var(--primary);
}

.btn-edit:hover {
    background: var(--primary);
    color: white;
}

.btn-delete {
    background: #fef2f2;
    color: var(--danger);
}

.btn-delete:hover {
    background: var(--danger);
    color: white;
}

/* === FAB Button (Cihazdaki gibi) === */
.fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.3);
    transition: all 0.2s ease;
    z-index: 100;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

/* === Modal (Cihazdaki gibi) === */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 25px 25px 0;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--dark);
}

.modal-body {
    padding: 25px;
}

.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-select {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: white;
    color: var(--dark);
    transition: all 0.2s;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.btn-submit {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-submit:hover {
    background: #2563eb;
}

.btn-cancel {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    margin-top: 10px;
}

/* === Empty State (Cihazdaki gibi) === */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.empty-state i {
    font-size: 48px;
    color: #cbd5e1;
    margin-bottom: 20px;
}

/* === Mobile Responsive === */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .test-grid {
        grid-template-columns: 1fr;
    }
    
    .search-row {
        flex-direction: column;
    }
    
    .search-box {
        min-width: 100%;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .range-grid {
        grid-template-columns: 1fr;
        gap: 5px;
    }
}
</style>

<div class="container">
    <!-- Header -->
    <div class="header">
        <h1>Laboratuvar Test Tanımları</h1>
        <p>Sistemde kayıtlı tüm laboratuvar test parametreleri ve referans aralıkları</p>
    </div>

    <!-- Statistics -->
    <div class="stats-grid">
        <div class="stat-item">
            <div class="stat-number"><?= $istatistikler['toplam'] ?></div>
            <div class="stat-label">Toplam Test</div>
        </div>
        <div class="stat-item">
            <div class="stat-number" style="color: var(--primary);"><?= $istatistikler['biyokimya'] ?></div>
            <div class="stat-label">Biyokimya</div>
        </div>
        <div class="stat-item">
            <div class="stat-number" style="color: var(--success);"><?= $istatistikler['hemogram'] ?></div>
            <div class="stat-label">Hemogram</div>
        </div>
        <div class="stat-item">
            <div class="stat-number" style="color: var(--warning);"><?= $istatistikler['hormon'] ?></div>
            <div class="stat-label">Hormon</div>
        </div>
        <div class="stat-item">
            <div class="stat-number" style="color: #8b5cf6;"><?= $istatistikler['seroloji'] + $istatistikler['digery'] ?></div>
            <div class="stat-label">Diğer Testler</div>
        </div>
    </div>

    <!-- Search and Filters -->
    <div class="search-container">
        <form id="filterForm" method="GET">
            <input type="hidden" name="sayfa" value="test-tanimlari">
            
            <div class="search-row">
                <div class="search-box">
                    <input type="text" name="arama" value="<?= h($arama) ?>" 
                           placeholder="Test adı veya kodu ile ara...">
                    <i class="fas fa-search"></i>
                </div>

                <div style="display: flex; gap: 10px; align-items: center;">
                    <select name="kategori" onchange="this.form.submit()" class="form-select" style="width: 200px;">
                        <?php foreach ($kategoriler as $key => $value): ?>
                            <option value="<?= h($key) ?>" <?= $kategori == $key ? 'selected' : '' ?>>
                                <?= h($value) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                    
                    <button type="button" onclick="openTestModal()" class="btn" 
                            style="background: var(--primary); color: white; border: none; padding: 12px 20px; border-radius: 10px; font-weight: 600; cursor: pointer;">
                        <i class="fas fa-plus"></i> Yeni Test
                    </button>
                </div>
            </div>

            <div class="filter-chips">
                <div class="chip <?= $kategori == 'all' ? 'active' : '' ?>" onclick="setFilter('all')">
                    <i class="fas fa-layer-group"></i> Tümü
                </div>
                <?php foreach ($kategoriler as $key => $value): ?>
                    <?php if ($key !== 'all'): ?>
                        <div class="chip <?= $kategori == $key ? 'active' : '' ?>" onclick="setFilter('<?= h($key) ?>')">
                            <i class="fas fa-flask"></i> <?= h($value) ?>
                        </div>
                    <?php endif; ?>
                <?php endforeach; ?>
            </div>
        </form>
    </div>

    <!-- Test Grid -->
    <?php if (empty($testler)): ?>
        <div class="empty-state">
            <i class="fas fa-vials"></i>
            <h3 style="margin-bottom:10px;">Test Bulunamadı</h3>
            <p>Henüz kayıtlı test bulunmuyor veya filtre kriterlerinize uygun test yok</p>
        </div>
    <?php else: ?>
        <div class="test-grid">
            <?php foreach ($testler as $t): 
                $kategoriClass = 'kategori-' . strtolower(str_replace(' ', '-', $t['kategori']));
            ?>
                <div class="test-card">
                    <div class="kategori-badge <?= $kategoriClass ?>">
                        <?= h($t['kategori']) ?>
                    </div>
                    
                    <div class="test-name"><?= h($t['test_adi']) ?></div>
                    
                    <div class="test-code">
                        <div class="code-item">
                            <i class="fas fa-barcode"></i> KOD: <?= h($t['test_kodu']) ?>
                        </div>
                        <div class="code-item">
                            <i class="fas fa-hashtag"></i> ID: <?= $t['id'] ?>
                        </div>
                    </div>

                    <div class="range-info">
                        <div class="range-grid">
                            <div class="range-item">
                                <div class="range-label">Min Değer</div>
                                <div class="range-value"><?= h($t['min_deger']) ?></div>
                            </div>
                            <div class="range-item">
                                <div class="range-label">Birim</div>
                                <div class="range-value" style="color: var(--primary);"><?= h($t['birim']) ?></div>
                            </div>
                            <div class="range-item">
                                <div class="range-label">Max Değer</div>
                                <div class="range-value"><?= h($t['max_deger']) ?></div>
                            </div>
                        </div>
                    </div>

                    <div class="meta-info">
                        <div class="meta-item">
                            <i class="far fa-calendar-alt"></i>
                            <span>Periyot: <?= h($t['periyot']) ?></span>
                        </div>
                        <div class="meta-item">
                            <i class="far fa-clock"></i>
                            <span>Kayıt: <?= date('d.m.Y', strtotime($t['kayit_tarihi'] ?? 'now')) ?></span>
                        </div>
                    </div>

                    <div class="action-bar">
                        <button type="button" class="btn btn-edit" onclick="editTest(<?= htmlspecialchars(json_encode($t), ENT_QUOTES, 'UTF-8') ?>)">
                            <i class="fas fa-edit"></i> Düzenle
                        </button>
                        
                        <a href="islem.php?islem=test_sil&id=<?= $t['id'] ?>" 
                           class="btn btn-delete" 
                           onclick="return confirm('Bu testi silmek istediğinize emin misiniz?')">
                            <i class="fas fa-trash"></i> Sil
                        </a>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
</div>

<!-- FAB Button -->
<button class="fab" onclick="openTestModal()">
    <i class="fas fa-plus"></i>
</button>

<!-- Add/Edit Modal -->
<div class="modal-overlay" id="testModal">
    <div class="modal-content">
        <div class="modal-header">
            <h3 id="modalTitle">Yeni Test Tanımla</h3>
        </div>
        
        <form id="testForm" method="POST" action="islem.php">
            <!-- İŞLEM.PHP'YE UYGUN OLARAK DEĞİŞTİRİLDİ -->
            <input type="hidden" name="test_id" id="f_test_id" value="">
            
            <div class="modal-body">
                <div class="form-grid">
                    <div class="form-group" style="grid-column: 1 / -1;">
                        <label class="form-label">Test Adı *</label>
                        <input type="text" name="test_adi" id="f_test_adi" class="form-input" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">Test Kodu (LIS) *</label>
                        <input type="text" name="test_kodu" id="f_test_kodu" class="form-input" required placeholder="Örn: HGB">
                    </div>

                    <div class="form-group">
                        <label class="form-label">Kategori *</label>
                        <select name="kategori" id="f_kategori" class="form-select" required>
                            <option value="">Kategori Seçiniz</option>
                            <option value="Biyokimya">Biyokimya</option>
                            <option value="Hemogram">Hemogram</option>
                            <option value="Hormon">Hormon</option>
                            <option value="Seroloji">Seroloji</option>
                            <option value="Diğer">Diğer</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label class="form-label">Birim</label>
                        <input type="text" name="birim" id="f_birim" class="form-input" placeholder="mg/dL, U/L, g/dL...">
                    </div>

                    <div class="form-group">
                        <label class="form-label">Minimum Değer</label>
                        <input type="number" step="0.01" name="min_deger" id="f_min_deger" class="form-input">
                    </div>

                    <div class="form-group">
                        <label class="form-label">Maksimum Değer</label>
                        <input type="number" step="0.01" name="max_deger" id="f_max_deger" class="form-input">
                    </div>

                    <div class="form-group">
                        <label class="form-label">Periyot</label>
                        <select name="periyot" id="f_periyot" class="form-select">
                            <option value="Haftalık">Haftalık</option>
                            <option value="Aylık">Aylık</option>
                            <option value="3 Aylık">3 Aylık</option>
                            <option value="6 Aylık">6 Aylık</option>
                            <option value="Yıllık">Yıllık</option>
                        </select>
                    </div>
                </div>
            </div>

            <div style="padding: 0 25px 25px;">
                <!-- İŞLEM.PHP'DEKİ 'test_islem' İLE AYNI OLMALI -->
                <button type="submit" name="test_islem" class="btn-submit" id="modalSubmitBtn">
                    <i class="fas fa-save"></i> Kaydet
                </button>
                <button type="button" class="btn-cancel" onclick="closeModal('testModal')">
                    İptal
                </button>
            </div>
        </form>
    </div>
</div>

<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">

<script>
// Modal Functions
function openModal(id) {
    document.getElementById(id).classList.add('show');
}

function closeModal(id) {
    document.getElementById(id).classList.remove('show');
}

// Open test modal
function openTestModal() {
    resetToAdd();
    openModal('testModal');
}

// Open modal when clicking outside
document.getElementById('testModal').addEventListener('click', function(e) {
    if (e.target === this) closeModal('testModal');
});

// Search debounce
(function() {
    const form = document.getElementById('filterForm');
    if (!form) return;
    
    let timeout = null;
    const searchInput = form.querySelector('input[name="arama"]');
    
    if (searchInput) {
        searchInput.addEventListener('input', function() {
            clearTimeout(timeout);
            timeout = setTimeout(() => {
                form.submit();
            }, 350);
        });
    }
})();

// Filter functions
function setFilter(kategori) {
    const form = document.getElementById('filterForm');
    const kategoriSelect = form.querySelector('select[name="kategori"]');
    kategoriSelect.value = kategori;
    form.submit();
}

// Edit test - İŞLEM.PHP'YE UYGUN ŞEKİLDE DÜZENLENDİ
function editTest(test) {
    document.getElementById('modalTitle').textContent = 'Test Düzenle';
    
    // İşlem.php'de güncelleme için test_id gerekiyor
    document.getElementById('f_test_id').value = test.id || '';
    document.getElementById('f_test_adi').value = test.test_adi || '';
    document.getElementById('f_test_kodu').value = test.test_kodu || '';
    document.getElementById('f_kategori').value = test.kategori || '';
    document.getElementById('f_birim').value = test.birim || '';
    document.getElementById('f_min_deger').value = test.min_deger || '';
    document.getElementById('f_max_deger').value = test.max_deger || '';
    document.getElementById('f_periyot').value = test.periyot || 'Haftalık';
    
    // Buton metnini güncelle
    document.getElementById('modalSubmitBtn').innerHTML = '<i class="fas fa-check"></i> Güncelle';
    
    openModal('testModal');
}

// Reset form for new test
function resetToAdd() {
    document.getElementById('modalTitle').textContent = 'Yeni Test Tanımla';
    document.getElementById('f_test_id').value = '';
    document.getElementById('f_test_adi').value = '';
    document.getElementById('f_test_kodu').value = '';
    document.getElementById('f_kategori').value = '';
    document.getElementById('f_birim').value = '';
    document.getElementById('f_min_deger').value = '';
    document.getElementById('f_max_deger').value = '';
    document.getElementById('f_periyot').value = 'Haftalık';
    
    // Buton metnini sıfırla
    document.getElementById('modalSubmitBtn').innerHTML = '<i class="fas fa-save"></i> Kaydet';
}

// FAB button click
document.querySelector('.fab').addEventListener('click', function() {
    openTestModal();
});

// ESC key closes modal
document.addEventListener('keydown', function(e) {
    if (e.key === 'Escape') {
        closeModal('testModal');
    }
});
</script>