<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

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

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

    <?php if (Yii::$app->session->hasFlash('success')) { ?>
        <div class="alert alert-success"><?= Html::encode(Yii::$app->session->getFlash('success')) ?></div>
    <?php } ?>

    <?php if (Yii::$app->session->hasFlash('error')) { ?>
        <div class="alert alert-danger"><?= Html::encode(Yii::$app->session->getFlash('error')) ?></div>
    <?php } ?>

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

    <?php $form = ActiveForm::begin(); ?>

    <div class="panel panel-default">
        <div class="panel-heading"><strong>Settings</strong></div>
        <div class="panel-body">
            <?= $form->field($model, 'enabled')->checkbox() ?>
            <?= $form->field($model, 'apiBaseUrl')->textInput(['maxlength' => true]) ?>
            <?= $form->field($model, 'stripeVersion')->textInput(['maxlength' => true]) ?>
            <?= $form->field($model, 'secretKey')->passwordInput(['maxlength' => true]) ?>
            <?= $form->field($model, 'webhookSigningSecret')->passwordInput(['maxlength' => true]) ?>
            <?= $form->field($model, 'timeout')->input('number', ['min' => 5, 'max' => 300]) ?>
            <?= $form->field($model, 'webhookTolerance')->input('number', ['min' => 0, 'max' => 86400]) ?>
            <?= $form->field($model, 'debug')->checkbox() ?>
        </div>
    </div>

    <div class="btn-group" role="group" aria-label="Stripe actions">
        <?= Html::submitButton('Save Configuration', ['class' => 'btn btn-success']) ?>
        <?= Html::submitButton('Test Balance Endpoint', [
            'class' => 'btn btn-primary',
            'name' => 'testAction',
            'value' => 'balance',
        ]) ?>
        <?= Html::submitButton('Test Customers Endpoint', [
            'class' => 'btn btn-default',
            'name' => 'testAction',
            'value' => 'customers',
        ]) ?>
    </div>

    <?php ActiveForm::end(); ?>

    <?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>
