<?php

use Appwrite\Utopia\View;

$events = $this->getParam('events', []);
$runtimes = $this->getParam('runtimes', []);
$runtimes['node-16.0']["cloud"] = true;
$runtimes['node-18.0']["cloud"] = true;
$runtimes['php-8.0']["cloud"] = true;
$runtimes['ruby-3.0']["cloud"] = true;
$runtimes['python-3.9']["cloud"] = true;
$runtimes['dart-2.17']["cloud"] = true;

$sorted_runtimes = [];

foreach ($runtimes as $key => $item) {
    $name = $item['name'];
    
    if (!isset($sorted_runtimes[$name])) {
        $sorted_runtimes[$name] = [];
    }

    $item['version'] = $key;

    $sorted_runtimes[$name]['versions'][] = $item;
}
?>


<p>
    Appwrite Functions supports an extensive list of runtimes to meet your unique tech preferences.
    Not all runtimes are available on Appwrite Cloud yet. Check for the <span class="tag green">Cloud</span> label in each listed runtime to know which ones are available.
</p>

<h2><a href="/docs/functions#supportedRuntimes" id="supportedRuntimes">Supported Runtimes</a></h2>

<p>Below is a list of supported Functions runtimes. The Appwrite team continually adds support for new runtimes.</p>

<table cellspacing="0" cellpadding="0" border="0" class="full margin-bottom-large">
    <thead>
        <tr>
            <th style="width: 50px"></th>
            <th style="width: 70px">Name</th>
            <th style="width: 100px">Version</th>
            <th style="width: 60px"></th>
            <th  style="width: 80px">Architectures</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($sorted_runtimes as $key => $runtime): ?>
        <tr>
            <td>
                <img src="" data-ls-attrs="src=/images/runtimes/<?php echo $this->escape($runtime['versions'][0]['logo'] ?? ''); ?>" alt="Function Env." class="avatar xxs" />
            </td>
            <td>                
            <a href="https://hub.docker.com/r/openruntimes/<?php echo $this->escape($runtime['versions'][0]['key']); ?>/tags" target="_blank" rel="noopener">
                <?php echo $this->escape($key); ?><i class="icon-link-ext"></i>
            </a>
            </td>
            <td>
            <?php foreach($runtime['versions'] as $key => $version): ?>
                <span data-general-copy><?php echo $this->escape($version['version']); ?> </span> <br>
            <?php endforeach; ?> 
            </td>
            <td>
            <?php foreach($runtime['versions'] as $key => $version): ?>
                <?php if (isset($version["cloud"])): ?>
                    <span class="tag green">Cloud</span>
                <?php endif; ?> 
            <?php endforeach; ?> 
            </td>   
            <td><?php echo $this->escape(implode(' / ', $runtime['versions'][0]['supports'] ?? [])); ?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>