<?php $statusMap = infl_status_map(); ?>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:16px;">
  <div style="background:#fff;border:1px solid #e5e7eb;border-radius:16px;padding:18px;">
    <h3 style="margin-top:0;">بيانات المؤثر</h3>
    <div style="display:grid;gap:12px;">
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">اسم المؤثر</label><input type="text" name="name" required value="<?php echo infl_h($form['name']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">كود الدخول</label><input type="text" name="login_code" required value="<?php echo infl_h($form['login_code']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">رقم الهاتف</label><input type="text" name="phone" required value="<?php echo infl_h($form['phone']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">معرف انستغرام</label><input type="text" name="instagram_username" value="<?php echo infl_h($form['instagram_username']); ?>" placeholder="username" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;"><?php echo !empty($isEdit) ? 'كلمة مرور جديدة (اختياري)' : 'كلمة المرور'; ?></label><input type="password" name="password" <?php echo empty($isEdit) ? 'required' : ''; ?> style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">الحالة</label><select name="status" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"><?php foreach ($statusMap as $k => $v): ?><option value="<?php echo (int)$k; ?>" <?php echo (string)$form['status'] === (string)$k ? 'selected' : ''; ?>><?php echo infl_h($v); ?></option><?php endforeach; ?></select></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">ملاحظات</label><textarea name="notes" rows="4" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"><?php echo infl_h($form['notes']); ?></textarea></div>
    </div>
  </div>
  <div style="background:#fff;border:1px solid #e5e7eb;border-radius:16px;padding:18px;">
    <h3 style="margin-top:0;">خصم الزبون وعمولة المؤثر</h3>
    <div style="display:grid;gap:12px;">
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">عنوان الكود</label><input type="text" name="promo_title" value="<?php echo infl_h($form['promo_title']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">كود الخصم</label><input type="text" name="promo_code" required value="<?php echo infl_h($form['promo_code']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div>
      <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;"><div><label style="display:block;margin-bottom:6px;font-size:13px;">نوع خصم الزبون</label><select name="discount_type" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"><option value="percent" <?php echo $form['discount_type']==='percent'?'selected':''; ?>>نسبة %</option><option value="fixed" <?php echo $form['discount_type']==='fixed'?'selected':''; ?>>مبلغ ثابت</option></select></div><div><label style="display:block;margin-bottom:6px;font-size:13px;">قيمة الخصم</label><input type="number" step="0.01" name="discount_value" value="<?php echo infl_h($form['discount_value']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div></div>
      <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;"><div><label style="display:block;margin-bottom:6px;font-size:13px;">نوع عمولة المؤثر</label><select name="influencer_commission_type" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"><option value="percent" <?php echo $form['influencer_commission_type']==='percent'?'selected':''; ?>>نسبة %</option><option value="fixed" <?php echo $form['influencer_commission_type']==='fixed'?'selected':''; ?>>مبلغ ثابت</option></select></div><div><label style="display:block;margin-bottom:6px;font-size:13px;">قيمة العمولة</label><input type="number" step="0.01" name="influencer_commission_value" value="<?php echo infl_h($form['influencer_commission_value']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div></div>
      <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;"><div><label style="display:block;margin-bottom:6px;font-size:13px;">الحد الأدنى للطلب</label><input type="number" step="0.01" name="minimum_order_amount" value="<?php echo infl_h($form['minimum_order_amount']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div><div><label style="display:block;margin-bottom:6px;font-size:13px;">الحد الأعلى للخصم (اختياري)</label><input type="number" step="0.01" name="maximum_discount_amount" value="<?php echo infl_h($form['maximum_discount_amount']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div></div>
      <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;"><div><label style="display:block;margin-bottom:6px;font-size:13px;">حد الاستخدام (اختياري)</label><input type="number" name="usage_limit" value="<?php echo infl_h($form['usage_limit']); ?>" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div><div><label style="display:block;margin-bottom:6px;font-size:13px;">حالة الكود</label><select name="promo_status" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"><option value="1" <?php echo (string)$form['promo_status']==='1'?'selected':''; ?>>فعال</option><option value="0" <?php echo (string)$form['promo_status']==='0'?'selected':''; ?>>غير فعال</option></select></div></div>
      <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;"><div><label style="display:block;margin-bottom:6px;font-size:13px;">بداية الكود</label><input type="text" name="start_at" value="<?php echo infl_h($form['start_at']); ?>" placeholder="2026-03-31 12:00:00" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div><div><label style="display:block;margin-bottom:6px;font-size:13px;">نهاية الكود</label><input type="text" name="end_at" value="<?php echo infl_h($form['end_at']); ?>" placeholder="2026-04-30 23:59:59" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"></div></div>
      <div><label style="display:block;margin-bottom:6px;font-size:13px;">ملاحظات الكود</label><textarea name="promo_notes" rows="3" style="width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:10px;"><?php echo infl_h($form['promo_notes']); ?></textarea></div>
    </div>
  </div>
</div>
<div style="margin-top:16px;display:flex;gap:10px;flex-wrap:wrap;"><button type="submit" style="background:#16a34a;color:#fff;border:none;padding:12px 18px;border-radius:10px;cursor:pointer;">حفظ</button><a href="list.php" style="display:inline-block;background:#111827;color:#fff;text-decoration:none;padding:12px 18px;border-radius:10px;">رجوع</a></div>
