<?php
if ( $extra_attributes ) {
	if ( ! $prefix ) {
		$prefix = 'extra_attributes';
	}
	if ( ! strlen( $idx ) ) {
		$idx = substr( sha1( uniqid( time() . wp_rand(), true ) ), 0, 8 );;
	}

	if ( $setup == 'request') {
		$alert_class = '';
	} else {
		$alert_class = 'col-xs-10 col-xs-offset-1';
	}

	if ( in_array( $tld, [ 'hk', 'com.hk', 'net.hk', 'org.hk', 'idv.hk' ] ) ) { ?>
		<div class="<?php echo esc_attr("alert alert-info {$alert_class}")?>">
			<?php echo wp_kses( icd_hosting_tr( 'hk_documents_notice' ), 'post' ); ?>
		</div>
	<?php }

	if ( in_array( $tld, [ 'uk', 'co.uk', 'org.uk' ] ) and $action == 'transfer' ) { ?>
		<div class="alert alert-info {$alert_class}">
			<?php echo esc_html( icd_hosting_tr( 'uk_transfer_notice' ) ); ?>
		</div>
	<?php }

	?>
	<div class="extra-attributes-domain" id="extra-attributes-domain-<?php echo esc_attr($idx) ?>">
		<?php foreach ( $extra_attributes as $key => $item ) {
			if ( $item['type'] == 'hidden' ) { ?>
				<input type="hidden" name="<?php echo esc_attr($prefix) ?>[<?php echo esc_attr($key) ?>]"
					   value="<?php echo esc_attr( $item['value'] ) ?>" <?php if ( $item['required'] ) { ?> data-ext-required="<?php echo esc_attr( $item['required'] ) ?>"<?php } ?>>
				<?php continue;
			}
			$label = icd_hosting_tr_empty( "extra_attributes." . $key . "_label",  $item['label'] ); ?>
			<div class="form-group">
				<label class="col-md-3 text-right control-label" for="<?php echo esc_attr($key . '-' . $idx) ?>">
					<?php echo wp_kses( $label, 'post' ) ?>:
					<?php if ( $item['required'] == 1 or $item['required'] == 2 ) { ?>
						<span class="mandatory">*</span>
					<?php } ?>
					<?php if ( icd_hosting_tr_has( "extra_attributes." . $key . "_help_title" ) and icd_hosting_tr_has( "extra_attributes." . $key . "_help_info" ) ) { ?>
						<a href="#" data-toggle="modal" data-target="#<?php echo esc_attr($key .'-modal-' . $idx) ?>"
						   class="label label-primary">?</a>
					<?php } ?>

					<!--{* Help messages *}-->
					<?php if ( icd_hosting_tr_has( "extra_attributes.help_msg." . $key ) ) {
						foreach ( icd_hosting_tr( "extra_attributes.help_msg." . $key ) as $k => $v ) { ?>
							<div class="ea-help-msg-<?php echo esc_attr($key . '-' . $k) ?> small text-muted pl-5 ea-help-msg"><?php echo wp_kses( $v, 'post') ?></div>
						<?php }
					} ?>
				</label>

				<div class="col-md-6">
					<?php if ( $item['type'] == 'select' ) { ?>
						<span class="selectwrap">
						<select id="<?php echo esc_attr($key . '-' . $idx) ?>" name="<?php echo esc_attr($prefix) ?>[<?php echo esc_attr($key) ?>]"
								class="form-control extra-attributes-select extra-attributes-<?php echo esc_attr($key) ?>"
								data-placeholder="<?php echo esc_attr($label) ?>"
								data-placeholder="<?php
								if ( ! empty( $item['placeholder'] ) ) {
									if ( icd_hosting_tr_has( "domains.extra_attributes.{$key}_placeholder"  ) ) {
										echo esc_attr(icd_hosting_tr( "domains.extra_attributes.{$key}_placeholder" ));
									} else {
										echo esc_attr( $item['placeholder'] );
									}
								} else {
									echo esc_attr( $label );
								} ?>"
								data-theme="bootstrap"<?php if ( $item['required'] ) { ?> data-ext-required="<?php echo esc_attr($item['required']) ?>" <?php } ?>
								data-field="domain_extra_attributes_<?php echo esc_attr($key . '_' . $idx) ?>">
							<option value=""></option>

							<?php if ( isset( $item['select_type'] ) and $item['select_type'] == 'country' ) { ?>
								<option value="">-- <?php echo esc_html( icd_hosting_tr( 'contacts.country' ) ) ?> --</option>
								<?php foreach ( $countries as $iso => $country ) { ?>
									<option
											value="<?php echo esc_attr($iso) ?>"<?php if ( isset( $data[ $key ] ) and $iso == $data[ $key ] ) { ?> selected="selected"<?php } ?>>
								<?php echo esc_html( $country['country'] ) ?>
								</option>
								<?php } ?>
							<?php } else {
								foreach ( $item['options'] as $k => $v ) { ?>
									<option value="<?php echo esc_attr( $k ) ?>"
										<?php if ( isset( $data[ $key ] ) && $data[ $key ] == $k ) { ?> selected <?php } ?>
										<?php if ( ! empty( $v['help_msg'] ) ) { ?> data-ext-help-msg="<?php echo esc_attr( $v['help_msg'] ) ?>"<?php } ?>
										<?php if ( ! empty( $v['requires'] ) ) { ?> data-ext-requires="<?php if ( is_array( $v['requires'] ) ) {
											echo esc_attr( implode( ',', $v['requires'] ) );
										} else {
											echo esc_attr( $v['requires'] );
										} ?>"<?php } ?>
										<?php if ( ! empty( $v['hide'] ) ) { ?> data-ext-hide="<?php echo esc_attr( $v['hide'] ) ?>"<?php } ?>>
												<?php echo esc_html( icd_hosting_tr_empty( "extra_attributes.$key.$k", $v['label'] ) ) ?></option>
								<?php } ?>
							<?php } ?>
						</select>
					</span>

						<!-- Static help messages -->
						<?php if ( icd_hosting_tr_has( "extra_attributes.static_help_msg." . $key ) ) { ?>
						<div class="ea-static-help-msg-<?php echo esc_attr($key) ?> ea-static-help-msg small text-muted pt-5 pb-5"><?php echo wp_kses( icd_hosting_tr("extra_attributes.static_help_msg." . $key), 'post' ); ?></div>
						<?php } ?>

						<label for="<?php echo esc_attr($key) ?>-<?php echo esc_attr($idx) ?>"
							   id="<?php echo esc_attr($key) ?>-error-<?php echo esc_attr($idx) ?>"
							   class="error display-none <?php echo esc_attr($key) ?>-error"></label>
					<?php } elseif ( $item['type'] == 'checkbox' ) { ?>
						<div class="checkbox">
							<?php foreach ( $item['options'] as $k => $v ) { ?>
								<label>
									<input id="<?php echo esc_attr($key . '-' . $idx) ?>" type="checkbox"
										   name="<?php echo esc_attr($prefix) ?>[<?php echo esc_attr($key) ?>]"
										   value="<?php echo esc_attr($k) ?>" class="extra-attributes-<?php echo esc_attr($key) ?>"
										<?php if ( isset( $data[ $key ] ) && $data[ $key ] == $k ) { ?> checked <?php } ?>
										<?php if ( $item['required'] ) { ?> data-ext-required="<?php echo esc_attr( $item['required'] ) ?>"<?php } ?>
										<?php if ( ! empty( $v['requires'] ) ) { ?> data-ext-requires="<?php if ( is_array( $v['requires'] ) ) {
											echo esc_attr( implode( ',', $v['requires'] ) );
										} else {
											echo esc_attr( $v['requires'] );
										} ?>"<?php } ?>
										   data-field="domain_extra_attributes_<?php echo esc_attr($key . '_' . $idx) ?>">

									<?php echo wp_kses( icd_hosting_tr_empty( "extra_attributes.$key.$k", $v['label'] ), 'post') ?>
								</label>
							<?php } ?>
						</div>

						<!-- Static help messages -->
						<?php if ( icd_hosting_tr_has( "extra_attributes.static_help_msg." . $key ) ) { ?>
							<div class="ea-static-help-msg-<?php echo esc_attr($key) ?> ea-static-help-msg small text-muted pt-5 pb-5"><?php echo esc_html( icd_hosting_tr( "extra_attributes.static_help_msg." . $key )); ?></div>
						<?php } ?>

						<br><label for="<?php echo esc_attr($key. '-' . $idx) ?>"
								   id="<?php echo esc_attr($key . '-error-' . $idx) ?>"
								   class="error display-none <?php echo esc_attr($key) ?>-error"></label>
					<?php } elseif ( $item['type'] == 'text' ) { ?>
						<input id="<?php echo esc_attr($key . '_' . $idx) ?>" type="text"
							   name="<?php echo esc_attr($prefix) ?>[<?php echo esc_attr($key) ?>]"
							   value="<?php echo isset($data[ $key ]) ? esc_attr( $data[ $key ] ) : '' ?>"
							   maxlength="255" placeholder="<?php
								if ( ! empty( $item['placeholder'] ) ) {
									if ( icd_hosting_tr_has( "domains.extra_attributes." . $key . "_placeholder" ) ) {
										echo esc_attr( icd_hosting_tr( "domains.extra_attributes." . $key . "_placeholder" ) );
									} else {
										echo esc_attr( $item['placeholder'] );
									}
								} else {
									echo esc_attr($label);
								}?>"
							   class="form-control extra-attributes-<?php echo esc_attr($key) ?>"
							<?php if ( ! empty( $item['required'] ) ) { ?> data-ext-required="<?php echo esc_attr( $item['required'] ) ?>"<?php } ?>
							<?php if ( ! empty( $item['requires'] ) ) { ?> data-ext-requires="<?php if ( is_array( $v['requires'] ) ) {
								echo esc_attr( implode( ',', $v['requires'] ) );
							} else {
								echo esc_attr( $v['requires'] );
							} ?>"<?php } ?>
							   data-field="domain_extra_attributes_<?php echo esc_attr($key . '_' . $idx) ?>">

						<!-- Static help messages -->
						<?php if ( icd_hosting_tr_has( "extra_attributes.static_help_msg." . $key ) ) { ?>
							<div class="ea-static-help-msg-<?php echo esc_attr($key) ?> ea-static-help-msg small text-muted pt-5 pb-5"><?php echo esc_html( icd_hosting_tr( "extra_attributes.static_help_msg." . $key ) ); ?></div>
						<?php } ?>

						<label for="<?php echo esc_attr($key . '-' . $idx)  ?>" id="<?php echo esc_attr($key .'-error-' . $idx) ?>"
							   class="error display-none <?php echo esc_attr($key) ?>-error"></label>
					<?php } ?>
				</div>
			</div>

			<?php if ( icd_hosting_tr_has( "extra_attributes.{$key}_help_title" ) and icd_hosting_tr_has( "extra_attributes.{$key}_help_info" ) ) { ?>
				<div class="modal" id="<?php echo esc_attr($key .'-modal-'. $idx) ?>" tabindex="-1" role="dialog" data-backdrop="false">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header popover-title">
								<h4 class="modal-title"
									id="<?php echo esc_attr($key .'-info-label-'. $idx) ?>"><?php echo esc_html ( icd_hosting_tr( "extra_attributes." . $key . "_help_title" ) ) ?></h4>
							</div>

							<div class="modal-body">
								<?php echo wp_kses( icd_hosting_tr( "extra_attributes." . $key . "_help_info" ), 'post' ) ?>
							</div>

							<div class="modal-footer">
								<button type="button" class="btn btn-info" data-dismiss="modal"><i
											class="glyphicon glyphicon-remove"></i> <?php echo esc_html ( icd_hosting_tr( 'btns.close' ) ) ?>
								</button>
							</div>
						</div>
					</div>
				</div>
			<?php } ?>
		<?php } ?>
	</div>
<?php } ?>






