<?php
namespace JetStudioModule\Menus;

use Jet\Tr;
use Jet\UI;
use Jet\UI_dialog;
use Jet\MVC_View;

/**
 * @var MVC_View $this
 */


$menu = Main::getCurrentMenu();
$form = $menu->getEditForm();


$delete_menu_dialog = UI::dialog( 'delete_menu_dialog', Tr::_( 'Delete menu' ), UI_dialog::SIZE_LARGE );

?>

<?= $form->start() ?>
<?= $form->getCommonMessage(); ?>

<div class="form-fields">
	<?= $form->field( 'id' ) ?>
	<?= $form->field( 'label' ) ?>
	<?= $form->field( 'icon' ) ?>
	<?= $form->field( 'index' ) ?>

	<label class="control-label"><?= Tr::_( 'Items:' ) ?></label>
	<div id="items_sort_area">

	<?php foreach( $menu->getMenuItems() as $item ): ?>
		<div class="list-group-item menu-item-sort-item" data-id="<?= $item->getId() ?>" style="display: flex;align-items: center;gap: 10px;">
			<input type="hidden" name="items_sort[]" value="<?= $item->getId() ?>">
			<div><span class="fa fa-arrows-v" style="font-size:16px;padding-right: 5px"></span></div>
			<div><a href="<?= Main::getActionUrl( '', [], null, null, $item->getId() ) ?>"><?= $item->getTitle() ?></a></div>
		</div>
	<?php endforeach; ?>
	</div>
	
</div>

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

<?php
echo $delete_menu_dialog->start();
echo Tr::_( 'Do you really want to delete this menu?' );
echo $delete_menu_dialog->footer();
echo UI::button_delete()->setUrl( Main::getActionUrl( 'menu_delete' ) );
echo $delete_menu_dialog->end();
?>

<?= $this->render( 'item/create/dialog' ); ?>

<script type="text/javascript">
	$(document).ready(function () {
		Menus.initSort();
	});
</script>
