<?php
$form_action = base_url() . 'admin/user/reset_password/' . (!empty($user_info->user_id) ? $user_info->user_id : '');
$target_name = !empty($user_info->user_id) ? fullname($user_info->user_id) : lang('user');
$render_password_field = function ($name, $label, $id, $placeholder, $attrs = array()) {
	$attrs = array_merge(array(
		'id' => $id,
		'name' => $name,
		'type' => 'password',
		'required' => 'required',
		'placeholder' => $placeholder,
		'autocomplete' => 'new-password',
		'class' => 'w-full rounded-lg border border-border bg-input py-2 pl-3 pr-11 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-secondary/30 dark:focus:border-secondary dark:focus:ring-3 dark:focus:ring-secondary/30',
	), $attrs);

	return '<label class="space-y-1 text-sm font-medium text-foreground block">'
		. '<span>' . $label . ' <span class="text-red-500">*</span></span>'
		. '<span class="relative block">'
		. '<input ' . build_html_attributes($attrs) . '>'
		. '<button type="button" class="absolute inset-y-0 right-0 inline-flex w-10 items-center justify-center rounded-r-lg text-muted-foreground transition hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-secondary/30" data-password-toggle="' . html_escape($id) . '" aria-label="Show password" title="Show password">'
		. '<i data-lucide="eye" class="h-4 w-4"></i>'
		. '</button>'
		. '</span>'
		. '</label>';
};
?>

<?= form_open($form_action, array(
	'id' => 'form',
	'class' => 'space-y-4',
	'enctype' => 'multipart/form-data',
	'data-parsley-validate' => '',
	'novalidate' => ''
)); ?>
<div class="space-y-4">
	<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
		<div class="space-y-1">
			<h3 class="text-sm font-semibold text-foreground"><?= lang('reset_password') ?></h3>
			<p class="text-xs text-muted-foreground"><?= lang('update') . ' ' . lang('password') . ' ' . lang('for') . ' ' . html_escape($target_name) ?></p>
		</div>
	</div>

	<div class="space-y-4">
		<?= $render_password_field(
			'my_password',
			lang('current') . ' ' . lang('password'),
			'change_email_password',
			lang('enter') . ' ' . lang('your') . ' ' . lang('current') . ' ' . lang('password'),
			array('autocomplete' => 'current-password')
		); ?>

		<?= $render_password_field(
			'password',
			lang('new') . ' ' . lang('password'),
			'new_password',
			lang('enter') . ' ' . lang('new') . ' ' . lang('password') . ' ' . lang('for') . ' ' . $target_name
		); ?>

		<?= $render_password_field(
			'confirm_password',
			lang('confirm_password'),
			'confirm_password',
			lang('enter') . ' ' . lang('confirm_password') . ' ' . lang('for') . ' ' . $target_name,
			array('data-parsley-equalto' => '#new_password')
		); ?>
	</div>

	<div class="flex items-center justify-end border-t border-border pt-4">
		<?= btn_modal_close(); ?>
		<?= btn_update(); ?>
	</div>
</div>
<?= form_close(); ?>
