<?php
/**
 * Shared profile fields for onboarding and Settings.
 *
 * @var array<string, string> $values
 * @var array<string, string> $errors
 * @var string $email
 */
$values = $values ?? [];
$errors = $errors ?? [];
$email  = $email ?? '';
$tieasy = config('Tieasy');

$val = static function (string $key) use ($values): string {
    return (string) ($values[$key] ?? '');
};

$invalid = static function (string $key) use ($errors): string {
    return isset($errors[$key]) ? ' is-invalid' : '';
};
?>

<label class="field-label" for="profile_name">Profile Name</label>
<input class="field-input<?= $invalid('profile_name') ?>" type="text" id="profile_name" name="profile_name" placeholder="John Doe" maxlength="100" autocomplete="name" value="<?= esc($val('profile_name')) ?>">
<?php if (isset($errors['profile_name'])): ?>
    <p class="field-error" role="alert"><?= esc($errors['profile_name']) ?></p>
<?php endif; ?>

<div class="field-row">
    <div>
        <label class="field-label" for="age_group">Age Group</label>
        <select class="field-input<?= $invalid('age_group') ?>" id="age_group" name="age_group">
            <option value="">- Select -</option>
            <?php foreach ($tieasy->ageGroups as $group): ?>
                <option value="<?= esc($group) ?>" <?= $val('age_group') === $group ? 'selected' : '' ?>><?= esc($group) ?></option>
            <?php endforeach; ?>
        </select>
        <?php if (isset($errors['age_group'])): ?>
            <p class="field-error" role="alert"><?= esc($errors['age_group']) ?></p>
        <?php endif; ?>
    </div>
    <div>
        <label class="field-label" for="gender">Gender</label>
        <select class="field-input<?= $invalid('gender') ?>" id="gender" name="gender">
            <option value="">- Select -</option>
            <?php foreach ($tieasy->genders as $gender): ?>
                <option value="<?= esc($gender) ?>" <?= $val('gender') === $gender ? 'selected' : '' ?>><?= esc($gender) ?></option>
            <?php endforeach; ?>
        </select>
        <?php if (isset($errors['gender'])): ?>
            <p class="field-error" role="alert"><?= esc($errors['gender']) ?></p>
        <?php endif; ?>
    </div>
</div>

<label class="field-label" for="occupation">Occupation</label>
<input class="field-input<?= $invalid('occupation') ?>" type="text" id="occupation" name="occupation" placeholder="Ex. Software Engineer" maxlength="100" autocomplete="organization-title" value="<?= esc($val('occupation')) ?>">
<?php if (isset($errors['occupation'])): ?>
    <p class="field-error" role="alert"><?= esc($errors['occupation']) ?></p>
<?php endif; ?>

<label class="field-label" for="phone">Phone</label>
<input class="field-input<?= $invalid('phone') ?>" type="tel" id="phone" name="phone" placeholder="+91 (555) 555 - 5555" maxlength="20" autocomplete="tel" value="<?= esc($val('phone')) ?>">
<?php if (isset($errors['phone'])): ?>
    <p class="field-error" role="alert"><?= esc($errors['phone']) ?></p>
<?php endif; ?>

<label class="field-label" for="profile_email">Email</label>
<input class="field-input" type="email" id="profile_email" value="<?= esc($email) ?>" readonly tabindex="-1" autocomplete="off">
