<?php
/**
 * ADMIN VENDOR DETAILS PAGE
 * File: admin/vendor-details.php
 * View detailed information about a specific vendor
 */

require_once '../app/Core/init.php';

// Check admin authentication
Auth::requireAdmin();

$page_title = "Vendor Details";
$active_menu = "vendors";

// Get vendor ID
$vendor_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if (!$vendor_id) {
    header('Location: vendors.php');
    exit;
}

// Initialize models
$db = Database::getInstance();
$vendor_model = new Vendor();

// Get vendor details with user information
$vendor_sql = "SELECT v.*, u.email, u.status as user_status, u.email_verified as reg_verification, u.email_verified, u.created_at as user_created,
               w.balance, w.total_earned, w.total_withdrawn
               FROM vendors v 
               LEFT JOIN users u ON v.user_id = u.id 
               LEFT JOIN wallets w ON v.user_id = w.user_id
               WHERE v.id = ?";
$vendor = $db->fetch($vendor_sql, [$vendor_id]);

if (!$vendor) {
    header('Location: vendors.php');
    exit;
}

// Get vendor statistics
$stats_sql = "SELECT 
              (SELECT COUNT(*) FROM items WHERE vendor_id = ?) as total_items,
              (SELECT COUNT(*) FROM items WHERE vendor_id = ? AND approval_status = 'pending') as pending_items,
              (SELECT COUNT(*) FROM items WHERE vendor_id = ? AND approval_status = 'approved') as approved_items,
              (SELECT COUNT(*) FROM orders WHERE vendor_id = ?) as total_orders,
              (SELECT COUNT(*) FROM orders WHERE vendor_id = ? AND status = 'completed') as completed_orders,
              (SELECT COALESCE(SUM(total_amount), 0) FROM orders WHERE vendor_id = ? AND payment_status = 'paid') as total_revenue,
              (SELECT COALESCE(SUM(commission_amount), 0) FROM commissions WHERE vendor_id = ?) as total_commission,
              (SELECT COALESCE(AVG(rating), 0) FROM reviews WHERE vendor_id = ?) as avg_rating,
              (SELECT COUNT(*) FROM reviews WHERE vendor_id = ?) as total_reviews";
$stats = $db->fetch($stats_sql, array_fill(0, 9, $vendor_id));

// Ensure stats has default values
if (!$stats || !is_array($stats)) {
    $stats = [];
}

$stats = array_merge([
    'total_items' => 0,
    'pending_items' => 0,
    'approved_items' => 0,
    'total_orders' => 0,
    'completed_orders' => 0,
    'total_revenue' => 0.00,
    'total_commission' => 0.00,
    'avg_rating' => 0.00,
    'total_reviews' => 0
], $stats);


// Get recent orders
$recent_orders_sql = "SELECT o.*, i.title as item_title, 
                      CONCAT(c.first_name, ' ', c.last_name) as customer_name
                      FROM orders o
                      LEFT JOIN items i ON o.item_id = i.id
                      LEFT JOIN customers c ON o.customer_id = c.id
                      WHERE o.vendor_id = ?
                      ORDER BY o.created_at DESC
                      LIMIT 10";
$recent_orders = $db->fetchAll($recent_orders_sql, [$vendor_id]);

// Get vendor items
$vendor_items_sql = "SELECT i.*, c.name as category_name,
                     (SELECT COUNT(*) FROM orders WHERE item_id = i.id) as total_orders
                     FROM items i
                     LEFT JOIN categories c ON i.category_id = c.id
                     WHERE i.vendor_id = ?
                     ORDER BY i.created_at DESC
                     LIMIT 20";
$vendor_items = $db->fetchAll($vendor_items_sql, [$vendor_id]);

// Get recent reviews
$recent_reviews_sql = "SELECT r.*, i.title as item_title,
                      CONCAT(c.first_name, ' ', c.last_name) as customer_name
                      FROM reviews r
                      LEFT JOIN items i ON r.item_id = i.id
                      LEFT JOIN customers c ON r.customer_id = c.id
                      WHERE r.vendor_id = ?
                      ORDER BY r.created_at DESC
                      LIMIT 10";
