<h1 class="title"><?= __('Register') ?></h1>

<ul class="breadcrumber">
    <li><a href="<?= url_to('/') ?>" data-ajax><?= __('Home') ?></a></li>
    <li class="active"><?= __('Register') ?></li>
</ul>

<div class="box-panel">
    <div class="box-panel-title"><?= __('Register') ?></div>
    <form data-ajax action="<?= url_to('/register') ?>" method="POST" class="form form-action">
        <?= csrf_field() ?>

        <div class="box-panel-content">
            <div class="row">
                <div class="label">
                    <label for="name"><?= __('Name') ?> <span class="required">*</span></label>
                </div>
                <div class="field">
                    <input type="text" name="name" value="<?= isset($data['firstName']) ? $data['firstName'] . ' ' . $data['lastName'] : '' ?>" id="name" style="width:250px" />
                </div>
            </div>

            <div class="row">
                <div class="label">
                    <label for="username"><?= __('Username') ?> <span class="required">*</span></label>
                </div>
                <div class="field">
                    <input type="text" name="username" maxlength="10" style="width:150px" id="username" />
                </div>
            </div>

            <div class="row">
                <div class="label">
                    <label for="password"><?= __('Password') ?> <span class="required">*</span></label>
                </div>
                <div class="field">
                    <input type="password" name="password" maxlength="10" style="width:150px" id="password" />
                </div>
            </div>

            <div class="row">
                <div class="label">
                    <label for="repassword"><?= __('Repeat password') ?> <span class="required">*</span></label>
                </div>
                <div class="field">
                    <input type="password" name="repassword" maxlength="10" style="width:150px" id="repassword" />
                </div>
            </div>

            <div class="row">
                <div class="label">
                    <label for="email"><?= __('E-mail') ?> <span class="required">*</span></label>
                </div>
                <div class="field">
                    <input type="text" name="email" value="<?= isset($data['email']) ? $data['email'] : '' ?>" id="email" style="width:250px" />
                </div>
            </div>

            <div class="row">
                <div class="label">
                    <label for="reemail"><?= __('Repeat e-mail') ?> <span class="required">*</span></label>
                </div>
                <div class="field">
                    <input type="text" name="reemail" value="<?= isset($data['email']) ? $data['email'] : '' ?>" id="reemail" style="width:250px" />
                </div>
            </div>

            <div class="row">
                <div class="label">
                    <label for="pid"><?= __('Personal ID') ?> <span class="required">*</span></label>
                </div>
                <div class="field">
                    <input type="text" name="pid" id="pid" maxlength="7" style="width:100px" />
                </div>
            </div>

            <?php if (config('register.secret_questions', [])): ?>
                <div class="row">
                    <div class="label">
                        <label for="secret_question"><?= __('Secret question') ?> <span class="required">*</span></label>
                    </div>
                    <div class="field">

                        <select name="secret_question" id="secret_question">
                            <option value=""></option>
                            <?php foreach (config('register.secret_questions', []) as $question): ?>
                                <option value="<?= $question ?>"><?= $question ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>
                </div>

                <div class="row">
                    <div class="label">
                        <label for="secret_answer"><?= __('Secret answer') ?> <span class="required">*</span></label>
                    </div>
                    <div class="field">
                        <input type="text" name="secret_answer" id="secret_answer" style="width:300px" />
                    </div>
                </div>
            <?php endif ?>

            <?php if (config('register.countries_flag_column', null)): ?>
                <div class="row">
                    <div class="label">
                        <label for="country"><?= __('Country') ?> <span class="required">*</span></label>
                    </div>
                    <div class="field">
                        <select name="country" id="country">
                            <option value=""></option>
                            <?php foreach (countries() as $id => $country): ?>
                                <option value="<?= $id ?>"><?= $country ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>
                </div>
            <?php endif ?>

            <?php foreach (config('register.custom_fields', []) as $field): ?>
                <div class="row<?= $field['type'] == 'checkbox' ? ' checkbox' : '' ?>">
                    <div class="label">
                        <label for="<?= $field['name'] ?>"><?= $field['label'] ?> <?= $field['required'] ? '<span class="required">*</span>' : '' ?></label>
                    </div>
                    <div class="field">
						<?php if ($field['type'] == 'text'): ?>
                        	<input type="text" name="<?= $field['name'] ?>" id="<?= $field['name'] ?>" style="width:300px" />
						<?php elseif ($field['type'] == 'select'): ?>
							<select name="<?= $field['name'] ?>">
								<option value=""></option>
								<?php foreach ($field['options'] as $id => $option): ?>
									<option value="<?= $id ?>"><?= $option ?></option>
								<?php endforeach ?>
							</select>
						<?php elseif ($field['type'] == 'checkbox'): ?>
							<input type="checkbox" name="<?= $field['name'] ?>" value="1"  />
						<?php elseif ($field['type'] == 'textarea'): ?>
							<textarea name="<?= $field['name'] ?>" id="<?= $field['name'] ?>" style="width:100%"></textarea>
						<?php endif ?>
                    </div>
                </div>
            <?php endforeach ?>

            <div class="row">
                <div class="label"></div>
                <div class="field">
                    <?= captcha() ?>
                </div>
            </div>

            <div class="row">
                <div class="label">
                    <label for="terms"><?= __('Terms of use') ?> <span class="required">*</span></label>
                </div>
                <div class="field checkbox">
                    <input type="checkbox" name="terms" id="terms" />
                    <a href="#" data-collapse="#terms-container"><?= __('I agree to the terms of use') ?></a>
                    <div id="terms-container" style="display:none"><?= config('register.terms') ?></div>
                </div>
            </div>
        </div>
        <div class="submit">
            <?php if (isset($provider)): ?>
                <input type="hidden" value="<?= $provider ?>" name="provider" />
                <input type="hidden" value="<?= $data['identifier'] ?>" name="<?= $provider ?>_id" />
            <?php endif ?>

            <input type="submit" value="<?= __('Register') ?>" class="btn" />
        </div>
    </form>
</div>
