<?php

namespace EasyEditor;

class FormFeature {
  
  

    // --- Statische Eigenschaften ---
  
  static private $featurestack = [];

    // --- Statische Methoden ---
  
  public static function pop() { 
    
    
    // --- BLOCK: main ---
    
		array_pop(self::$featurestack);
	
    
  }

  public static function isCollapsed() { 
    
    
    // --- BLOCK: main ---
    
		return (self::$featurestack ? end(self::$featurestack)['collapsed'] : 0);
	
    
  }

  public static function push($feature) { 
    
    
    // --- BLOCK: main ---
    
        if ($feature['mode'] == 'area') $feature['collapsed'] = 0;
		array_push(self::$featurestack, $feature);
	
    
  }

  public static function render($feature) { 
    
    
    // --- BLOCK: main ---
    
		// feature: id, title, order, mode, position, collapsed, canEdit
		?><div class='
			fop-form-feature
			fop-form-feature-mode-<?php echo htmlentities($feature['mode']); ?>
			<?php if ($feature['collapsed']) { ?> fop-form-feature-collapsed<?php } ?>
			fop-form-feature-position-<?php echo htmlentities($feature['position']); ?>'
			data-feature='<?php echo htmlentities($feature['id']); ?>'
			data-order='<?php echo htmlentities($feature['order']); ?>'
			id='form-<?php echo htmlentities($feature['id']); ?>'
			<?php if (isset($feature['visibility'])) echo 'ng-show="'.htmlentities($feature['visibility']).'"'; ?>>
			<?php if($feature['canEdit']) { ?>
			<button type='button' class='fop-form-feature-context mdl-button mdl-js-button mdl-button--icon' onclick="event.stopPropagation(); dropDownFixPosition($(this), $(this).next());">
				<i class='material-icons'>more_vert</i>
			</button>
			<ul style="max-height: 100vh; overflow-y: auto; display: none;" class="mdl-list mdl-card mdl-shadow--4dp noprint">
				<a class="mdl-list__item mdl-button" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'move', 'up');
						return false;">
					<i class="material-icons">keyboard_arrow_up</i><?php echo _('cff_up'); ?>
				</a>
				<a class="mdl-list__item mdl-button" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'move', 'down');
						return false;">
					<i class="material-icons">keyboard_arrow_down</i><?php echo _('cff_down'); ?>
				</a>
				<hr>
				<a class="mdl-list__item mdl-button" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'mode', 'area');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">border_clear</i><?php echo _('cff_noborder'); ?>
				</a>
				<a class="mdl-list__item mdl-button" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'mode', 'region');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">border_outer</i><?php echo _('cff_border'); ?>
				</a>
				<a class="mdl-list__item mdl-button" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'mode', 'tab');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">tab</i><?php echo _('cff_tab'); ?>
				</a>
				<hr class="only-big">
				<a class="mdl-list__item mdl-button only-big" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'position', 'full');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">fullscreen</i><?php echo _('cff_full'); ?>
				</a>
				<a class="mdl-list__item mdl-button only-big" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'position', 'half');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">swap_horiz</i><?php echo _('cff_half'); ?>
				</a>
				<a class="mdl-list__item mdl-button only-big" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'position', 'third');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">⅓</i><?php echo _('cff_third'); ?>
				</a>
				<a class="mdl-list__item mdl-button only-big" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'position', 'two-third');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">⅔</i><?php echo _('cff_twothirds'); ?>
				</a>
				<hr/>
				<a class="mdl-list__item mdl-button only-big" href="#"
					onclick="
						changeFeature('<?php echo htmlentities($feature['id']); ?>', 'reset', 'reset');
						$(this).closest('.overlay').click(); return false;">
					<i class="material-icons">refresh</i><?php echo _('reset'); ?>
				</a>
			</ul>
			<?php } /* canEdit */ ?>
			<?php if ($feature['title']) { ?>
			<h5 class='fop-form-feature-title' onclick='$(this).parent().toggleClass(&apos;fop-form-feature-collapsed&apos;);
				/* AJAX: save values */
				<?php if ($feature['canEdit']) { ?>
					setCFF(&apos;<?php echo htmlentities(urlencode($feature['id'])); ?>&apos;, &apos;collapsed&apos;, $(this).parent().hasClass(&apos;fop-form-feature-collapsed&apos;) ? 1 : 0);
					$(this).parent().find(&apos;.fop-lazy-reload&apos;).click();
				<?php } ?>'>
				<i class='material-icons expand-less'>expand_less</i>
				<i class='material-icons expand-more'>expand_more</i>
				<?php echo htmlentities($feature['title']); ?>
				<i class='fop-form-feature-title-addon'></i>
			</h5><?php } ?>
			<div class='fop-form-feature-content'>
				<?php echo $feature['html']; ?>
			</div>
		</div><?php
	
    
  }


  
  

  
  
}



