<?
  if ( \S::get( 'show_audit' ) )
  {
    $url = \front\factory\AuditSEO::audit( \S::get( 'audit_site' ) );
  }
?>
<div class="audit-result">
  <form method="POST" action="/audyt-seo/wynik">
    <input type="hidden" name="show_audit" value="1">
    <div class="form-group">
      <input type="text" name="audit_site" id="audit_site" class="form-control" value="" placeholder="adres url">
      <button type="submit">Audytuj</button>
    </div>
  </form>
  <div class="box">
    <div class="row">
      <div class="col-12 title">
        INFORMACJE OGÓLNE
      </div>
    </div>  
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Domena:</span>
        <span class="value" id="audit_domain"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">IP:</span>
        <span class="value" id="audit_ip"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Lokalizacja serwera:</span>
        <span class="value" id="audit_location"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Obecność favicon:</span>
        <span class="value" id="audit_favicon"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">CMS:</span>
        <span class="value" id="audit_cms"></span>
      </div>
    </div>
  </div>
  <div class="box">
    <div class="row">
      <div class="col-12 title">
        WIDOCZNOŚĆ DLA ROBOTÓW
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Indeksowanie meta robots:</span>
        <span class="value" id="audit_meta_robots"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Indeksowanie robots.txt:</span>
        <span class="value" id="audit_robots_txt"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Przekierowanie www / bez www:</span>
        <span class="value" id="audit_redirect_www"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">SSL:</span>
        <span class="value" id="audit_https"></span>
      </div>
    </div>
  </div>
  <div class="box">
    <div class="row">
      <div class="col-12 title">
        TREŚĆ
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Meta title:</span>
        <span class="value" id="audit_meta_title"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Meta description:</span>
        <span class="value" id="audit_meta_description"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Meta keywords:</span>
        <span class="value" id="audit_meta_keywords"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Stosunek treści do kodu:</span>
        <span class="value" id="audit_code_to_text_ratio"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Ilość słów:</span>
        <span class="value" id="audit_words_count"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <div class="subtitle bold">Nagłówki h1...h6:</div>
        <div>
          <span class="subtitle bold">H1:</span>
          <span class="value" id="audit_h1_count"></span>
        </div>
        <div>
          <span class="subtitle bold">H2:</span>
          <span class="value" id="audit_h2_count"></span>
        </div>
        <div>
          <span class="subtitle bold">H3:</span>
          <span class="value" id="audit_h3_count"></span>
        </div>
        <div>
          <span class="subtitle bold">H4:</span>
          <span class="value" id="audit_h4_count"></span>
        </div>
        <div>
          <span class="subtitle bold">H5:</span>
          <span class="value" id="audit_h5_count"></span>
        </div>
        <div>
          <span class="subtitle bold">H6:</span>
          <span class="value" id="audit_h6_count"></span>
        </div>
      </div>
    </div>
  </div>
  <div class="box">
    <div class="row">
      <div class="col-12 title">
        SZYBKOŚĆ STRONY
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Na komputerach:</span>
        <span class="value" id="audit_speed_computer"></span>
      </div>
    </div>
    <div class="row">
      <div class="col-12">
        <span class="subtitle bold">Na telefonach:</span>
        <span class="value" id="audit_speed_mobile"></span>
      </div>
    </div>
  </div>
</div>
<script class="footer" type="text/javascript">
  $( function()
  {
    <? if ( \S::get( 'show_audit' ) ):?>
      audit_data01();
    <? endif;?>
  });
  
  function audit_data01() 
  {
    $.ajax(
    {
      type: 'POST',
      cache: false,
      url: '/auditSEO/data01/',
      data: 
      {
        url: '<?= $url;?>'
      },
      beforeSend: function() 
      {

      },
      success: function( response ) 
      {
        data = jQuery.parseJSON( response );
        $( '#audit_domain' ).html( data.effective_url );
        $( '#audit_ip' ).html( data.ip );
        $( '#audit_location' ).html( data.location );
        $( '#audit_favicon' ).html( data.favicon );
        $( '#audit_cms' ).html( data.cms );
        
        audit_data02();
      }
    });
  }
  
  function audit_data02() 
  {
    $.ajax(
    {
      type: 'POST',
      cache: false,
      url: '/auditSEO/data02/',
      data: 
      {
        url: '<?= $url;?>'
      },
      beforeSend: function() 
      {

      },
      success: function( response ) 
      {
        data = jQuery.parseJSON( response );
        $( '#audit_meta_robots' ).html( data.meta_robots );
        $( '#audit_robots_txt' ).html( data.robots_txt );
        $( '#audit_redirect_www' ).html( data.redirect_www );
        $( '#audit_https' ).html( data.https );
        
        audit_data03();
      }
    });
  }
  
  function audit_data03() 
  {
    $.ajax(
    {
      type: 'POST',
      cache: false,
      url: '/auditSEO/data03/',
      data: 
      {
        url: '<?= $url;?>'
      },
      beforeSend: function() 
      {

      },
      success: function( response ) 
      {
        data = jQuery.parseJSON( response );
        $( '#audit_meta_title' ).html( data.meta_title );
        $( '#audit_meta_description' ).html( data.meta_description );
        $( '#audit_meta_keywords' ).html( data.meta_keywords );
        $( '#audit_code_to_text_ratio' ).html( data.code_to_text_ratio );
        $( '#audit_words_count' ).html( data.words_count );
        $( '#audit_h1_count' ).html( data.h1_count );
        $( '#audit_h2_count' ).html( data.h2_count );
        $( '#audit_h3_count' ).html( data.h3_count );
        $( '#audit_h4_count' ).html( data.h4_count );
        $( '#audit_h5_count' ).html( data.h5_count );
        $( '#audit_h6_count' ).html( data.h6_count );
        
        audit_data04();
      }
    });
  }
  
  function audit_data04() 
  {
    $.ajax(
    {
      type: 'POST',
      cache: false,
      url: '/auditSEO/data04/',
      data: 
      {
        url: '<?= $url;?>'
      },
      beforeSend: function() 
      {

      },
      success: function( response ) 
      {
        data = jQuery.parseJSON( response );
        $( '#audit_speed_computer' ).html( ( data.page_speed_insight_desktop.lighthouseResult.categories.performance.score * 100 ) );
        
        audit_data05();
      }
    });
  }
  
  function audit_data05() 
  {
    $.ajax(
    {
      type: 'POST',
      cache: false,
      url: '/auditSEO/data05/',
      data: 
      {
        url: '<?= $url;?>'
      },
      beforeSend: function() 
      {

      },
      success: function( response ) 
      {
        data = jQuery.parseJSON( response );
        $( '#audit_speed_mobile' ).html( ( data.page_speed_insight_mobile.lighthouseResult.categories.performance.score * 100 ) );
      }
    });
  }
</script>