<?php

use yii\bootstrap4\ActiveForm;
use yii\helpers\Html;

/** @var \PortalPeople\magento\models\ConfigForm $model */

$this->title = 'Magento Configuration';
?>

<div class="container-fluid">
    <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 endif; ?>
    <?php if (Yii::$app->session->hasFlash('error')) : ?>
        <div class="alert alert-danger"><?= Html::encode(Yii::$app->session->getFlash('error')) ?></div>
    <?php endif; ?>

    <?php $form = ActiveForm::begin(['id' => 'magento-config-form']); ?>

    <div class="card mb-3">
        <div class="card-header">Magento REST Connection</div>
        <div class="card-body">
            <?= $form->field($model, 'enabled')->checkbox() ?>
            <?= $form->field($model, 'apiUrl')->textInput(['placeholder' => 'https://your-store.com']) ?>
            <?= $form->field($model, 'accessToken')->passwordInput(['autocomplete' => 'off']) ?>
            <?= $form->field($model, 'adminUsername')->textInput() ?>
            <?= $form->field($model, 'adminPassword')->passwordInput(['autocomplete' => 'new-password']) ?>
            <?= $form->field($model, 'storeCode')->textInput(['placeholder' => 'default']) ?>
            <?= $form->field($model, 'timeout')->textInput(['type' => 'number', 'min' => 5, 'max' => 120]) ?>
        </div>
    </div>

    <div class="card mb-3">
        <div class="card-header">Sync / Import Settings</div>
        <div class="card-body">
            <?= $form->field($model, 'productSyncFields')->textInput(['placeholder' => 'price1,price2,price3']) ?>
            <?= $form->field($model, 'debug')->checkbox() ?>
            <?= $form->field($model, 'useQueue')->checkbox() ?>
        </div>
    </div>

    <div class="form-group">
        <?= Html::submitButton('Save Settings', ['class' => 'btn btn-primary']) ?>
    </div>

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