<?php
// Include database configuration
include('../config/database.php');
session_start();

if (!isset($_SESSION['assessor_id'])) {
    die("Access denied");
}

$assessor_id = $_SESSION['assessor_id'];
$proposal_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($proposal_id == 0) {
    die("Invalid request.");
}

// Fetch proposal details
$sql = "SELECT proposals.*, 
        (SELECT COUNT(*) FROM assessments WHERE proposal_id = proposals.id AND assessor_id = ?) AS assessed 
        FROM proposals 
        WHERE proposals.id = ?";
if ($stmt = $conn->prepare($sql)) {
    $stmt->bind_param("ii", $assessor_id, $proposal_id);
    $stmt->execute();
    $result = $stmt->get_result();
    if ($result->num_rows == 1) {
        $proposal = $result->fetch_assoc();
    } else {
        die("Proposal not found.");
    }
    $stmt->close();
} else {
    die("Database error: Unable to prepare statement.");
}

$conn->close();
?>

<h4><?php echo htmlspecialchars($proposal['business_idea_title']); ?></h4>
<p><?php echo htmlspecialchars($proposal['brief_description']); ?></p>
<p><strong>Programme of Study:</strong> <?php echo htmlspecialchars($proposal['programme_of_study']); ?></p>
<p><strong>Level:</strong> <?php echo htmlspecialchars($proposal['level']); ?></p>
<p><strong>Contact:</strong> <?php echo htmlspecialchars($proposal['contact']); ?></p>
<p><strong>Email:</strong> <?php echo htmlspecialchars($proposal['email']); ?></p>
<p><strong>Target Market:</strong> <?php echo htmlspecialchars($proposal['target_market']); ?></p>
<p><strong>Competitors:</strong> <?php echo htmlspecialchars($proposal['competitors']); ?></p>
<p><strong>Market Trends:</strong> <?php echo htmlspecialchars($proposal['market_trends']); ?></p>
<p><strong>Initial Capital:</strong> <?php echo htmlspecialchars($proposal['initial_capital']); ?></p>
<p><strong>Required Resources:</strong> <?php echo htmlspecialchars($proposal['required_resources']); ?></p>
<p><strong>Skills Needed:</strong> <?php echo htmlspecialchars($proposal['skills_needed']); ?></p>
<p><strong>Potential Partnerships:</strong> <?php echo htmlspecialchars($proposal['potential_partnerships']); ?></p>
<p><strong>Social Impact:</strong> <?php echo htmlspecialchars($proposal['social_impact']); ?></p>
<p><strong>Technological Elements:</strong> <?php echo htmlspecialchars($proposal['technological_elements']); ?></p>

<?php if ($proposal['assessed']): ?>
    <div class="badge bg-primary">Already Assessed</div>
<?php endif; ?>
