<style>
    :root {
        --toggle-off: #d3d3d8;
        --toggle-on: #2d95ea;
        --toggle-width: 40px;
        --toggle-height: 19px;
        --toggle-dot: 15px;

    }

    table.wc_emails .proqyz-email-settings-table-status, table.wc_gateways .proqyz-email-settings-table-status, table.wc_shipping .proqyz-email-settings-table-status {
        text-align: center;
        width: 1em;
    }
    .widefat tfoot tr td, .widefat tfoot tr th, .widefat thead tr td, .widefat thead tr th {
        color: #2c3338;
    }

    .proqyz__root .cont {
        text-align: center;
    }

    .proqyz__root .toggle {
        position: relative;
        display: inline-block;
    }

    .proqyz__root .toggle__input {
        display: none !important;
    }

    .proqyz__root .toggle__label {
        display: block;
        width: var(--toggle-width);
        height: var(--toggle-height);
        background-color: var(--toggle-off);
        border-radius: 99px;
        cursor: pointer;
        transition: background-color 0.3s ease;
    }

    .proqyz__root .toggle__input:checked + .toggle__label {
        background-color: var(--toggle-on);
    }

    .proqyz__root .toggle__input:checked + .toggle__label::after {
        left: 22px;
    }

    .proqyz__root .toggle__label::after {
        content: '';
        position: absolute;
        top: 2px;
        left: 2px;
        width: var(--toggle-dot);
        height: var(--toggle-dot);
        background-color: #ffffff;
        border-radius: 50%;
        transition: left 0.3s ease;
    }

    .proqyz-email-settings-table-name{
        font-weight: 700;
    }
    
    .notice { display:none; }

</style>
<div class="wrap proqyz__root proqyz__emails">
    <h2>Email notifications</h2>
    <div id="proqyz__email_notification_settings-description">
        <p>
        Email notifications sent from ProQyz are listed below. Click on an email to configure it.
        To ensure your website notifications arrive in yours and your students’ inboxes, we recommend connecting your email address to your domain and setting up a dedicated SMTP server. If something doesn’t seem to be sending correctly, install the WP Mail Logging Plugin.
        </p>
    </div>
    <table class="form-table">
		<tbody>
            <tr valign="top">
                <td class="wc_emails_wrapper" colspan="2">
                    <table class="wc_emails widefat" cellspacing="0">
                        <thead>
                            <tr>
                                <th class="proqyz-email-settings-table-status"></th>
                                <th class="proqyz-email-settings-table-name">Email</th>
                                <th class="proqyz-email-settings-table-email_type">Content type</th>
                                <th class="proqyz-email-settings-table-recipient">Recipient(s)</th>
                                <th class="proqyz-email-settings-table-actions"></th>						
                            </tr>
                        </thead>
                        <tbody>
                        <?php 
                            $emails_triggers = self::get_posts_by_post_type('proqyz-email');
                            if( count($emails_triggers) > 0 ) { 
                                foreach( $emails_triggers as $ekey => $ev ) {
                                    $email_id       = $ev->ID;

                                    $roles          = get_post_meta($email_id,'_proqyz__email-roles',true);
                                    $roles          = isset($roles)? (array) $roles : [];

                                    $emails         = get_post_meta($email_id,'_proqyz__email-recipient',true);
                                    $emails         = isset($emails)? (array) $emails : [];

                                    $email_enabled  = get_post_meta($email_id,'_proqyz__email-notification-enabled',true);
                                    $email_enabled  = isset($email_enabled)? (int) $email_enabled : 0;

                                ?>  
                                    <tr>
                                        <td class="proqyz-email-settings-table-status">
                                            <?php if($email_enabled == 1){ ?>
                                                <span class="dashicons dashicons-yes-alt" style="color:#2271b1;"></span>
                                            <?php }else { ?>
                                                <span class="dashicons dashicons-remove"></span>
                                            <?php } ?>
                                            
                                    
                                        </td>
                                        <td class="proqyz-email-settings-table-name">
                                            <a href="<?php echo $manage_url."".$ev->post_name; ?>">
                                                <?php echo $ev->post_title; ?>
                                            </a>
                                            <span class="woocommerce-help-tip" tabindex="0" aria-label="New order emails are sent to chosen recipient(s) when a new order is received."></span>
                                        </td>
                                        <td class="proqyz-email-settings-table-email_type">
                                            text/html
                                        </td>
                                        <td class="proqyz-email-settings-table-recipient">
                                            <?php if(in_array('student', $roles) || in_array('subscriber', $roles)){ ?>
                                                Student
                                            <?php } else if(in_array('teacher', $roles)){ ?>
                                                Teacher
                                            <?php } else if(in_array('administrator', $roles)) { ?>
                                                Administrator
                                            <?php } ?>
                                        </td>
                                        <td class="proqyz-email-settings-table-actions">
                                            <a class="button alignright" href="<?php echo $manage_url."".$ev->post_name; ?>">Manage</a>
                                        </td>
                                    </tr>
                                <?php
                                }
                            } ?>
                        </tbody>
                    </table>
                </td>
            </tr>
		</tbody>
    </table>

</div>

