{% extends "/layouts/main.twig" %}
{% set active_menu = '/admin/settings' %}

{% set xdata = 'settings' %}
{% block title p__('title', 'Intercom')|title %}

{% block template %}
	<div>
		{% include "snippets/back.twig" with {link: 'admin/settings/script-tags', label: 'Script tags'} %}

		<h1 class="mt-4">
			{{ p__('heading', 'Intercom') }}
		</h1>
	</div>

	<x-form>
		<form class="flex flex-col gap-8" @submit.prevent="submit" x-ref="form">
			<section class="grid grid-cols-1 gap-6 box" data-density="comfortable">

				<h2>{{ p__('heading', 'Config') }}</h2>

				<div class="flex items-center justify-between p-3 rounded-lg bg-intermediate">
					{{ p__('label', 'Status') }}

					<label class="inline-flex items-center gap-2 cursor-pointer">
						<input type="checkbox" name="script_tags[intercom][is_enabled]" class="hidden peer" {{ option.script_tags.intercom.is_enabled is defined and option.script_tags.intercom.is_enabled ? 'checked' : '' }}>

						<span class="h-6 w-10 rounded-3xl bg-line relative block peer-checked:bg-success transition-all after:h-5 after:w-5 after:top-0.5 after:absolute after:left-0 after:ms-0.5 after:transition-all after:rounded-full after:bg-white peer-checked:after:left-4"></span>

						<span class="text-content-dimmed peer-checked:hidden">
							{{ __("Disabled") }}
						</span>

						<span class="hidden text-success peer-checked:inline">
							{{ __("Enabled") }}
						</span>
					</label>
				</div>

				<div class="flex items-center justify-between p-3 rounded-lg bg-intermediate">
					{{ p__('label', 'Identity verification') }}

					<label class="inline-flex items-center gap-2 cursor-pointer">
						<input type="checkbox" name="script_tags[intercom][verification_is_enabled]" class="hidden peer" {{ option.script_tags.intercom.verification_is_enabled is defined and option.script_tags.intercom.verification_is_enabled ? 'checked' : '' }}>

						<span class="h-6 w-10 rounded-3xl bg-line relative block peer-checked:bg-success transition-all after:h-5 after:w-5 after:top-0.5 after:absolute after:left-0 after:ms-0.5 after:transition-all after:rounded-full after:bg-white peer-checked:after:left-4"></span>

						<span class="text-content-dimmed peer-checked:hidden">
							{{ __("Disabled") }}
						</span>

						<span class="hidden text-success peer-checked:inline">
							{{ __("Enabled") }}
						</span>
					</label>
				</div>

				<div>
					<label for="script_tags[intercom][app_id]">
						{{ p__('label', 'Workspace/App ID') }}
					</label>

					<input type="text" id="script_tags[intercom][app_id]" name="script_tags[intercom][app_id]" class="mt-2 input" autocomplete="off" required placeholder="{{ option.script_tags.intercom.app_id ?? '' }}" value="{{ option.script_tags.intercom.app_id ?? '' }}"/>

					<ul class="info mt-2">
						<li>
							{{ __("Don't know where to find the Workspace/App ID?") }}

							<a href="https://www.intercom.com/help/en/articles/8771110-getting-started-faqs#h_c12f89cf9d" target="_blank" class="text-content ">

								{{ p__('button', 'Click here') }}

								<i class="text-xs ti ti-external-link"></i>
							</a>
						</li>
					</ul>
				</div>

				<div>
					<label for="script_tags[intercom][secret_key]">
						{{ p__('label', 'Secret key') }}
					</label>

					<input type="password" id="script_tags[intercom][secret_key]" name="script_tags[intercom][secret_key]" class="mt-2 input" autocomplete="off" required value="{{ environment == 'demo' ? 'hidden-in-demo' : option.script_tags.intercom.secret_key ?? '' }}"/>

					<ul class="info mt-2">
						<li>
							{{ __('Secret key is required to enable Identity Verification') }}

							<a href="https://www.intercom.com/help/en/articles/7946878-what-is-identity-verification" target="_blank" class="text-content ">

								{{ p__('button', 'Learn more') }}

								<i class="text-xs ti ti-external-link"></i>
							</a>
						</li>
					</ul>
				</div>
			</section>

			<div class="flex justify-end gap-4">
				<a href="admin/settings/script-tags" class="button button-outline">
					{{ p__('button', 'Cancel') }}
				</a>

				<button type="submit" class="button button-accent" :processing="isProcessing">
					{% include "/snippets/spinner.twig" %}

					{{ p__('button', 'Save changes') }}
				</button>
			</div>
		</form>
	</x-form>
{% endblock %}
