<?php 
    $email_id           = $has_tabs->ID;
    $email_title        = $has_tabs->post_title;
    $email_description  = $has_tabs->post_content;
    $email_name         = $has_tabs->post_name;
    # default states
    $email_meta         = (array) isset($has_tabs->post_meta)? $has_tabs->post_meta : [
        "_proqyz__email-notification-enabled"   => 0,
        "_proqyz__email-recipient"              => "",
        "_proqyz__email-subject"                => "",
        "_proqyz__email-content"                => "",
        "_proqyz__email-roles"                  => ""
    ];

    # in update states
    $notic = ST_ProQyz_Admin_Page_Emails::proqyz_edit_post_handler($email_id);
    $input_recipient_disabled = true;

    $email_notification_enabled = get_post_meta($email_id,'_proqyz__email-notification-enabled',true);
    $email_recipient            = get_post_meta($email_id,'_proqyz__email-recipient',true);
    $email_subject              = get_post_meta($email_id,'_proqyz__email-subject',true);
    $email_content              = get_post_meta($email_id,'_proqyz__email-content',true);

    # modified states variables
    $email_notification_enabled = isset($email_notification_enabled)? $email_notification_enabled : $email_meta["_proqyz__email-notification-enabled"];
    $email_subject              = (isset($email_subject))? $email_subject : $email_meta["_proqyz__email-subject"];
    $email_content              = (isset($email_content))? $email_content : $email_meta["_proqyz__email-content"];


    $template_hints = "";
    if( $email_name === "on-writing-evaluation-student" || $email_name === "on-speaking-evaluation-student" ) {
        $email_recipient            = "student";
        if($email_name === "on-writing-evaluation-student") {
            ob_start(); ?>
            <tr>
                <th>{teacher_username}</th>
                <td>Display Teacher’s username.</td>
            </tr>
            <tr>
                <th>{teacher_email}</th>
                <td>Display Teacher’s email.</td>
            </tr>
            <tr>
                <th>{overall_score}</th>
                <td>Display writing task’s overall score’s.</td>
            </tr>
            <tr>
                <th>{task_title}</th>
                <td>Display essay’s / passages’s title.</td>
            </tr>
            <tr>
                <th>{score1}</th>
                <td>Display task achievement’s / task response score</td>
            </tr>
            <tr>
                <th>{score2}</th>
                <td>Display coherence and cohesion’s score</td>
            </tr>
            <tr>
                <th>{score3}</th>
                <td>Display lexical resource’s score</td>
            </tr>
            <tr>
                <th>{score4}</th>
                <td>Display grammatical range and accuracy’s score</td>
            </tr>
            
            <?php $template_hints .= ob_get_clean();
        } else if($email_name === "on-speaking-evaluation-student") {
            ob_start(); ?>
            <tr>
                <th>{teacher_username}</th>
                <td>Display Teacher’s username.</td>
            </tr>
            <tr>
                <th>{teacher_email}</th>
                <td>Display Teacher’s email.</td>
            </tr>
            <tr>
                <th>{overall_score}</th>
                <td>Display Speaking’s overall score</td>
            </tr>
            <tr>
                <th>{score1}</th>
                <td>Display Fluency's score</td>
            </tr>
            <tr>
                <th>{score2}</th>
                <td>Display Lexical resource’s score</td>
            </tr>
            <tr>
                <th>{score3}</th>
                <td>Display Grammatical range and accuracy’s score</td>
            </tr>
            <tr>
                <th>{score4}</th>
                <td>Display Pronunciation’s score</td>
            </tr>
            
            <?php $template_hints .= ob_get_clean();
        }

        

    } else if( $email_name === "on-writing-evaluation-teacher" || $email_name === "on-speaking-evaluation-teacher" ) {
        $email_recipient            = "teacher";
        ob_start(); ?>
        <tr>
            <th>{teacher_username}</th>
            <td>Displays the teacher's username associated with the student</td>
        </tr>
        <tr>
            <th>{teacher_email}</th>
            <td>Displays the teacher's email associated with the student</td>
        </tr>
        <?php $template_hints = ob_get_clean();

        if($email_name === "on-writing-evaluation-teacher") {
            ob_start(); ?>
            <tr>
                <th>{instructor_username}</th>
                <td>Display Instructor’s username.</td>
            </tr>
            <tr>
                <th>{instructor_email}</th>
                <td>Display Instructor’s email.</td>
            </tr>
            <tr>
                <th>{overall_score}</th>
                <td>Display writing task’s overall score’s.</td>
            </tr>
            <tr>
                <th>{task_title}</th>
                <td>Display essay’s / passages’s title.</td>
            </tr>
            <tr>
                <th>{score1}</th>
                <td>Display task achievement’s / task response score</td>
            </tr>
            <tr>
                <th>{score2}</th>
                <td>Display coherence and cohesion’s score</td>
            </tr>
            <tr>
                <th>{score3}</th>
                <td>Display lexical resource’s score</td>
            </tr>
            <tr>
                <th>{score4}</th>
                <td>Display grammatical range and accuracy’s score</td>
            </tr>
            <?php $template_hints .= ob_get_clean();
        } else if($email_name === "on-speaking-evaluation-teacher") {
            ob_start(); ?>
            <tr>
                <th>{instructor_username}</th>
                <td>Display Instructor’s username.</td>
            </tr>
            <tr>
                <th>{instructor_email}</th>
                <td>Display Instructor’s email.</td>
            </tr>
            <tr>
                <th>{overall_score}</th>
                <td>Display Speaking’s overall score</td>
            </tr>
            <tr>
                <th>{score1}</th>
                <td>Display Fluency's score</td>
            </tr>
            <tr>
                <th>{score2}</th>
                <td>Display Lexical resource’s score</td>
            </tr>
            <tr>
                <th>{score3}</th>
                <td>Display Grammatical range and accuracy’s score</td>
            </tr>
            <tr>
                <th>{score4}</th>
                <td>Display Pronunciation’s score</td>
            </tr>
            
            <?php $template_hints .= ob_get_clean();
        }

    } else if( $email_name === "on-writing-evaluation-owner" || $email_name === "on-speaking-evaluation-owner") {
        $email_recipient            = "Adminstrator";

        ob_start(); ?>
        <tr>
            <th>{admin_username}</th>
            <td>Displays the Admin's username.</td>
        </tr>
        <tr>
            <th>{admin_email}</th>
            <td>Displays the Admin's email.</td>
        </tr>
        <?php $template_hints = ob_get_clean();

        if($email_name === "on-writing-evaluation-owner") {
            ob_start(); ?>
            <tr>
                <th>{teacher_username}</th>
                <td>Display Teacher’s username.</td>
            </tr>
            <tr>
                <th>{teacher_email}</th>
                <td>Display Teacher’s email.</td>
            </tr>
            <tr>
                <th>{overall_score}</th>
                <td>Display writing task’s overall score’s.</td>
            </tr>
            <tr>
                <th>{task_title}</th>
                <td>Display essay’s / passages’s title.</td>
            </tr>
            <tr>
                <th>{score1}</th>
                <td>Display task achievement’s / task response score</td>
            </tr>
            <tr>
                <th>{score2}</th>
                <td>Display coherence and cohesion’s score</td>
            </tr>
            <tr>
                <th>{score3}</th>
                <td>Display lexical resource’s score</td>
            </tr>
            <tr>
                <th>{score4}</th>
                <td>Display grammatical range and accuracy’s score</td>
            </tr>
            
            <?php $template_hints .= ob_get_clean();
        } else if($email_name === "on-speaking-evaluation-owner") {
            ob_start(); ?>
            <tr>
                <th>{teacher_username}</th>
                <td>Display Teacher’s username.</td>
            </tr>
            <tr>
                <th>{teacher_email}</th>
                <td>Display Teacher’s email.</td>
            </tr>
            <tr>
                <th>{overall_score}</th>
                <td>Display Speaking’s overall score</td>
            </tr>
            <tr>
                <th>{score1}</th>
                <td>Display Fluency's score</td>
            </tr>
            <tr>
                <th>{score2}</th>
                <td>Display Lexical resource’s score</td>
            </tr>
            <tr>
                <th>{score3}</th>
                <td>Display Grammatical range and accuracy’s score</td>
            </tr>
            <tr>
                <th>{score4}</th>
                <td>Display Pronunciation’s score</td>
            </tr>
            
            <?php $template_hints .= ob_get_clean();
        }

    } else if( $email_name === "on-test-submit-student" ) {
        $email_recipient            = "student";
    } else if( $email_name === "on-test-submit-teacher" ) {
        $email_recipient            = "teacher";
        ob_start(); ?>
        <tr>
            <th>{teacher_username}</th>
            <td>Displays the teacher's username associated with the student</td>
        </tr>
        <tr>
            <th>{teacher_email}</th>
            <td>Displays the teacher's email associated with the student</td>
        </tr>
        <?php $template_hints = ob_get_clean();
    } else if( $email_name === "on-test-submit-owner" ) {
        $email_recipient            = "Adminstrator";
        ob_start(); ?>
        <tr>
            <th>{admin_username}</th>
            <td>Displays the admin's username.</td>
        </tr>
        <tr>
            <th>{admin_email}</th>
            <td>Displays the admin's email.</td>
        </tr>
        <?php $template_hints = ob_get_clean();

    }

    

    


