<?php defined('ABSPATH') || die('Cheatin\' uh?'); ?>
<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'> 
<?php

//echo wp_date('l jS \of F Y H:i:s');

// $post_group=[1,2,3];
// print_r($post_group);
// $newarray = array_diff($post_group, [ 2]);
// print_r($newarray);
// array_push($newarray,2,5);
// print_r($newarray);

//$post_group=NXTLVL_Classes_Helpers_Tools::getOption('post_sc');
//if($post_group!=null){
//$post_group = array_diff($post_group, [3447]);
//print_r($post_group);}

    // add_filter('cron_schedules','my_cron_schedules');
    // function my_cron_schedules($schedules){
    //     $schedules["5min"] = array(
    //         'interval' => 60,
    //         );
    //     return $schedules;
    // }
    
    //  wp_schedule_event(time(),'5min', 'my_5min_event');

    // function update_db_every_5mins() {
    //     $args=[
    //         'post_title'=>'new post by cron', 
    //         'post_author' =>  1,
    //     ];
    //     wp_insert_post($args);
    // }   
   
    // wp_schedule_event(time(),'5min','my_5min_event');
    // add_action('my_5min_event', 'update_db_every_5mins');
    // function update_db_every_5mins() {
    //     $args=[
    //         'post_title'=>'post by cron', 
    //         'post_author' =>  1,
    //     ];
    //     wp_insert_post($args);
    // }   
    // print_r(get_option('cron'));



    // $postdate = date('Y-m-d H:i:s', strtotime('2024-10-10 09:41:50'));
    // $args=[
    //     'post_title'=>'new post by cron test2', 
    //     'post_author' =>  1,
    //     'post_date'=>$postdate,
    // ];
    // wp_insert_post($args);

    
    //return;
    //  $tabs = NXTLVL_Classes_ObjController::getClass('NXTLVL_Models_Menu')->getTabs(NXTLVL_Classes_Helpers_Tools::getValue('page'));
    //  print_r($tabs);

    // echo  $postdate = date('Y-m-d H:i', strtotime('2024-07-08 09:41'))."***";
    // echo $date = wp_date('Y-m');
    
    // echo NXTLVL_Classes_Helpers_Tools::getOption("week_days");
     
     
     
     //echo $date = wp_date('m-d')." ";

     //echo $day = date('w')," ";
     //echo $week_start = date('m-d-Y', strtotime('-'.$day.' days'))." ";
     // echo $week_end = date('Y-m-d H:i:s', strtotime('+'.(6-$day).' days'))." ";



    // $args = array(
    //     'post_status' => ['draft','future'],
    //     'posts_per_page' =>8,
    //     'meta_key'=>'schedule_post',
    // );

    // $postslist = new WP_Query( $args );
    // foreach ($postslist->posts as $post){
    //     //echo $post->post_title." ";
    // }
    

    // $post_dates = NXTLVL_Classes_ObjController::getClass('NXTLVL_Controllers_Settings')->set_post_time();
    // print_r($post_dates);
    
   // echo  $postdate = date('m-d H:i', strtotime("2024-$post_dates[0]"));

    // $my_post=get_post( "3513" );
    
    // $my_post->edit_date = true;
    
     //$my_post->post_date = date('Y-m-d H:i', strtotime('2024-12-5 08:30'));
    // $my_post->post_date = date('Y-m-d H:i', strtotime("2024-$post_dates[0]"));
    // $my_post->post_status = "future";
    // wp_update_post( $my_post );