$recent_reviews = $db->fetchAll($recent_reviews_sql, [$vendor_id]);

// Handle flash messages
$flash_message = flash('message');

include '../templates/layouts/admin/head.php';
?>

<div class="main-content">
    <?php include '../templates/layouts/admin/header.php'; ?>
    
    <!-- Page Header -->
    <div style="padding: 30px; background: white; border-bottom: 1px solid #eee;">
        <h1 style="font-size: 28px; font-weight: 700; color: var(--dark); margin-bottom: 5px;">
            <?= Security::escapeOutput($vendor['business_name']) ?>
        </h1>
        <div style="display: flex; gap: 8px; font-size: 14px; color: #666;">
            <a href="index.php" style="color: var(--primary); text-decoration: none;">Home</a>
            <span>/</span>
            <a href="vendors.php" style="color: var(--primary); text-decoration: none;">Vendors</a>
            <span>/</span>
            <span><?= Security::escapeOutput($vendor['business_name']) ?></span>
        </div>
    </div>
    
    <!-- Content -->
    <div style="padding: 30px;">
        
        <!-- Flash Messages -->
        <?php if ($flash_message): ?>
            <div class="alert alert-<?= $flash_message['type'] ?>">
                <?= Security::escapeOutput($flash_message['message']) ?>
            </div>
        <?php endif; ?>
        
        <!-- Vendor Info Cards -->
        <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 30px;">
            <!-- Business Info -->
            <div style="background: white; border-radius: 12px; padding: 25px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);">
                <h3 style="font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--dark);">
                    <i class="fas fa-building"></i> Business Information
                </h3>
                
                <div style="space-y: 15px;">
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Business Name</label>
                        <div style="font-size: 16px; font-weight: 600;"><?= Security::escapeOutput($vendor['business_name']) ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Business Type</label>
                        <div style="font-size: 14px;"><?= Security::escapeOutput($vendor['business_type'] ?? 'Not specified') ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Business Description</label>
                        <div style="font-size: 14px; line-height: 1.5;"><?= Security::escapeOutput($vendor['business_description'] ?? 'No description') ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Contact Phone</label>
                        <div style="font-size: 14px;"><?= format_phone($vendor['phone']) ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Email Address</label>
                        <div style="font-size: 14px;"><?= Security::escapeOutput($vendor['email']) ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Location</label>
                        <div style="font-size: 14px;">
                            <?= Security::escapeOutput($vendor['address']) ?><br>
                            <?= Security::escapeOutput($vendor['city'] . ', ' . $vendor['state']) ?>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Financial Info -->
            <div style="background: white; border-radius: 12px; padding: 25px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);">
                <h3 style="font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--dark);">
                    <i class="fas fa-wallet"></i> Financial Overview
                </h3>
                
                <div style="space-y: 15px;">
                    <div style="margin-bottom: 15px; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Current Balance</label>
                        <div style="font-size: 20px; font-weight: 700; color: var(--success);">
                            <?= format_money($vendor['balance'] ?? 0) ?>
                        </div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Total Earned</label>
                        <div style="font-size: 16px; font-weight: 600;"><?= format_money($vendor['total_earned'] ?? 0) ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Total Withdrawn</label>
                        <div style="font-size: 16px; font-weight: 600;"><?= format_money($vendor['total_withdrawn'] ?? 0) ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Platform Commission</label>
                        <div style="font-size: 16px; font-weight: 600;"><?= format_money($stats['total_commission']) ?></div>
                    </div>
                    
                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Email Verification Status</label>
                        <div>
                            <?php
                            //registration confirmation
                            $reg_confirmation = '';
                            switch($vendor['reg_verification']) {
                                case '0':
                                    $reg_confirmation = 'status-pending';
                                    break;
                                case '1':
                                    $reg_confirmation = 'status-approved';
                                    break;
                            }
                            ?>
                            <span class="status-badge <?= $reg_confirmation ?>">
                                <?= ucfirst($vendor['reg_verification'] == 1 ? 'Verified' : 'Unverified') ?>
                            </span>
                        </div>
                    </div>

                    <div style="margin-bottom: 15px;">
                        <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Approval Status</label>
                        <div>
                            <?php
                            $status_class = '';
                            switch($vendor['approval_status']) {
                                case 'pending':
                                    $status_class = 'status-pending';
                                    break;
                                case 'approved':
                                    $status_class = 'status-approved';
                                    break;
                                case 'rejected':
                                    $status_class = 'status-rejected';
                                    break;
                                case 'suspended':
                                    $status_class = 'status-suspended';
                                    break;
                            }
                            ?>
                            <span class="status-badge <?= $status_class ?>">
                                <?= ucfirst($vendor['approval_status']) ?>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Statistics -->
            <div style="background: white; border-radius: 12px; padding: 25px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);">
                <h3 style="font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--dark);">
                    <i class="fas fa-chart-bar"></i> Performance Statistics
                </h3>
                
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
                    <div style="text-align: center; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <div style="font-size: 24px; font-weight: 700; color: var(--primary);"><?= number_format($stats['total_items']) ?></div>
                        <div style="font-size: 12px; color: #666;">Total Items</div>
                    </div>
                    
                    <div style="text-align: center; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <div style="font-size: 24px; font-weight: 700; color: var(--warning);"><?= number_format($stats['pending_items']) ?></div>
                        <div style="font-size: 12px; color: #666;">Pending Items</div>
                    </div>
                    
                    <div style="text-align: center; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <div style="font-size: 24px; font-weight: 700; color: var(--success);"><?= number_format($stats['approved_items']) ?></div>
                        <div style="font-size: 12px; color: #666;">Approved Items</div>
                    </div>
                    
                    <div style="text-align: center; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <div style="font-size: 24px; font-weight: 700; color: var(--info);"><?= number_format($stats['total_orders']) ?></div>
                        <div style="font-size: 12px; color: #666;">Total Orders</div>
                    </div>
                    
                    <div style="text-align: center; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <div style="font-size: 24px; font-weight: 700; color: var(--success);"><?= number_format($stats['completed_orders']) ?></div>
                        <div style="font-size: 12px; color: #666;">Completed Orders</div>
                    </div>
                    
                    <div style="text-align: center; padding: 15px; background: #f8f9fa; border-radius: 8px;">
                        <div style="font-size: 20px; font-weight: 700; color: var(--warning);">
                            <?= number_format($stats['avg_rating'], 1) ?>/5
                        </div>
                        <div style="font-size: 12px; color: #666;">Avg Rating</div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- Tabs for different sections -->
        <div style="background: white; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); overflow: hidden;">
            <div style="border-bottom: 1px solid #eee;">
                <div style="display: flex; padding: 0;">
                    <button class="tab-button active" onclick="showTab('items')">
                        <i class="fas fa-box"></i> Items (<?= count($vendor_items) ?>)
                    </button>
                    <button class="tab-button" onclick="showTab('orders')">
                        <i class="fas fa-shopping-bag"></i> Recent Orders (<?= count($recent_orders) ?>)
                    </button>
                    <button class="tab-button" onclick="showTab('reviews')">
                        <i class="fas fa-star"></i> Reviews (<?= count($recent_reviews) ?>)
                    </button>
                    <button class="tab-button" onclick="showTab('banking')">
                        <i class="fas fa-university"></i> Banking Details
                    </button>
                </div>
            </div>
            
            <!-- Items Tab -->
            <div id="items-tab" class="tab-content">
                <?php if (empty($vendor_items)): ?>
                    <div style="padding: 40px; text-align: center; color: #999;">
                        <i class="fas fa-box fa-3x mb-3"></i>
                        <p>No items found for this vendor</p>
                    </div>
                <?php else: ?>
                    <div style="padding: 20px;">
                        <div style="overflow-x: auto;">
                            <table style="width: 100%; border-collapse: collapse;">
                                <thead>
                                    <tr style="background: #f8f9fa;">
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Item</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Category</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Price/Day</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Status</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Orders</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($vendor_items as $item): ?>
                                        <tr style="border-bottom: 1px solid #f0f0f0;">
                                            <td style="padding: 15px;">
                                                <div style="display: flex; align-items: center; gap: 10px;">
                                                    <img src="<?= upload('items/' . ($item['main_image'] ?? 'default.jpg')) ?>" 
                                                         alt="<?= Security::escapeOutput($item['title']) ?>"
                                                         style="width: 40px; height: 40px; object-fit: cover; border-radius: 5px;">
                                                    <div>
                                                        <strong><?= Security::escapeOutput($item['title']) ?></strong><br>
                                                        <small style="color: #666;"><?= Security::escapeOutput($item['city']) ?></small>
                                                    </div>
                                                </div>
                                            </td>
                                            <td style="padding: 15px;"><?= Security::escapeOutput($item['category_name']) ?></td>
                                            <td style="padding: 15px;">
                                                <strong><?= format_money($item['price_per_day']) ?></strong><br>
                                                <small style="color: #666;">Qty: <?= $item['available_quantity'] ?>/<?= $item['quantity'] ?></small>
                                            </td>
                                            <td style="padding: 15px;">
                                                <?php
                                                $status_class = '';
                                                switch($item['approval_status']) {
                                                    case 'pending':
                                                        $status_class = 'status-pending';
                                                        break;
                                                    case 'approved':
                                                        $status_class = 'status-approved';
                                                        break;
                                                    case 'rejected':
                                                        $status_class = 'status-rejected';
                                                        break;
                                                    case 'suspended':
                                                        $status_class = 'status-suspended';
                                                        break;
                                                }
                                                ?>
                                                <span class="status-badge <?= $status_class ?>">
                                                    <?= ucfirst($item['approval_status']) ?>
                                                </span>
                                            </td>
                                            <td style="padding: 15px;">
                                                <span style="background: var(--info); color: white; padding: 4px 8px; border-radius: 12px; font-size: 12px;">
                                                    <?= $item['total_orders'] ?>
                                                </span>
                                            </td>
                                            <td style="padding: 15px;">
                                                <a href="item-details.php?slug=<?= $item['slug'] ?>" class="btn-action btn-view" title="View Item">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
            
            <!-- Orders Tab -->
            <div id="orders-tab" class="tab-content" style="display: none;">
                <?php if (empty($recent_orders)): ?>
                    <div style="padding: 40px; text-align: center; color: #999;">
                        <i class="fas fa-shopping-bag fa-3x mb-3"></i>
                        <p>No orders found for this vendor</p>
                    </div>
                <?php else: ?>
                    <div style="padding: 20px;">
                        <div style="overflow-x: auto;">
                            <table style="width: 100%; border-collapse: collapse;">
                                <thead>
                                    <tr style="background: #f8f9fa;">
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Order #</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Item</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Customer</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Amount</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Period</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Status</th>
                                        <th style="padding: 12px 15px; text-align: left; font-size: 13px; font-weight: 600; color: #666;">Date</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($recent_orders as $order): ?>
                                        <tr style="border-bottom: 1px solid #f0f0f0;">
                                            <td style="padding: 15px;">
                                                <strong><?= Security::escapeOutput($order['order_number']) ?></strong>
                                            </td>
                                            <td style="padding: 15px;">
                                                <?= Security::escapeOutput($order['item_title']) ?>
                                            </td>
                                            <td style="padding: 15px;">
                                                <?= Security::escapeOutput($order['customer_name']) ?>
                                            </td>
                                            <td style="padding: 15px;">
                                                <strong><?= format_money($order['total_amount']) ?></strong>
                                            </td>
                                            <td style="padding: 15px;">
                                                <small>
                                                    <?= format_date($order['start_date'], 'M d') ?> - 
                                                    <?= format_date($order['end_date'], 'M d') ?>
                                                </small>
                                            </td>
                                            <td style="padding: 15px;">
                                                <?php
                                                $status_class = '';
                                                switch($order['status']) {
                                                    case 'pending':
                                                        $status_class = 'status-pending';
                                                        break;
                                                    case 'confirmed':
                                                        $status_class = 'status-approved';
                                                        break;
                                                    case 'ongoing':
                                                        $status_class = 'status-info';
                                                        break;
                                                    case 'completed':
                                                        $status_class = 'status-success';
                                                        break;
                                                    case 'cancelled':
                                                        $status_class = 'status-rejected';
                                                        break;
                                                    case 'suspended':
                                                        $status_class = 'status-suspended';
                                                        break;
                                                }
                                                ?>
                                                <span class="status-badge <?= $status_class ?>">
                                                    <?= ucfirst($order['status']) ?>
                                                </span>
                                            </td>
                                            <td style="padding: 15px;">
                                                <small><?= format_date($order['created_at'], 'M d, Y') ?></small>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
            
            <!-- Reviews Tab -->
            <div id="reviews-tab" class="tab-content" style="display: none;">
                <?php if (empty($recent_reviews)): ?>
                    <div style="padding: 40px; text-align: center; color: #999;">
                        <i class="fas fa-star fa-3x mb-3"></i>
                        <p>No reviews found for this vendor</p>
                    </div>
                <?php else: ?>
                    <div style="padding: 20px;">
                        <?php foreach ($recent_reviews as $review): ?>
                            <div style="border-bottom: 1px solid #f0f0f0; padding: 20px 0;">
                                <div style="display: flex; justify-content: between; align-items: flex-start; margin-bottom: 10px;">
                                    <div style="flex: 1;">
                                        <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 5px;">
                                            <strong><?= Security::escapeOutput($review['customer_name']) ?></strong>
                                            <div style="color: #ffc107;">
                                                <?php for ($i = 1; $i <= 5; $i++): ?>
                                                    <i class="fas fa-star <?= $i <= $review['rating'] ? '' : 'text-light' ?>"></i>
                                                <?php endfor; ?>
                                            </div>
                                            <small style="color: #666;"><?= format_date($review['created_at'], 'M d, Y') ?></small>
                                        </div>
                                        <div style="font-size: 14px; margin-bottom: 8px;">
                                            <strong><?= Security::escapeOutput($review['item_title']) ?></strong>
                                        </div>
                                    </div>
                                </div>
                                <p style="margin: 0; line-height: 1.6;">
                                    <?= Security::escapeOutput($review['review']) ?>
                                </p>
                                <?php if (!empty($review['vendor_reply'])): ?>
                                    <div style="margin-top: 15px; padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 3px solid var(--primary);">
                                        <strong>Vendor Reply:</strong>
                                        <p style="margin: 5px 0 0 0; line-height: 1.5;">
                                            <?= Security::escapeOutput($review['vendor_reply']) ?>
                                        </p>
                                        <small style="color: #666;">
                                            <?= format_date($review['vendor_replied_at'], 'M d, Y h:i A') ?>
                                        </small>
                                    </div>
                                <?php endif; ?>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
            </div>
            
            <!-- Banking Tab -->
            <div id="banking-tab" class="tab-content" style="display: none;">
                <div style="padding: 20px;">
                    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px;">
                        <div>
                            <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Bank Name</label>
                            <div style="font-size: 16px; font-weight: 600; margin-bottom: 15px;">
                                <?= Security::escapeOutput($vendor['bank_name'] ?? 'Not provided') ?>
                            </div>
                        </div>
                        
                        <div>
                            <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Account Number</label>
                            <div style="font-size: 16px; font-weight: 600; margin-bottom: 15px;">
                                <?= Security::escapeOutput($vendor['account_number'] ?? 'Not provided') ?>
                            </div>
                        </div>
                        
                        <div>
                            <label style="font-weight: 600; color: #666; font-size: 12px; text-transform: uppercase;">Account Name</label>
                            <div style="font-size: 16px; font-weight: 600; margin-bottom: 15px;">
                                <?= Security::escapeOutput($vendor['account_name'] ?? 'Not provided') ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- Action Buttons -->
        <div style="margin-top: 30px; text-align: center;">
            <div style="display: flex; justify-content: center; gap: 15px;">
                <?php if ($vendor['approval_status'] === 'pending'): ?>
                    <button onclick="approveVendor(<?= $vendor['id'] ?>)" 
                            style="background: var(--success); color: white; border: none; padding: 12px 24px; border-radius: 6px; font-weight: 600; cursor: pointer;">
                        <i class="fas fa-check"></i> Approve Vendor
                    </button>
                    <button onclick="rejectVendor(<?= $vendor['id'] ?>)" 
                            style="background: var(--danger); color: white; border: none; padding: 12px 24px; border-radius: 6px; font-weight: 600; cursor: pointer;">
                        <i class="fas fa-times"></i> Reject Vendor
                    </button>
                <?php elseif ($vendor['approval_status'] === 'approved'): ?>
                    <button onclick="suspendVendor(<?= $vendor['id'] ?>)" 
                            style="background: var(--warning); color: white; border: none; padding: 12px 24px; border-radius: 6px; font-weight: 600; cursor: pointer;">
                        <i class="fas fa-ban"></i> Suspend Vendor
                    </button>
                <?php endif; ?>
                
                <button onclick="sendMessage(<?= $vendor['id'] ?>)" 
                        style="background: var(--primary); color: white; border: none; padding: 12px 24px; border-radius: 6px; font-weight: 600; cursor: pointer;">
                    <i class="fas fa-envelope"></i> Send Message
                </button>
            </div>
        </div>
    </div>
