<?= $this->extend('layouts/admin') ?>

<?= $this->section('content') ?>

<div>
        <div style="max-width: 800px; margin: 0 auto;">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px;">
                <h1><?= $title ?></h1>
                <a href="<?= base_url('admin') ?>" class="btn" style="border: 1px solid var(--text-muted); color: var(--text-muted);">Cancel</a>
            </div>

            <div class="admin-card" style="padding: 40px; background: #ffffff; border: 1px solid rgba(0,0,0,0.05); box-shadow: 0 10px 40px rgba(0,0,0,0.03);">
                <form action="<?= base_url('admin/project_save') ?>" method="post" enctype="multipart/form-data">
                    <?php if (isset($project)): ?>
                        <input type="hidden" name="id" value="<?= $project['id'] ?>">
                    <?php endif; ?>
                    <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
                        <div>
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Project Title</label>
                            <input type="text" name="title" value="<?= $project['title'] ?? '' ?>" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;" required>
                        </div>
                        <div>
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Client Name</label>
                            <input type="text" name="client_name" value="<?= $project['client_name'] ?? '' ?>" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;" placeholder="e.g. Acme Corp">
                        </div>
                        <div>
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Category</label>
                            <select name="category_id" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;">
                                <?php foreach ($categories as $cat): ?>
                                    <option value="<?= $cat['id'] ?>" <?= (isset($project) && $project['category_id'] == $cat['id']) ? 'selected' : '' ?>><?= $cat['name'] ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div>
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Project Status</label>
                            <select name="status" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;">
                                <option value="Planning" <?= (isset($project) && $project['status'] == 'Planning') ? 'selected' : '' ?>>Planning</option>
                                <option value="In Progress" <?= (isset($project) && $project['status'] == 'In Progress') ? 'selected' : '' ?>>In Progress</option>
                                <option value="Completed" <?= (isset($project) && $project['status'] == 'Completed') ? 'selected' : '' ?>>Completed</option>
                            </select>
                        </div>
                    </div>

                    <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
                        <div>
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Budget (₹)</label>
                            <input type="number" name="budget" value="<?= $project['budget'] ?? '' ?>" step="0.01" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;" required>
                        </div>
                        <div>
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Start Date</label>
                            <input type="date" name="start_date" value="<?= $project['start_date'] ?? '' ?>" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;" required>
                        </div>
                    </div>

                    <div style="margin-bottom: 20px;">
                        <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Project Banner Image <?= isset($project) ? '(Leave blank to keep current)' : '' ?></label>
                        <input type="file" name="image" style="width: 100%; padding: 10px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;" <?= isset($project) ? '' : 'required' ?>>
                    </div>

                    <div style="margin-bottom: 20px;">
                        <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Client Details</label>
                        <textarea name="client_details" rows="2" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;" placeholder="Client location, contact person, etc."><?= $project['client_details'] ?? '' ?></textarea>
                    </div>

                    <div style="margin-bottom: 30px;">
                        <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">Description</label>
                        <textarea name="description" rows="5" style="width: 100%; padding: 12px; background: #fbfbfb; border: 1px solid rgba(0,0,0,0.08); border-radius: 8px; color: #333;" required><?= $project['description'] ?? '' ?></textarea>
                    </div>

                    <button type="submit" class="btn btn-primary" style="width: 100%; padding: 15px; border-radius: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;">Save Project</button>
                </form>
            </div>

        </div>
    </div>
</div>

<?= $this->endSection() ?>
