<?php
/**
 * @author      Olegnax
 * @package     Olegnax_Core
 * @copyright   Copyright (c) 2023 Olegnax (http://olegnax.com/)
 * @license     https://olegnax.com/license
 */

use Olegnax\Core\Block\Adminhtml\Modules\Update;

/** @var $block Update */
$block->ForsedUpdate();
$modules = $block->getModuleVersions();
$themes = $block->getThemeVersions();
?>
<div class="admin__page-section-item ox-admin__modules">
	<div class="admin__page-section-item-content ox-admin__row">
		<?php foreach ($modules as $module) : ?>
		<?php if (is_array($module)): ?>
		<div class="ox-admin__module us-<?php echo ($module['update_status']) ? 'nok' : 'ok'; ?>">
			<div class="ox-admin__module-wrapper">
				<?php if (array_key_exists('image', $module) && !empty($module['image'])): ?>
					<div class="ox-admin__module-image">
						<img src="<?php echo $module['image'] ?>" />
					</div>
				<?php endif; ?>
				<div class="ox-admin__status-wrapper">
					<span class="ox-module-status ox-module-status-<?php echo ($module['update_status']) ? 'nok' : 'ok'; ?>"><?php echo ($module['update_status']) ? __('Update Required') : __('Up to Date'); ?></span>
					<?php if (array_key_exists('pro', $module)): ?>
						<a target="_blank" class="ox-pro-version" href="<?php echo $module['pro'] ?>"><?php echo __('Get Pro'); ?></a>
					<?php endif; ?>
				</div>
				<div class="ox-admin__module-title-wrapper">
					<a target="_blank" href="<?= array_key_exists('url', $module) ?: '#'; ?>">
						<span class="ox-module-title"><?php if (array_key_exists('title', $module)): echo $module['title']; else:  echo $module['name']; endif; ?>
						<?php if ($module['theme_module']) : ?>
							<span class="ox-module-theme-info"><?php echo __('Theme module'); ?></span>
						<?php endif; ?>
						</span>
					</a>
				</div>
				<div class="ox-admin__module-info">
					<table>
						<tr>
							<td><?php echo $block->escapeHtml(__('Installed Version')); ?></td>
							<td><?php echo $module['setup_version'] ?></td>
						</tr>
						<tr>
							<td><?php echo $block->escapeHtml(__('Latest Version')); ?></td>
							<td><span class="ox-server-version"><?php echo $module['server_version'] ?></span></td>
						</tr>	
						<tr>
							<td><?php echo $block->escapeHtml(__('Status')); ?></td>
							<td><?php echo ($module['enabled']) ? __('Enabled') : __('Disabled') ?></td>
						</tr>
						<tr>
							<td colspan="2"><span class="ox-module-full-name"><?php echo $module['name'] ?></span></td>
						</tr>
					</table>
				</div>
				<div class="ox-admin__modules-bottom">
                        <?php if (array_key_exists('docs', $module)): ?>
							<a target="_blank" href="<?php echo $module['docs'] ?>"><span class="icon-docs"></span><?php echo __('Docs'); ?></a>
						<?php endif; ?>		
						<?php if (array_key_exists('url_changelog', $module)): ?>
							<a target="_blank" class="changelog-link" href="<?php echo $module['url_changelog'] ?>"><?php echo __('Changelog'); ?></a>
						<?php endif; ?>
			
				</div>
			</div>
		</div>
		<?php endif; ?>
		<?php endforeach; ?>
	</div>
</div>

	<div class="admin__page-section-item ox-admin__modules">
		<div class="admin__page-section-item-title">
			<h1 class="page-title"><?php echo $block->escapeHtml(__('Themes')); ?></h1>
		</div>
		<div class="admin__page-section-item-content ox-admin__row">
			<?php foreach ($themes as $theme) : ?>
			<div class="ox-admin__theme us-<?php echo ($theme['update_status']) ? 'nok' : 'ok'; ?>">
				<div class="ox-admin__theme-wrapper">
					<div class="ox-admin__theme-image">
						<?php if (array_key_exists('image', $theme) && !empty($theme['image'])): ?>						
							<img src="<?php echo $theme['image'] ?>"/>
						<?php endif; ?>
					</div>
					<div class="ox-admin__theme-content">
						<div class="ox-admin__status-wrapper">
							<?php if($theme['established']) : ?>
							<span class="ox-module-status ox-module-status-<?php echo ($theme['update_status']) ? 'nok' : 'ok'; ?>"><?php echo ($theme['update_status']) ? __('Update Required') : __('Up to Date'); ?></span>
							<?php else: ?>
							<span class="ox-module-status ox-module-status-none"><?php echo __('Not Installed'); ?></span>
							<?php endif; ?>
						</div>
						<div class="ox-admin__module-title-wrapper">
							<a target="_blank" href="<?= array_key_exists('url', $theme) ?: '#'; ?>">
								<span class="ox-module-title"><?php if (array_key_exists('title', $theme)): echo $theme['title']; else:  echo $theme['name']; endif; echo __(' Theme'); ?></span>
							</a>
						</div>
						
						<div class="ox-admin__module-info">						
								<table>
									<?php if ($theme['established']) : ?>
									<tr>
										<td><?php echo $block->escapeHtml(__('Installed Version')); ?></td>
										<td><?php echo $theme['setup_version'] ?></td>
									</tr>
									<?php endif; ?>
									<tr>
										<td><?php echo $block->escapeHtml(__('Latest Version')); ?></td>
										<td><span class="ox-server-version"><?php echo $theme['server_version'] ?></span></td>
									</tr>	
								</table>							
						</div>
						<?php if (!$theme['established']) : ?>
						<div class="ox-admin__module-actions">		
							<a href="https://themeforest.net/item/athlete2-strong-magento-2-theme/23693737" target="_blank" class="ox-button -green">Download</a><a href="https://athlete2.com/landing/" target="_blank" class="ox-underlined -black">Preview</a>
						</div>
						<?php endif; ?>
						<div class="ox-admin__modules-bottom">
								<span class="icon-docs"></span>
								<?php if (array_key_exists('docs', $theme)): ?>
									<a target="_blank" href="<?php echo $theme['docs'] ?>"><?php echo __('Docs'); ?></a>
								<?php endif; ?>			
								<?php if (array_key_exists('url_changelog', $theme)): ?>
									<a target="_blank" class="changelog-link" href="<?php echo $theme['url_changelog'] ?>"><?php echo __('Changelog'); ?></a>
								<?php endif; ?>		
						</div>
					</div>
				</div>
			</div>
			<?php endforeach; ?>
		</div>
	</div>