</div>

<style>
.tab-button {
    background: none;
    border: none;
    padding: 15px 20px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    color: #666;
    transition: all 0.3s;
    font-size: 14px;
}

.tab-button:hover {
    color: var(--primary);
    background: #f8f9fa;
}

.tab-button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: #f8f9fa;
}

.status-pending {
    background: var(--warning);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-approved {
    background: var(--success);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-rejected {
    background: var(--danger);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-info {
    background: var(--info);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-success {
    background: var(--success);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-suspended {
    background: #6c757d;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.btn-action {
    background: none;
    border: 1px solid #ddd;
    padding: 8px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
    color: #666;
}

.btn-action:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #f8f9fa;
}
</style>

<script>
function showTab(tabName) {
    // Hide all tabs
    const tabs = ['items', 'orders', 'reviews', 'banking'];
    tabs.forEach(tab => {
        const tabElement = document.getElementById(tab + '-tab');
        const buttonElement = document.querySelector(`[onclick="showTab('${tab}')"]`);
        if (tabElement) tabElement.style.display = 'none';
        if (buttonElement) buttonElement.classList.remove('active');
    });
    
    // Show selected tab
    const selectedTab = document.getElementById(tabName + '-tab');
    const selectedButton = document.querySelector(`[onclick="showTab('${tabName}')"]`);
    if (selectedTab) selectedTab.style.display = 'block';
    if (selectedButton) selectedButton.classList.add('active');
}

function approveVendor(vendorId) {
    if (confirm('Are you sure you want to approve this vendor?')) {
        window.location.href = 'vendor-approve.php?id=' + vendorId;
    }
}

function rejectVendor(vendorId) {
    const reason = prompt('Please enter rejection reason:');
    if (reason !== null && reason.trim() !== '') {
        window.location.href = 'vendor-reject.php?id=' + vendorId + '&reason=' + encodeURIComponent(reason);
    }
}

function suspendVendor(vendorId) {
    if (confirm('Are you sure you want to suspend this vendor?')) {
        window.location.href = 'vendor-suspend.php?id=' + vendorId;
    }
}

function sendMessage(vendorId) {
    // Implementation for sending message to vendor
    alert('Message feature coming soon!');
}
</script>

<?php include '../templates/layouts/admin/footer.php'; ?>