<?php
// Icons from https://icon-icons.com/fr/pack/BigMug-Line-icons/935

global $account;
$periods = Period::LoadPendingPeriods();
$events = [];
$nbPeriods = count($periods);
if ($nbPeriods)
    $events = Event::LoadForPeriod($periods[$nbPeriods -1]);

?><!DOCTYPE html5><html><head>
<link rel="stylesheet" href="public/css/bootstrap.min.css" />
<link rel="stylesheet" href="public/css/style.css" />
</head><body>
<div class="row">
<div class="col-12 col-md-3 col-xl-2 bd-sidebar">
<h3>Pending periods</h3>
<ul class="container">
<?php foreach ($periods as $i) echo '<a href="#" onclick="setPeriodStart(\'' .$i->getStart() .'\')"><li>' .$i->getLabel() .' (from ' .$i->getStart() .')</li></a>'; ?>
</ul>
<h3>Past periods</h3>
<ul class="container">
<?php
$past = Period::LoadPastPeriods();
foreach ($past as $i) echo '<a href="#" onclick="setPeriodId(\'' .$i->getId() .'\')"><li>' .$i->getLabel() .' (from ' .$i->getStart() .' to ' .$i->getEnd() .')</li></a>'; ?>
</ul>
<h3>Settings</h3>
<div class="container">
    <a href="periods"/>Periods</a>
    <a href="logout"/>Logout</a>
</div></div>
<div class="col-12 col-md-9 col-xl-8 py-md-3 pl-md-5 bd-content">
<table class="table table-striped table-hover"><thead><tr><th>Date</th><th>Label</th><th>Beneficiary</th><th>Context</th><th>Amount</th><th>Action</th></tr></thead><tbody id="events"></tbody></table>
<button onclick="javascript:document.location.href='event/add'" class="btn btn-primary">Add</button>
<div class="row"><div class="col-sm">
<table class="table table-striped table-hover"><thead><tr><th>Beneficiary</th><th>Amount</th></tr></thead><tbody id="beneficiaries"></tbody></table></div><div class="col-sm">
<table class="table table-striped table-hover"><thead><tr><th>Context</th><th>Amount</th></tr></thead><tbody id="contexts"></tbody></table></div></div>
<script>window["PERIODS"] = [<?php $written = false;
foreach ($periods as $i) {
    echo ($written ? ',' : '') .'{start:"' .$i->getStart() .'"}';
    $written = true;
}; ?>];window["EVENTS"]= [<?php $written = false;
foreach ($events as $i) {
    echo ($written ? ',' : '') .json_encode($i->toArray());
    $written = true;
}?>];</script>
<script src="public/js/jquery-3.3.1.slim.min.js"></script>
<script src="public/js/popper.min.js"></script>
<script src="public/js/bootstrap.min.js"></script>
<script src="public/js/script.min.js"></script>
</body></html>
