<div class="cs-space-20 cs-space-md-120"></div>
<div class="d-none d-md-block cs-space-40"></div>
<div class="container">
  <?php
  // Verificar si la API está disponible
  if (!$all || !isset($all[0])) {
      // Obtener información del endpoint desde la clase API (URL correcta hardcodeada)
      $api_instance = scm_secmca_api_instance();
      $url_base = $api_instance->url_base; // Usar URL hardcodeada en la clase, no de Theme Options
      $data_param = isset($_GET["data"]) ? $_GET["data"] : 'N/A';
      
      // Construir la URL exacta como lo hace la clase API
      $url_endpoint = 'public/v1/criterios/';
      
      echo '<div class="alert alert-danger" role="alert" style="margin: 20px 0; padding: 20px; background: #fff3cd; border: 1px solid #ffc107; border-radius: 8px;">';
      echo '<h4 class="alert-heading" style="color: #856404; margin-bottom: 15px;">⚠️ Error de Conexión con la API</h4>';
      echo '<p style="color: #856404; margin-bottom: 10px;"><strong>No se pudo conectar con el servicio de datos.</strong></p>';
      echo '<hr style="border-top: 1px solid #ffc107; margin: 15px 0;">';
      echo '<div style="background: #fff; padding: 15px; border-radius: 4px; margin: 10px 0;">';
      echo '<p style="margin: 5px 0; font-family: monospace; font-size: 13px;"><strong>Endpoint Base:</strong> <code style="background: #f8f9fa; padding: 4px 8px; border-radius: 3px; color: #d63384;">' . esc_html($url_base) . '</code></p>';
      echo '<p style="margin: 5px 0; font-family: monospace; font-size: 13px;"><strong>URL Endpoint:</strong> <code style="background: #f8f9fa; padding: 4px 8px; border-radius: 3px; color: #d63384;">' . esc_html($url_endpoint) . '</code></p>';
      echo '<p style="margin: 5px 0; font-family: monospace; font-size: 13px;"><strong>Parámetro Data:</strong> <code style="background: #f8f9fa; padding: 4px 8px; border-radius: 3px; color: #d63384;">' . esc_html($data_param) . '</code></p>';
      if ($url_base && $url_endpoint && $data_param != 'N/A') {
          $full_url = $url_base . $url_endpoint . $data_param;
          echo '<p style="margin: 10px 0 5px 0; font-family: monospace; font-size: 13px;"><strong>URL Completa:</strong></p>';
          echo '<p style="margin: 0; word-break: break-all;"><code style="background: #f8f9fa; padding: 8px 12px; border-radius: 3px; color: #d63384; display: block;">' . esc_html($full_url) . '</code></p>';
      }
      echo '</div>';
      echo '<p style="color: #856404; margin-top: 15px; margin-bottom: 5px;"><strong>Posibles causas:</strong></p>';
      echo '<ul style="color: #856404; margin: 5px 0;">';
      echo '<li>El servidor de la API está apagado o no es accesible</li>';
      echo '<li>La red no tiene acceso a la IP configurada</li>';
      echo '<li>El servicio en el puerto especificado no está corriendo</li>';
      echo '<li>Problemas de configuración de firewall o red</li>';
      echo '</ul>';
      echo '<p style="color: #856404; margin-top: 15px; margin-bottom: 0;"><small>Si el problema persiste, verifique que el servidor de la API esté funcionando y sea accesible desde esta red.</small></p>';
      echo '</div>';
      return;
  }
  ?><?php
  //trae el campo desccat1 de la categoria
  foreach ($categories as $key => $category) {
    if($category['title'] == $current_parent) {
      $childs = $category["sub_crb_cat"];
      if($key == intval($_GET['cid'])){
          $current_img  = $category["crb_cat_photo"];
      }
        foreach ($childs as $scid => $child) {
          if($child["title"] == $_GET['son']){
            if(! empty($child["sub_sub_crb_cat"])) {
              //si tiene hijos...
              foreach ($child["sub_sub_crb_cat"] as $k => $vv) {
                //foreach del hijo..
                  if($key == intval($_GET['cid']) && $scid == intval($_GET['scid']) && $k == intval($_GET['scsid']) && $_GET['son'] == $child["title"]) {
                    //current son ?
                    $desc_cat1 = $vv["desc"];
                    $desc_cat2 = $desc_cat1;
                    $unidadM = $vv["desc_medida"];
                    $limYear = $vv["limyear"];
                    $showregions = $vv["crb_show_content"];
                  }
                  // else {
                  //     $desc_cat2 = $child["desc"];
                  //     $unidadM = $vv["desc_medida"];
                  // }
              }
              // var_dump($unidadM);
            }else {
              $limYear = $child["limyear"];
              $desc_cat2 = $child["desc"];
              $unidadM = $child["desc_medida"];
              $showregions = $child["crb_show_content"];
            }
          }


          if($scid == intval($_GET['scid'])){
            // foreach ($child["sub_sub_crb_cat"] as $k => $last_c) {
            //   if(intval($_GET['son']) == $child["title"]) {
            //       $desc_cat1 = $child["desc"];
            //   }
            // }
            $extra1 = $child["extra1"];
            $ex_2 = $child["extra2"];
            $ex_tit1 = $child["extra1tit"];
            $ex_tit2 = $child["extra2tit"];
            // $meta = $child["meta"];
          }

        }
    }
  }
   ?>
