<?php require_once __DIR__ . '/../layout.php'; ?>

<div style="max-width: 800px; margin: 0 auto;">
    <div style="margin-bottom: 2rem; display: flex; align-items: center; justify-content: space-between;">
        <div>
            <h3 style="margin: 0 0 0.5rem; color: white;">Edit Execution Log Entry</h3>
            <p style="color: var(--text-muted); margin: 0;">Modify or annotate system execution logs.</p>
        </div>
        <a href="/superadmin/settings" class="btn-outline-gold" style="display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; padding: 0.6rem 1.2rem; border-radius: 8px;">
            <i class="ph ph-arrow-left"></i> Back to Settings
        </a>
    </div>

    <div class="card" style="padding: 2.5rem; background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: 16px; backdrop-filter: blur(10px);">
        <form action="/superadmin/logUpdate/<?php echo $record['id']; ?>" method="POST">
            
            <div class="form-row" style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem;">
                <!-- Date & Time (Readonly) -->
                <div class="input-group">
                    <label style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: block;">Execution Timestamp</label>
                    <input type="text" value="<?php echo htmlspecialchars($record['created_at']); ?>" readonly style="width: 100%; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid rgba(255,255,255,0.05); background: rgba(15,23,42,0.3); color: var(--text-muted); outline: none; font-size: 0.95rem; cursor: not-allowed;">
                </div>

                <!-- Tenant Name (Readonly) -->
                <div class="input-group">
                    <label style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: block;">Tenant Pharmacy</label>
                    <input type="text" value="<?php echo htmlspecialchars($record['tenant_name'] ?? 'System / Global'); ?>" readonly style="width: 100%; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid rgba(255,255,255,0.05); background: rgba(15,23,42,0.3); color: var(--text-muted); outline: none; font-size: 0.95rem; cursor: not-allowed;">
                </div>

                <!-- Trigger Type (Readonly) -->
                <div class="input-group">
                    <label style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: block;">Trigger Type</label>
                    <input type="text" value="<?php echo ($record['alert_type'] === 'manual') ? 'Manual' : 'Scheduler'; ?>" readonly style="width: 100%; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid rgba(255,255,255,0.05); background: rgba(15,23,42,0.3); color: var(--text-muted); outline: none; font-size: 0.95rem; cursor: not-allowed;">
                </div>
            </div>

            <!-- Recipients -->
            <div class="input-group" style="margin-bottom: 1.5rem;">
                <label for="recipients" style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: block;">Recipients (Comma-separated)</label>
                <input type="text" id="recipients" name="recipients" value="<?php echo htmlspecialchars($record['recipients'] ?? ''); ?>" style="width: 100%; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid var(--glass-border); background: rgba(15,23,42,0.6); color: white; outline: none; font-size: 0.95rem;">
            </div>

            <div class="form-row" style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem;">
                <!-- Items Count -->
                <div class="input-group">
                    <label for="items_count" style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: block;">Items Affected Count</label>
                    <input type="number" id="items_count" name="items_count" value="<?php echo intval($record['items_count']); ?>" min="0" style="width: 100%; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid var(--glass-border); background: rgba(15,23,42,0.6); color: white; outline: none; font-size: 0.95rem;">
                </div>

                <!-- Status -->
                <div class="input-group">
                    <label for="status" style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: block;">Execution Status</label>
                    <select id="status" name="status" style="width: 100%; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid var(--glass-border); background: rgba(15,23,42,0.6); color: white; outline: none; font-size: 0.95rem;">
                        <option value="success" <?php echo $record['status'] === 'success' ? 'selected' : ''; ?> style="background: var(--bg-dark); color: white;">SUCCESS</option>
                        <option value="failure" <?php echo $record['status'] === 'failure' ? 'selected' : ''; ?> style="background: var(--bg-dark); color: white;">FAILURE</option>
                    </select>
                </div>
            </div>

            <!-- Failure Reason / Notes -->
            <div class="input-group" style="margin-bottom: 2rem;">
                <label for="failure_reason" style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: block;">Failure Reason / Admin Notes</label>
                <textarea id="failure_reason" name="failure_reason" rows="4" style="width: 100%; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid var(--glass-border); background: rgba(15,23,42,0.6); color: white; outline: none; font-family: 'Inter', sans-serif; font-size: 0.95rem; resize: vertical;"><?php echo htmlspecialchars($record['failure_reason'] ?? ''); ?></textarea>
            </div>

            <!-- Form Submit -->
            <button type="submit" class="btn-gold" style="width: 100%; justify-content: center; height: 46px;">
                <i class="ph ph-floppy-disk" style="font-size: 1.25rem;"></i> Update Log Entry
            </button>
        </form>
    </div>
</div>