//return;
    //set date
    
    //    $week_days = NXTLVL_Classes_Helpers_Tools::getOption("week_days");
    //    $week_split= preg_split('/(?=[A-Z])/',$week_days);
       
    //    $days=["Su","Mo","Tu","We","Th","Fr","Sa"];
    //    $Days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
    //    $dd=[];

    //    foreach($week_split as $key=>$week_day){
    //         if($key>0){   
    //             $index=array_search($week_day,$days);
    //             array_push($dd,$Days[$index]);
    //         }
    //    }
        // print_r($dd);    

        // return;

        //echo  $first= date('l - d/m g:i a', strtotime("Monday + $hour hours 30 minutes"))." ";
        
        // $post_dates=[];
        // $hours=NXTLVL_Classes_Helpers_Tools::getOption("hours");
        // $minutes=NXTLVL_Classes_Helpers_Tools::getOption("minutes");   
        // $time_format= NXTLVL_Classes_Helpers_Tools::getOption("time_format");
        // $time_split= preg_split('/[\s]+/',$time_format);

        // foreach($dd as $d){
        //     foreach($hours as $key=>$hour){
        //         if($time_split[$key]==="PM"){
        //             $hour=$hour+12;
        //         }
        //         array_push($post_dates, date('d/m - H:i a', strtotime("$d + $hour hours+$minutes[$key] minutes")));
        //     }
        // }
       
        // sort($post_dates);
        // print_r($post_dates);

        

        // $post_dates = NXTLVL_Classes_ObjController::getClass('NXTLVL_Controllers_Settings')->set_post_time();
        // print_r($post_dates);


        //date('d/m H:i a', strtotime("$d + $hour hours+$minutes[$key] minutes +1 Week")

        // echo $post_dates[1];
        // echo date('w', strtotime($post_dates[1]))." ";

        
        // $time_format= NXTLVL_Classes_Helpers_Tools::getOption("time_format");
        // $time_split= preg_split('/[\s]+/',$time_format);

    

    
        // $tabs = NXTLVL_Classes_ObjController::getClass('NXTLVL_Models_Menu')->getTabs(NXTLVL_Classes_Helpers_Tools::getValue('page'));
        // $menuid=0;
        // if ( '' === $menuid || false !== strpos( $menuid, '/' ) ) {
        //    list($menuid, $tab) = explode('/', $menuid);
        // }
    
        //var_dump( $post_dates );
        //sort($post_dates);

        // return;

        // $hours=NXTLVL_Classes_Helpers_Tools::getOption("hours");
        // print_r($hours);
        // echo count($hours).' ';

        // echo $date = wp_date('m-d-Y g:i a')." ";
        // $day = date('w');
        // echodate('Y-m-d H:i:s', strtotime('+'.(6-$day).' days'))." ";
      
        //print_r($postslist);
        //return $postslist;
   
        // echo sizeof($hours);
        //return;
?>


<div style="width:100%;">

