<?php      
    if(isset($_GET['pige'])) {
        $pige = get_post($_GET['pige']);
    } else {
        die();
    }       
?>

<div class="wrap locked-pige">
<?php 
    $sTitle = preg_replace('#^\[.*\] - #', '', get_the_title($pige->ID));
?>

    <h1><?php echo e($__page->get('title').' : '.$sTitle); ?></h1>
    
    <div class="content">
<?php if($pige->post_status == "demander-relecture"): ?>
        <div class="notice notice-warning">
            <p><?php _e( 'Cette pige est encours de relecture vous ne pouvez pas faire de modification.', 'farandole' ); ?></p>
        </div>
<?php elseif($pige->post_status == "pige-valider"): ?>
        <div class="notice notice-warning">
            <p><?php _e( 'Cette pige est validé vous ne pouvez plus faire de modification.', 'farandole' ); ?></p>
        </div>
 <?php endif;
//     $demandePige = get_field( 'demande_de_pige', $pige->ID );
//     if($demandePige){ 
//         echo "<h2>Demande de pige : ".get_the_title($demandePige)."<h2>";
//     }

    if($demandePigeAuthor){
        $assistantEditorial = get_user_by('id', $demandePigeAuthor);           
        if($assistantEditorial){          
            echo "<h2>Responsable / Assistant éditorial : " . $assistantEditorial->display_name . "</h2>";         
        }
    }

    $pigiste = get_post_field('post_author', $pige->ID);
    if($pigiste){        
        $user = get_user_by('id', $pigiste);       
        if($user){
            echo "<h2>Pigiste : " . $user->display_name . "</h2>";
        }
    }
?>
        <h2>Image à la une : </h2>

        <?php echo get_the_post_thumbnail($pige->ID); ?>

        <h2>Contenu de la pige :</h2> 
        <div class="description">
        
<?php   echo apply_filters( 'the_content', $pige->post_content ); ?>
        
        </div>
        
        <h2>Historique des statuts :</h2>
    
<?php
    $historyStatus = new historyStatus( $pige->ID );
    $status = $historyStatus->_getStatus();
    if( $status ){
?>
        <table width="100%">
            <thead>
                <th>Utilisateur</th>
                <th>Statut</th>
                <th>Date</th>
                <th>Commentaire</th>
            </thead>
            <tbody>
<?php foreach( $status as $statu ): ?>
                <tr>
                    <td><?php echo $statu['modified_by']; ?></td>
                    <td><?php echo $statu['status']; ?></td>
                    <td><?php echo date_i18n( "d/m/Y à H:i:s", $statu['timestamp'], false ); ?></td>
                    <td><?php echo $statu['commentaire']; ?></td>
                </tr>
<?php   endforeach; ?>
            </tbody>
        </table>
<?php  
    }
?>
    
    </div>
</div>
