@version(2)
@load('css/contact.css')

<div class="ctc">
	@if(!$form)
	<p class="ctc-empty">{{ $lang->no_form_notice }}</p>
	@else

	@if(count($form_list) > 1)
	<ul class="ctc-tabs">
		@foreach($form_list as $ctc_form)
		<li @if((int)$ctc_form->form_srl === (int)$form->form_srl) class="is-active" @endif>
			<a href="{{ getUrl('', 'mid', $module_info->mid, 'act', 'dispContactForm', 'form_srl', $ctc_form->form_srl) }}">{{ $ctc_form->title }}</a>
		</li>
		@endforeach
	</ul>
	@endif

	<div class="ctc-head">
		<h2 class="ctc-title">{{ $form->title }}</h2>
		@if($form->description)
		<p class="ctc-desc">{!! nl2br(htmlspecialchars($form->description, ENT_QUOTES, 'UTF-8')) !!}</p>
		@endif
	</div>

	@if(!count($fields))
	<p class="ctc-empty">{{ $lang->msg_form_has_no_field }}</p>
	@else
	<form class="ctc-form" action="{{ getUrl() }}" method="post" enctype="multipart/form-data">
		<input type="hidden" name="module" value="contact" />
		<input type="hidden" name="act" value="procContactInsert" />
		<input type="hidden" name="mid" value="{{ $module_info->mid }}" />
		<input type="hidden" name="form_srl" value="{{ $form->form_srl }}" />
		<input type="hidden" name="form_open_time" value="{{ $form_open_time }}" />

		<div class="ctc-hp" aria-hidden="true">
			<label>Leave this field empty<input type="text" name="contact_hp" value="" tabindex="-1" autocomplete="off" /></label>
		</div>

		@foreach($fields as $field)
		<div class="ctc-row ctc-row-{{ $field->field_type }}">
			@if($field->field_type !== 'agreement')
			<label class="ctc-label" for="ctc_{{ $field->field_name }}">
				{{ $field->label }}
				@if($field->is_required === 'Y')<em class="ctc-req">{{ $lang->required_mark }}</em>@endif
			</label>
			@else
			<span class="ctc-label">{{ $field->label }}@if($field->is_required === 'Y')<em class="ctc-req">{{ $lang->required_mark }}</em>@endif</span>
			@endif

			<div class="ctc-input">
				@if($field->field_type === 'textarea')
				<textarea id="ctc_{{ $field->field_name }}" name="contact_field[{{ $field->field_name }}]" rows="8" placeholder="{{ $field->placeholder }}" @if($field->is_required === 'Y') required @endif></textarea>

				@elseif($field->field_type === 'select')
				<select id="ctc_{{ $field->field_name }}" name="contact_field[{{ $field->field_name }}]" @if($field->is_required === 'Y') required @endif>
					<option value="">-</option>
					@foreach(array_filter(array_map('trim', explode("\n", $field->options))) as $ctc_option)
					<option value="{{ $ctc_option }}">{{ $ctc_option }}</option>
					@endforeach
				</select>

				@elseif($field->field_type === 'radio')
				@foreach(array_filter(array_map('trim', explode("\n", $field->options))) as $ctc_option)
				<label class="ctc-choice"><input type="radio" name="contact_field[{{ $field->field_name }}]" value="{{ $ctc_option }}" @if($field->is_required === 'Y') required @endif /> {{ $ctc_option }}</label>
				@endforeach

				@elseif($field->field_type === 'checkbox')
				@foreach(array_filter(array_map('trim', explode("\n", $field->options))) as $ctc_option)
				<label class="ctc-choice"><input type="checkbox" name="contact_field[{{ $field->field_name }}][]" value="{{ $ctc_option }}" /> {{ $ctc_option }}</label>
				@endforeach

				@elseif($field->field_type === 'file')
				@if($use_file)
				<input type="file" id="ctc_{{ $field->field_name }}" name="contact_file_{{ $field->field_name }}[]" multiple @if($field->is_required === 'Y') required @endif />
				<small class="ctc-help">{{ implode(', ', $allowed_extensions) }}</small>
				@endif

				@elseif($field->field_type === 'agreement')
				<div class="ctc-agreement">{!! nl2br(htmlspecialchars($field->options, ENT_QUOTES, 'UTF-8')) !!}</div>
				<label class="ctc-choice">
					<input type="checkbox" name="contact_field[{{ $field->field_name }}]" value="Y" @if($field->is_required === 'Y') required @endif />
					{{ $lang->agreement_agree }}
				</label>

				@else
				<input type="{{ $field->field_type === 'email' ? 'email' : ($field->field_type === 'tel' ? 'tel' : ($field->field_type === 'number' ? 'number' : ($field->field_type === 'date' ? 'date' : 'text'))) }}" id="ctc_{{ $field->field_name }}" name="contact_field[{{ $field->field_name }}]" value="" placeholder="{{ $field->placeholder }}" @if($field->is_required === 'Y') required @endif />
				@endif

				@if($field->help)
				<small class="ctc-help">{{ $field->help }}</small>
				@endif
			</div>
		</div>
		@endforeach

		@if($use_lookup && !$is_logged)
		<div class="ctc-row">
			<label class="ctc-label" for="ctc_lookup_password">
				{{ $lang->lookup_password }}<em class="ctc-req">{{ $lang->required_mark }}</em>
			</label>
			<div class="ctc-input">
				<input type="password" id="ctc_lookup_password" name="lookup_password" required autocomplete="off" />
				<small class="ctc-help">{{ $lang->lookup_password_help }}</small>
			</div>
		</div>
		@endif

		<div class="ctc-actions">
			<button type="submit" class="ctc-submit">{{ $lang->submit }}</button>
			@if($use_lookup)
			<a class="ctc-link" href="{{ getUrl('', 'mid', $module_info->mid, 'act', 'dispContactMyList') }}">{{ $lang->lookup }}</a>
			@endif
		</div>
	</form>
	@endif
	@endif
</div>
