<?php
  /**
   * Common control library 0.1 for Conjuro.
   */
  return [
    new class('admin-title') extends Control{
      protected function getControlPlaceholders(){
        return [];
      }
      protected function renderControl($meta,$data) {
        ?>
          <div id="<?=$meta['id']?>" class="admin-title <?=$meta['class']?>"><?=$meta['title']?>
            <?php if ($meta['left']) foreach($meta['left'] as $child) c()->renderContent($child,$data); ?>
          </div>
          <div class="admin-title-right <?=$meta['class']?>">&nbsp;<i class="fa-solid fa-gear btn-ico"></i></div>
          <div class="clear"></div>
        <?php
      }
    },
    new class('admin-panel-buttons') extends Control{
      protected function getControlPlaceholders(){
        return [];
      }
      protected function renderControl($meta,$data) {
        foreach(m('Admin')->do('get-panel-links') as $lnk){
          c()->control('admin-panel-button')->render($lnk,$data);
        }
      }
    },
    new class('admin-panel-button') extends Control{
      protected function getControlPlaceholders(){
        return [];
      }
      protected function renderControl($meta,$data) {
        echo '<div class="admin-panel-button">';
        echo '<i class="admin-panel-button-icon fa-solid fa-'.$meta['icon'].'"></i>';
        echo '<a class="admin-panel-button-link" href="'.$meta['link'].'">'.$meta['title'].'</a>';
        echo '</div>';
      }
    },
    new class('admin-section') extends Control{
      protected function getControlPlaceholders(){
        return [
          'class'     =>['type'=>'s','description'=>'Clase opcional para el control de sección.'],
          'title'     =>['type'=>'s','description'=>'Título'],
          'body-class'=>['type'=>'s','description'=>'Clase opcional para el cuerpo del control de sección.'],
          'content'   =>['type'=>'a','description'=>'Contenido'],
        ];
      }
      protected function renderControl($meta,$data) {
        ?>
          <div class="admin-tile <?=$meta['class']?>">
            <div class="admin-tile-header"><?=$meta['title']?></div>
            <div class="admin-tile-body" <?=$meta['body-class']?>>
              <?php if ($meta['content']) foreach($meta['content'] as $child) c()->renderContent($child,$data); ?>
            </div>
          </div><!-- Tile -->
        <?php
      }
    },
    new class('builder') extends Control{
      protected function getControlPlaceholders(){
        return [];
      }
      // Para medir el layout usar una clase Page falsa que genere metricas sobre el uso del layout

      protected function renderControl($meta,$data) {
          include('builder.html');
        ?><script>builder.init(<?=json_encode($data['page'])?>);</script><?php
      }
    },
  ];
?>