<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

$make_info = SftcyWordformConnectMake::get_make_webhook_url();
$make_webhook_url = isset( $make_info['webhookPostUrl'] ) ? $make_info['webhookPostUrl'] : '';
?>
<!-- Start Make Configure Modal Form -->
<div id="MakeAPIModal" title="Make Connection Configure" class="" style="display: none;">
	<h5>How to configure Make connection</h5>
	<p>
		<a href="https://help.make.com/webhooks" target="_blank" rel="noopener">Make Webhooks Help</a> |
		<a href="https://help.make.com/custom-webhooks" target="_blank" rel="noopener">Make Custom Webhooks Guide</a>
	</p>
	<div id="make-webhook-create-help" class="accordion">
		<h3>Step 1 - Create a scenario in Make</h3>
		<div>
			<p>Log into Make, create a new scenario, and add a <strong>Webhooks</strong> module as the first step.</p>
		</div>

		<h3>Step 2 - Create a custom webhook</h3>
		<div>
			<p>Create a new <strong>Custom webhook</strong> in Make and copy the generated webhook URL.</p>
		</div>

		<h3>Step 3 - Save the webhook URL in WordForm</h3>
		<div>
			<p>Paste the copied Make webhook URL below and click <strong>Save / Update</strong>.</p>
		</div>

		<h3>Step 4 - Connect forms and test</h3>
		<div>
			<p>After saving, connect only the forms you want by using <strong>Select Form + Select Application + Create Connection</strong>, then submit a test form entry to let Make capture the payload.</p>
		</div>
	</div>

	<div class="make-connection-input-elements-wrapper" style="display: flex; flex-direction:column;">
		<div class="wordform-make-app-feedback-msg"></div>
		<div>
			<label for="MakeWebhookUrl" class="wordai-label-webhook">
				<span class="dashicons dashicons-rest-api" aria-hidden="true"></span>
				Make Webhook URL
				<a class="wordform-field-help-link" href="https://help.make.com/custom-webhooks" target="_blank" rel="noopener" aria-label="How to get your Make Custom Webhook URL">
					<span class="dashicons dashicons-editor-help" aria-hidden="true"></span>
				</a>
			</label><br/>
			<input type="text" id="MakeWebhookUrl" name="make-webhook-url" class="make-webhook-url" value="<?php echo esc_url( $make_webhook_url ); ?>" placeholder="https://hook.eu2.make.com/xxxxxxxxxxxxxxxxxxxx">
		</div>

		<div class="wordform-connect-inline-actions">
			<button
				type="button"
				class="button button-secondary wordform-connect-check-webhook-endpoint-button"
				data-check-action="wordform_connect_check_webhook_endpoint"
				data-url-selector=".make-webhook-url"
				data-feedback-selector=".wordform-make-app-feedback-msg"
				data-application-slug="make"
				data-invalid-msg="Please enter valid Make Webhook URL."
			><i class="fa-solid fa-signal"></i> Check URL</button>
			<button
				class="button button-primary wordform-connect-save-update-webhook-like-app-button"
				data-save-action="wordform_connect_save_make_data_as_wp_option_data"
				data-url-selector=".make-webhook-url"
				data-feedback-selector=".wordform-make-app-feedback-msg"
				data-url-param-key="makeWebhookUrl"
				data-invalid-msg="Please enter valid Make Webhook URL."
			><i class="fa-solid fa-gear"></i> Save / Update</button>
		</div>
	</div>
</div>
<!-- End Make Configure Modal Form -->
