<?php
require_once __DIR__.'/includes/functions.php';
require_once __DIR__.'/includes/account-v281-ui.php';
mj_v281_ensure_schema();
$u = require_user();
$userId = (int)$u['id'];
mj_require_user_feature('account_center', $userId, 'Account Center is not enabled for your account.');
$pageTitle = 'Account Center';
$tabs = [
  'overview'=>'Overview','profile'=>'Profile','company'=>'Company','wallet'=>'Wallet','billing'=>'Billing','security'=>'Security','notifications'=>'Notifications','privacy'=>'Privacy','saved'=>'Saved Searches','blocked'=>'Blocked Users','activity'=>'Activity','limits'=>'My Limits','automation'=>'Automation','marketing'=>'Marketing Tools'
];
if (!mj_user_feature_enabled('wallet', $userId)) { unset($tabs['wallet']); }
if (!mj_user_feature_enabled('billing_payments', $userId)) { unset($tabs['billing']); }
$tab = (string)($_GET['tab'] ?? 'overview');
if (!isset($tabs[$tab])) { $tab = 'overview'; }
try {
  if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    verify_csrf();
    $action = (string)($_POST['action'] ?? '');
    if ($action === 'save_preferences') {
      mj_v281_save_user_preferences($userId, $_POST);
      flash('success','Account preferences saved.');
      redirect('account-center.php?tab=' . urlencode((string)($_POST['return_tab'] ?? 'profile')));
    }
    if ($action === 'add_saved_search') {
      $title = trim((string)($_POST['title'] ?? ''));
      $url = trim((string)($_POST['search_url'] ?? ''));
      if ($title === '') { throw new RuntimeException('Saved search title is required.'); }
      q('INSERT INTO mj_saved_searches(user_id,title,search_url,filters_json,alert_enabled,created_at) VALUES(?,?,?,?,?,NOW())', [$userId, substr($title,0,190), substr($url,0,500), '{}', !empty($_POST['alert_enabled'])?1:0]);
      mj_v281_log_activity($userId,'saved_search_added','Added saved search: '.$title);
      flash('success','Saved search added.');
      redirect('account-center.php?tab=saved');
    }
    if ($action === 'block_user') {
      $email = trim((string)($_POST['blocked_email'] ?? ''));
      $reason = trim((string)($_POST['reason'] ?? ''));
      if ($email === '') { throw new RuntimeException('Email or contact is required to block.'); }
      q('INSERT INTO mj_blocked_users(user_id,blocked_email,reason,created_at) VALUES(?,?,?,NOW())', [$userId, substr($email,0,190), substr($reason,0,255)]);
      mj_v281_log_activity($userId,'blocked_contact','Blocked contact: '.$email);
      flash('success','Blocked contact saved.');
      redirect('account-center.php?tab=blocked');
    }
    if ($action === 'privacy_request') {
      $type = in_array((string)($_POST['request_type'] ?? ''), ['download_data','delete_account','deactivate_account'], true) ? (string)$_POST['request_type'] : 'download_data';
      if (table_exists('mj_user_privacy_requests')) {
        q('INSERT INTO mj_user_privacy_requests(user_id,request_type,status,notes,created_at) VALUES(?,?,' . "'pending'" . ',?,NOW())', [$userId, $type, trim((string)($_POST['notes'] ?? ''))]);
      }
      mj_v281_log_activity($userId,'privacy_request','Submitted privacy request: '.$type);
      flash('success','Privacy request submitted for admin review.');
      redirect('account-center.php?tab=privacy');
    }
  }
} catch (Throwable $e) { flash('error',$e->getMessage()); }
$prefs = mj_v281_user_preferences($userId);
$completion = mj_v281_completion_score($u);
$limitsListing = mj_user_can_add_listing($userId);
$limitsCompany = mj_user_can_add_company($userId);
$companies = table_exists('mj_companies') ? all_rows('SELECT * FROM mj_companies WHERE user_id=? ORDER BY id DESC LIMIT 10', [$userId]) : [];
$wallet = table_exists('mj_wallets') ? one('SELECT * FROM mj_wallets WHERE user_id=? LIMIT 1', [$userId]) : null;
$walletTx = table_exists('mj_wallet_transactions') ? all_rows('SELECT * FROM mj_wallet_transactions WHERE '.(mj_column_exists('mj_wallet_transactions','user_id')?'user_id=?':'wallet_id=?').' ORDER BY id DESC LIMIT 10', [mj_column_exists('mj_wallet_transactions','user_id')?$userId:(int)($wallet['id']??0)]) : [];
$savedSearches = table_exists('mj_saved_searches') ? all_rows('SELECT * FROM mj_saved_searches WHERE user_id=? ORDER BY id DESC LIMIT 20', [$userId]) : [];
$blocked = table_exists('mj_blocked_users') ? all_rows('SELECT * FROM mj_blocked_users WHERE user_id=? ORDER BY id DESC LIMIT 20', [$userId]) : [];
$devices = table_exists('mj_user_devices') ? all_rows('SELECT * FROM mj_user_devices WHERE user_id=? ORDER BY last_seen_at DESC LIMIT 10', [$userId]) : [];
$privacyReq = table_exists('mj_user_privacy_requests') ? all_rows('SELECT * FROM mj_user_privacy_requests WHERE user_id=? ORDER BY id DESC LIMIT 10', [$userId]) : [];
$activities = mj_v281_recent_activity($userId, 12);
$billingPendingReview = 0;
if (table_exists('mj_upgrade_payment_proofs')) { $billingPendingReview += safe_count('SELECT COUNT(*) c FROM mj_upgrade_payment_proofs WHERE user_id=? AND status IN ("submitted","uploaded","pending","pending_review")', [$userId]); }
$billingPendingTotal = mj_v281_table_count('mj_payment_requests','user_id=? AND status IN ("pending","overdue","unpaid")',[$userId]) + $billingPendingReview;
include __DIR__.'/includes/header.php';
?>
<div class="container py-5"><div class="sidebar-layout"><?php include __DIR__.'/includes/account-sidebar.php'; ?><section>
  <div class="mj-page-hero rounded-4 mb-4"><div class="container-fluid"><span class="mj-badge mb-2"><i class="bi bi-person-gear"></i> Account Center</span><h1 class="fw-bold mb-1">Account Center</h1><p class="text-muted mb-0">Profile, company, wallet, security, privacy, notifications, saved searches, limits and automation in one clean place.</p></div></div>
  <?php mj_v281_tabs($tabs,$tab,'account-center.php'); ?>

  <?php if($tab==='overview'): ?>
    <div class="row g-4 mb-4">
      <div class="col-md-6 col-xl-3"><div class="stat"><b><?=e($completion['score'])?>%</b><br><span class="muted">Account Complete</span><div class="mj-progress-soft mt-2"><span style="width:<?=e($completion['score'])?>%"></span></div></div></div>
      <div class="col-md-6 col-xl-3"><div class="stat"><b><?=e((int)($u['trust_score'] ?? 0))?>%</b><br><span class="muted">Trust Score</span><div class="mj-progress-soft mt-2"><span style="width:<?=e(min(100,max(0,(int)($u['trust_score'] ?? 0))))?>%"></span></div></div></div>
      <div class="col-md-6 col-xl-3"><div class="stat"><b><?=e($limitsListing['used'])?> / <?=e($limitsListing['max']<=0?'∞':$limitsListing['max'])?></b><br><span class="muted">Listing Slots</span></div></div>
      <div class="col-md-6 col-xl-3"><div class="stat"><b><?=e($limitsCompany['used'])?> / <?=e($limitsCompany['max']<=0?'∞':$limitsCompany['max'])?></b><br><span class="muted">Company Slots</span></div></div>
    </div>
    <div class="card card-body border-0 rounded-4 shadow-sm mb-4"><h3 class="h5 fw-bold">Completion Checklist</h3><div class="mj-feature-list"><?php foreach($completion['checks'] as $name=>$ok): ?><div class="item"><i class="bi <?= $ok?'bi-check-circle-fill':'bi-circle' ?>"></i><?=e($name)?> <?= $ok?'<span class="badge text-bg-success float-end">Done</span>':'<span class="badge text-bg-warning float-end">Pending</span>' ?></div><?php endforeach; ?></div></div>
    <?php mj_v281_feature_grid([
      ['bi-person','Profile Quality','Warns users when photo, mobile, address, company or timezone is missing.'],['bi-building','Company Profile','Company logo, address, website, social links, opening hours and branches.'],['bi-wallet2','Wallet & Credits','Listing credits, sponsor credits, package history and refund credit notes.'],['bi-shield-lock','Privacy Control','Hide email/phone, login-only contacts, data download and delete account request.'],['bi-bell','Notification Rules','Email, WhatsApp, SMS, in-app, daily digest and do-not-disturb options.'],['bi-robot','Seller Automation','Away mode, auto reply, follow-up reminders and renew countdowns.']
    ]); ?>

  <?php elseif($tab==='profile'): ?>
    <form method="post" class="card card-body border-0 rounded-4 shadow-sm"><?=csrf_input()?><input type="hidden" name="action" value="save_preferences"><input type="hidden" name="return_tab" value="profile"><h3 class="h5 fw-bold mb-3">Profile & Contact Preferences</h3><div class="row g-3">
      <div class="col-md-6"><label class="label">Name</label><input class="form-control" value="<?=e($u['name'] ?? '')?>" readonly></div><div class="col-md-6"><label class="label">Email</label><input class="form-control" value="<?=e($u['email'] ?? '')?>" readonly></div>
      <div class="col-md-4"><label class="label">Preferred Contact</label><select class="form-select" name="preferred_contact_method"><?php foreach(['whatsapp'=>'WhatsApp','phone'=>'Phone Call','email'=>'Email','chat'=>'Marketplace Chat'] as $k=>$v): ?><option value="<?=e($k)?>" <?=$prefs['preferred_contact_method']===$k?'selected':''?>><?=e($v)?></option><?php endforeach; ?></select></div>
      <div class="col-md-4"><label class="label">Profile Visibility</label><select class="form-select" name="profile_visibility"><?php foreach(['public'=>'Public','login_required'=>'Login Required','private'=>'Private'] as $k=>$v): ?><option value="<?=e($k)?>" <?=$prefs['profile_visibility']===$k?'selected':''?>><?=e($v)?></option><?php endforeach; ?></select></div>
      <div class="col-md-4"><label class="label">Contact Visibility</label><select class="form-select" name="contact_visibility"><?php foreach(['public'=>'Show Public','login_required'=>'Show After Login','hidden'=>'Hide Contact'] as $k=>$v): ?><option value="<?=e($k)?>" <?=$prefs['contact_visibility']===$k?'selected':''?>><?=e($v)?></option><?php endforeach; ?></select></div>
      <div class="col-md-4"><label class="label">Language</label><input class="form-control" name="language_preference" value="<?=e($prefs['language_preference'])?>"></div><div class="col-md-4"><label class="label">Currency</label><input class="form-control" name="currency_code" value="<?=e($prefs['currency_code'])?>"></div><div class="col-md-4"><label class="label">Timezone</label><input class="form-control" name="timezone" value="<?=e($prefs['timezone'])?>"></div>
    </div><div class="mt-3"><button class="btn btn-primary rounded-pill px-4">Save Preferences</button></div></form>

  <?php elseif($tab==='company'): ?>
    <div class="d-flex justify-content-between align-items-center mb-3"><h3 class="h5 fw-bold mb-0">Company Profiles</h3><a class="btn btn-primary rounded-pill" href="<?=base_url('add-company.php')?>"><i class="bi bi-building-add me-1"></i>Add Company</a></div>
    <?php if(!$companies): mj_v281_empty('No company profile yet','Add your company profile with logo, address, website, social links, documents and opening hours.','bi-building'); else: ?><div class="row g-3"><?php foreach($companies as $co): ?><div class="col-md-6"><div class="mj-mini-card"><h5 class="fw-bold"><?=e($co['name'] ?? 'Company')?></h5><p class="text-muted mb-2"><?=e($co['address'] ?? '')?></p><div class="d-flex gap-2 flex-wrap"><a class="btn btn-sm btn-outline-primary" href="<?=base_url('company-edit.php?id='.(int)$co['id'])?>">Edit</a><a class="btn btn-sm btn-outline-secondary" href="<?=base_url('company.php?id='.(int)$co['id'])?>">Public Preview</a></div></div></div><?php endforeach; ?></div><?php endif; ?>
    <div class="mt-4"><?php mj_v281_feature_grid([['bi-people','Staff Users','Company owner can add staff logins and assign permissions.'],['bi-geo-alt','Branch Management','Multiple outlets, opening hours and branch-level contact details.'],['bi-folder-check','Company Documents','Business registration, license, certificates and expiry reminders.']]); ?></div>

  <?php elseif($tab==='wallet'): ?>
    <div class="row g-4 mb-4"><div class="col-md-4"><div class="stat"><b><?=money((float)($wallet['balance'] ?? 0), (string)($wallet['currency_code'] ?? $prefs['currency_code']))?></b><br><span class="muted">Wallet Balance</span></div></div><div class="col-md-4"><div class="stat"><b><?=e($billingPendingTotal)?></b><br><span class="muted">Pending Payment / Review</span></div></div><div class="col-md-4"><div class="stat"><b><?=e(mj_v281_table_count('mj_invoices','user_id=?',[$userId]))?></b><br><span class="muted">Invoices</span></div></div></div>
    <div class="card card-body border-0 rounded-4 shadow-sm"><h3 class="h5 fw-bold">Wallet Ledger</h3><?php if(!$walletTx): mj_v281_empty('No wallet transaction yet','Credits and debits will appear here after payments, upgrades, refunds or admin adjustments.','bi-wallet2'); else: ?><div class="table-responsive"><table class="table"><thead><tr><th>Date</th><th>Type</th><th>Description</th><th class="text-end">Amount</th></tr></thead><tbody><?php foreach($walletTx as $tx): ?><tr><td><?=e($tx['created_at'] ?? '')?></td><td><?=e($tx['transaction_type'] ?? $tx['type'] ?? '')?></td><td><?=e($tx['description'] ?? $tx['notes'] ?? '')?></td><td class="text-end fw-bold"><?=money((float)($tx['amount'] ?? 0), (string)($tx['currency_code'] ?? $wallet['currency_code'] ?? $prefs['currency_code']))?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?></div>

  <?php elseif($tab==='billing'): ?>
    <?php mj_v281_feature_grid([['bi-file-earmark-text','Invoices','Proforma invoice, official receipt, print and download-ready invoice center.'],['bi-upload','Payment Proof','Upload proof for renew, sponsor, featured listing or extra slot payment.'],['bi-percent','Tax / GST','Admin can enable GST/VAT by country with invoice tax details.'],['bi-arrow-counterclockwise','Refund Request','Refund and credit note request flow for admin approval.'],['bi-receipt','Receipts','Auto receipt after admin approves payment.'],['bi-calendar-check','Payment Reminder','Unpaid and overdue reminders by in-app/email/WhatsApp/SMS.']]); ?>
    <div class="mt-4"><a class="btn btn-primary rounded-pill" href="<?=base_url('billing-payments.php')?>">Open Billing & Payments</a></div>

  <?php elseif($tab==='security'): ?>
    <div class="row g-4"><div class="col-lg-6"><form method="post" class="mj-mini-card"><?=csrf_input()?><input type="hidden" name="action" value="save_preferences"><input type="hidden" name="return_tab" value="security"><h3 class="h5 fw-bold">Security Settings</h3><div class="form-check form-switch mt-3"><input class="form-check-input" type="checkbox" name="security_login_alert" value="1" <?=$prefs['security_login_alert']?'checked':''?>><label class="form-check-label">New login alert</label></div><div class="form-check form-switch"><input class="form-check-input" type="checkbox" name="do_not_disturb" value="1" <?=$prefs['do_not_disturb']?'checked':''?>><label class="form-check-label">Do not disturb for non-important alerts</label></div><button class="btn btn-primary rounded-pill mt-3">Save Security</button></form></div><div class="col-lg-6"><div class="mj-mini-card"><h3 class="h5 fw-bold">2FA / Google Auth</h3><p class="text-muted">Ready for email OTP, mobile OTP and Google Authenticator module connection.</p><span class="badge text-bg-info">Prepared</span></div></div></div>
    <div class="card card-body border-0 rounded-4 shadow-sm mt-4"><h3 class="h5 fw-bold">Recent Devices</h3><?php if(!$devices): mj_v281_empty('No device history yet','Login device tracking appears here after device records are stored.','bi-phone'); else: ?><div class="table-responsive"><table class="table"><thead><tr><th>IP</th><th>Device</th><th>Last Seen</th></tr></thead><tbody><?php foreach($devices as $d): ?><tr><td><?=e($d['ip_address'] ?? '')?></td><td><?=e($d['user_agent'] ?? '')?></td><td><?=e($d['last_seen_at'] ?? '')?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?></div>

  <?php elseif($tab==='notifications'): ?>
    <form method="post" class="card card-body border-0 rounded-4 shadow-sm"><?=csrf_input()?><input type="hidden" name="action" value="save_preferences"><input type="hidden" name="return_tab" value="notifications"><h3 class="h5 fw-bold mb-3">Notification Preferences</h3><div class="row g-3">
      <?php foreach(['notify_inapp'=>'In-app Alerts','notify_email'=>'Email Alerts','notify_sms'=>'SMS Alerts','notify_whatsapp'=>'WhatsApp Alerts','daily_digest'=>'Daily Digest','important_alerts_only'=>'Important Alerts Only'] as $k=>$label): ?><div class="col-md-4"><div class="form-check form-switch"><input class="form-check-input" type="checkbox" name="<?=e($k)?>" value="1" <?=!empty($prefs[$k])?'checked':''?>><label class="form-check-label fw-bold"><?=e($label)?></label></div></div><?php endforeach; ?>
    </div><button class="btn btn-primary rounded-pill mt-3">Save Notification Rules</button></form>
    <div class="mt-4"><?php mj_v281_feature_grid([['bi-clock','Renew Reminders','7 days, 3 days, 1 day and expired listing reminders.'],['bi-chat-dots','Lead Alerts','Quote received, offer received, missed lead and follow-up reminders.'],['bi-wallet2','Payment Alerts','Payment request, proof uploaded, approved, rejected, invoice overdue.']]); ?></div>

  <?php elseif($tab==='privacy'): ?>
    <div class="row g-4"><div class="col-lg-6"><form method="post" class="mj-mini-card"><?=csrf_input()?><input type="hidden" name="action" value="privacy_request"><h3 class="h5 fw-bold">Privacy Request</h3><label class="label">Request Type</label><select class="form-select" name="request_type"><option value="download_data">Download my data</option><option value="deactivate_account">Deactivate account</option><option value="delete_account">Delete account request</option></select><label class="label">Notes</label><textarea class="form-control" name="notes" rows="4"></textarea><button class="btn btn-primary rounded-pill mt-3">Submit Request</button></form></div><div class="col-lg-6"><div class="mj-mini-card"><h3 class="h5 fw-bold">Privacy Controls</h3><div class="mj-feature-list"><div class="item"><i class="bi bi-eye-slash"></i>Hide phone/email</div><div class="item"><i class="bi bi-person-lock"></i>Login-only contact</div><div class="item"><i class="bi bi-download"></i>Data download</div><div class="item"><i class="bi bi-trash"></i>Delete request</div></div></div></div></div>
    <div class="card card-body border-0 rounded-4 shadow-sm mt-4"><h3 class="h5 fw-bold">Request History</h3><?php if(!$privacyReq): mj_v281_empty('No privacy requests','Submitted privacy and account delete/deactivate requests will show here.','bi-shield-lock'); else: ?><div class="table-responsive"><table class="table"><thead><tr><th>Date</th><th>Type</th><th>Status</th><th>Notes</th></tr></thead><tbody><?php foreach($privacyReq as $r): ?><tr><td><?=e($r['created_at'] ?? '')?></td><td><?=e($r['request_type'] ?? '')?></td><td><?=mj_v281_badge((string)($r['status'] ?? 'pending'))?></td><td><?=e($r['notes'] ?? '')?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?></div>

  <?php elseif($tab==='saved'): ?>
    <form method="post" class="card card-body border-0 rounded-4 shadow-sm mb-4"><?=csrf_input()?><input type="hidden" name="action" value="add_saved_search"><h3 class="h5 fw-bold">Add Saved Search Alert</h3><div class="row g-3"><div class="col-md-4"><label class="label">Title</label><input class="form-control" name="title" placeholder="Example: MacBook under $800"></div><div class="col-md-6"><label class="label">Search URL</label><input class="form-control" name="search_url" placeholder="browse.php?q=..."></div><div class="col-md-2 d-flex align-items-end"><div class="form-check"><input class="form-check-input" type="checkbox" name="alert_enabled" value="1" checked><label class="form-check-label">Alert me</label></div></div></div><button class="btn btn-primary rounded-pill mt-3">Save Search</button></form>
    <?php if(!$savedSearches): mj_v281_empty('No saved searches','Save filters and get alerts when a matching listing is posted.','bi-search-heart'); else: ?><div class="row g-3"><?php foreach($savedSearches as $s): ?><div class="col-md-6"><div class="mj-mini-card"><h5 class="fw-bold"><?=e($s['title'])?></h5><p class="text-muted mb-1"><?=e($s['search_url'] ?? '')?></p><?=mj_v281_badge(!empty($s['alert_enabled'])?'active':'disabled')?></div></div><?php endforeach; ?></div><?php endif; ?>

  <?php elseif($tab==='blocked'): ?>
    <form method="post" class="card card-body border-0 rounded-4 shadow-sm mb-4"><?=csrf_input()?><input type="hidden" name="action" value="block_user"><h3 class="h5 fw-bold">Block User / Contact</h3><div class="row g-3"><div class="col-md-5"><label class="label">Email / Contact</label><input class="form-control" name="blocked_email"></div><div class="col-md-7"><label class="label">Reason</label><input class="form-control" name="reason"></div></div><button class="btn btn-primary rounded-pill mt-3">Block</button></form>
    <?php if(!$blocked): mj_v281_empty('No blocked users','Blocked buyers, sellers or contacts will appear here.','bi-slash-circle'); else: ?><div class="table-responsive card card-body border-0 rounded-4 shadow-sm"><table class="table"><thead><tr><th>Contact</th><th>Reason</th><th>Date</th></tr></thead><tbody><?php foreach($blocked as $b): ?><tr><td><?=e($b['blocked_email'] ?? $b['blocked_user_id'] ?? '')?></td><td><?=e($b['reason'] ?? '')?></td><td><?=e($b['created_at'] ?? '')?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?>

  <?php elseif($tab==='activity'): ?>
    <?php if(!$activities): mj_v281_empty('No activity yet','Login, listing, payment, enquiry, preference and support actions will show here.','bi-activity'); else: ?><div class="mj-timeline"><?php foreach($activities as $a): ?><div class="mj-timeline-item"><b><?=e(ucwords(str_replace('_',' ',$a['action'] ?? 'activity')))?></b><div class="text-muted small"><?=e($a['created_at'] ?? '')?> · <?=e($a['ip_address'] ?? '')?></div><p class="mb-0"><?=e($a['description'] ?? '')?></p></div><?php endforeach; ?></div><?php endif; ?>

  <?php elseif($tab==='limits'): ?>
    <div class="row g-4"><div class="col-md-6"><div class="mj-mini-card"><div class="mj-icon"><i class="bi bi-tags"></i></div><h3 class="h5 fw-bold">Listing Limit</h3><p><?=e($limitsListing['message'])?></p><?php if(mj_user_feature_enabled('extra_listing_slots',$userId)): ?><a class="btn btn-primary rounded-pill" href="<?=base_url('request-more-slots.php?type=listing')?>">Request More Listing Slots</a><?php else: ?><div class="alert alert-warning rounded-4 mb-0">Extra listing slots are not enabled for your account.</div><?php endif; ?></div></div><div class="col-md-6"><div class="mj-mini-card"><div class="mj-icon"><i class="bi bi-building"></i></div><h3 class="h5 fw-bold">Company Limit</h3><p><?=e($limitsCompany['message'])?></p><?php if(mj_user_feature_enabled('extra_company_slots',$userId)): ?><a class="btn btn-primary rounded-pill" href="<?=base_url('request-more-slots.php?type=company')?>">Request More Company Slots</a><?php else: ?><div class="alert alert-warning rounded-4 mb-0">Extra company slots are not enabled for your account.</div><?php endif; ?></div></div></div>

  <?php elseif($tab==='automation'): ?>
    <form method="post" class="card card-body border-0 rounded-4 shadow-sm mb-4"><?=csrf_input()?><input type="hidden" name="action" value="save_preferences"><input type="hidden" name="return_tab" value="automation"><h3 class="h5 fw-bold">Seller Automation</h3><div class="form-check form-switch mb-2"><input class="form-check-input" type="checkbox" name="away_mode" value="1" <?=$prefs['away_mode']?'checked':''?>><label class="form-check-label">Vacation / Away Mode</label></div><label class="label">Away Message</label><textarea class="form-control" name="away_message" rows="3"><?=e($prefs['away_message'])?></textarea><div class="form-check form-switch mt-3"><input class="form-check-input" type="checkbox" name="auto_reply_enabled" value="1" <?=$prefs['auto_reply_enabled']?'checked':''?>><label class="form-check-label">Auto Reply When Offline</label></div><label class="label">Auto Reply Message</label><textarea class="form-control" name="auto_reply_message" rows="3"><?=e($prefs['auto_reply_message'])?></textarea><button class="btn btn-primary rounded-pill mt-3">Save Automation</button></form>
    <?php mj_v281_feature_grid([['bi-alarm','Follow-up Reminder','Remind seller to follow up hot leads.'],['bi-exclamation-triangle','Missed Lead Alert','Warn seller when enquiry is not answered after admin-set hours.'],['bi-graph-up','Low Performance Alert','Suggest title/photo/boost when listing views are low.']]); ?>

  <?php elseif($tab==='marketing'): ?>
    <?php mj_v281_feature_grid([['bi-magic','AI Listing Helper','Improve title, description, keywords and category content.'],['bi-reply','AI Reply Helper','Suggest friendly replies to customer enquiries.'],['bi-translate','Auto Translate','Translate listings by country/language.'],['bi-google','SEO Preview','Show how listing appears on Google and social media.'],['bi-image','Share Poster','Create ready-to-share listing poster with QR code.'],['bi-whatsapp','WhatsApp Catalogue','Share listing or company profile nicely on WhatsApp.']]); ?>
  <?php endif; ?>
</section></div></div>
<?php include __DIR__.'/includes/footer.php'; ?>
