<?php 
    $page_slug      = (isset($_GET['page']) && !empty($_GET['page']))? $_GET['page'] : 'st-proqyz-groups';
    $post_action    = (isset($_GET['post_action']) && !empty($_GET['post_action']))? $_GET['post_action'] : 'list';
    $post_status    = (isset($_GET['post_status']) && !empty($_GET['post_status']))? (($_GET['post_status'] == "publish")? 'publish' : 'trash') : 'publish';  
    $current_page   = (isset($_GET['current_page']) && !empty($_GET['current_page']))? $_GET['current_page'] : 1;
    $per_page       = (isset($_GET['per_page']) && !empty($_GET['per_page']))? $_GET['per_page'] : 100;

    $params         = (object) [
        "current_page"  => $current_page,
        "per_page"      => $per_page,
        "post_status"   => $post_status == "publish"? 1 : 0,
        "post_action"   => $post_action,
        "page_slug"     => $page_slug
    ];


    if( $post_action === "list" ) {
        $list_groups    = (object) ST_ProQyz_Admin_Page_Groups::get_groups_list($params);
        $table_rows     = $list_groups->rows;
        $published      = $list_groups->published;
        $trashed        = $list_groups->trashed;
        $published_url  = ST_ProQyz_Admin_Page_Groups::get_table_action_url($params, 'publish');
        $trashed_url    = ST_ProQyz_Admin_Page_Groups::get_table_action_url($params, 'trash');
    } else if($post_action === "trash") {
        $post_id = (isset($_GET['post_id']) && !empty($_GET['post_id']))? $_GET['post_id'] : null;
        ST_ProQyz_Admin_Page_Groups::process_trash($params, $post_id);
    } else if($post_action === "restore") {
        $post_id = (isset($_GET['post_id']) && !empty($_GET['post_id']))? $_GET['post_id'] : null;
        ST_ProQyz_Admin_Page_Groups::process_restore($params, $post_id);
    } else if($post_action === "delete") {
        $post_id = (isset($_GET['post_id']) && !empty($_GET['post_id']))? $_GET['post_id'] : null;
        ST_ProQyz_Admin_Page_Groups::process_delete($params, $post_id);
    } 


