<?php
/*
 * frmdforms configuration and Intigration page
 * @since 1.0
 */

// Exit if accessed directly.
if (!defined('ABSPATH')) {
	exit();
}

$active_tab = isset($_GET['tab']) && sanitize_text_field(wp_unslash($_GET['tab'])) ? sanitize_text_field(wp_unslash($_GET['tab'])) : 'integration';

$allowed_tags = array(
	'a' => array(
		'href' => array(),
		'title' => array(),
	),
	'br' => array(),
	'em' => array(),
	'strong' => array(),
);

$active_tab_name = '';
if ($active_tab == 'integration') {
	$active_tab_name = 'Integration';
} elseif ($active_tab == 'form_feed_settings') {
	$active_tab_name = 'Form Feeds';
} elseif ($active_tab == 'settings') {
	$active_tab_name = 'Settings';
} elseif ($active_tab == 'extensions') {
	$active_tab_name = 'Extensions';
}

// Check plugin version and subscription plan
$plugin_version = defined('GSCFRMDFORM_VERSION_VERSION') ? GSCFRMDFORM_VERSION_VERSION : 'N/A';

?>
<div class="gsheet-header">
	<div class="gsheet-logo">
		<a href="https://www.gsheetconnector.com/"><i></i></a>
	</div>
	<h1 class="gsheet-logo-text">
		<span><?php echo esc_html(__('Formidable GSheetConnector', 'gsheetconnector-formidable-forms')); ?></span>
		<small><?php echo esc_html(__('Version :', 'gsheetconnector-formidable-forms')); ?>
			<?php echo esc_html($plugin_version, 'gsheetconnector-formidable-forms'); ?> </small>
	</h1>
	<ul>
        <li><a href="<?php echo admin_url( 'admin.php?page=formidable-form-google-sheet-config&tab=extensions', 'gsconnector' ); ?>" title="Extensions">
          <i class="fa-solid fa-puzzle-piece"></i></a></li>
        <li><a href="https://www.gsheetconnector.com/docs/formidable-forms-gsheetconnector/installation-process-free-version" title="Document" target="_blank" rel="noopener noreferrer">
			<i class="fa-regular fa-file-lines"></i></a></li>
        <li><a href="https://www.gsheetconnector.com/support" title="Support" target="_blank" rel="noopener noreferrer"><i class="fa-solid fa-life-ring"></i></a></li>
        <li><a href="https://wordpress.org/plugins/gsheetconnector-formidable-forms/#developers" title="Changelog" target="_blank" rel="noopener noreferrer"><i class="fa-solid fa-bullhorn"></i></a></li>
    </ul>
</div>

<div class="breadcrumb">
<span class="dashboard-gsc"><?php echo esc_html(__('DASHBOARD', 'gsheetconnector-formidable-forms')); ?></span>
<span class="divider-gsc"> / </span>
<span class="modules-gsc"> <?php echo esc_html($active_tab_name); ?></span>
</div>


	<?php

	$tabs = array(
		'integration' => esc_html__('Integration', 'gsheetconnector-formidable-forms'),
		'form_feed_settings' => esc_html__('Form Feeds', 'gsheetconnector-formidable-forms'),
		'settings' => esc_html__('Settings', 'gsheetconnector-formidable-forms'),
		'extensions' => esc_html__('Extensions', 'gsheetconnector-formidable-forms'),
		//'system_status' => esc_html__('System Status', 'gsheetconnector-formidable-forms'),
		//'general_settings' => esc_html('General Settings', 'gsheetconnector-formidable-forms'),
	);

	echo '<div id="icon-themes" class="icon32"><br></div>';
	echo '<div class="nav-tab-wrapper">';

	foreach ($tabs as $tab => $name) {
		$class = ($tab == $active_tab) ? ' nav-tab-active' : '';
		echo '<a class="nav-tab' . esc_attr($class) . '" href="' . esc_url(
			add_query_arg(
				array(
					'page' => 'formidable-form-google-sheet-config',
					'tab' => $tab,
				)
			)
		) . '">' . wp_kses($name, $allowed_tags) . '</a>';
	}
	echo '</div><div class="wrap-gsc">';

	switch ($active_tab) {
		case 'integration':
			include GSCFRMDFORM_VERSION_PATH . 'includes/class-formidable-forms-integration.php';
			break;
		case 'form_feed_settings':
			if (isset($_GET['form_id']) && isset($_GET['feed_id'])) {
				$form_id = intval($_GET['form_id']);
				$feed_id = intval($_GET['feed_id']);
				include(GSCFRMDFORM_VERSION_PATH . "includes/pages/edit-feed.php");
			} else {
				include(GSCFRMDFORM_VERSION_PATH . "includes/pages/gsc-feed-google-sheet.php");
			}
			break;
		case 'settings':
			include GSCFRMDFORM_VERSION_PATH . "includes/pages/google-sheet-settings.php";
			break;
		case 'extensions':
			include GSCFRMDFORM_VERSION_PATH . 'includes/pages/extensions/extensions.php';
			break;

	}
	?>

</div>
<?php include(GSCFRMDFORM_VERSION_PATH . "/includes/pages/admin-footer.php"); ?>