<?php
require_once __DIR__ . '/includes/auth.php';

$successMessage = '';
$errorMessage = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $residentName = trim($_POST['resident_name'] ?? '');
    $residentDob = trim($_POST['resident_dob'] ?? '');
    $contactName = trim($_POST['contact_name'] ?? '');
    $contactRelationship = trim($_POST['contact_relationship'] ?? '');
    $contactPhone = trim($_POST['contact_phone'] ?? '');
    $contactEmail = trim($_POST['contact_email'] ?? '');
    $preferredMoveDate = trim($_POST['preferred_move_date'] ?? '');
    $careLevel = trim($_POST['care_level'] ?? '');
    $specialNeeds = trim($_POST['special_needs'] ?? '');

    try {
        $conn = getDBConnection();
        $sql = 'INSERT INTO admissions (resident_name, resident_dob, contact_name, contact_relationship, contact_phone, contact_email, preferred_move_date, care_level, special_needs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
        $stmt = $conn->prepare($sql);
        $stmt->bind_param(
            'sssssssss',
            $residentName,
            $residentDob,
            $contactName,
            $contactRelationship,
            $contactPhone,
            $contactEmail,
            $preferredMoveDate,
            $careLevel,
            $specialNeeds
        );

        if ($stmt->execute()) {
            $successMessage = 'Thank you for your interest in Oldage Home. We will contact you within 2 business days to discuss next steps!';
        } else {
            $errorMessage = 'Sorry, there was an error submitting your application. Please try again or contact us directly.';
        }

        $stmt->close();
        $conn->close();
    } catch (Throwable $exception) {
        $errorMessage = 'Sorry, there was an error submitting your application. Please try again or contact us directly.';
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admission - Oldage Home</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="css/style.css">
    <style>
        .admission-hero {
            position: relative;
            overflow: hidden;
            min-height: 60vh;
            display: flex;
            align-items: center;
            background:
                linear-gradient(135deg, rgba(18, 52, 77, 0.92), rgba(30, 95, 116, 0.76)),
                url('images/hero-image.jpg') center/cover no-repeat;
        }
        .admission-hero::before,
        .admission-hero::after {
            content: '';
            position: absolute;
            border-radius: 999px;
            background: rgba(255, 255, 255, 0.08);
        }
        .admission-hero::before {
            width: 260px;
            height: 260px;
            top: -80px;
            right: -45px;
        }
        .admission-hero::after {
            width: 180px;
            height: 180px;
            bottom: -55px;
            left: -30px;
        }
        .admission-hero__card {
            position: relative;
            z-index: 1;
            background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
            border: 1px solid rgba(255, 255, 255, 0.14);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border-radius: 30px;
            padding: 2.2rem;
            box-shadow: 0 28px 64px rgba(5, 18, 31, 0.28);
        }
        .admission-hero__eyebrow {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 0.55rem 0.9rem;
            border-radius: 999px;
            background: rgba(255, 255, 255, 0.92);
            color: #12344d;
            font-size: 0.78rem;
            font-weight: 700;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            margin-bottom: 1rem;
        }
        .admission-stat {
            background: rgba(255, 255, 255, 0.96);
            border-radius: 22px;
            padding: 1.2rem;
            box-shadow: 0 16px 34px rgba(31, 51, 73, 0.08);
            height: 100%;
        }
        .admission-stat__icon {
            width: 52px;
            height: 52px;
            border-radius: 16px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, rgba(255, 140, 66, 0.16), rgba(21, 152, 149, 0.14));
            color: #12344d;
            font-size: 1.2rem;
            margin-bottom: 0.95rem;
        }
        .admission-panel,
        .admission-form-card,
        .admission-steps,
        .admission-cta {
            background: #fff;
            border-radius: 28px;
            box-shadow: 0 18px 44px rgba(31, 51, 73, 0.08);
        }
        .admission-panel,
        .admission-form-card,
        .admission-steps,
        .admission-cta {
            padding: 2rem;
        }
        .admission-panel__tag,
        .admission-form-card__tag {
            display: inline-flex;
            align-items: center;
            gap: 7px;
            padding: 0.45rem 0.78rem;
            border-radius: 999px;
            background: rgba(18, 52, 77, 0.06);
            color: #12344d;
            font-size: 0.76rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            margin-bottom: 1rem;
        }
        .admission-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .admission-list li {
            display: flex;
            gap: 12px;
            margin-bottom: 0.95rem;
            color: #3b556a;
            font-weight: 500;
        }
        .admission-list i {
            margin-top: 0.22rem;
        }
        .admission-list--docs i {
            color: #e85d2a;
        }
        .admission-list--checks i {
            color: #159895;
        }
        .admission-form-card {
            background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
            border: 1px solid rgba(18, 52, 77, 0.06);
        }
        .admission-form-card .form-label {
            font-weight: 600;
            color: #12344d;
        }
        .admission-form-card .form-control,
        .admission-form-card .form-select {
            min-height: 52px;
            border-radius: 16px;
            border-color: rgba(18, 52, 77, 0.12);
            box-shadow: none;
        }
        .admission-form-card textarea.form-control {
            min-height: 120px;
        }
        .admission-form-card .form-control:focus,
        .admission-form-card .form-select:focus {
            border-color: rgba(30, 95, 116, 0.42);
            box-shadow: 0 0 0 0.22rem rgba(30, 95, 116, 0.12);
        }
        .admission-step {
            position: relative;
            padding-left: 4.5rem;
            min-height: 64px;
        }
        .admission-step__number {
            position: absolute;
            top: 0;
            left: 0;
            width: 52px;
            height: 52px;
            border-radius: 18px;
            background: linear-gradient(135deg, #ff8c42 0%, #e85d2a 100%);
            color: #fff;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            box-shadow: 0 14px 30px rgba(232, 93, 42, 0.22);
        }
        .admission-cta {
            background: linear-gradient(135deg, #12344d 0%, #1e5f74 55%, #159895 100%);
            color: #fff;
            box-shadow: 0 24px 54px rgba(18, 52, 77, 0.18);
        }
        @media (max-width: 991.98px) {
            .admission-hero {
                min-height: auto;
                padding: 2rem 0;
            }
            .admission-hero__card,
            .admission-panel,
            .admission-form-card,
            .admission-steps,
            .admission-cta {
                padding: 1.5rem;
            }
        }
        @media (max-width: 767.98px) {
            .admission-hero {
                padding: 1.2rem 0 1.5rem;
            }
            .admission-hero__card,
            .admission-panel,
            .admission-form-card,
            .admission-steps,
            .admission-cta {
                border-radius: 22px;
            }
            .admission-hero__card {
                padding: 1.2rem;
            }
            .admission-hero__eyebrow {
                font-size: 0.66rem;
                padding: 0.48rem 0.72rem;
                margin-bottom: 0.85rem;
            }
            .admission-hero h1 {
                font-size: 1.78rem;
                line-height: 1.15;
                margin-bottom: 0.8rem !important;
            }
            .admission-hero .lead {
                font-size: 0.95rem;
                line-height: 1.58;
                margin-bottom: 1rem !important;
            }
            .admission-hero .btn {
                flex: 1 1 auto;
            }
            .admission-stat {
                padding: 1rem 0.92rem;
                border-radius: 18px;
            }
            .admission-stat__icon {
                width: 46px;
                height: 46px;
                border-radius: 14px;
                font-size: 1rem;
            }
            .admission-panel,
            .admission-form-card,
            .admission-steps,
            .admission-cta {
                padding: 1.25rem;
            }
            .admission-panel h2,
            .admission-form-card h2,
            .admission-steps h2,
            .admission-cta h2 {
                font-size: 1.5rem;
                line-height: 1.2;
            }
            .admission-panel p,
            .admission-form-card p,
            .admission-steps p,
            .admission-cta p,
            .admission-list li {
                font-size: 0.9rem;
                line-height: 1.58;
            }
            .admission-form-card .form-control,
            .admission-form-card .form-select {
                min-height: 48px;
                border-radius: 14px;
            }
            .admission-step {
                padding-left: 3.8rem;
                min-height: 58px;
            }
            .admission-step__number {
                width: 44px;
                height: 44px;
                border-radius: 15px;
                font-size: 0.92rem;
            }
        }
    </style>
</head>
<body>
    <?php include 'includes/header.php'; ?>

    <section class="admission-hero">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-xl-10">
                    <div class="admission-hero__card text-white text-center text-lg-start">
                        <div class="row align-items-center g-4">
                            <div class="col-lg-7">
                                <span class="admission-hero__eyebrow"><i class="fas fa-door-open"></i>Resident Onboarding</span>
                                <h1 class="display-5 fw-bold mb-3">A Calm, Guided Admission Journey for Families and Residents</h1>
                                <p class="lead mb-4">Our admission process is designed to feel clear, respectful, and supportive from the first inquiry to move-in day, so families can make decisions with confidence.</p>
                                <div class="d-flex flex-wrap gap-2 justify-content-center justify-content-lg-start">
                                    <a href="#admission-form" class="btn btn-primary">Start Inquiry</a>
                                    <a href="contact.php" class="btn btn-outline-light">Talk to Admissions</a>
                                </div>
                            </div>
                            <div class="col-lg-5">
                                <div class="row g-3">
                                    <div class="col-6">
                                        <div class="admission-stat text-dark">
                                            <div class="admission-stat__icon"><i class="fas fa-phone-volume"></i></div>
                                            <h3 class="h5 fw-bold mb-1">Quick Response</h3>
                                            <p class="mb-0 text-muted small">Our team follows up promptly after every inquiry.</p>
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="admission-stat text-dark">
                                            <div class="admission-stat__icon"><i class="fas fa-user-shield"></i></div>
                                            <h3 class="h5 fw-bold mb-1">Personal Guidance</h3>
                                            <p class="mb-0 text-muted small">We help families choose the right level of care.</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="py-5">
        <div class="container">
            <div class="row g-4 align-items-start">
                <div class="col-lg-5">
                    <div class="admission-panel h-100">
                        <span class="admission-panel__tag"><i class="fas fa-clipboard-check"></i>Requirements</span>
                        <h2 class="fw-bold mb-3">Who We Welcome and What You Should Prepare</h2>
                        <p class="text-muted mb-4">We welcome residents who need day-to-day support and families looking for a safe, compassionate, and community-focused living environment.</p>

                        <h5 class="fw-bold mb-3">Eligibility Criteria</h5>
                        <ul class="admission-list admission-list--checks mb-4">
                            <li><i class="fas fa-check-circle"></i><span>Age 65 and older</span></li>
                            <li><i class="fas fa-check-circle"></i><span>Requires help with at least 2 ADLs (Activities of Daily Living)</span></li>
                            <li><i class="fas fa-check-circle"></i><span>Medically stable and suitable for community living</span></li>
                            <li><i class="fas fa-check-circle"></i><span>Able to participate in daily routines and care planning</span></li>
                            <li><i class="fas fa-check-circle"></i><span>No active infectious disease requiring isolation care</span></li>
                        </ul>

                        <h5 class="fw-bold mb-3">Helpful Documents</h5>
                        <ul class="admission-list admission-list--docs mb-0">
                            <li><i class="fas fa-file-alt"></i><span>Medical records and health history</span></li>
                            <li><i class="fas fa-file-alt"></i><span>Current medications and prescriptions list</span></li>
                            <li><i class="fas fa-file-alt"></i><span>Insurance details and health coverage information</span></li>
                            <li><i class="fas fa-file-alt"></i><span>Legal documents such as power of attorney</span></li>
                            <li><i class="fas fa-file-alt"></i><span>Financial or billing-related information if needed</span></li>
                        </ul>
                    </div>
                </div>

                <div class="col-lg-7">
                    <div class="admission-form-card" id="admission-form">
                        <span class="admission-form-card__tag"><i class="fas fa-notes-medical"></i>Admission Inquiry</span>
                        <h2 class="fw-bold mb-3">Tell Us About the Resident and Your Care Needs</h2>
                        <p class="text-muted mb-4">Complete this short form and our admissions team will contact you to discuss the next steps, availability, and recommended care options.</p>

                        <?php if ($successMessage !== ''): ?>
                            <div class="alert alert-success"><?php echo htmlspecialchars($successMessage); ?></div>
                        <?php endif; ?>

                        <?php if ($errorMessage !== ''): ?>
                            <div class="alert alert-danger"><?php echo htmlspecialchars($errorMessage); ?></div>
                        <?php endif; ?>

                        <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
                            <h5 class="fw-bold mb-3">Resident Information</h5>
                            <div class="row g-3 mb-4">
                                <div class="col-md-6">
                                    <label for="resident_name" class="form-label">Resident Full Name *</label>
                                    <input type="text" class="form-control" id="resident_name" name="resident_name" required>
                                </div>
                                <div class="col-md-6">
                                    <label for="resident_dob" class="form-label">Date of Birth *</label>
                                    <input type="date" class="form-control" id="resident_dob" name="resident_dob" required>
                                </div>
                            </div>

                            <h5 class="fw-bold mb-3">Contact Person Information</h5>
                            <div class="row g-3 mb-4">
                                <div class="col-md-6">
                                    <label for="contact_name" class="form-label">Contact Person Name *</label>
                                    <input type="text" class="form-control" id="contact_name" name="contact_name" required>
                                </div>
                                <div class="col-md-6">
                                    <label for="contact_relationship" class="form-label">Relationship to Resident *</label>
                                    <select class="form-select" id="contact_relationship" name="contact_relationship" required>
                                        <option value="">Select Relationship</option>
                                        <option value="Spouse">Spouse</option>
                                        <option value="Child">Child</option>
                                        <option value="Sibling">Sibling</option>
                                        <option value="Other Family">Other Family</option>
                                        <option value="Legal Guardian">Legal Guardian</option>
                                        <option value="Friend">Friend</option>
                                        <option value="Other">Other</option>
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <label for="contact_phone" class="form-label">Phone Number *</label>
                                    <input type="tel" class="form-control" id="contact_phone" name="contact_phone" required>
                                </div>
                                <div class="col-md-6">
                                    <label for="contact_email" class="form-label">Email Address *</label>
                                    <input type="email" class="form-control" id="contact_email" name="contact_email" required>
                                </div>
                            </div>

                            <h5 class="fw-bold mb-3">Admission Details</h5>
                            <div class="row g-3 mb-4">
                                <div class="col-md-6">
                                    <label for="preferred_move_date" class="form-label">Preferred Move-in Date</label>
                                    <input type="date" class="form-control" id="preferred_move_date" name="preferred_move_date">
                                </div>
                                <div class="col-md-6">
                                    <label for="care_level" class="form-label">Anticipated Care Level</label>
                                    <select class="form-select" id="care_level" name="care_level">
                                        <option value="">Select Care Level</option>
                                        <option value="Assisted Living">Assisted Living</option>
                                        <option value="Memory Care">Memory Care</option>
                                        <option value="Skilled Nursing">Skilled Nursing</option>
                                        <option value="Rehabilitation">Rehabilitation</option>
                                    </select>
                                </div>
                            </div>

                            <div class="mb-4">
                                <label for="special_needs" class="form-label">Special Needs or Considerations</label>
                                <textarea class="form-control" id="special_needs" name="special_needs" rows="4" placeholder="Please describe any special care needs, dietary restrictions, mobility concerns, or other important details"></textarea>
                            </div>

                            <button type="submit" class="btn btn-primary btn-lg">Submit Admission Inquiry</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="pb-5">
        <div class="container">
            <div class="row g-4 align-items-stretch">
                <div class="col-lg-7">
                    <div class="admission-steps h-100">
                        <h2 class="fw-bold mb-4">What Happens After You Submit</h2>
                        <div class="admission-step mb-4">
                            <div class="admission-step__number">1</div>
                            <h3 class="h5 fw-bold mb-2">Initial Contact</h3>
                            <p class="mb-0 text-muted">Our admissions team reaches out within 2 business days to understand your needs and answer your questions.</p>
                        </div>
                        <div class="admission-step mb-4">
                            <div class="admission-step__number">2</div>
                            <h3 class="h5 fw-bold mb-2">Tour and Assessment</h3>
                            <p class="mb-0 text-muted">We arrange a facility tour and discuss care preferences, health requirements, and resident comfort priorities.</p>
                        </div>
                        <div class="admission-step mb-4">
                            <div class="admission-step__number">3</div>
                            <h3 class="h5 fw-bold mb-2">Documentation Review</h3>
                            <p class="mb-0 text-muted">We review medical, legal, and care-related documents to prepare a smooth admission plan.</p>
                        </div>
                        <div class="admission-step">
                            <div class="admission-step__number">4</div>
                            <h3 class="h5 fw-bold mb-2">Move-In Support</h3>
                            <p class="mb-0 text-muted">Once approved, we help coordinate move-in and make the resident’s transition feel calm and welcoming.</p>
                        </div>
                    </div>
                </div>
                <div class="col-lg-5">
                    <div class="admission-cta h-100 d-flex flex-column justify-content-between">
                        <div>
                            <span class="badge bg-light text-dark px-3 py-2 mb-3 rounded-pill">Need Help Deciding?</span>
                            <h2 class="fw-bold mb-3">Our Admissions Team Is Ready to Guide You</h2>
                            <p class="mb-0 text-white-50">If you are unsure about eligibility, care level, or the next step, we can walk you through the process and help you choose confidently.</p>
                        </div>
                        <div class="d-flex flex-wrap gap-2 mt-4">
                            <a href="contact.php" class="btn btn-light">Contact Admissions</a>
                            <a href="tel:+15551234567" class="btn btn-outline-light">Call (555) 123-4567</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <?php include 'includes/footer.php'; ?>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="js/main.js"></script>
</body>
</html>