<?php

use yii\helpers\Html;

$this->title = 'Stripe Module Config';
?>

<div class="stripe-config-index">
    <h1><?= Html::encode($this->title) ?></h1>

    <?php if ($error !== null) { ?>
        <div class="alert alert-danger"><?= Html::encode($error) ?></div>
    <?php } ?>

    <h3>Current Configuration</h3>
    <table class="table table-striped table-bordered">
        <tbody>
            <?php foreach ($config as $key => $value) { ?>
                <tr>
                    <th style="width: 260px;"><?= Html::encode($key) ?></th>
                    <td>
                        <?php
                        $displayValue = is_bool($value)
                            ? ($value ? 'true' : 'false')
                            : (string) $value;
                        ?>
                        <?= Html::encode($displayValue) ?>
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>

    <h3>Connection Tests</h3>
    <form method="post">
        <input
            type="hidden"
            name="<?= Html::encode(Yii::$app->request->csrfParam) ?>"
            value="<?= Html::encode(Yii::$app->request->csrfToken) ?>"
        >

        <div
            class="btn-group"
            role="group"
            aria-label="Stripe tests"
        >
            <button class="btn btn-primary" type="submit" name="testAction" value="balance">
                Test Balance Endpoint
            </button>
            <button class="btn btn-default" type="submit" name="testAction" value="customers">
                Test Customers Endpoint
            </button>
        </div>
    </form>

    <?php if ($result !== null) { ?>
        <h3 style="margin-top: 24px;">Result</h3>
        <?php $jsonResult = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); ?>
        <pre style="max-height: 420px; overflow: auto;"><?= Html::encode($jsonResult) ?></pre>
    <?php } ?>
</div>