<div  style="position:relative;top:4vw;margin-left:15%;min-height:30vw;width:70vw;background-color:black;background-image:radial-gradient(at 59% 100%, hsla(180, 100%, 10%, 1) 0px, transparent 50%), radial-gradient(at 0% 42%, hsla(180, 100%, 11%, 1) 0px, transparent 50%), radial-gradient(at 100% 4%, hsla(180, 100%, 17%, 1) 0px, transparent 50%);box-shadow: 0 4px 30px rgba(0,0,0, 0.4);border-radius:16px;backdrop-filter: blur(12px);padding-left:2vw;padding-top:2vw;padding-bottom:2vw;display:flex;flex-direction:column;gap:2vw;position:relative;">
    
    <a href="<?php echo esc_url(NXTLVL_Classes_Helpers_Tools::getAdminUrl("next_lvl"));?>" style="width:10vw;">
        <div class="manage-post-nav" style="">
            Manage posts<i style="position:absolute;margin-top:1px;right:14px;font-weight:900;font-size:1.5vw;" class="bx bx-chevron-right"></i>
        </div>
    </a>
    <div style="display:flex;justify-content:center;position:absolute;right:15px;top:2vw;">
        <div class="open-schedule meta-checkbox"  style="width:3vw;height:3vw;display:flex;flex-direction:column;gap:0.4vw;align-items:center;justify-content:center;">
            <div style="background-color:#50E0FE;width:0.3vw;height:0.3vw;border-radius:50%;"></div>
            <div style="background-color:#50E0FE;width:0.3vw;height:0.3vw;border-radius:50%;"></div>
            <div style="background-color:#50E0FE;width:0.3vw;height:0.3vw;border-radius:50%;"></div>
        </div>
        <input class="post_id" type="hidden" value='.$post->ID.' />
    </div>

    <div class="schedule-pannel" style="">
        <?php  $wd=["Su","Mo","Tu","We","Th","Fr","Sa"];
        $checked_days=NXTLVL_Classes_Helpers_Tools::getOption("week_days");?>

        <div style="font-size:1.1vw;font-weight:700;border-bottom: 1px solid white;">Schedule</div>

        <div style="display:flex;justify-content:space-around;margin-top:1vw;background-color:black;padding:5px;border-radius:20px; box-shadow: 0 10px 30px rgba(0,0,0, 0.2);">
            <?php foreach($wd as $d){
                if(str_contains($checked_days,$d)){
                    echo '<div class="time-week time-week-selected" style="font-size:0.9vw;">'.$d.'</div>';
                }
                else echo '<div class="time-week" style="font-size:0.9vw;">'.$d.'</div>';
            }?>
        </div>

        <div  style="margin-top:1vw;display:flex;gap:7vw;">
        </div>

        <div class="schedule-time-pannel" style="display:flex;flex-direction:column;gap:1vw;min-height:6vw;background-color:gray;padding:0.8vw;padding-bottom:3vw;margin-top:0.8vw;border-radius:15px; box-shadow: 0 10px 30px rgba(0,0,0, 0.2);position:relative;">   
                <?php $hours=NXTLVL_Classes_Helpers_Tools::getOption("hours");
                       $minutes=NXTLVL_Classes_Helpers_Tools::getOption("minutes");
                       $time_format=NXTLVL_Classes_Helpers_Tools::getOption("time_format");
                       $time_split= preg_split('/[\s]+/',$time_format);
                    if($hours==null){?>
                    <div class="new-time-slot">
                        <select class="hour-input" style="border-radius:15px;font-size:0.9vw;">
                            <?php $format_arr = array(" 1 "," 2 "," 3 ","4","5","6","7","8","9","10","11","12");
                                foreach ($format_arr as $format){
                                     echo "<option class='select-channel'  style='width:5vw;height:5px;font-weight:500;'>
                                            $format
                                        </option>";
                                }?>   
                        </select>    
                        :

                        <select class="minute-input" style="border-radius:15px;font-size:0.9vw;">
                                <?php $format_arr = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25", "26" ,"27"," 28" ,"29"," 30", "31," ,"32" ,"33"," 34"," 35"," 36"," 37" ,"38"," 39"," 40"," 41" ,"42", "43", "44", "45", "46", "47", "48" ,"49" ,"50" ,"51", "52" ,"53"," 54" ,"55"," 56", "57", "58" ,"59");
                                    foreach ($format_arr as $format){
                                            echo "<option class='select-channel'  style='width:5vw;height:5px;font-weight:500;'>
                                                    $format
                                                </option>";
                                    }?>   
                        </select> 

                        <select class="time-format"  style="border-radius:15px;font-size:0.7vw;">
                                <?php $format_arr = array("AM","PM");
                                    foreach ($format_arr as $format){
                                            echo "<option class='select-channel'  style='width:5vw;height:5px;font-weight:500;'>
                                                    $format
                                                </option>";
                                    }?>   
                        </select>         
                </div> 
                <?php }?>

                <?php $hours=NXTLVL_Classes_Helpers_Tools::getOption("hours");
                        if($hours!=null){
                            foreach($hours as $key=>$time){?>
                                <div class="new-time-slot time-<?php echo $key; ?>">
                                    <select class="hour-input" style="border-radius:15px;font-size:0.9vw;">
                                        <option><?php echo " ".$time." "; ?></option>
                                        <?php $format_arr = array(" 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "," 10 "," 11 "," 12 ");
                                            foreach ($format_arr as $format){
                                                echo "<option class='select-channel' style='width:5vw;height:5px;font-weight:500;'>
                                                        $format
                                                    </option>";
                                            }?>   
                                    </select>    
                                    :
        
                                    <select class="minute-input" style="border-radius:15px;font-size:0.9vw;">
                                        <option><?php echo " ".$minutes[$key]." "; ?></option>
                                            <?php $format_arr = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25", "26" ,"27"," 28" ,"29"," 30", "31," ,"32" ,"33"," 34"," 35"," 36"," 37" ,"38"," 39"," 40"," 41" ,"42", "43", "44", "45", "46", "47", "48" ,"49" ,"50" ,"51", "52" ,"53"," 54" ,"55"," 56", "57", "58" ,"59");
                                                foreach ($format_arr as $format){
                                                        echo "<option class='select-channel' style='width:5vw;height:5px;font-weight:500;'>
                                                                $format
                                                            </option>";
                                                }?>   
                                    </select> 

                                    <select class="time-format" style="border-radius:15px;font-size:0.8vw;">
                                        <option><?php echo " ".$time_split[$key]." "; ?></option>
                                            <?php $format_arr = array("AM","PM");
                                                foreach ($format_arr as $format){
                                                        echo "<option class='select-channel' style='width:5vw;height:5px;font-weight:500;'>
                                                                $format
                                                            </option>";
                                                }?>   
                                    </select>  
                            <div id="<?php echo $key; ?>" class="remove-time" style="font-size:1vw;">-</div>   
                            
                        </div>
                        <?php }
                      }?>

                <div class="add-time" style="padding:0.3vw;border-radius:2vw;background-color:white;font-weight:700;width:5vw;margin-top:1vw;font-size:0.8vw;position:absolute;bottom:10px;">+Add</div>
                <div class="add-time" style="display:none;padding:0.3vw;border-radius:2vw;background-color:rgb(255, 0, 0,0.9);color:white;font-weight:700;width:5vw;margin-top:1vw;font-size:0.8vw;position:absolute;bottom:10px;right:1vw;">-Remove</div>
        </div>

        <div class="save-schedule" style="box-shadow: 0 4px 30px rgba(0,0,0, 0.2);margin-top:3vw;width:6vw;height:2.5vw;background-color:#50E0FE;color:black;border-radius:2vw;font-size:0.9vw;font-weight:700;display:flex;align-items:center;justify-content:center;">Save</div>
    </div>

   

    <?php $postslist = NXTLVL_Controllers_Settings::get_sched_posts();
          $post_dates = NXTLVL_Classes_ObjController::getClass('NXTLVL_Controllers_Settings')->set_post_time();
          $key=0;
            if ($postslist->have_posts() ){
                foreach($postslist->posts as $key=>$post){       
                      if($post->post_status!="publish"){

                            $auth_id = $post->post_author;
                            $scheduled=get_post_meta( $post->ID,'schedule_post', true );
                          
                            NXTLVL_Classes_ObjController::getClass('NXTLVL_Controllers_Settings')->schedule_post($post->ID,$post_dates[$key]);

                            if($scheduled=="true"){      
                                $current_user = get_user_by('id',$auth_id);
                                echo'<div class="all-posts'.$post->ID.'" style="width: 42vw;background-color:rgb(80, 224, 254,0.15);border-radius:15px;padding:1vw;display:flex;">
                                    
                                    <div>
                                        <div style="font-weight:700;padding:7px;background-color:rgba(150,150,150,0.8);border-radius:1vw;width:17vw;height:2.5vw;font-size:0.8vw;color:white;padding:0.7vw;vertical-align:center;box-shadow: 0 10px 30px rgba(0,0,0, 0.1);">Publish on '.$post_dates[$key].'</div>
                                        
                                        <div class="post-details" style="background-color:rgba(150,150,150,0.7);border-radius:15px;padding:0.9vw;margin-top:0.8vw;border:1px solid white;">
                                            <div style="width:30vw;">
                                                <div style="height:100%;font-weight:600;padding-top:2px;font-size:0.9vw;">
                                                    <div style="color:black;line-height:1.3vw;" class="perma-title'.$post->ID.'">'.$post->post_title.'</div>
                                                    <div style="font-size:0.8vw;font-weight:700;margin-top:2px;line-height:1.2vw;margin-bottom:5px;"><a style="color:#50E0FE;" href='.get_permalink($post->ID).'>'.get_permalink($post->ID).'</a></div>
                                                </div>
                                            </div>

                                            <div class="edit-current-user" style="display:flex;align-items:center;min-width:26vw;height:3vw;">
                                                <img style="height:2vw;width:2vww;border-radius:50%;" src="'.get_avatar_url( $current_user->ID ).'" />
                                                <div style="color:black;font-weight:700;font-size:1vw;margin-left:10px;display:column;">
                                                    '. esc_html( $current_user->display_name ) .'
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div style="display:flex;flex-direction:column;">
                                        <div class="remove-post" style="margin-left:1.4vw;">x Remove</div>
                                        <div class="'.$post->ID.'"></div>
                                    </div>
                                </div>
                            ';
                        }
                    }
                }
                if (isset($_GET['paged']))
                    $paged = $_GET['paged'];
                else $paged=1;

                if ( $postslist->max_num_pages > 1) {
                    echo "<div style='padding-left:20px;font-weight:600;font-size:20px;height:60px;padding-top:15px;margin-top:1.5vw;'>" 
                            .paginate_links(array(
                                'total' => $postslist->max_num_pages,
                                'format' => '?paged=%#%',
                                'current' => max( 1, $paged ),
                                'prev_next' => true,
                                'prev_text' => __( '&laquo; Previous' ),
                                'next_text' => 'Next' 
                                    )).
                        "</div>";
                }
            }
                
    ?>
