<?php require __DIR__ . '/../layouts/header.php'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="page-title"><i class="fa-solid fa-spell-check"></i><?= e(trans('copyeditor_workspace')) ?></h1>
    <a href="<?= e(base_path('dashboard')) ?>" class="btn btn-outline-secondary rounded-3"><?= e(trans('back')) ?></a>
</div>

<?php if (empty($rows)): ?>
    <div class="alert alert-info rounded-4"><?= e(trans('no_data')) ?></div>
<?php else: ?>
    <?php foreach ($rows as $r): ?>
        <div class="card border-0 shadow-sm rounded-4 mb-3">
            <div class="card-body p-4">
                <div class="d-flex justify-content-between flex-wrap gap-2">
                    <div>
                        <div class="fw-bold"><?= e((string)($r['submission_no'] ?? '')) ?> — <?= e((string)($r['title'] ?? '')) ?></div>
                        <div class="small text-muted"><?= e(current_lang()==='ar' ? (string)($r['conference_title_ar']??'') : (string)($r['conference_title_en']??'')) ?></div>
                    </div>
                    <div class="d-flex gap-2">
                        <span class="badge bg-primary"><?= e(trans((string)($r['status'] ?? 'assigned'))) ?></span>
                        <span class="badge bg-secondary"><?= e((string)($r['due_date'] ?? '-')) ?></span>
                    </div>
                </div>

                <hr>

                <form method="post" action="<?= e(base_path('copyeditor/update')) ?>">
                    <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                    <input type="hidden" name="submission_id" value="<?= e((string)$r['submission_id']) ?>">

                    <div class="row g-3">
                        <div class="col-md-4">
                            <label class="form-label"><?= e(trans('status')) ?></label>
                            <select name="status" class="form-select rounded-3">
                                <?php foreach (['assigned','in_progress','returned','completed'] as $st): ?>
                                    <option value="<?= e($st) ?>" <?= (($r['status'] ?? 'assigned') === $st) ? 'selected' : '' ?>><?= e(trans($st)) ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>

                        <div class="col-md-4">
                            <label class="form-label"><?= e(trans('due_date')) ?></label>
                            <input class="form-control rounded-3" value="<?= e((string)($r['due_date'] ?? '')) ?>" disabled>
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">Notes EN</label>
                            <textarea name="notes_en" class="form-control rounded-3 richtext" rows="4"><?= e((string)($r['notes_en'] ?? '')) ?></textarea>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Notes AR</label>
                            <textarea name="notes_ar" class="form-control rounded-3 richtext" rows="4"><?= e((string)($r['notes_ar'] ?? '')) ?></textarea>
                        </div>
                    </div>

                    <div class="mt-3">
                        <button class="btn btn-success rounded-3"><?= e(trans('save')) ?></button>
                    </div>
                </form>
            </div>
        </div>
    <?php endforeach; ?>
<?php endif; ?>

<?php require __DIR__ . '/../layouts/footer.php'; ?>
