<?php

namespace Main\Controllers;

use Main\Core\Controller;
use Main\Services\SeoService;
use PDO;

class VoteController extends Controller
{
		protected string $route_type = 'vote';
		
    public function index()
    {
				SeoService::set('vote');
				
        $voteLinks = db()->query("SELECT * FROM VoteLinks");
        $voteLinks = $voteLinks->fetchAll(PDO::FETCH_ASSOC);
	    
		    $voteLinks = array_map(function($voteLink) {
						$link = $voteLink["link"];
						if (auth()->check()) $link .= "?username=" . auth()->user()->displayName();
						$voteLink["link"] = $link;
						
						return $voteLink;
				}, $voteLinks);

        return $this->view('vote', compact('voteLinks'));
    }
}