<?php
/**
 * Meeting Agenda Detail — OT Taskforce meeting summaries + PDF preview
 */
$meetingId = (int)($_GET['id'] ?? 0);

$meetings = [
    1 => [
        'title' => 'Meeting One — CFD Overtime Taskforce Kickoff',
        'date' => 'Tuesday, March 25, 2026',
        'time' => '3:00 PM',
        'location' => 'Fire Administration Conference Room',
        'status' => 'completed',
        'pdf' => 'assets/data/meetings/ot-meeting-2026-03-25.pdf',
        'summary' => '<p>The inaugural CFD Overtime Taskforce meeting established a <strong>5-week sprint</strong> to produce prioritized, actionable recommendations to reduce overtime for the upcoming fiscal year and beyond. The taskforce was formed to identify, quantify, and address the primary drivers of overtime across the department.</p>
<p><strong>Goal:</strong> Produce implementable recommendations within 30 days that reduce unsustainable OT costs while maintaining safe, legally compliant staffing and operations.</p>
<p><strong>Key finding discussed:</strong> 17 members over 23 months in OT represent a 5.1% reduction target by department heads. July alone saw $60K in the first pay period. The executive summary report is due <strong>April 8, 2026</strong>.</p>
<p>The group discussed staffing optimization, noting that the authorized headcount increased to ~2,000 but actual staffing patterns show 10→13 ambulances in service, with questions about what impact this increase has on OT. Members raised concerns about "scheduling at a deficit" and whether Cronos (timekeeping) data is reliable, noting union restrictions on scheduling flexibility.</p>
<p>A predictive modeling concept was introduced — identifying members voluntarily running time for 6+ months straight, and members with 25+ years who could be assumed to use sick→vacation→leave policies before retirement ("burning time / terminal leave").</p>',
        'attendees' => ['All Assistant Fire Chiefs', 'Human Resources', 'Chief of Staff (Finance team)', 'Chief Uhl', 'Chief Neiheisel', 'Executive Assistant to Fire Chief', 'Kelsey Braido (Office of Performance & Data Analytics)', 'Solicitor\'s Office Representative', 'John O\'Connell'],
        'topics' => [
            ['title' => 'Taskforce Purpose & 30-Day Goal', 'description' => 'Produce a prioritized set of implementable recommendations within 30 days that reduce unsustainable overtime costs while maintaining safe, legally compliant staffing and operations.'],
            ['title' => 'Overtime Categories Defined', 'description' => '9 categories identified: minimum staffing OT (Peak Demand program), backfill OT (leave, injury, vacancies), training-related OT, leave designations & burning leave before retirement, 24-hour to 40-hour movement, detail assignments (~20 current members), contractual/policy constraints, data monitoring & enforcement, and forecasting improvements.'],
            ['title' => '5-Week Phase Plan', 'description' => 'Week 0 (Mar 25): Distribute data & assign leads. Week 1 (Apr 2): Data consolidation & initial observations. Week 2 (Apr 9): Root-cause deep dive with Solicitor present. Week 3 (Apr 16): Cost/benefit & implementation planning. Week 4 (Apr 23): Final recommendations & approval roadmap.'],
            ['title' => 'Subcommittee Structure', 'description' => '4 subcommittees formed: (1) Staffing & Deployment — minimum staffing, 24-hour scheduling, detail impacts. (2) Leave Management — sick, vacation, IWP patterns, retirement leave-burning. (3) Operations & Scheduling — shift trades, training overlap, special events. (4) Fleet/Out-of-Service Impact — apparatus downtime causing backfill OT. (5) Policy/Contract/Admin — labor agreement constraints, policy changes.'],
            ['title' => 'Staffing Optimization Discussion', 'description' => 'Authorized headcount increased to ~2,000 but ambulance count went from 10→13, raising questions about service impact vs OT impact. The group discussed whether help department staffing matches actual need — "how many officers do we need on any given day?"'],
            ['title' => 'Scheduling At A Deficit', 'description' => 'Cronos timekeeping data reliability questioned. Union restrictions on scheduling flexibility identified as a key constraint. Vector Solutions and other scheduling tools discussed. The question of "where do we start?" was raised for addressing scheduling-driven OT.'],
            ['title' => 'Leave Burning & Terminal Leave', 'description' => '18 members + 3 more identified as burning terminal leave. Two options discussed: (1) Don\'t accrue additional time, or (2) Daily fill is cheaper than OT backfill. Legal review assigned to Caldwell regarding MOV for burning time policies.'],
            ['title' => 'Data Requirements ("What We Know")', 'description' => 'Data needs identified for Week 1: total OT YTD vs prior years (12-24 months), OT by unit/company/division, OT by cause (sick, vacation, IWP, injury, vacancies, training, special events), retirement projections, training schedules for next 12 months, vacancy data, and historically used backfill patterns.'],
            ['title' => 'Monitoring & Governance', 'description' => 'Office of Performance and Data Analytics to maintain a weekly OT dashboard by unit, cause, and cost. Monthly executive review post-taskforce. Permanent OT reduction coordinator role proposed.'],
        ],
        'action_items' => [
            ['task' => 'Confirm subcommittee chairs and membership within 48 hours', 'assigned' => 'All Assistant Chiefs'],
            ['task' => 'Compile and distribute Week 1 "What We Know" data packet', 'assigned' => 'Data Lead, HR, Finance'],
            ['task' => 'Review initial observations and bring to Week 1 meeting', 'assigned' => 'All Members'],
            ['task' => 'Verify Cronos data accuracy for scheduling analysis', 'assigned' => 'Chris (referenced in notes)'],
            ['task' => '3-year leave breakdown with % change year-over-year, by rank and leave type', 'assigned' => 'O\'Connell'],
            ['task' => 'Legal review of MOV for burning time / terminal leave policies', 'assigned' => 'Caldwell / Solicitor\'s Office'],
            ['task' => 'Executive summary report due April 8, 2026', 'assigned' => 'Taskforce Lead'],
            ['task' => 'Set up @Drive: Overtime Task Force access (OneDrive, Notepad, Teams Channel)', 'assigned' => 'Admin Support'],
            ['task' => 'Schedule next meeting: Wednesday April 2 @ 3PM or 2PM — "Venn Diagrams" topic', 'assigned' => 'Taskforce Lead'],
        ],
    ],
    2 => [
        'title' => 'Meeting Two',
        'date' => 'Tuesday, April 1, 2026',
        'time' => '2:00 PM',
        'location' => 'Fire Administration, 3rd Floor Conference Room',
        'status' => 'upcoming',
        'pdf' => null,
        'summary' => null,
        'attendees' => [],
        'topics' => [],
        'action_items' => [],
    ],
];

