<?php

use ChurchCRM\dto\SystemURLs;

include SystemURLs::getDocumentRoot() . '/Include/Header.php';
?>

<div class="container-fluid">
    <div class="card shadow-sm">
        <div class="card-body">
            <form method="POST" action="<?= SystemURLs::getRootPath() ?>/admin/website/groups/<?= $group ? 'edit/' . $group['grp_id'] : 'create' ?>" enctype="multipart/form-data">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label"><?= gettext('Group Name') ?> <span class="text-danger">*</span></label>
                        <input type="text" name="name" class="form-control" required value="<?= $group['grp_name'] ?? '' ?>">
                    </div>
                    <div class="col-md-3 mb-3">
                        <label class="form-label"><?= gettext('Day') ?></label>
                        <input type="text" name="day" class="form-control" placeholder="e.g. Tuesdays" value="<?= $group['grp_day'] ?? '' ?>">
                    </div>
                    <div class="col-md-3 mb-3">
                        <label class="form-label"><?= gettext('Time') ?></label>
                        <input type="text" name="time" class="form-control" placeholder="e.g. 7:00 PM" value="<?= $group['grp_time'] ?? '' ?>">
                    </div>
                </div>

                <div class="mb-3">
                    <label class="form-label"><?= gettext('Location') ?></label>
                    <input type="text" name="location" class="form-control" placeholder="e.g. Fellowship Hall" value="<?= $group['grp_location'] ?? '' ?>">
                </div>

                <div class="mb-3">
                    <label class="form-label"><?= gettext('Description') ?></label>
                    <textarea name="description" class="form-control" rows="4"><?= $group['grp_description'] ?? '' ?></textarea>
                </div>

                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="form-label"><?= gettext('Leader') ?></label>
                        <input type="text" name="leader" class="form-control" placeholder="e.g. Pastor David" value="<?= $group['grp_leader'] ?? '' ?>">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label"><?= gettext('Contact Email') ?></label>
                        <input type="email" name="email" class="form-control" placeholder="group@church.org" value="<?= $group['grp_email'] ?? '' ?>">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label"><?= gettext('Sort Order') ?></label>
                        <input type="number" name="sort_order" class="form-control" value="<?= $group['grp_sort_order'] ?? 0 ?>">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label"><?= gettext('Image URL') ?></label>
                        <input type="url" name="image_url" class="form-control" placeholder="https://example.com/group.jpg" value="<?= $group['grp_image_url'] ?? '' ?>">
                        <small class="text-secondary"><?= gettext('Or upload a file below') ?></small>
                        <input type="file" name="image_file" class="form-control mt-1" accept="image/*">
                    </div>
                    <div class="col-md-3 mb-3">
                        <label class="form-label"><?= gettext('Color') ?></label>
                        <input type="color" name="color" class="form-control form-control-color" value="<?= $group['grp_color'] ?? '#0d6efd' ?>">
                    </div>
                </div>

                <div class="d-flex gap-2">
                    <button type="submit" class="btn btn-primary">
                        <i class="fa-solid fa-save me-1"></i> <?= gettext('Save') ?>
                    </button>
                    <a href="<?= SystemURLs::getRootPath() ?>/admin/website/groups" class="btn btn-outline-secondary">
                        <?= gettext('Cancel') ?>
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>

<?php include SystemURLs::getDocumentRoot() . '/Include/Footer.php'; ?>
