<?php
if (!defined('ABSPATH'))
    exit;
$email_settings = dspp_display_email_settings();
$admin_email = get_option('admin_email');
$email_templates = dspp_get_email_templates();
//echo '<pre>';
//print_r($email_templates);
//exit;
?>
<!-- Fullscreen Loader Overlay -->
<div id="fullpage-loader" class="dspp-loader-overlay" style="display: none;">
    <div class="dspp-loader-spinner">
        <div class="spinner-border text-light" role="status">
            <span class="visually-hidden">Loading...</span>
        </div>
        <div class="dspp-loader-text mt-2">Updating...</div>
    </div>
</div>
<div id="edit-email-template-modal" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
        <h2>Edit Status</h2>
        <form id="edit-email-temp-form" method="post" action="" class="validate">
            <div class="form-field form-required term-name-wrap">
                <label for="email_temp_subject">Subject</label>
                <input name="email_temp_subject" id="email_temp_subject" type="text" value="" size="40" aria-required="true" aria-describedby="name-description" required="required" />
                <p id="name-description">Subject of the email sent to the user.</p>
            </div>
            <div class="form-field term-description-wrap">
                <label for="email_temp_message">Message</label>
                <div class="editableContent" id="email_temp_message" contenteditable="true"></div>

                <!--<textarea name="email_temp_message" id="email_temp_message" rows="5" cols="40" aria-describedby="description-description" required="required"></textarea>-->
                <!--<p id="description-description">The description is not prominent by default; however, some themes may show it.</p>-->
            </div>
            <p class="submit">
                <input type="hidden" id="email_temp_id" name="email_temp_id">
                <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes" />
                <input type="button" name="cancel" id="close_popup" class="button close_popup button-warning" value="Cancel" />
                <span class="spinner"></span>
            </p>
        </form>
    </div>
</div>
<div class="wrap">
    <h1 class="wp-heading-inline"><?php esc_html_e('Email Settings', 'digital-service-provider-crm'); ?></h1>
    <hr class="wp-header-end">
    <div id="col-container" class="wp-clearfix">
        <div id="col-left">
            <div class="col-wrap">
                <div class="form-wrap">
                    <form id="dspp_admin_email_settings_form" method="post" action="" class="validate">
                        <div class="form-field form-required">
                            <label for="from_name">Sender name</label>
                            <input name="from_name" id="sender-name" type="text" value="<?php echo $email_settings->from_name;?>" size="40" aria-required="true" required="required" />
                        </div>
                        <div class="form-field">
                            <label for="from_email">Sender email</label>
                            <input type="text" name="from_email" id="from-email" class="form-control" placeholder="e.g. info@bestitsol.com" value="<?php echo $admin_email;?>" disabled="disabled" required="required">
                        </div>
                        <br>
                        <p class="submit">
                            <input type="hidden" name="action" value="submit" />
                            <input type="submit" name="submit" id="dspp-save-email-settings" class="button button-primary" value="Save changes" />
                            <span class="spinner"></span>
                        </p>
                    </form>
                </div>
            </div>
        </div>
        <!-- /col-left -->
        <div id="col-right">
            <div class="col-wrap">
                <form id="posts-filter" method="post">
                    <div class="tablenav top">
                        <div class="tablenav-pages one-page">
                            <span class="pagination-links">
                                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>
                                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>
                                <span class="paging-input">
                                    <label for="current-page-selector" class="screen-reader-text">Current Page</label>
                                    <input class="current-page" id="current-page-selector" type="text" name="paged" value="1" size="1" aria-describedby="table-paging">
                                    <span class="tablenav-paging-text"> of <span class="total-pages">1</span>
                                    </span>
                                </span>
                                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>
                                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>
                            </span>
                        </div>
                        <br class="clear">
                    </div>
                    <h2 class="screen-reader-text">Statuses list</h2>
                    <table class="wp-list-table widefat fixed striped table-view-list tags">
                        <caption class="screen-reader-text">Table ordered hierarchically. Ascending.</caption>
                        <thead>
                            <tr>
                                <th scope="col" class="manage-column column-name column-primary sorted asc" aria-sort="ascending" abbr="Name">
                                    <a href="#">
                                        <span>Name</span>
                                    </a>
                                </th>
                                <th scope="col" class="manage-column column-description sortable desc" abbr="Description">
                                    <a href="#">
                                        <span>Description</span>
                                    </a>
                                </th>
                                <th scope="col" class="manage-column column-description sortable desc" abbr="Module">
                                    <a href="#">
                                        <span>Module</span>
                                    </a>
                                </th>
                                <th scope="col" id="action" class="manage-column column-description sortable desc" abbr="Actions">
                                    <a href="#">
                                        <span>Actions</span>
                                    </a>
                                </th>                
                            </tr>
                        </thead>
                        <tbody id="the-list" data-wp-lists="list:tag">
                            <?php
                            if (!empty($email_templates)) {
                                foreach ($email_templates as $email_template) {
                                    ?>
                                    <tr id="tag-1" class="level-0">
                                        <td class="name column-name has-row-actions column-primary" data-colname="Name">
                                            <strong>
                                                <?php echo esc_html($email_template->email_title); ?>
                                            </strong>
                                        </td>
                                        <td class="description column-description" data-colname="Description">
                                            <span aria-hidden="true"><?php echo esc_html($email_template->action_description); ?></span>
                                        </td>
                                        <td class="" data-colname="Module">
                                            <span aria-hidden="true"><?php echo esc_html($email_template->module); ?></span>
                                        </td>
                                        <td class="">
                                            <a class="edit-email-template" id="edit-email-template" href="#" data-email-template-id="<?php echo esc_attr($email_template->id); ?>"  aria-label="">
                                                Edit
                                            </a>
                                            | 
                                            <a class="reset-email-template" href="#" data-email-template-id="<?php echo esc_attr($email_template->id); ?>" aria-label="">
                                                Reset
                                            </a>
                                        </td>
                                    </tr>
                                    <?php
                                }
                            } else {
                                ?>
                                <tr id="tag-1" class="level-0">
                                    <td>

                                    </td>
                                    <td>
                                        No records found! 
                                    </td>
                                    <td>

                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th scope="col" class="manage-column column-name column-primary sorted asc" aria-sort="ascending" abbr="Name">
                                    <a href="#">
                                        <span>Name</span>
                                    </a>
                                </th>
                                <th scope="col" class="manage-column column-description sortable desc" abbr="Description">
                                    <a href="#">
                                        <span>Description</span>
                                    </a>
                                </th>
                                <th scope="col" class="manage-column column-description sortable desc" abbr="Module">
                                    <a href="#">
                                        <span>Module</span>
                                    </a>
                                </th>
                                <th scope="col" id="action" class="manage-column column-description sortable desc" abbr="Actions">
                                    <a href="#">
                                        <span>Actions</span>
                                    </a>
                                </th> 
                            </tr>
                        </tfoot>
                    </table>
                </form>
            </div>
        </div>
        <!-- /col-right -->
    </div>

</div>