<?php 
/** 
 * @package JREALTIME::OVERVIEW::administrator::components::com_jrealtimeanalytics
 * @subpackage views
 * @subpackage overview
 * @subpackage tmpl
 * @author Joomla! Extensions Store
 * @copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html  
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\CMS\Language\Text;
?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
	<span class='badge bg-primary label-large'><?php echo $this->statsDomain; ?></span> 
	<?php echo $this->hasOwnCredentials ? null : "<span data-bs-content='" . Text::_('COM_JREALTIME_GOOGLE_APP_NOTSET_DESC') . "' class='badge bg-warning hasPopover google pull-right'>" . Text::_('COM_JREALTIME_GOOGLE_APP_NOTSET') . "</span>"; ?>
	
	<table class="headerlist">
		<tr>
			<td class="left">
				<div class="input-group input-group-date active">
					<span class="input-group-text" aria-label="<?php echo Text::_('COM_JREALTIME_FILTER_BY_DATE_FROM');?>"><span class="icon-calendar" aria-hidden="true"></span> <?php echo Text::_('COM_JREALTIME_FILTER_BY_DATE_FROM' ); ?>:</span>
					<input type="text" name="fromperiod" id="fromPeriod" data-role="calendar" autocomplete="off" value="<?php echo $this->dates['start'];?>" class="text_area"/>
				</div>
				
				<div class="input-group input-group-date active">
					<span class="input-group-text" aria-label="<?php echo Text::_('COM_JREALTIME_FILTER_BY_DATE_TO');?>"><span class="icon-calendar" aria-hidden="true"></span> <?php echo Text::_('COM_JREALTIME_FILTER_BY_DATE_TO' ); ?>:</span>
					<input type="text" name="toperiod" id="toPeriod" data-role="calendar" autocomplete="off" value="<?php echo $this->dates['to'];?>" class="text_area"/>
				</div>
				<button class="btn btn-primary btn-sm" onclick="this.form.submit();"><?php echo Text::_('COM_JREALTIME_GO' ); ?></button>
			</td>
		</tr>
	</table>
	
	<!-- GOOGLE SEARCH CONSOLE STATS PAGES -->
	<div class="accordion" id="jrealtime_googleconsole_query_accordion">
		<div class="row tablestats no-margin">
			<div class="col-md-12 ps-0 span12">
				<div class="card card-default accordion-group">
					<div class="card-header p-0 accordion-heading">
						<div class="accordion-toggle accordion_lightblue" data-bs-toggle="collapse" data-bs-target="#jrealtime_google_pages">
							<h3 class="card-title m-3 accordion-title"><span class="icon-copy" aria-hidden="true"></span> <?php echo Text::_ ('COM_JREALTIME_GOOGLE_WEBMASTERS_STATS_KEYWORDS_BY_PAGES' ); ?></h3>
						</div>
					</div>
					<div id="jrealtime_google_pages" class="card-body card-block accordion-body accordion-inner collapse">
						<table id="jrealtime_table_webmasters_pages_stats" class="adminlist table table-striped table-hover table-webmasters">
							<thead>
								<tr>
									<th>
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_PAGES' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_CLICKS' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_IMPRESSION' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_CTR' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_POSITION' ); ?></span>
									</th>
								</tr>
							</thead>
							
							<tbody>
								<?php // Render errors count
									if(!empty($this->googleData['results_page'])){
										foreach ($this->googleData['results_page'] as $dataGroupedByPage) { ?>
											<tr>
												<td data-bind="pagestats_page">
													<span class="label-italic">
														<?php $dataGroupedKeys = $dataGroupedByPage->getKeys();?>
														<a href="<?php echo $dataGroupedKeys[0];?>" target="_blank">
															<?php echo $dataGroupedKeys[0];?> <span class="icon-out" aria-hidden="true"></span>
														</a>
													</span>
												</td>
												<td data-bind="pagestats_clicks">
													<?php echo $dataGroupedByPage->getClicks();?>
												</td>
												<td data-bind="pagestats_impressions">
													<?php echo $dataGroupedByPage->getImpressions();?>
												</td>
												<td data-bind="pagestats_rate">
													<?php echo round(($dataGroupedByPage->getCtr() * 100), 2) . '%';?>
												</td>
												<td data-bind="pagestats_position">
													<?php 
														$serpPosition = (int)$dataGroupedByPage->getPosition();
														$classLabel = $serpPosition > 30 ? 'bg-danger' : 'bg-success';
													?>
													<span class="badge <?php echo $classLabel;?>">
														<?php echo $serpPosition;?>
													</span>
												</td>
											</tr>
									<?php }
									}
								?>
							</tbody>
						</table>
					</div>
					<canvas id="pagestats-chart"></canvas>
				</div>
			</div>
		</div>
	</div>
	
	<!-- GOOGLE SEARCH CONSOLE STATS KEYWORDS -->
	<div class="accordion" id="jrealtime_googleconsole_accordion">
		<div class="row tablestats no-margin">
			<div class="col-md-12 ps-0 span12">
				<div class="card card-default accordion-group">
					<div class="card-header p-0 accordion-heading">
						<div class="accordion-toggle accordion_lightblue" data-bs-toggle="collapse" data-bs-target="#jrealtime_google_query">
							<h3 class="card-title m-3 accordion-title"><span class="icon-list-view" aria-hidden="true"></span> <?php echo Text::_ ('COM_JREALTIME_GOOGLE_WEBMASTERS_STATS_KEYWORDS_BY_QUERY' ); ?></h3>
						</div>
					</div>
					<div id="jrealtime_google_query" class="card-body card-block accordion-body accordion-inner collapse">
						<table id="jrealtime_table_webmasters_keywords_stats" class="adminlist table table-striped table-hover table-webmasters">
							<thead>
								<tr>
									<th>
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_KEYS' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_CLICKS' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_IMPRESSION' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_CTR' ); ?></span>
									</th>
									<th class="title">
										<span><?php echo Text::_('COM_JREALTIME_GOOGLE_WEBMASTERS_POSITION' ); ?></span>
									</th>
								</tr>
							</thead>
							
							<tbody>
								<?php // Render errors count
									if(!empty($this->googleData['results_query'])){
										foreach ($this->googleData['results_query'] as $dataGroupedByQuery) { ?>
											<tr>
												<td data-bind="querystats_keyword">
													<span class="badge bg-info label-large">
														<?php $dataGroupedQuery = $dataGroupedByQuery->getKeys();?>
														<?php echo htmlspecialchars( $dataGroupedQuery[0], ENT_QUOTES, 'UTF-8');?>
													</span>
													<a href="https://www.google.com/#q=<?php echo urlencode($dataGroupedQuery[0]);?>" target="_blank">
														<span class="icon-out" aria-hidden="true"></span>
													</a>
												</td>
												<td data-bind="querystats_clicks">
													<?php echo $dataGroupedByQuery->getClicks();?>
												</td>
												<td data-bind="querystats_impressions">
													<?php echo $dataGroupedByQuery->getImpressions();?>
												</td>
												<td data-bind="querystats_rate">
													<?php echo round(($dataGroupedByQuery->getCtr() * 100), 2) . '%';?>
												</td>
												<td data-bind="querystats_position">
													<?php 
														$serpPosition = (int)$dataGroupedByQuery->getPosition();
														$classLabel = $serpPosition > 30 ? 'bg-danger' : 'bg-success';
													?>
													<span class="badge <?php echo $classLabel;?>">
														<?php echo $serpPosition;?>
													</span>
												</td>
											</tr>
									<?php }
									}
								?>
							</tbody>
						</table>
					</div>
					<canvas id="querystats-chart"></canvas>
				</div>
			</div>
		</div>
	</div>
	
	<input type="hidden" name="option" value="<?php echo $this->option;?>" />
	<input type="hidden" name="task" value="webmasters.display" />
</form>