<?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/sermons/<?= $sermon ? 'edit/' . $sermon['serm_id'] : 'create' ?>" enctype="multipart/form-data">
                <div class="row">
                    <div class="col-md-8 mb-3">
                        <label class="form-label"><?= gettext('Title') ?> <span class="text-danger">*</span></label>
                        <input type="text" name="title" class="form-control" required
                               value="<?= $sermon['serm_title'] ?? '' ?>">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label"><?= gettext('Speaker') ?></label>
                        <input type="text" name="speaker" class="form-control"
                               value="<?= $sermon['serm_speaker'] ?? '' ?>">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="form-label"><?= gettext('Date') ?></label>
                        <input type="date" name="date" class="form-control"
                               value="<?= $sermon['serm_date'] ?? '' ?>">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label"><?= gettext('Scripture Reference') ?></label>
                        <input type="text" name="scripture" class="form-control" placeholder="e.g. John 3:16"
                               value="<?= $sermon['serm_scripture'] ?? '' ?>">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label"><?= gettext('Featured') ?></label>
                        <select name="featured" class="form-control">
                            <option value="0" <?= isset($sermon) && !$sermon['serm_featured'] ? 'selected' : '' ?>><?= gettext('No') ?></option>
                            <option value="1" <?= isset($sermon) && $sermon['serm_featured'] ? 'selected' : '' ?>><?= gettext('Yes') ?></option>
                        </select>
                    </div>
                </div>

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

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label"><?= gettext('Audio URL') ?></label>
                        <input type="url" name="audio_url" class="form-control" placeholder="https://example.com/sermon.mp3"
                               value="<?= $sermon['serm_audio_url'] ?? '' ?>">
                        <small class="text-secondary"><?= gettext('Link to an audio file (MP3)') ?></small>
                        <input type="file" name="audio_file" class="form-control mt-1" accept="audio/*">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label"><?= gettext('Video URL') ?></label>
                        <input type="url" name="video_url" class="form-control" placeholder="https://youtube.com/watch?v=..."
                               value="<?= $sermon['serm_video_url'] ?? '' ?>">
                        <small class="text-secondary"><?= gettext('Link to a video (YouTube, Vimeo, etc.)') ?></small>
                    </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/image.jpg"
                               value="<?= $sermon['serm_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>

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

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