</div>
</div>
<div style="height:100px;"></div>

<style>
    html{
        min-height:100vh;
        background-color:#EBEBEC;
    }
    body{
        min-height:100vh;
    }
    .time-week:hover{
        opacity:0.8;
    }
    .time-week{
        border-radius:50%;
        background-color:white;
        height:1.8vw;
        width:1.8vw;
        font-size:0.6vw;
        font-weight:700;
        display:flex;
        align-items:center;
        justify-content:center;
        background-color:#4AC34;
    }
    .time-week-selected{
        background-color:#4AC34A;
        color:white;
    }
    .schedule-pannel{
        position:absolute;
        top:2vw;
        right:72px;
        width:21vw;
        min-height:23vw;
        background-color:rgba(196,196,196,0.6);
        border-radius:15px;
        padding:15px;
        display:none;
    }
    .schedule-pannel-open{
        display:block;
    }

    .save-schedule{

    }
    .save-schedule:hover{
        opacity:0.8;
    }
    .new-time-slot{
        display:flex;
        gap:1vw;
        font-weight:700;
        font-size:1vw;
        background-color:black;
        border-radius:20px; 
        padding:0.4vw;
        color:white; 
    }
    .hour-input{
        height:30px;
        width:4vw;
        border:none;
        border-radius:15px;
    }
    .minute-input{
        height:30px;
        width:4vw;
        border:none;
        border-radius:15px;
    }
    .time-format{
        height:30px;
        width:3vw;
        border:none;
        border-radius:15px;
    }
  
    .remove-post{
        box-shadow: 0 4px 30px rgba(0,0,0, 0.2);
        width:7vw;
        height:2.5vw;
        font-size:0.9vw;
        background-color:#ff4900;
        color:white;
        border-radius:1vw;
        font-weight:700;
        display:flex;
        align-items:center;
        justify-content:center;
    }
    .remove-post:hover{
        background-color:rgba(255, 0, 0,0.9);
    }
    .add-time:hover{
        opacity:0.8;
    }
    .post-details:hover{
       opacity:0.8;
  
    }
    .open-schedule:hover{
        border-radius:50%;
        background-color:black;
    }
    .manage-post-nav{
        width:10vw;
        height:3vw;
        background-color:rgba(80, 224, 254,0.3);
        color:white;
        font-weight:600;
        font-size:1vw;
        border-radius:3vw;
        padding:0.8vw;
        position:relative;
    }
    .manage-post-nav:hover{
        background-color:rgba(80, 224, 254,0.9);
        box-shadow: 0 10px 30px rgba(80, 224, 254, 0.2);
    }
    .remove-time:hover{
        color:red;
    }
    .page-numbers{
        border:none;
        padding:15px;
        text-decoration:none;
        color:white;
        background-color:#3c434a;
        border-radius:20px;
        font-weight:500;
    }
    .page-numbers:hover{
        color:aqua;
        opacity:90%;
    }
    .page-numbers.current{
        color:aqua;
    }
    .install-btn:hover{
        opacity:80%;
    }

</style>