<div class="container-fluid mails-page">
    <div class="row">
        <div class="col-12">

            <!-- Email Settings Card -->
            <div class="card shadow-sm border-0 mb-4">
                <div class="card-header bg-primary text-white py-3">
                    <div class="d-flex justify-content-between align-items-center">
                        <div class="d-flex align-items-center">
                            <i class="bi bi-gear me-2 fs-4"></i>
                            <div>
                                <h4 class="mb-0 fw-bold"><?= __('admin.email_settings') ?></h4>
                                <small class="opacity-75"><?= __('admin.configure_email_template_settings') ?></small>
                            </div>
                        </div>
                        <button class="btn btn-outline-light btn-sm" onclick="$('#setting-body').slideToggle()">
                            <i class="bi bi-sliders me-1"></i><?= __('admin.toggle_settings') ?>
                        </button>
                    </div>
                </div>

                <div class="card-body" id="setting-body" style="display: none;">
                    <form action="" method="POST" enctype="multipart/form-data">
                        <div class="row g-4">
                            <!-- Footer Text Section -->
                            <div class="col-lg-8">
                                <div class="border rounded p-4 bg-light h-100">
                                    <div class="d-flex align-items-center mb-3">
                                        <div class="bg-info bg-opacity-10 rounded-circle p-2 me-3">
                                            <i class="bi bi-textarea-t text-info fs-5"></i>
                                        </div>
                                        <h5 class="mb-0"><?= __('admin.footer_text') ?></h5>
                                    </div>
                                    <textarea name="emailsetting[footer]" class="form-control summernote-img" rows="8"><?= $emailsetting['footer']; ?></textarea>
                                    <div class="form-text"><?= __('admin.email_footer_description') ?></div>
                                </div>
                            </div>

                            <!-- Header Logo Section -->
                            <div class="col-lg-4">
                                <div class="border rounded p-4 bg-light h-100">
                                    <div class="d-flex align-items-center mb-3">
                                        <div class="bg-primary bg-opacity-10 rounded-circle p-2 me-3">
                                            <i class="bi bi-image text-primary fs-5"></i>
                                        </div>
                                        <h5 class="mb-0"><?= __('admin.header_logo') ?></h5>
                                    </div>
                                    <div class="text-center mb-3">
                                        <?php $img = $emailsetting['logo'] ? base_url('assets/images/site/'. $emailsetting['logo']) : base_url('assets/vertical/assets/images/users/avatar-1.jpg'); ?>
                                        <img src="<?= $img ?>" class="img-fluid rounded border" style="max-width: 200px; max-height: 150px;" alt="Email Logo">
                                    </div>
                                    <div class="mb-3">
                                        <input type="file" name="emailsetting_logo" class="form-control" accept="image/*">
                                        <div class="form-text"><?= __('admin.upload_email_logo') ?></div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="d-flex justify-content-end gap-2 mt-4">
                            <button type="button" class="btn btn-secondary" onclick="$('#setting-body').slideToggle()">
                                <i class="bi bi-x-circle me-1"></i><?= __('admin.cancel') ?>
                            </button>
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-save me-1"></i><?= __('admin.save') ?>
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Mail Templates List -->
            <div class="card shadow-sm border-0">
                <div class="card-header bg-white border-bottom py-3">
                    <div class="d-flex align-items-center">
                        <i class="bi bi-envelope me-2 fs-5 text-primary"></i>
                        <div>
                            <h5 class="mb-0 fw-bold"><?= __('admin.mail_templates') ?></h5>
                            <small class="text-muted"><?= __('admin.manage_email_templates') ?></small>
                        </div>
                    </div>
                </div>

                <div class="card-body p-0">
                    <?php if (empty($templates)) { ?>
                        <div class="text-center py-5 mails-empty-state">
                            <i class="bi bi-envelope-x display-1 text-muted opacity-50"></i>
                            <h3 class="text-muted mt-3"><?= __('admin.no_templates_found') ?></h3>
                        </div>
                    <?php } else { ?>
                        <div class="table-responsive">
                            <table class="table table-hover align-middle mb-0">
                                <thead class="table-light">
                                    <tr>
                                        <th class="ps-4"><?= __('admin.name') ?></th>
                                        <th><?= __('admin.subject') ?></th>
                                        <th><?= __('admin.admin_subject') ?></th>
                                        <th><?= __('admin.client_subject') ?></th>
                                        <th class="text-center pe-4"><?= __('admin.action') ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($templates as $key => $value) { ?>
                                        <tr class="template-row">
                                            <td class="ps-4">
                                                <div class="d-flex align-items-center">
                                                    <div class="bg-primary bg-opacity-10 rounded-circle p-2 me-2">
                                                        <i class="bi bi-envelope-fill text-primary"></i>
                                                    </div>
                                                    <strong><?= htmlspecialchars($value['name']) ?></strong>
                                                </div>
                                            </td>
                                            <td>
                                                <span class="text-truncate d-inline-block" style="max-width: 250px;" title="<?= htmlspecialchars($value['subject']) ?>">
                                                    <?= htmlspecialchars($value['subject']) ?>
                                                </span>
                                            </td>
                                            <td>
                                                <span class="text-truncate d-inline-block" style="max-width: 250px;" title="<?= htmlspecialchars($value['admin_subject']) ?>">
                                                    <?= htmlspecialchars($value['admin_subject']) ?>
                                                </span>
                                            </td>
                                            <td>
                                                <span class="text-truncate d-inline-block" style="max-width: 250px;" title="<?= htmlspecialchars($value['client_subject']) ?>">
                                                    <?= htmlspecialchars($value['client_subject']) ?>
                                                </span>
                                            </td>
                                            <td class="text-center pe-4">
                                                <a href="<?= base_url('admincontrol/mails_edit/'. $value['id']) ?>" class="btn btn-outline-primary btn-sm">
                                                    <i class="bi bi-pencil-square me-1"></i><?= __('admin.edit') ?>
                                                </a>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    <?php } ?>
                </div>
            </div>

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