<?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/ministries/<?= $ministry ? 'edit/' . $ministry['min_id'] : 'create' ?>" enctype="multipart/form-data">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label"><?= gettext('Ministry Title') ?> <span class="text-danger">*</span></label>
                        <input type="text" name="title" class="form-control" required value="<?= $ministry['min_title'] ?? '' ?>">
                    </div>
                    <div class="col-md-3 mb-3">
                        <label class="form-label"><?= gettext('Icon Class') ?></label>
                        <input type="text" name="icon" class="form-control" placeholder="fa-solid fa-child" value="<?= $ministry['min_icon'] ?? '' ?>">
                        <small class="text-secondary"><?= gettext('Font Awesome icon class') ?></small>
                    </div>
                    <div class="col-md-3 mb-3">
                        <label class="form-label"><?= gettext('Sort Order') ?></label>
                        <input type="number" name="sort_order" class="form-control" value="<?= $ministry['min_sort_order'] ?? 0 ?>">
                    </div>
                </div>

                <div class="mb-3">
                    <label class="form-label"><?= gettext('Description') ?></label>
                    <textarea name="description" class="form-control" rows="4"><?= $ministry['min_description'] ?? '' ?></textarea>
                </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/ministry.jpg" value="<?= $ministry['min_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('Background Color') ?></label>
                        <input type="color" name="bg_color" class="form-control form-control-color" value="<?= $ministry['min_bg_color'] ?? '#e3f2fd' ?>">
                    </div>
                </div>

                <?php if ($ministry && $ministry['min_image_url']): ?>
                <div class="mb-3">
                    <label class="form-label"><?= gettext('Current Image') ?></label><br>
                    <img src="<?= $ministry['min_image_url'] ?>" alt="" style="max-height:120px;border-radius:8px;">
                </div>
                <?php endif; ?>

                <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/ministries" class="btn btn-outline-secondary">
                        <?= gettext('Cancel') ?>
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>

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