<div class="row">
  <div class="cs-space-20 d-md-none"></div>
  <div class="col-12 breadcrums">
    <a href="<?php echo get_permalink($repo_page); ?>">Temas/<?php echo $current_parent ?></a>
    <?php foreach ($categories as $key => $catogory):
      $childs = $catogory["sub_crb_cat"];
        foreach ($childs as $x => $child):
          if($catogory['title'] == $current_parent):
          if($key == $_GET['cid'] && $x == $_GET['scid']):
            $maintitle = $child["title"];?>
        <a href="#">/<?php echo $child["title"]; ?></a>
    <?php
      endif;
      foreach ($child['sub_sub_crb_cat'] as $k => $last_child):
      if($key == $_GET['cid'] && $x == $_GET['scid'] && $k == $_GET['scsid'] && isset($_GET['scsid'])):
        $maintitle = $last_child["title"];
        ?>
        <a href="#">/<?php echo $last_child["title"]; ?></a>
        <?php
      endif;
      endforeach;
      endif;
      endforeach;
    endforeach; ?>
  </div>
  <div class="cs-space-20 d-md-none"></div>
</div>
</div>
<div class="d-none d-md-block cs-space-40"></div>
<section id="single-params">
  <div class="container">
    <div class="row">
        <div class="col-12 col-md-4">
          <div class="lateral-menu">
            <div class="header-lateral-menu">
              <div class="row">
                <div class="col-4 d-flex align-items-center">
                  <img class="logo" src="<?php echo $current_img; ?>">
                </div>
                <div class="col-8">
                  <h4><?php echo $current_parent; ?></h4>
                </div>
              </div>
            </div>
            <div class="body-lateral-menu">
              <?php foreach ($categories as $cid => $category) {
                if($category['title'] == $current_parent) {
                  $childs = $category["sub_crb_cat"];
                  foreach ($childs as $scid => $child) {
                  $child_title = str_replace(".", "", $child["title"]);
              ?>
                <div class="row">
                  <div class="align-items-end col-2 col-md-2 flex-column">
                    <a class="more " data-toggle="collapse" href="#<?php echo "op-" . $scid ?>" role="button" aria-expanded="false" aria-controls="<?php echo "op-" . $scid ?>">
                      <?php if(!empty($child['sub_sub_crb_cat'])) : ?>
                        <p>+</p>
                      <?php else: ?>
                        <p>-</p>
                      <?php endif; ?>
                    </a>
                  </div>
                  <div class="col-10 col-md-8">
    <a href="<?php echo get_permalink($pageID); ?>/?scid=<?php echo $scid ?>&cid=<?php echo $cid ?>&data=<?php echo $child['api_title'] ?>&parent=<?php echo $category['title'] ?>&son=<?php echo $child['title'] ?>&list">
        <h3 class="<?php echo ($scid == $_GET['scid'] && empty($child['sub_sub_crb_cat'])) ? 'active' : 'active-noborder' ?> js-ids"  data-cid="<?php echo $_GET['cid']; ?>" data-scid=<?php echo $_GET['scid']; ?> aria-expanded="false" aria-controls="<?php echo $child_title; ?>">
            <?php echo $child["title"]; ?>
        </h3>
    </a>
</div>

                </div>
                <div class="multi-collapse row collapse <?php echo ($scid == $_GET['scid']) ? 'show' : '' ?> collapse-info" id="<?php echo "op-" . $scid ?>">
                  <div class="col-2 col-md-2"></div>
                  <div class="col-10 col-md-12" style="margin-left: 40px;">
                    <?php if(! empty($child['sub_sub_crb_cat'])) : ?>
                    <ul>
                      <?php $count = 0; ?>
                      <?php foreach ($child['sub_sub_crb_cat'] as $k => $last_child):?>
                        <?php if(isset($_GET['list'])): ?>
                          <?php if($count == 0 && $_GET['son'] == $child["title"]) {
                            $maintitle = $last_child["title"];
                            $desc_cat1 = $last_child["desc"];
                          } ?>
                          <li class="<?php echo ($count == 0 && $_GET['son'] == $child["title"]) ? 'active' : '' ?>">
                            <a class="js-ids1" href="<?php echo get_permalink($pageID); ?>/?scsid=<?php echo $count; ?>&cid=<?php echo $cid ?>&scid=<?php echo $scid ?>&data=<?php echo $last_child['api_title'] ?>&parent=<?php echo $current_parent; ?>&son=<?php echo $child['title'] ?>" data-scsid="<?php echo $count; ?>"><?php echo $subcat['title'] ?>
                              <?php echo $last_child["title"]; ?>
                            </a>
                          </li>
                        <?php else: ?>
                          <li class="<?php echo ($cid == $_GET['cid'] && $scid == $_GET['scid'] && $k == $_GET['scsid'] && isset($_GET['scsid'])) ? 'active' : '' ?>">
                            <a class="js-ids1" href="<?php echo get_permalink($pageID); ?>/?scsid=<?php echo $count; ?>&cid=<?php echo $cid ?>&scid=<?php echo $scid ?>&data=<?php echo $last_child['api_title'] ?>&parent=<?php echo $current_parent; ?>&son=<?php echo $child['title'] ?>" data-scsid="<?php echo $count; ?>"><?php echo $subcat['title'] ?>
                              <?php echo $last_child["title"]; ?>
                            </a>
                          </li>
                        <?php endif; ?>
                    <?php
                    $count = $count + 1;
                  endforeach; ?>
                    </ul>
                  <?php endif; ?>
                  </div>
                </div>
              <?php }
                }
              }?>
            </div>
          </div>
        </div>
        <div class="cs-space-20 d-md-none"></div>
        <div class="col-12 col-md-8" id="parameters">
          <h2 class="js-current-son" data-son="<?php echo $_GET['son'] ?>" data-parent="<?php echo $current_parent; ?>"><?php echo $maintitle; ?></h2>
          <div class="cs-space-20"></div>
          <p class="params-p"><?php echo $desc_cat2; ?></p>
          <p style="font-weight: bold;color: black;">
            Unidad de medida:
            <span class="params-p">
              <?php echo $unidadM; ?>
            </span>
          </p>
          <div class="cs-space-20 d-md-none"></div>
          <div class="d-none d-md-block cs-space-40"></div>
          <ul class="nav nav-pills mb-3" id="main-pills-tab" role="tablist">
            <li class="nav-item">
              <a class="nav-link active" id="IPC-pill" data-toggle="pill" href="#IPC-ext0" role="tab" aria-controls="IPC-tab" aria-selected="true"><?php echo $current_parent; ?></a>
            </li>
            <?php if(! empty($extra1) && empty($ex_2)): ?>
            <li class="nav-item">
              <a class="nav-link" id="IPC-pill-2" data-toggle="pill" href="#IPC-ext1" role="tab" aria-controls="IPC-more-1" aria-selected="false"><?php echo $ex_tit1; ?></a>
            </li>
          <?php endif; ?>
          <?php if(! empty($ex_2) && ! empty($extra1)):?>
            <li class="nav-item">
              <a class="nav-link" id="IPC-pill-2" data-toggle="pill" href="#IPC-ext1" role="tab" aria-controls="IPC-more-1" aria-selected="false"><?php echo $ex_tit1; ?></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" id="IPC-pill-3" data-toggle="pill" href="#IPC-ext2" role="tab" aria-controls="IPC-more-2" aria-selected="false"><?php echo $ex_tit2; ?></a>
            </li>
          <?php endif; ?>
          </ul>
          <div class="cs-space-20 d-md-none"></div>
          <div class="tab-content" id="main-pills-tabContent">
            <div class="tab-pane fade show active parameters" id="IPC-ext0" role="tabpanel" aria-labelledby="IPC-ext0">
              <div class="container">
                <div class="row">
                  <div class="col-12">
                    <div class="cs-space-10"></div>
                    <h3>Parámetros de la consulta</h3>
                    <div class="cs-space-10"></div>
                  </div>
                </div>
              </div>
              <form id="params-form" class="" action="/graphic-single?parent=<?php echo $current_parent; ?>" method="POST">
              <div class="container">
                <div class="row">
                  <?php if($all && isset($all[0]["paises"]) && count($all[0]["paises"]) != 1): ?>
                  <div class="col-12 col-md-6">
                    <div class="params-box">
                      <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
                        <li class="nav-item">
                          <a class="nav-link active" id="pills-home-tab" data-toggle="pill" href="#pill-country" role="tab" aria-controls="pill-country" aria-selected="true">Pais</a>
                        </li>
                        <li class="nav-item <?php if($showregions == false){
                          echo 'd-none';
                        } ?>">
                          <a class="nav-link" id="IPC-more-tab" data-toggle="pill" href="#pill-region" role="tab" aria-controls="pills-profile" aria-selected="false">Regiones</a>
                        </li>
                      </ul>
                      <div class="tab-content" id="pills-tabContent">
                        <div class="tab-pane fade show active" id="pill-country" role="tabpanel" aria-labelledby="pills-home-tab">
                          <?php if($all): foreach ($all[0]["paises"] as $x => $value): 
                            // Determinar si es país (no región) - regiones tienen nombres cortos como CA, CARD, CAPARD
                            $is_country = !in_array($value["nombre"], array("CA", "CARD", "CAPARD"));
                            if($is_country) : 
                              $country_code = simafir_country_id_to_code($value["id"]);
                          ?>
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-variables" id="country<?php echo $x; ?>" name="country[]" value="<?php echo $country_code; ?>">
                              <label class="custom-control-label" for="country<?php echo $x; ?>"><?php echo $value["nombre"]; ?></label>
                            </div>
                          <?php endif; endforeach; endif;?>
                         <div class="button-box">
                           <button type="button" class="btn btn-primary all js-take-all-tabs js-remove-all-tabs js-all-ajax">Seleccionar todo</button>
                           <button type="button" class="btn btn-primary not-all RemoveAll js-remove-all js-remove-all-tabs">Eliminar todo</button>
                         </div>
                        </div>
                        <div class="tab-pane fade" id="pill-region" role="tabpanel" aria-labelledby="IPC-more-tab">
                          <?php foreach ($all[0]["paises"] as $x => $value): 
                            // Determinar si es región - regiones tienen nombres cortos como CA, CARD, CAPARD
                            $is_region = in_array($value["nombre"], array("CA", "CARD", "CAPARD"));
                            if($is_region) : 
                              $region_code = simafir_country_id_to_code($value["id"]);
                          ?>
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-variables" id="country<?php echo $x; ?>" name="country[]" value="<?php echo $region_code; ?>">
                              <label class="custom-control-label" for="country<?php echo $x; ?>"><?php echo $value["descripcion"]; ?></label>
                            </div>
                          <?php endif; endforeach;?>
                         <div class="button-box">
                           <button type="button" class="btn btn-primary all js-take-all-tabs">Seleccionar todo</button>
                           <button type="button" class="btn btn-primary not-all RemoveAll js-remove-all">Eliminar todo</button>
                         </div>
                        </div>
                      </div>
                      <div class="options-wrapper options-country-wrapper">
                      </div>
                    </div>
                  </div>
                <?php else: ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
                        <li class="nav-item">
                          <a class="nav-link active" id="pills-home-tab" data-toggle="pill" href="#pill-country" role="tab" aria-controls="pill-country" aria-selected="true">Pais</a>
                        </li>
                        <li class="nav-item <?php if($showregions == false){
                          echo 'd-none';
                        } ?>">
                          <a class="nav-link" id="IPC-more-tab" data-toggle="pill" href="#pill-region" role="tab" aria-controls="pills-profile" aria-selected="false">Regiones</a>
                        </li>
                      </ul>
                      <div class="tab-content" id="pills-tabContent">
                        <div class="tab-pane fade show active" id="pill-country" role="tabpanel" aria-labelledby="pills-home-tab">
                          <?php 
                            $first_country = $all[0]["paises"][0];
                            $is_country = !in_array($first_country["nombre"], array("CA", "CARD", "CAPARD"));
                            if($is_country) : 
                              $country_code = simafir_country_id_to_code($first_country["id"]);
                          ?>
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-aju radio-variables" id="country<?php echo 0; ?>" name="country[]" value="<?php echo $country_code; ?>" checked readonly>
                              <label class="custom-control-label" for="country<?php echo 0; ?>"><?php echo $first_country["nombre"]; ?></label>
                            </div>
                          <?php endif; ?>
                         <div class="button-box">
                           <button type="button" class="btn btn-primary all js-take-all-tabs js-remove-all-tabs">Seleccionar todo</button>
                           <button type="button" class="btn btn-primary not-all RemoveAll js-remove-all js-remove-all-tabs">Eliminar todo</button>
                         </div>
                        </div>
                        <div class="tab-pane fade" id="pill-region" role="tabpanel" aria-labelledby="IPC-more-tab">
                          <?php 
                            $first_region = $all[0]["paises"][0];
                            $is_region = in_array($first_region["nombre"], array("CA", "CARD", "CAPARD"));
                            if($is_region) : 
                              $region_code = simafir_country_id_to_code($first_region["id"]);
                          ?>
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input" id="country<?php echo 0; ?>" name="country[]" value="<?php echo $region_code; ?>" checked readonly>
                              <label class="custom-control-label" for="country<?php echo 0; ?>"><?php echo $first_region["descripcion"]; ?></label>
                            </div>
                          <?php endif; ?>
                         <div class="button-box">
                           <button type="button" class="btn btn-primary all js-take-all-tabs">Seleccionar todo</button>
                           <button type="button" class="btn btn-primary not-all RemoveAll js-remove-all">Eliminar todo</button>
                         </div>
                        </div>
                      </div>
                      <div class="options-wrapper options-country-wrapper">
                      </div>
                    </div>
                  </div>
                <?php endif; ?>
                <?php if($all && isset($all[0]["variables"]) && count($all[0]["variables"]) != 1): ?>
                  <div class="col-12 col-md-6">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Variables</h3>
                      </div>
                      <div class="box-content">

                        <?php if($all): foreach ($all[0]["variables"] as $x => $value):
                            $new = explode("|",$value["nombreEsp"]);
                            if(count($new) == 2):
                            ?>
                            <div class="custom-control custom-checkbox d-none">
                                <input type="checkbox" class="custom-control-input radio-variables" id="var<?php echo $x; ?>" name="var[]" data-varname="<?php echo $value["orden"] . "|" . $value["nombreEsp"]; ?>" value="<?php echo $value["codigoVariable"]; ?>"readonly>
                              <label class="custom-control-label" for="var<?php echo $x; ?>"><?php echo $value["nombreEsp"]; ?></label>
                            </div>
                          <?php else: ?>
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-variables" id="var<?php echo $x; ?>" name="var[]" data-varname="<?php echo $value["orden"] . "|" . $value["nombreEsp"]; ?>" value="<?php echo $value["codigoVariable"]; ?>">
                              <label class="custom-control-label" for="var<?php echo $x; ?>"><?php echo $value["nombreEsp"]; ?></label>
                            </div>
                          <?php endif; ?>
                        <?php endforeach; endif;?>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all js-all-ajax">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-var-wrapper"></div>
                    </div>
                  </div>
                <?php else: ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Variables</h3>
                      </div>
                      <div class="box-content">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input radio-aju" id="var<?php echo 0; ?>" name="var[]" data-varname="<?php echo $all[0]["variables"][0]["orden"] . "|" . $all[0]["variables"][0]["nombreEsp"]; ?>" value="<?php echo $all[0]["variables"][0]["codigoVariable"]; ?>" checked readonly>
                          <label class="custom-control-label" for="var<?php echo 0; ?>"><?php echo $all[0]["variables"][0]["nombreEsp"]; ?></label>
                        </div>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-var-wrapper">
                      </div>
                    </div>
                  </div>
                <?php endif; ?>
                  <?php if($all && isset($all[0]["frecuencias"]) && count($all[0]["frecuencias"]) != 1): ?>
                    <div class="col-12 col-md-6">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Frecuencia</h3>
                      </div>
                      <div class="box-content">
                        <?php if($all): foreach ($all[0]["frecuencias"] as $x => $value):?>
                            <div class="custom-control custom-checkbox">
                                  <input type="checkbox" class="custom-control-input radio-per" id="per<?php echo $x; ?>" name="per[]" value="<?php echo $value["codigoSDMX"]; ?>">
                                <label class="custom-control-label" for="per<?php echo $x; ?>"><?php echo $value["nombre"]; ?></label>
                            </div>
                        <?php endforeach; endif; ?>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-fe-wrapper"></div>
                    </div>
                  </div>
                  <?php else: ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Frecuencia</h3>
                      </div>
                      <div class="box-content">
                          <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-aju" id="per<?php echo 0; ?>" name="per[]" value="<?php echo $all[0]["frecuencias"][0]["codigoSDMX"]; ?>" checked readonly>
                              <label class="custom-control-label" for="per<?php echo 0; ?>"><?php echo $all[0]["frecuencias"][0]["nombre"]; ?></label>
                          </div>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-fe-wrapper">
                      </div>
                    </div>
                  </div>
                <?php endif; ?>
                <?php if($all && isset($all[0]["unidades"]) && count($all[0]["unidades"]) != 1): ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>UNIDAD DE MEDIDA</h3>
                      </div>
                      <div class="box-content">
                        <?php if($all):
                          foreach ($all[0]["unidades"] as $x => $value): ?>
                          <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-un" id="unit<?php echo $x; ?>" name="units[]" value="<?php echo $value["codigoSDMX"]; ?>" checked readonly>
                              <label class="custom-control-label" for="unit<?php echo $x; ?>"><?php echo $value["nombre"]; ?></label>
                            </div>
                        <?php endforeach; endif; ?>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-unit-wrapper">
                      </div>
                    </div>
                  </div>
                <?php else: ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>UNIDAD DE MEDIDA</h3>
                      </div>
                      <div class="box-content">
                        <?php if($all && isset($all[0]["unidades"]) && count($all[0]["unidades"]) == 1): ?>
                          <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-aju" id="unit<?php echo 0; ?>" name="units[]" value="<?php echo $all[0]["unidades"][0]["codigoSDMX"]; ?>" checked readonly>
                              <label class="custom-control-label" for="unit<?php echo 0; ?>"><?php echo $all[0]["unidades"][0]["nombre"]; ?></label>
                            </div>
                        <?php endif; ?>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-unit-wrapper">
                      </div>
                    </div>
                  </div>
                <?php endif; ?>
                  <div class="col-12 col-md-12">
                    <div class="params-box">
                       <ul class="nav nav-pills mb-3" id="pills-tab1" role="tablist">
                         <li class="nav-item">
                          <a data-limyear="<?php echo $limYear; ?>" class="nav-link active" id="IPC-more-tab2" data-toggle="pill" href="#pill-rango" role="tab" aria-controls="pills-profile" aria-selected="false">Por Rango</a>
                        </li>
                        <li class="nav-item <?php echo ($_GET["data"] == 'TIP_CAMB_DIARIO') ? 'd-none' : ''; ?>">
                          <a class="nav-link" id="pills-fecha-tab" data-toggle="pill" href="#pill-fecha" role="tab" aria-controls="pill-fecha" aria-selected="true">Por Fechas</a>
                        </li>
                      </ul>
                      <div class="tab-content" id="pills-tab1Content">
                        <div class="tab-pane fade" id="pill-fecha" role="tabpanel" aria-labelledby="pills-fecha-tab">
                          <div class="box-content js-custom-years">
                            <img class="loader_years" src="<?php echo get_template_directory_uri(); ?>/src/images/load_years.gif" alt="">
                              <div class="options-wrapper options-fe-wrapper js-custom-wrapper"></div>
                          </div>
                          <div class="button-box">
                                <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                                <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                          </div>
                        </div>
                        <div class="tab-pane fade show active" id="pill-rango" role="tabpanel" aria-labelledby="pills-home-tab">
                          <div class="container js-custom-years1">
                            <div class="row">
                              <div class="col-12 text-center mb-4 mt-4">
                                <h2>Seleccione un rango de fechas para la selección</h2>
                              </div>
                              <div class="col-6 range-select">
                                <p>Desde :</p>
                                 <select class="extra_years" id="extra-year-first">
                                  </select>
                              <select class="extra_mouths" id="extra-mouth-first">
                                <option value="1">Enero</option>
                                <option value="2">Febrero</option>
                                <option value="3">Marzo</option>
                                <option value="4">Abril</option>
                                <option value="5">Mayo</option>
                                <option value="6">Junio</option>
                                <option value="7">Julio</option>
                                <option value="8">Agosto</option>
                                <option value="9">Septiembre</option>
                                <option value="10">Octubre</option>
                                <option value="11">Noviembre</option>
                                <option value="12">Diciembre</option>
                              </select>
                              <select class="extra_mouths" id="extra-per-first">
                                <option value="0">--Selecciona un periodo--</option>
                                <option value="1">I</option>
                                <option value="2">II</option>
                                <option value="3">III</option>
                                <option value="4">IV</option>
                              </select>
                              </div>
                              <div class="col-6 range-select">
                                <p>Hasta :</p>
                                 <select class="extra_years" id="extra-year-last">
                              </select>
                              <select class="extra_mouths" id="extra-mouth-last">
                                <option value="1">Enero</option>
                                <option value="2">Febrero</option>
                                <option value="3">Marzo</option>
                                <option value="4">Abril</option>
                                <option value="5">Mayo</option>
                                <option value="6">Junio</option>
                                <option value="7">Julio</option>
                                <option value="8">Agosto</option>
                                <option value="9">Septiembre</option>
                                <option value="10">Octubre</option>
                                <option value="11">Noviembre</option>
                                <option value="12">Diciembre</option>
                              </select>
                              <select class="extra_mouths" id="extra-per-last">
                                <option value="0">--Selecciona un periodo--</option>
                                <option value="1">I</option>
                                <option value="2">II</option>
                                <option value="3">III</option>
                                <option value="4">IV</option>
                              </select>
                              </div>
                            </div>
                            <div class="row js-msg">
                              <p class="text-center w-100 d-none" style="color: red;">El año inicial desde el cual haces la consulta debe ser menor al año hasta el cual deseas la consulta.</p>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <?php if($all && isset($all[0]["valoraciones"]) && count($all[0]["valoraciones"]) != 1): ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Valoración</h3>
                      </div>
                      <div class="box-content">
                        <?php if($all): foreach ($all[0]["valoraciones"] as $x => $value): ?>
                          <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-ref" id="ref<?php echo $x; ?>" name="refs[]" value="<?php echo $value["id"]; ?>" checked readonly>
                              <label class="custom-control-label" for="ref<?php echo $x; ?>"><?php echo $value["nombre"]; ?></label>
                            </div>
                        <?php endforeach; endif; ?>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-ref-wrapper">
                      </div>
                    </div>
                  </div>
                <?php else: ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Valoración</h3>
                      </div>
                      <div class="box-content">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input radio-aju" id="ref<?php echo 0; ?>" name="refs[]" value="<?php echo $all[0]["valoraciones"][0]["id"]; ?>" checked readonly>
                          <label class="custom-control-label" for="ref<?php echo $x; ?>"><?php echo $all[0]["valoraciones"][0]["nombre"]; ?></label>
                        </div>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-ref-wrapper"></div>
                    </div>
                  </div>
                <?php endif; ?>
                <!-- && count($all[0]["ajuste"]) != 2 -->
                  <?php if($all && isset($all[0]["ajustes"]) && count($all[0]["ajustes"]) != 1): ?>
                  <div class="col-12 col-md-6  <?php echo ($_GET["data"] == 'EXPRT_FOB' || $_GET["data"] == 'IMPRT_CIF' || $_GET["data"] == 'SALD_COMERCIAL' || $_GET["data"] == 'REM_FAM_IEN' || $_GET["data"] == 'IED_TRIMESTRAL' || $_GET["data"] == 'BALAN_CUENT_CORRT_TRIM' || $_GET["data"] == 'CUENT_CAPIT_TRIM' || $_GET["data"] == 'CUENT_FINAN_TRIM' || $_GET["data"] == 'IMPORT_EXPORT_TRIM' || $_GET["data"] == 'VOL_TRANS_X_MERC' || $_GET["data"] == 'VOL_TRANS_X_SECT' || $_GET["data"] == 'VOL_TRANS_X_MONEDA' || $_GET["data"] == 'MERCADO_REPORTOS' || $_GET["data"] == 'GAST_TOTALES' || $_GET["data"] == 'AHORRO_CORRIENTE' || $_GET["data"] == 'INGR_TOTALES' || $_GET["data"] == 'FINAN_INTR_EXTR' || $_GET["data"] == 'RESULT_FISC_RELAC_PIB' || $_GET["data"] == 'RESULT_FISC_INGR_GAST_DONS') ? 'd-none' : '' ?>">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Ajuste</h3>
                      </div>
                      <div class="box-content">
                        <?php if($all): foreach ($all[0]["ajustes"] as $x => $value): ?>
                          <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input radio-aju" id="ajust<?php echo $x; ?>" name="fits[]" value="<?php echo $value["codigoSDMX"]; ?>" <?php echo ($_GET["data"] == 'EXPRT_FOB' || $_GET["data"] == 'IMPRT_CIF' || $_GET["data"] == 'SALD_COMERCIAL' || $_GET["data"] == 'REM_FAM_IEN' || $_GET["data"] == 'IED_TRIMESTRAL' || $_GET["data"] == 'BALAN_CUENT_CORRT_TRIM' || $_GET["data"] == 'CUENT_CAPIT_TRIM' || $_GET["data"] == 'CUENT_FINAN_TRIM' || $_GET["data"] == 'IMPORT_EXPORT_TRIM' || $_GET["data"] == 'VOL_TRANS_X_MERC' || $_GET["data"] == 'VOL_TRANS_X_SECT' || $_GET["data"] == 'VOL_TRANS_X_MONEDA' || $_GET["data"] == 'MERCADO_REPORTOS' || $_GET["data"] == 'GAST_TOTALES' || $_GET["data"] == 'AHORRO_CORRIENTE' || $_GET["data"] == 'INGR_TOTALES' || $_GET["data"] == 'FINAN_INTR_EXTR' || $_GET["data"] == 'RESULT_FISC_RELAC_PIB' || $_GET["data"] == 'RESULT_FISC_INGR_GAST_DONS') ? 'checked readonly' : '' ?>>
                              <label class="custom-control-label" for="ajust<?php echo $x; ?>"><?php echo $value["nombre"]; ?></label>
                            </div>
                        <?php endforeach; endif; ?>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-ajust-wrapper"></div>
                    </div>
                  </div>
                <?php else: ?>
                  <div class="col-12 col-md-6 d-none">
                    <div class="params-box">
                      <div class="box-header">
                        <h3>Ajuste</h3>
                      </div>
                      <div class="box-content">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input radio-aju" id="ajust<?php echo 0; ?>" name="fits[]" value="<?php echo $all[0]["ajustes"][0]["codigoSDMX"]; ?>" checked readonly>
                          <label class="custom-control-label" for="ajust<?php echo $x; ?>"><?php echo $all[0]["ajustes"][0]["nombre"]; ?></label>
                        </div>
                      </div>
                      <div class="button-box">
                        <button type="button" class="btn btn-primary all js-take-all">Seleccionar todo</button>
                        <button type="button" class="btn btn-primary not-all js-remove-all">Eliminar todo</button>
                      </div>
                      <div class="options-wrapper options-ajust-wrapper">
                      </div>
                    </div>
                  </div>
                <?php endif; ?>
                  <div class="col-12 send-params">
                      <label><input type="checkbox" id="cbox1" value="first_checkbox"> Ver datos en formato JSON</label><br>
                    <button id="send" data-subjectid="<?php echo $all[0]["idTema"] ?>" data-restpage="<?php echo get_page_link($page_results); ?>" type="submit" name="Submit" class="btn btn-primary w-100">Consultar datos</button>
                    <span class="toolong">Por favor ajuste la consulta a max 15 variables y 5 años, para mejorar la experiencia.</span>
                    <img class="loader_years_load" src="<?php echo get_template_directory_uri(); ?>/src/images/load_years.gif" alt="">
                  </div>
              </div>
              </form>
              <div class="cs-space-40 d-md-none"></div>
            </div>
            </div>
            <div class="tab-pane fade" id="IPC-ext1" role="tabpanel" aria-labelledby="IPC-ext1">
              <pre>
                <?php echo $extra1; ?>
              </pre>
            </div>
            <div class="tab-pane fade" id="IPC-ext2" role="tabpanel" aria-labelledby="IPC-ext2">
              <pre>
                <?php echo $ex_2; ?>
              </pre>
            </div>
          </div>
        </div>
    </div>
  </div>
</section>
<div class="d-none d-md-block cs-space-40"></div>
