<?php
/**
 * Template part for displaying the AUX components audit page in the WordPress admin.
 *
 * Loaded by /inc/WP_AUX/Entities/Admin/AuxComponents/AuxComponentsPageEntity.php.
 *
 * @package MarComm-AUX
 * @since 1.0.0
 */
declare(strict_types=1);

use WP_AUX\Entities\Admin\AuxComponents\AuxComponentsAuditEntity;
use WP_AUX\Services\Admin\AuxComponents\AuxComponentsAuditPageService;

/**
 * @var $auxComponentsAudit AuxComponentsAuditEntity
 */
$auxComponentsAudit = $args['auxComponentsAudit'];
$components = $auxComponentsAudit->getAuditComponents();

add_thickbox();
?>
<h1>AUX Components</h1>
<p>Components are Advanced Custom Fields "Field Groups", defined in code.
  These "Field Groups" are set up as "entities" in the
  <?php AuxComponentsAuditPageService::renderDirectoryPath(WP_AUX::FIELD_GROUPS_DIR, 'group'); ?> directory.</p>
  <table class="table" id="aux-components">
    <thead>
    <tr>
      <th>Component</th>
      <th>File</th>
      <th>Has Block</th>
      <th>Fields</th>
      <th>Active</th>
    </tr>
    </thead>
    <tbody>
    <?php
    foreach ($components as $componentKey => $component) {
      $fieldGroup = $component->fieldGroup;
      ?>
      <tr>
        <th>
          <div>
            <a href="#TB_inline?&width=960&height=550&inlineId=component-<?php echo $componentKey; ?>" class="component-details-trigger thickbox">
              <?php echo $component->title ? $component->title . ' | ' : ''; ?>
              <em><?php echo $componentKey; ?></em>
            </a>
            <?php AuxComponentsAuditPageService::renderDocumentationLink($component); ?>
          </div>
          <div style="font-weight: normal;"><?php echo $fieldGroup->getDescription(); ?></div>
          <div style="font-weight: normal;">by <?php echo @$component->blockConfig['author']; ?></div>
        </th>
        <td>
          <?php AuxComponentsAuditPageService::renderFilePath(
            $component->file->getRelativePath(), $component->file->getPathKey()
          ); ?>
        </td>
        <td><?php echo !empty($component->blockConfig) ? 'Yes' : 'No'; ?></td>
        <td>
          <?php echo $component->fieldsCount; ?>
          (<?php echo $component->allFieldsCount; ?>)
        </td>
        <td>
          <?php echo $component->isActive ? 'Yes' : 'No'; ?>
          <?php echo 'dev' === $component->state ? '(dev)' : ''; ?>
        </td>
      </tr>
      <?php
    }
    ?>
    </tbody>
  </table>
  <?php
  foreach ($components as $componentKey => $component) {
    AuxComponentsAuditPageService::renderComponentDetails($component);
  }
  ?>