?>

<style>
    input, textarea {
        font-size: 14px;
    }

    input[type=date], input[type=datetime-local], input[type=datetime], input[type=email], input[type=month], input[type=number], input[type=password], input[type=search], input[type=tel], input[type=text], input[type=time], input[type=url], input[type=week] {
        padding: 0 8px;
        line-height: 2;
        min-height: 30px;
    }
    input[type=color], input[type=date], input[type=datetime-local], input[type=datetime], input[type=email], input[type=month], input[type=number], input[type=password], input[type=search], input[type=tel], input[type=text], input[type=time], input[type=url], input[type=week], select, textarea {
        box-shadow: 0 0 0 transparent;
        border-radius: 4px;
        border: 1px solid #8c8f94;
        background-color: #fff;
        color: #2c3338;
    }

    input[type="text"]:disabled, input[type="text"][readonly] {
        cursor: no-drop;
        opacity: 0.6;
    }


    .proqyz__manage-email table input[type="text"]{
        padding: 0 8px;
    }

    .proqyz__manage-email input[type="text"]{
        width: 400px;
        margin: 0;
        padding: 6px;
        box-sizing: border-box;
        vertical-align: top;
    }

    .proqyz__manage-email .description table {width: 100%;}

    .proqyz__manage-email .description table caption {
        font-weight: bold;
        padding: 15px;
        border-bottom: 1px solid #d9d8d8;
    }

    .proqyz__manage-email .description table th, .description table td {
        padding: 10px;
        border: 1px solid #d9d8d8;
    }

    .proqyz__manage-email .description table tbody th, .description table tbody td {
        color: #8d8d8d;
    }

    .proqyz__manage-email .description {
        border: 1px dashed;
        background: white;
        border-radius: 3px;
        margin-bottom: 10px;
    }
    
    .notice { display:none; }
