<?php


$html_import = get_field('html_import') ? get_field('html_import') : false;
$thumb_import = get_field('thumb_import') ? get_field('thumb_import') : false;
$categories = get_the_category(get_the_ID());
$category_name = '';
if (is_array($categories) && isset($categories[0]) && is_object($categories[0]) && isset($categories[0]->name)) {
  $category_name = $categories[0]->name;
}
$hide_cover = get_field('hide_cover') ? get_field('hide_cover') : false;
$img_cover = get_field('img_cover') ? get_field('img_cover') : '';
$img_a_la_une = get_field('a_la_une') ? get_field('a_la_une') : '';
?>
<div class="main-content v2 bg-white">
  <?php if ($html_import):

    // OLD VERSION LPMAGAZINE
    // OLD VERSION LPMAGAZINE
    // OLD VERSION LPMAGAZINE
    // OLD VERSION LPMAGAZINE
    // OLD VERSION LPMAGAZINE
    // OLD VERSION LPMAGAZINE
  ?>
    <article class="post">
      <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri() ?>/dist/lpmag.css">
      <?php echo $html_import; ?>
    </article>
  <?php
  else:
    // new version LP
    // new version LP
    // new version LP
    // new version LP
    // new version LP
  ?>
    <article class="post">
      <?php if ($hide_cover != true): ?>
        <section class="blog-title blog-title__dark blog-title__featured scroll-appear">
          <div class="bg">
            <?php
            if (is_array($img_cover) && count($img_cover) > 0) {
              echo wp_get_attachment_image($img_cover['id'], 'full', false,);
            } elseif (is_array($img_a_la_une) && count($img_a_la_une) > 0) {
              echo wp_get_attachment_image($img_a_la_une['id'], 'full', false,);
            } else {
              the_post_thumbnail('full');
            }

            ?>
          </div>
          <div class="wrapper relative ">
            <?php if (!empty($category_name)) : ?>
              <span class="uptitle block"><?php echo esc_html($category_name); ?></h2>
              <?php endif; ?>
              <?php the_title('<h1 class="title" >', '</h1>'); ?>
              <time class="date" datetime="<?php echo esc_attr(get_the_date(DATE_W3C)); ?>"><?php echo esc_html(get_the_date('F Y')); ?></time>
              <meta content="<?php echo esc_attr(get_the_modified_date(DATE_W3C)); ?>" />
              <link href="<?php echo esc_url(get_permalink()); ?>" />
          </div>
        </section>
      <?php endif; ?>
      <?php
      $chapitres = get_field('chapitre_edito');
      if (is_array($chapitres) && count($chapitres) > 0) {
        get_template_part('partials/content', 'pagemenu', ['data' => $chapitres]);
        echo '<div class="main content ">';
        get_template_part('partials/content', 'chapitre-edito', ['data' => $chapitres]);
        echo '</div>';
      } else {
        echo '<div class="main container max-w-960 py-20 ">';
        the_content();
        echo '</div>';
      }
      ?>
    </article>
  <?php
  endif; ?>
</div>
