<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $impressions = $_POST['impressions'];
    $cpm = $_POST['cpm'];
    $ad_type = $_POST['ad_type'];

    if (is_numeric($impressions) && is_numeric($cpm)) {
        $earnings = ($impressions / 1000) * $cpm;
    } else {
        $error = "Please enter valid numbers for impressions and CPM.";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Podcast CPM Calculator</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css">
    <style>
        body {
            background-color: #f8f9fa;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            overflow: hidden;
        }
        .container-wrapper {
            display: flex;
            gap: 30px;
            max-width: 1200px;
            width: 100%;
            padding: 30px;
            background: #ffffff;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        .calculator-container {
            flex: 1;
        }
        .info-box {
            flex: 1;
            background-color: #e9ecef;
            padding: 15px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
<div class="container-wrapper">
    <div class="calculator-container">
        <h3 class="text-center">Podcast CPM Calculator</h3>
        <form method="post" action="">
            <div class="mb-3">
                <label for="impressions" class="form-label">Number of Impressions</label>
                <input type="text" class="form-control" id="impressions" name="impressions" required>
            </div>
            <div class="mb-3">
                <label for="cpm" class="form-label">CPM Rate ($)</label>
                <input type="text" class="form-control" id="cpm" name="cpm" required>
            </div>
            <div class="mb-3">
                <label for="ad_type" class="form-label">Podcast Ad Type</label>
                <select class="form-select" id="ad_type" name="ad_type" required>
                    <option value="Baked-In Host Read">Baked-In Host Read ($25-$40 CPM)</option>
                    <option value="Dynamic Episodic">Dynamic Episodic ($20-$25 CPM)</option>
                    <option value="Dynamic Catalog">Dynamic Catalog ($15-$20 CPM)</option>
                    <option value="Programmatic">Programmatic ($12-$15 CPM)</option>
                </select>
            </div>
            <button type="submit" class="btn btn-primary w-100">Calculate Earnings</button>
        </form>
        
        <?php if (isset($earnings)) { ?>
            <div class="alert alert-success mt-4" role="alert">
                Estimated Earnings: $<?php echo number_format($earnings, 2); ?>
            </div>
        <?php } elseif (isset($error)) { ?>
            <div class="alert alert-danger mt-4" role="alert">
                <?php echo $error; ?>
            </div>
        <?php } ?>
    </div>

    <div class="info-box">
        <h5>Types of Podcast Ads</h5>
        <ul>
            <li><strong>Baked-In Host Read:</strong> 30 or 60-second ad read by the host. Ad stays in the episode forever. Ideal for controlling which shows run your ad.</li>
            <li><strong>Dynamic Episodic:</strong> 30 or 60-second ad dynamically inserted into new episodes. Great for targeting specific podcasts and episodes.</li>
            <li><strong>Dynamic Catalog:</strong> Ad dynamically inserted into any episode within the entire catalog. Useful for targeting specific time frames or genres.</li>
            <li><strong>Programmatic:</strong> Pre-produced ad delivered across many podcasts. Ideal for geo-targeting and reaching specific audience segments.</li>
        </ul>
        <p><strong>CPM (Cost Per Mille)</strong> stands for the cost per 1,000 impressions. Use this calculator to estimate how much you could earn based on your ad type and audience reach.</p>
    </div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
</body>
</html>
