<!-- Sidebar -->
<?php $this->load->view('restricted/layout/sidebar_admin'); ?>
<!-- Sidebar -->

<div id="content-wrapper" class="d-flex flex-column">
    <div id="content">

        <!-- NavBar -->
        <?php $this->load->view('restricted/layout/navbar'); ?>
        <!-- Navbar -->

        <!-- Container Fluid-->
        <div class="container-fluid" id="container-wrapper">
            <div class="d-sm-flex align-items-center justify-content-between mb-4">
                <h1 class="h3 mb-0 text-gray-800"><?php echo $title; ?></h1>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="./">Home</a></li>
                    <li class="breadcrumb-item active" aria-current="page"><?php echo $title; ?></li>
                </ol>
            </div>

            <div class="row">
                <div class="col-lg-10 align-items-center" style="margin: 0 auto;">
                    <!-- Form Basic -->
                    <div class="card mb-4">
                        <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                            <h6 class="m-0 font-weight-bold text-primary"><?php echo $title; ?></h6>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table align-items-center table-flush table-hover" id="dataTableHover">
                                    <thead class="thead-light">
                                        <tr>
                                            <th>Título</th>
                                            <th>Assunto</th>
                                            <th>Ação</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach($email_templates as $email): ?>
                                            <tr>
                                                <td><?php echo $email->title; ?></td>
                                                <td><?php echo $email->subject; ?></td>
                                                <td>
                                                    <a href="#" data-toggle="modal" data-target=".modalEmail<?php echo $email->id; ?>" class="btn btn-info btn-sm">
                                                        <i class="fas fa-eye"></i>
                                                    </a>
                                                </td>
                                            </tr>
                                        
                                            <!-- Modal Chapter -->
                                            <div class="modal fade modalEmail<?php echo $email->id; ?>" tabindex="-1" role="dialog" aria-labelledby="modalEmailTitle" aria-hidden="true">
                                                <div class="modal-dialog modal-dialog-centered" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header bg-primary">
                                                            <h5 class="modal-title text-white" id="modalChapterTitle">Detalhes do email</h5>
                                                        </div>
                                                        <div class="modal-body">
                                                            <div class="row">
                                                                <div class="col-sm-6 py-3">
                                                                    <h5 class="text-primary">Título</h5>
                                                                    <p><?php echo $email->title; ?></p>
                                                                </div>
                                                                <div class="col-sm-6 py-3">
                                                                    <h5 class="text-primary">Assunto</h5>
                                                                    <p><?php echo $email->title; ?></p>
                                                                </div>
                                                                <div class="col-sm-12 py-3">
                                                                    <h5 class="text-primary">Variáveis ​​de configuração de email</h5>
                                                                    <p>
                                                                        <b>Nome do administrador</b> - <i>%admin_name%</i> <br>
                                                                        <b>Nome do autor</b> - <i>%author_name%</i> <br>
                                                                        <b>Nome do editor</b> - <i>%editor_name%</i> <br>  
                                                                        <b>Nome do revisor</b> - <i>%reviewer_name%</i> <br>  
                                                                        <b>Título do capítulo</b> - <i>%chapter_title%</i> <br>
                                                                        <b>Código do capítulo</b> - <i>%chapter_code%</i> <br>  
                                                                    </p>
                                                                </div>
                                                                <?php echo form_open('restricted/admin/email/save_email_configuration/' . $email->id); ?>
                                                                <div class="col-sm-12">
                                                                    <h5 class="text-primary">Mensagem</h5>
                                                                    <div class="col-sm-12">
                                                                        <textarea class="form-control ck_editor_general" name="email_body" rows="15"><?php echo $email->body; ?></textarea>
                                                                    </div>
                                                                </div>
                                                                <button type="submit" class="btn btn-primary mt-1 ml-4">Enviar</button>
                                                                <?php echo form_close(); ?>
                                                            </div>
                                                            <!-- /Row -->
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-outline-primary" data-dismiss="modal">Fechar</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endforeach; ?>

                                    </tbody>
                                </table>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <!--Row-->


            <!-- Modal Logout -->
            <?php $this->load->view('restricted/layout/modal_logout'); ?>
            <!-- /Modal -->

        </div>
        <!--- /Container Fluid-->
    </div><!-- /Content -->