<?php

require('misc.php');

$pageTitle = empty($this->pageTitle) ? VEXON_SITE_NAME : VEXON_SITE_NAME." - ".$this->pageTitle;

echo <<<END
<!doctype html>
<html class="no-js" lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Vexon Pool mining dashboard for Blake256r14 ASIC miners">
<meta name="keywords" content="Vexon,VEX,mining,pool,Blake256r14,WhatsMiner D1">
<link id="favicon" rel="icon" type="image/png" sizes="64x64" href="/favicon.png?v=20260627b">
<link rel="icon" type="image/png" sizes="192x192" href="/android-chrome-192x192.png?v=20260627b">
<link rel="icon" type="image/png" sizes="512x512" href="/android-chrome-512x512.png?v=20260627b">
<link rel="shortcut icon" href="/favicon.ico?v=20260627b">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=20260627b">
<link rel="manifest" href="/site.webmanifest?v=20260627b">
<meta name="theme-color" content="#ffffff">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/mstile-150x150.png?v=20260627b">
<title>{$pageTitle}</title>
END;

echo CHtml::cssFile("/extensions/jquery/themes/ui-lightness/jquery-ui.css");
echo CHtml::cssFile('/vexon/ui/css/main.css');
echo CHtml::cssFile('/vexon/ui/css/table.css');
echo CHtml::cssFile('/vexon/ui/css/vexon-pool.css?v=20260629m');

$cs = app()->getClientScript();
$cs->registerCoreScript('jquery.ui');

echo CHtml::scriptFile('/vexon/ui/js/jquery.tablesorter.js');

echo "</head>";
echo '<body class="page vexon-pool">';
echo '<a href="/site/mainbtc" style="display: none;">main</a>';

showPageHeader();
showPageContent($content);
showPageFooter();

echo "</body></html>";
return;

function showItemHeader($selected, $url, $name)
{
	$selected_text = $selected ? "class='selected'" : '';
	echo "<a $selected_text href='$url'>$name</a>";
}

function showPageHeader()
{
	$action = controller()->action->id;
	$wallet = user()->getState('vexon-wallet');
	$ad = isset($_GET['address']);

	echo '<header class="vexon-header">';
	echo '<div class="vexon-brand"><a href="/" aria-label="Vexon Pool home"><img class="vexon-logo" src="/vexon/ui/images/vexon-logo.png" alt="Vexon"><span>'.VEXON_SITE_NAME.'</span></a></div>';
	echo '<nav class="vexon-nav">';

	showItemHeader(controller()->id=='site' && $action=='index' && !$ad, '/', 'Overview');
	showItemHeader($action=='mining', '/site/mining', 'Mining');
	if ($wallet)
		showItemHeader(controller()->id=='site'&&($action=='index' || $action=='wallet') && $ad, "/?address=$wallet", 'Dashboard');
	showItemHeader($action=='miners', '/site/miners', 'Miners');
	if (VEXON_PUBLIC_EXPLORER)
		showItemHeader(controller()->id=='explorer', '/explorer', 'Explorer');
	showItemHeader(controller()->id=='site' && $action=='api', '/site/api', 'API');
	showExternalHeader(VEXON_WALLET_URL, 'Wallet');
	showExternalHeader(VEXON_DOCS_URL, 'Docs');
	showExternalHeader(VEXON_OFFICIAL_URL, 'Website');
	if(controller()->admin)
	{
		showItemHeader($action=='common', '/site/common', 'Dashboard');
		showItemHeader(controller()->id=='coin', '/coin', 'Coins');
		showItemHeader(controller()->id=='site'&&$action=='admin', "/site/admin", 'Wallets');
	}

	echo '</nav>';

	$mining = getdbosql('db_mining');
	$lastPayout = $mining ? intval($mining->last_payout) : 0;
	$nextpayment = function_exists('vexon_next_payout_timestamp') ? vexon_next_payout_timestamp($lastPayout) : $lastPayout+VEXON_PAYMENTS_FREQ;
	echo '<div class="vexon-header-meta"><span>Payout</span><strong>'.date('M j H:i T', $nextpayment).'</strong></div>';

	echo '</header>';
}

function showExternalHeader($url, $name)
{
	if (empty($url)) return;
	$url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
	$name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
	echo "<a href='$url' target='_blank' rel='noopener'>$name</a>";
}

function showPageFooter()
{
	$year = date("Y", time());
	echo '<footer class="vexon-footer">';
	echo '<span>&copy; '.$year.' '.VEXON_SITE_NAME.'</span>';
	echo '<span>VEX Blake256r14 mining pool</span>';
	echo '</footer>';
}
