<?php
$variables = $this->getParam('variables', []);

$markdown = new \Parsedown();
$markdown->setSafeMode(true);
?>

<p>Appwrite environment variables allow you to edit your server setup configuration and customize it. You can easily change the environment variables by changing them when running Appwrite using Docker CLI or Docker Compose.</p>

<p>Updating your Appwrite environment variables requires you to edit your Appwrite <code>.env</code> file. Your Docker files should be located inside the "appwrite" folder at the location where you first run the Appwrite installation script. It's recommended to use the <code>.env</code> file as a central point for updating your Appwrite configuration rather than changing them directly in your <code>docker-compose.yml</code> file.</p>

<p>After editing your <code>docker-compose.yml</code> or <code>.env</code> files, you will need to recreate your Appwrite stack by running the following compose command in your terminal:</p>

<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash">
    <pre class="line-numbers"><code class="prism language-bash" data-prism>docker compose up -d</code></pre>
</div>

<p>You can verify if the changes have been successfully applied by running this command:</p>
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash">
    <pre class="line-numbers"><code class="prism language-bash" data-prism>docker compose exec appwrite vars</code></pre>
</div>

<p><b>All Options:</b></p>

<ul>
    <?php foreach($variables as $node):
        $category = $node['category'] ?? '';
        ?>

        <li class="margin-bottom-small"><a href="/docs/environment-variables#<?php echo $this->escape(strtolower(str_replace(' ', '_', $category))); ?>"><i class="icon-angle-circled-right margin-start-negative-tiny margin-end-tiny"></i> <?php echo $this->escape($category); ?></a></li>
    <?php endforeach; ?>
</ul>

<?php foreach($variables as $node):
    $category = $node['category'] ?? '';
    $description = $node['description'] ?? '';
    ?>

    <h2 id="<?php echo $this->escape(strtolower(str_replace(' ', '_', $category))); ?>"><a href="/docs/environment-variables#<?php echo $this->escape(strtolower(str_replace(' ', '_', $category))); ?>"><?php echo $this->escape($category); ?></a></h2>

    <?php if($description): ?>
        <p><?php echo $markdown->text($this->escape($description)); ?></p>
    <?php endif; ?>

    <table cellspacing="0" cellpadding="0" border="0" class="full margin-bottom-large">
    <thead>
        <tr>
            <th style="width: 240px">Name</th>
            <th>Description</th>
        </tr>
        </thead>
            <tbody>
            <?php foreach($node['variables'] ?? [] as $var):
                $name = $var['name'] ?? '';
                $description = $var['description'] ?? '';
                $introduction = $var['introduction'] ?? '';
            ?>
                <tr>
                    <td>
                        <?php echo $this->escape($name); ?>

                        <?php if($introduction): ?>
                            <p class="margin-top-small text-fade">version >= <?php echo $this->escape($introduction); ?></p>
                        <?php endif; ?>
                    </td>
                    <td><?php echo $markdown->text($this->escape($description)); ?></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php endforeach; ?>