<?php
require_once __DIR__ . '/../src/bootstrap.php';
require_once __DIR__ . '/../src/functions.php';

$flash = getFlash();
?>
<!doctype html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Yeni Müşteri Grubu</title>
<style>
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; background: #f5f7fb; color: #111827; }
.container { max-width: 900px; margin: 30px auto; padding: 0 16px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.topbar h1 { margin: 0; font-size: 28px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer; font-weight: 600; font-size: 14px; min-height: 44px; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-secondary { background: #e5e7eb; color: #111827; }
.card { background: #fff; border-radius: 18px; box-shadow: 0 10px 30px rgba(0,0,0,0.06); padding: 20px; }
.field { margin-bottom: 16px; }
label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
input[type="text"], input[type="file"], textarea { width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 12px 14px; font-size: 14px; background: #fff; outline: none; }
input:focus, textarea:focus { border-color: #2563eb; }
textarea { min-height: 140px; resize: vertical; }
.upload-box { border: 1px dashed #cbd5e1; border-radius: 12px; padding: 16px; background: #f8fafc; }
.muted { color: #6b7280; font-size: 13px; margin-top: 6px; line-height: 1.6; }
.limit-box { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; padding: 14px 16px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; line-height: 1.6; }
.flash { padding: 14px 16px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; }
.flash.success { background: #dcfce7; color: #166534; }
.flash.error { background: #fee2e2; color: #991b1b; }
@media (max-width: 640px) { .topbar h1 { font-size: 22px; } .actions { width: 100%; } .btn { width: 100%; } }
</style>
</head>
<body>
<div class="container">
    <div class="topbar">
        <h1>Yeni Müşteri Grubu</h1>
        <div class="actions">
            <a href="customer_groups.php" class="btn btn-secondary">Gruplara Dön</a>
            <a href="index.php" class="btn btn-secondary">Panele Dön</a>
        </div>
    </div>

    <?php if ($flash): ?>
        <div class="flash <?= e($flash['type']) ?>"><?= e($flash['message']) ?></div>
    <?php endif; ?>

    <div class="limit-box">
        Maksimum <strong>100 benzersiz alıcı</strong> kabul edilir. Excel / CSV dosyasında sistem yalnızca <strong>email</strong> başlıklı sütunu okur.
    </div>

    <div class="card">
        <form method="post" action="customer_group_store.php" enctype="multipart/form-data">
            <div class="field">
                <label for="name">Grup Adı</label>
                <input type="text" id="name" name="name" required placeholder="Örn: Hollanda Bayileri">
            </div>

            <div class="field">
                <label for="recipients_file">Excel / CSV Dosyası</label>
                <div class="upload-box">
                    <input type="file" id="recipients_file" name="recipients_file" accept=".xlsx,.csv" required>
                    <div class="muted">Dosyada ilk satır başlık satırı olmalı. Örnek: <strong>name | email | note</strong><br>Sistem yalnızca <strong>email</strong> sütununu okur.</div>
                </div>
            </div>

            <div class="field">
                <label for="extra_emails">Ek Mail Adresleri</label>
                <textarea id="extra_emails" name="extra_emails" placeholder="mail1@example.com, mail2@example.com&#10;mail3@example.com"></textarea>
                <div class="muted">İstersen Excel dışı ek mailleri de buradan ekleyebilirsin.</div>
            </div>

            <button type="submit" class="btn btn-primary">Grubu Kaydet</button>
        </form>
    </div>
</div>
</body>
</html>