$meeting = $meetings[$meetingId] ?? null;
if (!$meeting) {
    echo '<div class="card" style="text-align:center;padding:60px;"><h2>Meeting not found</h2><a href="dashboard.php?page=overtime-taskforce" class="btn">Back to Overtime Taskforce</a></div>';
    return;
}

$isCompleted = $meeting['status'] === 'completed';
$hasPdf = !empty($meeting['pdf']) && file_exists($meeting['pdf']);
?>

<!-- Back nav -->
<div style="margin-bottom:16px;">
    <a href="dashboard.php?page=overtime-taskforce" style="display:inline-flex; align-items:center; gap:6px; text-decoration:none; color:var(--accent); font-size:13px; font-weight:600;">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>
        Overtime Taskforce
    </a>
</div>

<!-- Meeting Header -->
<div style="
    position:relative; border-radius:16px; overflow:hidden; margin-bottom:24px;
    background:linear-gradient(135deg, #0B2240 0%, #163158 50%, #1B6CB0 100%);
    padding:32px 36px; color:#fff;
">
    <div style="position:absolute; top:-30px; right:-30px; width:160px; height:160px; background:radial-gradient(circle, rgba(91,164,217,0.15) 0%, transparent 70%); border-radius:50%;"></div>

    <div style="position:relative; z-index:2; display:flex; align-items:center; justify-content:space-between;">
        <div>
            <div style="display:flex; align-items:center; gap:10px; margin-bottom:10px;">
                <div style="width:52px; height:52px; background:rgba(255,255,255,0.1); border:1px solid rgba(255,255,255,0.15); border-radius:14px; display:flex; flex-direction:column; align-items:center; justify-content:center;">
                    <span style="font-size:20px; font-weight:800; line-height:1;"><?= date('d', strtotime($meeting['date'])) ?></span>
                    <span style="font-size:9px; font-weight:600; text-transform:uppercase; color:rgba(255,255,255,0.6);"><?= date('M', strtotime($meeting['date'])) ?></span>
                </div>
                <div>
                    <h1 style="font-size:24px; font-weight:800; margin-bottom:2px;"><?= htmlspecialchars($meeting['title']) ?></h1>
                    <p style="font-size:14px; color:rgba(255,255,255,0.6);"><?= $meeting['date'] ?> &middot; <?= $meeting['time'] ?></p>
                </div>
            </div>
            <?php if ($meeting['location']): ?>
            <div style="display:flex; align-items:center; gap:6px; font-size:12px; color:rgba(255,255,255,0.4);">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg>
                <?= htmlspecialchars($meeting['location']) ?>
            </div>
            <?php endif; ?>
        </div>
        <span style="padding:6px 16px; border-radius:20px; font-size:12px; font-weight:700; <?= $isCompleted ? 'background:rgba(140,198,63,0.2);color:#8CC63F;border:1px solid rgba(140,198,63,0.3);' : 'background:rgba(255,149,0,0.2);color:#FF9500;border:1px solid rgba(255,149,0,0.3);' ?>">
            <?= $isCompleted ? 'Completed' : 'Upcoming' ?>
        </span>
    </div>
</div>

<?php if ($isCompleted): ?>
<!-- Two-column layout: Summary + PDF -->
<div class="grid grid-2" style="margin-bottom:24px; align-items:start;">

    <!-- Left: Meeting Analysis -->
    <div>
        <?php if (!empty($meeting['attendees'])): ?>
        <div class="card" style="margin-bottom:16px;">
            <h3 style="font-size:14px; font-weight:700; color:var(--primary); margin-bottom:12px; display:flex; align-items:center; gap:8px;">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="2"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
                Attendees
            </h3>
            <div style="display:flex; flex-wrap:wrap; gap:6px;">
                <?php foreach ($meeting['attendees'] as $a): ?>
                <span style="padding:4px 12px; background:var(--ios-bg); border:1px solid var(--ios-border); border-radius:20px; font-size:12px; color:var(--primary); font-weight:500;"><?= htmlspecialchars($a) ?></span>
                <?php endforeach; ?>
            </div>
        </div>
        <?php endif; ?>

        <div class="card" style="margin-bottom:16px;">
            <h3 style="font-size:14px; font-weight:700; color:var(--primary); margin-bottom:12px; display:flex; align-items:center; gap:8px;">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="2"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
                Meeting Analysis
            </h3>
            <?php if ($meeting['summary']): ?>
                <div style="font-size:13px; color:var(--primary); line-height:1.7;"><?= $meeting['summary'] ?></div>
            <?php else: ?>
                <div style="text-align:center; padding:24px; background:var(--ios-bg); border-radius:12px; border:1px dashed var(--ios-border);">
                    <svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="var(--ios-tertiary)" stroke-width="1.5" style="margin-bottom:8px;">
                        <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/>
                    </svg>
                    <p style="font-size:13px; font-weight:600; color:var(--primary); margin-bottom:4px;">Awaiting PDF Upload</p>
                    <p style="font-size:12px; color:var(--ios-tertiary);">Upload the meeting agenda PDF to generate an AI-powered analysis with discussion topics, key decisions, and action items.</p>
                </div>
            <?php endif; ?>
        </div>

        <?php if (!empty($meeting['topics'])): ?>
        <div class="card" style="margin-bottom:16px;">
            <h3 style="font-size:14px; font-weight:700; color:var(--primary); margin-bottom:12px; display:flex; align-items:center; gap:8px;">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="2"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>
                Discussion Topics
            </h3>
            <?php foreach ($meeting['topics'] as $i => $topic): ?>
            <div style="display:flex; gap:12px; padding:12px 0; <?= $i > 0 ? 'border-top:1px solid var(--ios-border);' : '' ?>">
                <div style="width:28px; height:28px; background:var(--accent); border-radius:8px; display:flex; align-items:center; justify-content:center; flex-shrink:0; color:#fff; font-size:12px; font-weight:700;"><?= $i + 1 ?></div>
                <div>
                    <div style="font-size:14px; font-weight:600; color:var(--primary); margin-bottom:2px;"><?= htmlspecialchars($topic['title']) ?></div>
                    <div style="font-size:12px; color:var(--ios-secondary); line-height:1.5;"><?= htmlspecialchars($topic['description']) ?></div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>

        <?php if (!empty($meeting['action_items'])): ?>
        <div class="card">
            <h3 style="font-size:14px; font-weight:700; color:var(--primary); margin-bottom:12px; display:flex; align-items:center; gap:8px;">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#8CC63F" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
                Action Items
            </h3>
            <?php foreach ($meeting['action_items'] as $item): ?>
            <div style="display:flex; align-items:flex-start; gap:10px; padding:8px 0; border-bottom:1px solid var(--ios-border);">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--ios-tertiary)" stroke-width="2" style="flex-shrink:0; margin-top:2px;"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>
                <div>
                    <div style="font-size:13px; color:var(--primary);"><?= htmlspecialchars($item['task']) ?></div>
                    <?php if (!empty($item['assigned'])): ?>
                    <div style="font-size:11px; color:var(--ios-tertiary); margin-top:2px;">Assigned: <?= htmlspecialchars($item['assigned']) ?></div>
                    <?php endif; ?>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>

    <!-- Right: PDF Preview -->
    <div>
        <div class="card" style="overflow:hidden; padding:0;">
            <div style="padding:14px 20px; background:var(--ios-bg); border-bottom:1px solid var(--ios-border); display:flex; align-items:center; justify-content:space-between;">
                <div style="display:flex; align-items:center; gap:8px;">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#DC2626" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
                    <span style="font-size:13px; font-weight:600; color:var(--primary);">Meeting Agenda PDF</span>
                </div>
                <?php if ($hasPdf): ?>
                <a href="<?= $meeting['pdf'] ?>" target="_blank" class="btn btn-sm" style="font-size:11px;">
                    <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right:4px;"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
                    Open Full PDF
                </a>
                <?php endif; ?>
            </div>
            <?php if ($hasPdf): ?>
            <div style="height:700px; background:#525659;">
                <iframe src="<?= $meeting['pdf'] ?>" style="width:100%; height:100%; border:0;"></iframe>
            </div>
            <?php else: ?>
            <div style="height:400px; display:flex; flex-direction:column; align-items:center; justify-content:center; background:var(--ios-bg); color:var(--ios-tertiary);">
                <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="margin-bottom:12px; opacity:0.4;">
                    <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/>
                </svg>
                <p style="font-size:14px; font-weight:600; color:var(--primary); margin-bottom:4px;">No PDF Uploaded Yet</p>
                <p style="font-size:12px;">The meeting agenda document will appear here once uploaded.</p>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<?php else: ?>
<!-- Upcoming meeting: placeholder -->
<div class="card" style="text-align:center; padding:60px 32px;">
    <svg width="60" height="60" viewBox="0 0 24 24" fill="none" stroke="var(--ios-orange)" stroke-width="1.5" style="margin-bottom:16px; opacity:0.5;">
        <rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/>
    </svg>
    <h2 style="font-size:22px; font-weight:800; color:var(--primary); margin-bottom:6px;">Upcoming Meeting</h2>
    <p style="font-size:15px; color:var(--ios-secondary); margin-bottom:4px;"><?= $meeting['date'] ?> at <?= $meeting['time'] ?></p>
    <p style="font-size:13px; color:var(--ios-tertiary);">Agenda and documents will be available after the meeting.</p>
</div>
<?php endif; ?>
