<?php
$form = is_array($form ?? null) ? $form : [];
$validationSummaryErrors = is_array($validationSummaryErrors ?? null) ? $validationSummaryErrors : [];
$errors = is_array($errors ?? null) ? $errors : [];
$warnings = is_array($warnings ?? null) ? $warnings : [];
$closeTarget = $closeTarget ?? 'helpdesk/software-products';

$values = $form;
$formId = 'software-product-form';
$active = (int) ($values['active'] ?? 1);
?>
<div class="app-details-container">
  <section>
    <?php
    $titlebar = [
        'title' => $titleText ?? t('Edit software product'),
        'backHref' => $closeTarget,
        'backTitle' => t('Back to list'),
        'actions' => [
            [
                'form' => $formId,
                'name' => 'action',
                'value' => 'save',
                'class' => 'secondary outline',
                'label' => t('Save'),
            ],
            [
                'form' => $formId,
                'name' => 'action',
                'value' => 'save_close',
                'class' => 'primary',
                'label' => t('Save & close'),
            ],
        ],
    ];
    require templatePath('partials/app-details-titlebar.phtml');
    ?>

    <?php require templatePath('partials/app-details-validation-summary.phtml'); ?>

    <?php if ($warnings): ?>
      <div class="app-details-warnings">
        <div class="notice" data-variant="info">
          <ul>
            <?php foreach ($warnings as $warning): ?>
              <li><?php e($warning); ?></li>
            <?php endforeach; ?>
          </ul>
        </div>
      </div>
    <?php endif; ?>

    <?php require __DIR__ . '/_form.phtml'; ?>
  </section>

  <aside id="app-details-aside-section">
    <div class="app-details-aside-section">
      <hgroup>
        <h2><?php e($values['code'] ?? ''); ?></h2>
        <p><?php e(t('Software product')); ?></p>
      </hgroup>
      <div class="badge-list">
        <?php if ($active): ?>
          <span class="badge" data-variant="success"><?php e(t('Active')); ?></span>
        <?php else: ?>
          <span class="badge" data-variant="neutral"><?php e(t('Inactive')); ?></span>
        <?php endif; ?>
      </div>
      <?php if (!empty($values['bc_description'])): ?>
        <hr>
        <p><small><?php e(t('BC description')); ?></small><br><?php e($values['bc_description']); ?></p>
      <?php endif; ?>
      <?php if (!empty($values['synced_at'])): ?>
        <hr>
        <p><small><?php e(t('Last synced')); ?></small><br><?php e(dt($values['synced_at'])); ?></p>
      <?php endif; ?>
      <hr>
      <?php if (!empty($values['created_at'])): ?>
        <p><small><?php e(t('Created')); ?></small><br><?php e(dt($values['created_at'])); ?></p>
      <?php endif; ?>
      <?php if (!empty($values['updated_at'])): ?>
        <p><small><?php e(t('Modified')); ?></small><br><?php e(dt($values['updated_at'])); ?></p>
      <?php endif; ?>
      <hr>
    </div>
  </aside>
</div>