?>
<style>
    body {
        background: #f0f0f1;
        color: #3c434a;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
        font-size: 13px;
        line-height: 1.4em;
        min-width: 600px;
    }

    h2, h3 {
        color: #1d2327;
        font-size: 1.3em;
        margin: 1em 0;
    }
    h1, h2, h3, h4, h5, h6 {
        display: block;
        font-weight: 600;
    }

        .ielts-lms-binary-selector{ margin-bottom:20px;clear: both; width: 100%;margin: 0;padding: 0;}
        .ielts-lms-binary-selector .left-selector{ width: 47%;float: left;}
        .ielts-lms-binary-selector .center-selector{width: 5%;float: left;text-align: center;margin-top: 8%;}
        .ielts-lms-binary-selector .right-selector{ width: 47%;float: left;}
        .ielts-lms-binary-selector .ielts-lms-binary-search{width: 100%;float: left;}
        .ielts-lms-binary-selector .ielts-lms-binary-selector-select{border: 1px solid #ccc;padding: 5px;width: 100%;max-width: 100%;min-height: 240px;max-height: 240px;}
        .ielts-lms-binary-selector .ielts-lms-binary-selector-select > option.ielts-lms-binary-selector-select-options {padding: 0.15em 0;width: 100%;}
        .ielts-lms-binary-selector .ielts-lms-binary-selector-buttons{ margin-bottom: -12px !important;display: block;}
        .ielts-lms-binary-selector .ielts-lms-binary-selector-table{width: 100%;}
        .ielts-lms-binary-selector option.ielts-lms-binary-selector-item-disabled {text-decoration: line-through;}
        .ielts-lms-binary-selector .right-selector option.ielts-lms-binary-selector-select-options {color: #0b66af;}
        .ielts-lms-binary-selector .right-selector option.ielts-lms-binary-selector-select-options, .ielts-lms-binary-selector .left-selector option.ielts-lms-binary-selector-select-options{cursor: pointer;}
        .ielts-lms-pagination {display: -webkit-flex;display: -ms-flexbox;display: flex;padding-left: 0;list-style: none;border-radius: 0.25rem;align-items: center;justify-content: space-around;margin-top: 14px;}
        .md-styled-btn-primary{background: #0085ba;border-color: #006a95 #00648c #00648c;box-shadow: inset 0 -1px 0 #00648c;color: #fff;text-decoration: none;text-shadow: 0 -1px 1px #005d82, 1px 0 1px #005d82, 0 1px 1px #005d82, -1px 0 1px #005d82;}
        .md-styled-btn{font-size: 13px;padding: 0 10px 1px;line-height: 26px;height: 28px;border-radius: 3px;white-space: nowrap;border-width: 1px;border-style: solid;vertical-align: top;margin: 0 0 0 3px;cursor: pointer;}
        .md-styled-btn-default{color: #555;border-color: #ccc;background: #f7f7f7;box-shadow: inset 0 -1px 0 #ccc;}
        .notice { display:none; }

</style>
<div class="wrap proqyz_groups">
    <div style="display:flex;align-items:center;">
        <h2>Groups</h2>
        <button class="proqyz-create_group-btn page-title-action" style="top:0;margin-left:10px;height: 30px;display: flex;flex-direction: row;align-items: center;" data-target="#modal-group">
            Add New Group
        </button>
    </div>

    <p>Groups are sometimes called classes or batches or can go by other names, and here you can assign teacher(s) to groups of students. This allows teachers to access all of their students in the progress report.</p>

    <?php if($post_action === "list"){ ?>
        <ul class="subsubsub">
            <li class="publish">
                <a href="<?php echo $published_url; ?>" class="<?php echo ($post_status == 'publish')? 'current' : ''; ?>">
                    Published <span class="count">(<span class="all-count"><?php echo $published; ?></span>)</span>
                </a> |
            </li>
            <li class="trash">
                <a href="<?php echo $trashed_url; ?>" class="<?php echo ($post_status == 'trash')? 'current' : ''; ?>">
                    Trash <span class="count">(<span class="trash-count"><?php echo $trashed; ?></span>)</span>
                </a>
            </li>
        </ul>
        <table class="wp-list-table widefat fixed striped table-view-list">
            <thead>
                <tr>
                    <th class="manage-column column-sr-no" style="width:100px;">
                        Sr. no.
                    </th>
                    <th scope="col" id="group-title" class="manage-column column-group-title column-primary">
                        Group title
                    </th>
                </tr>
            </thead>
            <tbody id="the-groups-list">
            <?php 
                if( count($table_rows) > 0 ) { 
                    foreach( $table_rows as $lg => $list ) {
                        ?>
                        <tr id="group-<?php echo $list->ID; ?>" class="comment even thread-even depth-1 approved">
                            <td><?php echo $lg+1; ?></td>
                            <td class="column-group-title has-row-actions">
                                <?php echo $list->group_title; ?>
                                <div class="row-actions">
                                    <?php if($post_status == "publish"){ ?>
                                        <span class="edit">
                                            <a 
                                                data-type="proqyz-groups-action"
                                                data-proqyz-groups-action-id="<?php echo $list->ID; ?>" 
                                                data-proqyz-groups-action-type="edit"
                                                class="edit_btn" 
                                                href="javascript:;" 
                                                aria-label="Edit this group"
                                            >
                                            Edit
                                            </a>
                                        </span>
                                        <span class="trash"> 
                                            | 
                                            <a
                                                href="<?php echo ST_ProQyz_Admin_Page_Groups::action_url($params, $list->ID, 'trash'); ?>" 
                                                class="delete vim-d vim-destructive aria-button-if-js" 
                                                aria-label="Move this comment to the Trash" 
                                            >
                                                Trash
                                            </a>
                                        </span>
                                    <?php } ?>
                                    <?php if($post_status == "trash"){ ?>
                                        <span class="edit">
                                            <a 
                                                class="edit_btn" 
                                                href="<?php echo ST_ProQyz_Admin_Page_Groups::action_url($params, $list->ID, 'restore'); ?>" 
                                                aria-label="restore group"
                                            >
                                            Restore
                                            </a>
                                        </span>
                                        <span class="trash"> 
                                            | 
                                            <a
                                            href="<?php echo ST_ProQyz_Admin_Page_Groups::action_url($params, $list->ID, 'delete'); ?>" 
                                                class="delete vim-d vim-destructive aria-button-if-js" 
                                                aria-label="Move this comment to the Trash" 
                                            >
                                                Delete Permanently
                                            </a>
                                        </span>
                                    <?php } ?>

                                </div>
                            </td>
                        </tr>
                        <?php 
                    }
                } else { ?>
                    <tr class="no-items">
                        <td class="colspanchange" colspan="2">
                            <?php if($post_status == "publish"){ ?>
                                No Groups found.
                            <?php } else if($post_status == "trash"){ ?>
                                Trash is empty
                            <?php } ?>
                        </td>
                    </tr>
                <?php }
            ?>
            </tbody>
            <tfoot>
                <tr>
                    <th class="manage-column column-sr-no" style="width:100px;">
                        Sr. no.
                    </th>
                    <th scope="col" id="group-title" class="manage-column column-group-title column-primary">
                        Group title
                    </th>
                </tr>
            </tfoot>
        </table>
    <?php } ?>

    <?php if($post_action === "trash"){ ?>
        
    <?php } ?>


    <div class="modal fade" tabindex="-1" role="dialog" id="modal-group" style="z-index:999999;">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content"></div>
        </div>
    </div>
</div>
