<?php

/**
 * @package JoomShopping for Joomla!
 * @subpackage payment
 * @author YooMoney
 * @copyright Copyright (C) 2025 YooMoney. All rights reserved.
 */

use YooMoney\Model\KassaPaymentMethod;

defined('_JEXEC') or die('Restricted access');

/** @var KassaPaymentMethod $kassa Класс методов для оплаты через ЮКассу */
/** @var array $params Настройки модуля оплаты */
$isDisabledClass = !$kassa->getKassaMode() ? 'disabled' : '';
?>

<div class="row qa-oauth-info">
    <?php if ($kassa->isAuthorization() && $kassa->isConnectFailed()) : ?>
        <div class="span11 offset1">
            <div class="alert alert-danger" role="alert">
                <strong><?php echo _JSHOP_YOO_AUTHORIZATION_TITLE_ERROR; ?></strong><br>
                <?php echo _JSHOP_YOO_AUTHORIZATION_TEXT_ERROR; ?>
            </div>
            <button class="btn btn-warning btn-oauth-connect qa-yookassa-entrance" <?php echo $isDisabledClass ?>><?php echo _JSHOP_YOO_OAUTH_BTN_RECONNECT; ?></button>
        </div>
    <?php endif; ?>

    <?php if ($kassa->isBasicAuthorization() && !$kassa->isConnectFailed()) : ?>
        <?php if ($kassa->isSberLoanAvailable()) : ?>
            <div class="span10 offset1">
                <div class="col-12">
                    <div class="alert alert-warning offset-top-10" role="alert">
                        <strong><?php echo _JSHOP_YOO_SBER_LOAN_WARNING_TITLE; ?></strong>
                        <p><?php echo _JSHOP_YOO_SBER_LOAN_WARNING_TEXT; ?></p>
                        <p><?php echo _JSHOP_YOO_SBER_LOAN_WARNING_TEXT_INSTRUCTION; ?></p>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <div class="span5 offset1">
            <div class="form-group">
                <div class="span2"><label for="pm_params-shop-id"><?php echo _JSHOP_YOO_KASSA_SHOP_ID_LABEL; ?></label>
                </div>
                <div class="span9">
                    <input name="pm_params[shop_id]"
                           type="text"
                           class="form-control qa-shop-id"
                           data-qa-shop-id="<?php echo escapeValue($kassa->getShopId()); ?>"
                           id="pm_params-shop-id"
                           value="<?php echo escapeValue($kassa->getShopId()); ?>"
                    >
                    <p class="help-block"><?php echo _JSHOP_YOO_KASSA_SHOP_ID_DESCRIPTION; ?></p>
                </div>
            </div>
            <div class="form-group">
                <div class="span2">
                    <label for="pm-params-shop-password" class=""><?php echo _JSHOP_YOO_KASSA_PASSWORD_LABEL; ?></label></div>
                <div class="span9">
                    <input name="pm_params[shop_password]"
                           type="text"
                           class="form-control"
                           id="pm-params-shop-password"
                           value="<?php echo escapeValue($kassa->getPassword()); ?>"
                    >
                    <p class="help-block"><?php echo _JSHOP_YOO_KASSA_PASSWORD_DESCRIPTION; ?></p>
                    <p style="margin-bottom:3px;"><?php echo _JSHOP_YOO_SHOP_INSTRUCTION; ?></p>
                    <button class="btn btn-warning btn-oauth-connect offset-top-10 qa-change-shop-button <?php echo $isDisabledClass ?>">
                        <?php echo _JSHOP_YOO_OAUTH_BTN_CHANGE; ?>
                    </button>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <?php if ($kassa->isOauthAuthorization() && !$kassa->isConnectFailed()) : ?>
        <?php if ($kassa->isSberLoanAvailable()) : ?>
            <div class="span10 offset1">
                <div class="col-12">
                    <div class="alert alert-warning offset-top-10" role="alert">
                        <strong><?php echo _JSHOP_YOO_SBER_LOAN_WARNING_TITLE; ?></strong>
                        <p><?php echo _JSHOP_YOO_SBER_LOAN_WARNING_TEXT; ?></p>
                        <p><?php echo _JSHOP_YOO_SBER_LOAN_WARNING_TEXT_INSTRUCTION; ?></p>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <div class="span5 offset1">
            <div class="form-group">
                <div class="span12">
                    <?php if (isSelected($params, 'kassamode')) : ?>
                        <span class="qa-shop-type"
                              data-qa-shop-type="<?php echo $kassa->isTest() ? 'test' : 'prod'; ?>">
                            <?php echo $kassa->isTest() ? _JSHOP_YOO_KASSA_TEST_STORE : _JSHOP_YOO_KASSA_REAL_STORE; ?>
                        </span>
                        <br>
                    <?php endif; ?>
                    <span class="qa-shop-id"
                          data-qa-shop-id="<?php echo escapeValue($kassa->getShopId()) ?>">
                        <?php echo _JSHOP_YOO_KASSA_SHOP_ID_LABEL . ': ' .escapeValue($kassa->getShopId()); ?>
                    </span>
                    <?php if ($kassa->isTest()) : ?>
                        <br>
                        <span>
                            <strong><?php echo _JSHOP_YOO_KASSA_TEST_SHOP_HELP_HEAD ?></strong><br>
                            <?php echo _JSHOP_YOO_KASSA_TEST_SHOP_HELP_TEXT ?>
                        </span>
                    <?php endif; ?>
                    <div>
                        <button class="btn btn-warning btn-oauth-connect offset-top-10 qa-change-shop-button <?php echo $isDisabledClass ?>">
                            <?php echo _JSHOP_YOO_OAUTH_BTN_CHANGE ?>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <?php if (!$kassa->isAuthorization()) : ?>
        <div class="span2 offset1">
            <button class="btn btn-warning btn-oauth-connect qa-connect-shop-button" <?php echo $isDisabledClass ?>><?php echo _JSHOP_YOO_OAUTH_BTN_CONNECT; ?></button>
        </div>
    <?php endif; ?>

    <div class="span11 offset1 d-none offset-top-10 connect-error">
        <div class="form-group alert alert-danger" role="alert">
            <?php echo _JSHOP_YOO_OAUTH_CONNECT_ERROR; ?>
        </div>
    </div>
</div>
