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

include_once SFTCY_WORDFORM_PLUGIN_DIR . 'admin/views/pages-header-template.php';

$wordform_upgrade_url = class_exists( 'SftcyWordformFeatures' ) ? SftcyWordformFeatures::wordform_get_upgrade_url() : 'https://softcoy.com/products/wordform-pro/checkout';
$locked_tab_copy = array(
	'scWordFormCoupons'        => array(
		'title'       => __( 'Coupons are available in WordForm Pro', 'wordform' ),
		'description' => __( 'Unlock discount codes, campaign-specific offers, and richer checkout flows directly inside your forms.', 'wordform' ),
		'demoType'    => 'coupons',
	),
	'scWordFormPaymentReports' => array(
		'title'       => __( 'Payment Reports are available in WordForm Pro', 'wordform' ),
		'description' => __( 'Track payment activity, revenue history, and form-level payment performance from the dashboard.', 'wordform' ),
		'demoType'    => 'payment_reports',
	),
);

$render_locked_demo_shell = static function( $demo_type = '' ) {
	switch ( $demo_type ) {
		case 'coupons':
			?>
			<div class="wordform-pro-demo-shell">
				<div class="wordform-settings-overview-card">
					<div class="wordform-settings-overview-copy">
						<strong><?php esc_html_e( 'Coupon usage hints', 'wordform' ); ?></strong>
						<p><?php esc_html_e( 'Create reusable coupon codes here, then add a Coupon element to payment forms later. Coupons can be time-limited, usage-limited, and restricted to selected forms.', 'wordform' ); ?></p>
					</div>
				</div>
				<div class="wordform-coupons-toolbar-card">
					<div class="wordform-coupons-toolbar-copy">
						<h4><?php esc_html_e( 'Coupon Manager', 'wordform' ); ?></h4>
						<p><?php esc_html_e( 'Manage coupon codes centrally so payment forms can reuse the same discount rules.', 'wordform' ); ?></p>
					</div>
					<div class="wordform-coupons-toolbar-actions">
						<span class="button button-primary"><?php esc_html_e( 'Create Coupon', 'wordform' ); ?></span>
					</div>
				</div>
				<table class="display hover stripe wp-list-table widefat fixed striped table-view-list wordform-pro-demo-table">
					<thead>
						<tr>
							<th><?php esc_html_e( 'Coupon Code', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Type', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Value', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Status', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Usage', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Validity', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Forms', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Actions', 'wordform' ); ?></th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>SPRING10</td>
							<td><?php esc_html_e( 'Percentage', 'wordform' ); ?></td>
							<td>10%</td>
							<td><?php esc_html_e( 'Active', 'wordform' ); ?></td>
							<td>18 / 100</td>
							<td><?php esc_html_e( 'Apr 01 - Apr 30', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'Booking, Checkout', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'Edit / Delete', 'wordform' ); ?></td>
						</tr>
						<tr>
							<td>VIP50</td>
							<td><?php esc_html_e( 'Fixed', 'wordform' ); ?></td>
							<td>$50.00</td>
							<td><?php esc_html_e( 'Scheduled', 'wordform' ); ?></td>
							<td>0 / <?php esc_html_e( 'Unlimited', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'May 01 - Jun 15', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'Consultation Form', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'Edit / Delete', 'wordform' ); ?></td>
						</tr>
					</tbody>
				</table>
			</div>
			<?php
			break;
		case 'payment_reports':
			?>
			<div class="wordform-pro-demo-shell">
				<div class="wordform-connection-status-toolbar wordform-connection-status-toolbar-panel">
					<div class="wordform-connection-status-filter-grid wordform-payment-report-filter-grid">
						<div class="wordform-connection-status-filter">
							<label><strong><?php esc_html_e( 'Filter by Form', 'wordform' ); ?></strong></label><br />
							<div class="wordform-pro-demo-input"><?php esc_html_e( 'Booking and checkout forms', 'wordform' ); ?></div>
						</div>
						<div class="wordform-connection-status-filter">
							<label><strong><?php esc_html_e( 'Filter by Gateway', 'wordform' ); ?></strong></label><br />
							<div class="wordform-pro-demo-input"><?php esc_html_e( 'Stripe and PayPal', 'wordform' ); ?></div>
						</div>
						<div class="wordform-connection-status-filter">
							<label><strong><?php esc_html_e( 'Filter by Status', 'wordform' ); ?></strong></label><br />
							<div class="wordform-pro-demo-input"><?php esc_html_e( 'Completed and Processing', 'wordform' ); ?></div>
						</div>
						<div class="wordform-connection-status-filter wordform-connection-status-filter-summary">
							<h4><?php esc_html_e( 'Current View', 'wordform' ); ?></h4>
							<p class="description"><?php esc_html_e( 'Showing all payment records across all forms, gateways, and statuses.', 'wordform' ); ?></p>
							<p class="description"><?php esc_html_e( 'Filters update the report instantly without leaving the Payment Reports tab.', 'wordform' ); ?></p>
							<p class="wordform-payment-report-reset-line"><span class="button button-secondary"><?php esc_html_e( 'Reset Filters', 'wordform' ); ?></span></p>
						</div>
					</div>
				</div>
				<table class="display hover stripe wp-list-table widefat fixed striped table-view-list wordform-pro-demo-table">
					<thead>
						<tr>
							<th><?php esc_html_e( 'Form Name', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Gateway', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Status', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Amount', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Coupon', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Currency', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Transaction Ref', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Submission Date', 'wordform' ); ?></th>
							<th><?php esc_html_e( 'Details', 'wordform' ); ?></th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td><?php esc_html_e( 'Checkout Form', 'wordform' ); ?></td>
							<td>Stripe</td>
							<td><?php esc_html_e( 'Completed', 'wordform' ); ?></td>
							<td>$120.00</td>
							<td>SPRING10</td>
							<td>USD</td>
							<td>pi_3QDemo123</td>
							<td><?php esc_html_e( '2026-04-08 10:24', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'View', 'wordform' ); ?></td>
						</tr>
						<tr>
							<td><?php esc_html_e( 'Ticket Order', 'wordform' ); ?></td>
							<td>PayPal</td>
							<td><?php esc_html_e( 'Processing', 'wordform' ); ?></td>
							<td>$79.00</td>
							<td><?php esc_html_e( 'None', 'wordform' ); ?></td>
							<td>USD</td>
							<td>PAY-8B7Demo</td>
							<td><?php esc_html_e( '2026-04-08 09:17', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'View', 'wordform' ); ?></td>
						</tr>
						<tr>
							<td><?php esc_html_e( 'Consultation Deposit', 'wordform' ); ?></td>
							<td>Stripe</td>
							<td><?php esc_html_e( 'Refunded', 'wordform' ); ?></td>
							<td>$45.00</td>
							<td>VIP50</td>
							<td>USD</td>
							<td>pi_3QDemo987</td>
							<td><?php esc_html_e( '2026-04-07 18:06', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'View', 'wordform' ); ?></td>
						</tr>
						<tr>
							<td><?php esc_html_e( 'Workshop Registration', 'wordform' ); ?></td>
							<td>PayPal</td>
							<td><?php esc_html_e( 'Pending', 'wordform' ); ?></td>
							<td>$199.00</td>
							<td><?php esc_html_e( 'None', 'wordform' ); ?></td>
							<td>USD</td>
							<td>PAY-5Z1Demo</td>
							<td><?php esc_html_e( '2026-04-07 14:41', 'wordform' ); ?></td>
							<td><?php esc_html_e( 'View', 'wordform' ); ?></td>
						</tr>
					</tbody>
				</table>
			</div>
			<?php
			break;
	}
};

$settings_tabs = array(
	'scWordFormGeneral'    => array(
		'label' => __( 'General', 'wordform' ),
		'icon'  => 'dashicons-admin-settings',
		'view'  => 'admin/views/settings_callback_general_tab_page.php',
		'title' => __( 'General Settings', 'wordform' ),
		'available' => true,
	),
	'scWordFormValidation' => array(
		'label' => __( 'Validation', 'wordform' ),
		'icon'  => 'dashicons-admin-settings',
		'view'  => 'admin/views/settings_callback_validation_tab_page.php',
		'title' => __( 'Validation Message Settings', 'wordform' ),
		'available' => true,
	),
	'scWordFormUpload'     => array(
		'label' => __( 'Upload', 'wordform' ),
		'icon'  => 'dashicons-admin-settings',
		'view'  => 'admin/views/settings-callback-upload-tab-page.php',
		'title' => __( 'Upload Settings', 'wordform' ),
		'available' => true,
	),
	'scWordFormPayment'    => array(
		'label' => __( 'Payment', 'wordform' ),
		'icon'  => 'dashicons-cart',
		'view'  => 'admin/views/settings-callback-payment-tab-page.php',
		'title' => __( 'Payment Settings', 'wordform' ),
		'available' => true,
	),
);

	$settings_tabs['scWordFormCoupons'] = array(
		'label' => __( 'Coupons', 'wordform' ),
		'icon'  => 'dashicons-tickets-alt',
		'view'  => 'admin/views/settings-callback-coupons-tab-page.php',
		'title' => __( 'Coupons', 'wordform' ),
		'available' => class_exists( 'SftcyWordformFeatures' ) ? SftcyWordformFeatures::wordform_is_feature_available( 'payment_coupon' ) : true,
	);

	$settings_tabs['scWordFormPaymentReports'] = array(
		'label' => __( 'Payment Reports', 'wordform' ),
		'icon'  => 'dashicons-chart-bar',
		'view'  => 'admin/views/settings-callback-payment-reports-tab-page.php',
		'title' => __( 'Payment Reports', 'wordform' ),
		'available' => class_exists( 'SftcyWordformFeatures' ) ? SftcyWordformFeatures::wordform_is_feature_available( 'payment_reporting_dashboard' ) : true,
	);

	$settings_tabs['scWordFormgreCaptcha'] = array(
		'label' => __( 'Google reCaptcha', 'wordform' ),
		'icon'  => 'dashicons-admin-settings',
		'view'  => 'admin/views/settings-callback-gcaptcha-tab-page.php',
		'title' => __( 'Google reCaptcha', 'wordform' ),
		'available' => class_exists( 'SftcyWordformFeatures' ) ? SftcyWordformFeatures::wordform_is_feature_available( 'google_recaptcha' ) : true,
	);

if ( class_exists( 'SftcyWordformFeatures' ) && SftcyWordformFeatures::wordform_is_feature_available( 'hcaptcha' ) ) {
	$settings_tabs['scWordFormhCaptcha'] = array(
		'label' => __( 'hCaptcha', 'wordform' ),
		'icon'  => 'dashicons-shield-alt',
		'view'  => 'admin/views/settings-callback-hcaptcha-tab-page.php',
		'title' => __( 'hCaptcha', 'wordform' ),
		'available' => true,
	);
}
?>
<div class="wrap" style="margin: 1%;">
	<div id="tabs" class="sc-wordform-tabs-wrapper-div" style="display: none;">
		<ul>
			<?php foreach ( $settings_tabs as $tab_id => $tab ) { ?>
			<li class="<?php echo empty( $tab['available'] ) ? 'wordform-pro-locked-nav' : ''; ?>">
				<a
					href="#<?php echo esc_attr( $tab_id ); ?>"
					class="sc-wordform-tab-label<?php echo empty( $tab['available'] ) ? ' wordform-pro-locked-tab-link' : ''; ?>"
					<?php if ( empty( $tab['available'] ) ) { ?>
						data-upgrade-url="<?php echo esc_url( $wordform_upgrade_url ); ?>"
						title="<?php esc_attr_e( 'Get Pro', 'wordform' ); ?>"
					<?php } ?>
				><i class="dashicons <?php echo esc_attr( $tab['icon'] ); ?> dashicon-custom-color"></i>&nbsp;<?php echo esc_html( $tab['label'] ); ?></a>
			</li>
			<?php } ?>
		</ul>

		<?php foreach ( $settings_tabs as $tab_id => $tab ) { ?>
		<div id="<?php echo esc_attr( $tab_id ); ?>">
			<h3><i class="dashicons <?php echo esc_attr( $tab['icon'] ); ?> dashicon-custom-color"></i>&nbsp;<?php echo esc_html( $tab['title'] ); ?></h3>
			<?php if ( ! empty( $tab['available'] ) ) { ?>
				<?php require_once SFTCY_WORDFORM_PLUGIN_DIR . $tab['view']; ?>
			<?php } else {
				$locked_copy = isset( $locked_tab_copy[ $tab_id ] ) ? $locked_tab_copy[ $tab_id ] : array(
					'title'       => __( 'This settings area is available in WordForm Pro', 'wordform' ),
					'description' => __( 'Upgrade to unlock this tab in the dashboard.', 'wordform' ),
				);
			?>
				<div class="wordform-pro-locked-panel">
					<div class="wordform-pro-locked-panel-head">
						<div>
							<h3><?php echo esc_html( $locked_copy['title'] ); ?></h3>
							<p><?php echo esc_html( $locked_copy['description'] ); ?></p>
						</div>
						<span class="wordform-pro-preview-badge"><?php esc_html_e( 'Pro', 'wordform' ); ?></span>
					</div>
					<div class="wordform-pro-preview-frame">
						<?php $render_locked_demo_shell( isset( $locked_copy['demoType'] ) ? $locked_copy['demoType'] : '' ); ?>
						<a class="wordform-pro-preview-overlay wordform-pro-locked-button" href="<?php echo esc_url( $wordform_upgrade_url ); ?>" target="_blank" rel="noopener" data-upgrade-url="<?php echo esc_url( $wordform_upgrade_url ); ?>" title="<?php esc_attr_e( 'Get Pro', 'wordform' ); ?>">
							<span class="wordform-pro-preview-overlay-chip"><?php esc_html_e( 'Get Pro', 'wordform' ); ?></span>
							<strong><?php esc_html_e( 'Unlock the full settings experience', 'wordform' ); ?></strong>
							<small><?php esc_html_e( 'Edit live values, save advanced controls, and manage the real workflow in WordForm Pro.', 'wordform' ); ?></small>
						</a>
					</div>
				</div>
			<?php } ?>
		</div>
		<?php } ?>
	</div>
</div>
