<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// phpcs:disable Generic.Files.LineLength.TooLong
use Magento\Customer\Block\Form\Login;

/** @var Login $block */
if (!$block->getButtonLockManager() && class_exists(\Magento\Framework\View\Element\ButtonLockManager::class)) {
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $block->setButtonLockManager(
        $objectManager->get(\Magento\Framework\View\Element\ButtonLockManager::class)
    );
}
/** @var $escaper \Magento\Framework\Escaper */

$is_disabled = false;
if(method_exists($block, 'getButtonLockManager')){
    $is_disabled = $block->getButtonLockManager()->isDisabled('customer_login_form_submit');
} elseif($loginButtonViewModel = $block->getData('login_button_view_model')){
    $is_disabled = $loginButtonViewModel->disabled();
}

?>
<div class="block block-customer-login">
    <div class="block-title">
        <strong id="block-customer-login-heading" role="heading" aria-level="2"><?= $escaper->escapeHtml(__('Registered Customers')) ?></strong>
    </div>
    <div class="block-content" aria-labelledby="block-customer-login-heading">
        <form class="form form-login"
              action="<?= $escaper->escapeUrl($block->getPostActionUrl()) ?>"
              method="post"
              id="ox-loginmodal-login-form"
              data-mage-init='{"validation":{}}'>
            <?= $block->getBlockHtml('formkey') ?>
            <fieldset class="fieldset login" data-hasrequired="<?= $escaper->escapeHtml(__('* Required Fields')) ?>">
                <div class="field note"><?= $escaper->escapeHtml(__('If you have an account, sign in with your email address.')) ?></div>
                <div class="field email required">
                    <label class="label" for="ox-loginmodal-email"><span><?= $escaper->escapeHtml(__('Email')) ?></span></label>
                    <div class="control">
                        <input name="login[username]" value="<?= $escaper->escapeHtmlAttr($block->getUsername()) ?>"
                            <?php if ($block->isAutocompleteDisabled()): ?> autocomplete="off"<?php endif; ?>
                               id="ox-loginmodal-email" type="email" class="input-text"
                               title="<?= $escaper->escapeHtmlAttr(__('Email')) ?>"
                               data-mage-init='{"mage/trim-input":{}}'
                               data-validate="{required:true, 'validate-email':true}">
                    </div>
                </div>
                <div class="field password required">
                    <label for="ox-loginmodal-password" class="label"><span><?= $escaper->escapeHtml(__('Password')) ?></span></label>
                    <div class="control">
                        <input name="login[password]" type="password"
                            <?php if ($block->isAutocompleteDisabled()): ?> autocomplete="off"<?php endif; ?>
                               class="input-text" id="ox-loginmodal-password"
                               title="<?= $escaper->escapeHtmlAttr(__('Password')) ?>"
                               data-validate="{required:true}">
                    </div>
                </div>
				<input type="hidden" name="login_redirect" value="referer"/>
                <?= $block->getChildHtml('form_additional_info_drop') ?>
                <div class="actions-toolbar">
                    <div class="primary">
                        <button type="submit" class="action login primary" name="send" id="send2" <?php if ($is_disabled): ?> disabled="disabled" <?php endif; ?>>
                            <span><?= $escaper->escapeHtml(__('Sign In')) ?></span>
                        </button>
                    </div>
                    <div class="secondary"><a class="action remind" href="<?= $escaper->escapeUrl($block->getForgotPasswordUrl()) ?>"><span><?= $escaper->escapeHtml(__('Forgot Your Password?')) ?></span></a></div>
                </div>
            </fieldset>
        </form>
    </div>
    <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Customer/js/block-submit-on-send": {
                    "formId": "ox-loginmodal-login-form"
                }
            }
        }
    </script>
</div>
