<?php
namespace JetStudioModule\ApplicationModules;

use Jet\SysConf_Jet_Modules;
use Jet\SysConf_Path;
use Jet\Tr;
use Jet\MVC_View;
use Jet\UI;
use Jet\UI_button;
use Jet\UI_dialog;
use JetStudio\JetStudio_UI;

/**
 * @var MVC_View $this
 */

$current = Main::getCurrentModule();

if( !$current ) {
	return;
}

$form = $current->getEditForm();

?>

<?= $form->start() ?>
<input type="hidden" name="generate" value="0"/>

<?= JetStudio_UI::messages(); ?>

<div class="section-title">
	<?= Tr::_( 'Module' ) ?>
	<span style="font-weight: bolder"><?= $current->getLabel() ?></span>
	<span style="color: #aaaaaa;font-size: 12px;"><?= $current->getName() ?></span>
</div>


<div class="form-fields">
	<?= $form->field( 'module_name' ) ?>
	<?= $form->field( 'module_label' ) ?>
	<?= $form->field( 'vendor' ) ?>
	<?= $form->field( 'version' ) ?>
	<?= $form->field( 'description' ) ?>
	<?= $form->field( 'is_mandatory' ) ?>
	<?= $form->field( 'is_active' ) ?>
	<?= $form->field( 'is_installed' ) ?>

	
	<div><?=Tr::_('ACL action')?></div>
	<div>
		<div style="display: grid;justify-content:left;grid-template-columns: auto auto;gap: 10px;">
			<div><?= Tr::_( 'Action' ) ?></div>
			<div><?= Tr::_( 'Description' ) ?></div>
			
			<?php for( $m = 0; $m < Modules_Manifest::MAX_ACL_ACTION_COUNT; $m++ ):
				$prefix = '/ACL_action/' . $m;
				
				if( !$form->fieldExists( $prefix . '/action' ) ) {
					break;
				}
				
				$action = $form->field( $prefix . '/action' );
				$action->input()->addCustomCssStyle( 'width:300px;' );
				$description = $form->field( $prefix . '/description' );
				$description->input()->addCustomCssStyle( 'width:300px;' );
				
				?>

				<div><?= $action->input() ?></div>
				<div><?= $description->input() ?></div>

			<?php endfor; ?>

		</div>
		
	</div>
</div>

<?= $form->end() ?>

<?php
$delete_module_info = UI::dialog(
	id: 'delete_module_info',
	title: Tr::_('How to delete module?'),
	size: UI_dialog::SIZE_LARGE
);

echo $delete_module_info->start();

?>
<b><?=Tr::_('Deleting a module is potential risc operation!')?></b>
<br><br>
<p><?=Tr::_('But it is possible for sure and it is very easy.')?></p>

<ol start="1">
	<?php if($current->isMandatory()): ?>
	<li><?=Tr::_('This module is <b>marked as mandatory</b>.<br><br>Please change manually this definition in the manifest file:<br><b>%manifest_path%</b>', [
			'manifest_path' => $current->getModuleDir().SysConf_Jet_Modules::getManifestFileName()
		])?>
		<br><br>
		<?=Tr::_('And then reload Jet Studio')?>
		<br><br>
	</li>
	<?php endif; ?>
	
	<?php if($current->isActivated()):?>
	<li>
		<?=Tr::_('Deactivate module by this tool using <b>"Deactivate" button</b>.')?>
		<br><br>
	</li>
	<?php endif; ?>
	
	<?php if($current->isInstalled()): ?>
	<li>
		<?=Tr::_('Uninstall module by this tool using <b>"Uninstall" button</b>.')?>
		<br><br>
	</li>
	<?php endif; ?>
	
	<li>
		<?=Tr::_('Manually delete directory:<br><b>%module_dir%</b>', [
				'module_dir'=>$current->getModuleDir()
		])?>
		<br><br>
	</li>
</ol>
<?php
echo $delete_module_info->end();




$collect_dictionaries_info = UI::dialog(
	id: 'collect_dictionaries_info',
	title: Tr::_('Collect module dictionaries'),
	size: UI_dialog::SIZE_LARGE
);

echo $collect_dictionaries_info->start();

echo Tr::_('<b>Warning!</b><br>
<br>
This function uploads all current translation dictionaries from the %DICT_DIR% directory to the module installation directory %INSTALL_DIR%.<br>
<br>
This will allow dictionaries to be updated for further distribution and installation of the module.<br>
<br>
<b>But it is necessary to warn you that the existing installation dictionaries will be overwritten.</b>', [
	'DICT_DIR' => '<br><br><i>'.SysConf_Path::getDictionaries().'</i><br><br>',
	'INSTALL_DIR' => '<br><br><i>'.$current->getModuleInstallDictionariesDirPath().'</i><br>',
]);

echo $collect_dictionaries_info->footer();
echo UI::button(Tr::_('OK - let\'s do it!'))->setClass(UI_button::CLASS_DANGER)->setUrl(Main::getActionUrl('collect_dictionaries'));
echo $collect_dictionaries_info->end();





$clone_module_dialog = UI::dialog(
	id: 'clone_module_dialog',
	title: Tr::_('Clone module'),
	size: UI_dialog::SIZE_LARGE
);

echo $clone_module_dialog->start();

?>
<div id="clone_module_form_area">
	<?php require __DIR__.'/../clone/form.phtml'; ?>
</div>
<?php
echo $clone_module_dialog->footer();
	echo UI::button(Tr::_('Clone'))->setOnClick('Modules.cloneModule.clone();')->setClass(UI_button::CLASS_PRIMARY)->setIcon('clone');
echo $clone_module_dialog->end();
?>

