<?php
require_once __DIR__ . '/../includes/config.php';
if (file_exists(__DIR__ . '/../includes/auth.php')) require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/functions.php';
$issues = infl_schema_issues();
$form = infl_default_form();
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$issues) {
    $form = array_merge($form, $_POST);
    $result = infl_create_influencer($_POST, false);
    if ($result['success']) infl_redirect('view.php?id='.(int)$result['data']['id'].'&msg='.urlencode($result['message']));
    $error = $result['message'];
}
include __DIR__ . '/../includes/header.php';
if (file_exists(__DIR__ . '/../includes/sidebar.php')) include __DIR__ . '/../includes/sidebar.php';
?>
<div class="content-wrapper" style="padding:20px;">
  <div style="margin-bottom:18px;"><h1 style="margin:0 0 8px;">إضافة مؤثر</h1><p style="margin:0;color:#6b7280;">إنشاء مؤثر كامل مع كود الخصم وعمولته من نفس الصفحة.</p></div>
  <?php if ($issues): ?><div style="margin-bottom:16px;padding:12px 14px;border-radius:12px;background:#fff7ed;border:1px solid #fdba74;color:#9a3412;">أكو SQL ناقص، راجع صفحة index.</div><?php endif; ?>
  <?php if ($error): ?><div style="margin-bottom:16px;padding:12px 14px;border-radius:12px;background:#fef2f2;border:1px solid #fecaca;color:#991b1b;"><?php echo infl_h($error); ?></div><?php endif; ?>
  <form method="post"><?php $isEdit = false; include __DIR__ . '/_form.php'; ?></form>
</div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