</style>
<style>


    .proqyz_email-modal{
        --bs-modal-zindex:1055;
        --bs-modal-width:500px;
        --bs-modal-padding:1.75rem;
        --bs-modal-margin:0.5rem;
        --bs-modal-bg: #fff;
        --bs-modal-border-color:var(--bs-border-color-translucent);
        --bs-modal-border-width:0;
        --bs-modal-border-radius:0.475rem;
        --bs-modal-box-shadow:0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
        --bs-modal-inner-border-radius:0.475rem;
        --bs-modal-header-padding-x:1.75rem;
        --bs-modal-header-padding-y:1.75rem;
        --bs-modal-header-padding:1.75rem 1.75rem;
        --bs-modal-header-border-color:#F1F1F4;
        --bs-modal-header-border-width:1px;
        --bs-modal-title-line-height:1.5;
        --bs-modal-footer-gap:0.5rem;
        --bs-modal-footer-border-color:#F1F1F4;
        --bs-modal-footer-border-width:1px;
        position:fixed;
        top:0;
        left:0;
        z-index:100001;
        display:none;
        width:100%;
        height:100%;
        overflow-x:hidden;
        overflow-y:auto;
        outline:0
    }
    .proqyz_email-modal-dialog{position:relative;width:auto;margin:var(--bs-modal-margin);pointer-events:none}.proqyz_email-modal.fade .proqyz_email-modal-dialog{transition:transform .3s ease-out;transform:translate(0,-50px)}@media (prefers-reduced-motion:reduce){.proqyz_email-modal.fade .proqyz_email-modal-dialog{transition:none}}.proqyz_email-modal.show .proqyz_email-modal-dialog{transform:none}.proqyz_email-modal.proqyz_email-modal-static .proqyz_email-modal-dialog{transform:scale(1.02)}.proqyz_email-modal-dialog-scrollable{height:calc(100% - var(--bs-modal-margin) * 2)}.proqyz_email-modal-dialog-scrollable .proqyz_email-modal-content{max-height:100%;overflow:hidden}.proqyz_email-modal-dialog-scrollable .proqyz_email-modal-body{overflow-y:auto}.proqyz_email-modal-dialog-centered{display:flex;align-items:center;min-height:calc(100% - var(--bs-modal-margin) * 2)}.proqyz_email-modal-content{position:relative;display:flex;flex-direction:column;width:100%;color:var(--bs-modal-color);pointer-events:auto;background-color:var(--bs-modal-bg);background-clip:padding-box;border:var(--bs-modal-border-width) solid var(--bs-modal-border-color);border-radius:var(--bs-modal-border-radius);box-shadow:var(--bs-modal-box-shadow);outline:0}.proqyz_email-modal-backdrop{--bs-backdrop-zindex:1050;--bs-backdrop-bg:#000000;--bs-backdrop-opacity:0.4;position:fixed;top:0;left:0;z-index:var(--bs-backdrop-zindex);width:100vw;height:100vh;background-color:var(--bs-backdrop-bg)}.proqyz_email-modal-backdrop.fade{opacity:0}.proqyz_email-modal-backdrop.show{opacity:var(--bs-backdrop-opacity)}.proqyz_email-modal-header{display:flex;flex-shrink:0;align-items:center;padding:var(--bs-modal-header-padding);border-bottom:var(--bs-modal-header-border-width) solid var(--bs-modal-header-border-color);border-top-left-radius:var(--bs-modal-inner-border-radius);border-top-right-radius:var(--bs-modal-inner-border-radius)}.proqyz_email-modal-header .btn-close{padding:calc(var(--bs-modal-header-padding-y) * .5) calc(var(--bs-modal-header-padding-x) * .5);margin:calc(-.5 * var(--bs-modal-header-padding-y)) calc(-.5 * var(--bs-modal-header-padding-x)) calc(-.5 * var(--bs-modal-header-padding-y)) auto}.proqyz_email-modal-title{margin-bottom:0;line-height:var(--bs-modal-title-line-height)}.proqyz_email-modal-body{position:relative;flex:1 1 auto;padding:var(--bs-modal-padding)}.proqyz_email-modal-footer{display:flex;flex-shrink:0;flex-wrap:wrap;align-items:center;justify-content:flex-end;padding:calc(var(--bs-modal-padding) - var(--bs-modal-footer-gap) * .5);background-color:var(--bs-modal-footer-bg);border-top:var(--bs-modal-footer-border-width) solid var(--bs-modal-footer-border-color);border-bottom-right-radius:var(--bs-modal-inner-border-radius);border-bottom-left-radius:var(--bs-modal-inner-border-radius)}.proqyz_email-modal-footer>*{margin:calc(var(--bs-modal-footer-gap) * .5)}@media (min-width:576px){.proqyz_email-modal{--bs-modal-margin:1.75rem;--bs-modal-box-shadow:0 0.5rem 1rem rgba(0, 0, 0, 0.1)}.proqyz_email-modal-dialog{max-width:var(--bs-modal-width);margin-right:auto;margin-left:auto}.proqyz_email-modal-sm{--bs-modal-width:300px}}@media (min-width:992px){.proqyz_email-modal-lg,.proqyz_email-modal-xl{--bs-modal-width:800px}}@media (min-width:1200px){.proqyz_email-modal-xl{--bs-modal-width:1140px}}.proqyz_email-modal-fullscreen{width:100vw;max-width:none;height:100%;margin:0}.proqyz_email-modal-fullscreen .proqyz_email-modal-content{height:100%;border:0;border-radius:0}.proqyz_email-modal-fullscreen .proqyz_email-modal-footer,.proqyz_email-modal-fullscreen .proqyz_email-modal-header{border-radius:0}.proqyz_email-modal-fullscreen .proqyz_email-modal-body{overflow-y:auto}@media (max-width:575.98px){.proqyz_email-modal-fullscreen-sm-down{width:100vw;max-width:none;height:100%;margin:0}.proqyz_email-modal-fullscreen-sm-down .proqyz_email-modal-content{height:100%;border:0;border-radius:0}.proqyz_email-modal-fullscreen-sm-down .proqyz_email-modal-footer,.proqyz_email-modal-fullscreen-sm-down .proqyz_email-modal-header{border-radius:0}.proqyz_email-modal-fullscreen-sm-down .proqyz_email-modal-body{overflow-y:auto}}@media (max-width:767.98px){.proqyz_email-modal-fullscreen-md-down{width:100vw;max-width:none;height:100%;margin:0}.proqyz_email-modal-fullscreen-md-down .proqyz_email-modal-content{height:100%;border:0;border-radius:0}.proqyz_email-modal-fullscreen-md-down .proqyz_email-modal-footer,.proqyz_email-modal-fullscreen-md-down .proqyz_email-modal-header{border-radius:0}.proqyz_email-modal-fullscreen-md-down .proqyz_email-modal-body{overflow-y:auto}}@media (max-width:991.98px){.proqyz_email-modal-fullscreen-lg-down{width:100vw;max-width:none;height:100%;margin:0}.proqyz_email-modal-fullscreen-lg-down .proqyz_email-modal-content{height:100%;border:0;border-radius:0}.proqyz_email-modal-fullscreen-lg-down .proqyz_email-modal-footer,.proqyz_email-modal-fullscreen-lg-down .proqyz_email-modal-header{border-radius:0}.proqyz_email-modal-fullscreen-lg-down .proqyz_email-modal-body{overflow-y:auto}}@media (max-width:1199.98px){.proqyz_email-modal-fullscreen-xl-down{width:100vw;max-width:none;height:100%;margin:0}.proqyz_email-modal-fullscreen-xl-down .proqyz_email-modal-content{height:100%;border:0;border-radius:0}.proqyz_email-modal-fullscreen-xl-down .proqyz_email-modal-footer,.proqyz_email-modal-fullscreen-xl-down .proqyz_email-modal-header{border-radius:0}.proqyz_email-modal-fullscreen-xl-down .proqyz_email-modal-body{overflow-y:auto}}@media (max-width:1399.98px){.proqyz_email-modal-fullscreen-xxl-down{width:100vw;max-width:none;height:100%;margin:0}.proqyz_email-modal-fullscreen-xxl-down .proqyz_email-modal-content{height:100%;border:0;border-radius:0}.proqyz_email-modal-fullscreen-xxl-down .proqyz_email-modal-footer,.proqyz_email-modal-fullscreen-xxl-down .proqyz_email-modal-header{border-radius:0}.proqyz_email-modal-fullscreen-xxl-down .proqyz_email-modal-body{overflow-y:auto}}
</style>
<div class="wrap proqyz__root proqyz__manage-email">
    <?php if($notic){ ?><div class="proqyz__email-notifications">
        <?php echo $notic; ?>
    </div><?php } ?>
    <form method="post" action="">

        <h2>
            <?php echo $email_title; ?>
            <small class="wc-admin-breadcrumb">
                <a href="<?php echo $list_url; ?>" aria-label="Return to emails">
                    ⤴︎
                </a>
            </small>
        </h2>
        <p><?php echo $email_description; ?></p>
        <table class="form-table">
            <tbody>
                <tr valign="top">
                    <th scope="row" class="titledesc">
                        <label for="woocommerce_new_order_enabled">Enable/Disable </label>
                    </th>
                    <td class="forminp">
                        <fieldset>
                            <legend class="screen-reader-text">
                                <span>Enable/Disable</span>
                            </legend>
                            <label for="_proqyz__email-notification-enabled">
                                <input 
                                    class="" 
                                    type="checkbox" 
                                    name="_proqyz__email-notification-enabled" 
                                    id="_proqyz__email-notification-enabled" 
                                    style="" 
                                    value="1" 
                                    <?php echo $email_notification_enabled == 1? ' checked' : ''; ?>
                                /> Enable this email notification
                            </label>
                            <br>
                        </fieldset>
                    </td>
                </tr>
                
                <tr valign="top">
                    <th scope="row" class="titledesc">
                        <label for="_proqyz__email-recipient">
                            Recipient(s) 
                            <span 
                                class="woocommerce-help-tip" 
                                tabindex="0" 
                                aria-label="Enter recipients (comma separated) for this email. Defaults to unitygroupbfgi2019@gmail.com."
                            ></span>
                        </label>
                    </th>
                    <td class="forminp">
                        <fieldset>
                            <legend class="screen-reader-text">
                                <span>Recipient(s)</span>
                            </legend>
                            <input 
                                class="input-text regular-input " 
                                type="text" 
                                name="_proqyz__email-recipient" 
                                id="_proqyz__email-recipient" 
                                style="" 
                                value="<?php echo $email_recipient; ?>" 
                                placeholder=""
                                required
                                <?php echo ($input_recipient_disabled)? 'disabled readonly' : ''; ?>
                            />
                        </fieldset>
                    </td>
                </tr>

                <tr valign="top">
                    <th scope="row" class="titledesc">
                        <label for="_proqyz__email-subject">
                            Subject 
                            <span 
                                class="woocommerce-help-tip" 
                                tabindex="0" 
                                aria-label="Available placeholders: {site_title}, {site_address}, {site_url}, {order_date}, {order_number}"
                            ></span>
                        </label>
                    </th>
                    <td class="forminp">
                        <fieldset>
                            <legend class="screen-reader-text">
                                <span>Subject</span>
                            </legend>
                            <input 
                                class="input-text regular-input " 
                                type="text" 
                                name="_proqyz__email-subject" 
                                id="_proqyz__email-subject" 
                                value="<?php echo $email_subject; ?>" 
                                placeholder=""
                                required
                            />
                        </fieldset>
                    </td>
                </tr>

                <tr valign="top">
                    <th scope="row" class="titledesc">
                        <label for="_proqyz__email-content">
                            Email template
                            <span class="woocommerce-help-tip" tabindex="0"></span>
                        </label>
                    </th>
                    <td class="forminp">
                        <fieldset>
                            <legend class="screen-reader-text">
                                <span>Email template</span>
                            </legend>
                            
                            <div class="description">
                                <table>
                                    <caption>Variables</caption>
                                    <thead>
                                        <th>Variable</th>
                                        <th>Description</th>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <th>{student_username}</th>
                                            <td>Display student’s username.</td>
                                        </tr>
                                        <tr>
                                            <th>{student_email}</th>
                                            <td>Display student’s email.</td>
                                        </tr>
                                        <tr>
                                            <th>{quiz_title}</th>
                                            <td>Display quiz’s title</td>
                                        </tr>
                                        <tr>
                                            <th>{quiz_category}</th>
                                            <td>Display quiz’s category eg. Listening, Reading, writing, Speaking, Competitive exam</td>
                                        </tr>
                                        <tr>
                                            <th>{result_url}</th>
                                            <td>Display Result's url</td>
                                        </tr>
                                        <?php echo $template_hints; ?>
                                    </tbody>
                                </table>
                            </div>        

                            <?php echo wp_editor($email_content,'_proqyz__email-content', []); ?>
                        </fieldset>
                    </td>
                </tr>



            </tbody>
        </table>
        <p class="submit">
            <input type="hidden" name="proqyz__email-edit" value="1" />
            <button name="save" class="button-primary woocommerce-save-button" type="submit" value="Save changes">
                Save changes
            </button>
        </p>
    </form>

</div>