<?php /** @var BelboonAdvertiserTrackingPlugin $belboon_plugin */;?>
<?php $belboon_plugin->getDataFromAPI();?>
<?php $apiKeyIsValid = $belboon_plugin->getApiKey() !== '' && $belboon_plugin->isApiKeyValid();?>
<div class="wrap">
	<h1>
		<?php esc_html_e('belboon WooCommerce Advertiser Plugin', BELBOON_TACKING_TEXTDOMAIN);?>
	</h1>
	<div class="bb-option-container">
		<div class="bb-option-box left">
			<form method="post" action="options.php">
				<?php settings_fields(BelboonAdvertiserTrackingPlugin::OPTION_GROUP);?>
				<?php do_settings_sections(BelboonAdvertiserTrackingPlugin::OPTION_GROUP);?>
				<table class="form-table">
                    <tr valign="top">
                        <th scope="row"><?php _e("Advertiser ID", BELBOON_TACKING_TEXTDOMAIN);?></th>
                        <td>
                            <?php if($apiKeyIsValid !== true):?>
                                <input type="text" name="<?php echo BelboonAdvertiserTrackingPlugin::OPTION_ADVERTISER_ID;?>" value="<?php echo $belboon_plugin->getAdvertiserId();?>" />
                            <?php else:?>
	                            <?php echo $belboon_plugin->getAdvertiserId();?>
                            <?php endif?>
                        </td>
                    </tr>
                    <tr valign="top">
                        <th scope="row"><?php _e("Tracking Domain", BELBOON_TACKING_TEXTDOMAIN);?></th>
                        <td>
	                        <?php if($apiKeyIsValid !== true):?>
                                <input type="text" name="<?php echo BelboonAdvertiserTrackingPlugin::OPTION_TRACKING_DOMAIN;?>" value="<?php echo $belboon_plugin->getTrackingDomain();?>" />
	                        <?php else:?>
		                        <?php echo $belboon_plugin->getTrackingDomain();?>
	                        <?php endif?>
                        </td>
                    </tr>
					<tr valign="top">
						<th scope="row"><?php _e("API Key", BELBOON_TACKING_TEXTDOMAIN);?></th>
						<td>
							<input type="text" class="bb-input-long" name="<?php echo BelboonAdvertiserTrackingPlugin::OPTION_API_KEY;?>" value="<?php echo $belboon_plugin->getApiKey();?>" />
							<div class="bb-small">
								<?php
                                    if($belboon_plugin->getApiKey() === '') {
	                                    printf(
		                                    __(
			                                    'You don\'t have an API yet? Contact <a href="%1$s">our technical support</a> to get yours. Please <a href="%1$s">click here</a> to contact our support team.',
			                                    BELBOON_TACKING_TEXTDOMAIN
		                                    ),
		                                    'mailto:' . BelboonAdvertiserTrackingPlugin::BB_CONTACT_MAIL
	                                    );
                                    } else {
                                        if($apiKeyIsValid === true) {
                                            echo '✅ ' . __("Key is valid", BELBOON_TACKING_TEXTDOMAIN);
                                        } else {
                                            echo '❌ ' . __("Key is invalid", BELBOON_TACKING_TEXTDOMAIN);
                                        }
									}
								?>
                            </div>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row">&nbsp;</th>
						<td>
                            <?php
								submit_button(
									null,
									'bb-button',
								);
							?>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div class="right">
			<?php
				echo $belboon_plugin->getView(
					'admin_sidebar'
				);
			?>
		</div>
	</div>
</div>
