<?php
namespace JetApplicationModule\Admin\ManageAccess\RESTClients\Users;

use JetApplication\Auth_RESTClient_User as User;

use Jet\UI;
use Jet\MVC_View;
use Jet\Form;
use Jet\Form_Renderer;
use Jet\Tr;

/**
 * @var MVC_View $this
 * @var Form $form
 * @var User $user
 */
$form = $this->getRaw( 'form' );

$form->setAutocomplete( false );
$form->renderer()->setDefaultLabelWidth( [Form_Renderer::LJ_SIZE_MEDIUM => 1] );
$form->renderer()->setDefaultFieldWidth( [Form_Renderer::LJ_SIZE_MEDIUM => 4] );

$user = $this->getRaw( 'user' );
$router = $this->getController()->getControllerRouter();
?>


<?= $form->start() ?>

<div class="row toolbar" id="main-toolbar">
	<div class="col-md-12">
		<?= UI::button_goBack()->setUrl($this->getString( 'list_url' )) ?>

		<?php if( !$form->getIsReadonly() ): ?>
			<?= UI::button_save() ?>

			<?php if( !$user->getIsNew() ): ?>
				<div class="btn-group" style="margin-left: 10px">
					<a href="<?= $router->action( 'reset_password' )->URI( $user->getId() ) ?>" class="btn btn-warning">
						<?= UI::icon( 'refresh' ) ?>
						<?= Tr::_( 'Reset password' ) ?>
					</a>
				</div>
			<?php endif; ?>
		<?php endif; ?>
	</div>
</div>

<div class="row">
	<div class="col-md-12" id="main-col">

		<?= $form->field( 'username' ) ?>

		<?= $form->fieldExists( 'password' ) ? $form->field( 'password' ) : '' ?>
		<?= $form->field( 'email' ) ?>
		<?= $form->field( 'locale' ) ?>
		<?= $form->field( 'description' ) ?>
		<?= $form->field( 'roles' ) ?>

		<hr class="separator">
		<?= $form->field( 'user_is_blocked' ) ?>
		<?= $form->field( 'user_is_blocked_till' ) ?>
		<hr class="separator">
	</div>
</div>

<?= $form->end() ?>
