<?php
$toolbarFilterSchema = is_array($toolbarFilterSchema ?? null) ? $toolbarFilterSchema : [];
$searchToolbarFilterSchema = is_array($searchToolbarFilterSchema ?? null) ? $searchToolbarFilterSchema : [];
$drawerToolbarFilterSchema = is_array($drawerToolbarFilterSchema ?? null) ? $drawerToolbarFilterSchema : [];
$toolbarFilterState = is_array($toolbarFilterState ?? null) ? $toolbarFilterState : [];
$toolbarOptionSets = is_array($toolbarOptionSets ?? null) ? $toolbarOptionSets : [];
$clientFilterSchema = is_array($clientFilterSchema ?? null) ? $clientFilterSchema : [];
$searchConfig = is_array($searchConfig ?? null) ? $searchConfig : null;
$filterChipMeta = is_array($filterChipMeta ?? null) ? $filterChipMeta : [];
$canCreate = $canCreate ?? false;
$canManage = $canManage ?? false;
$activeView = $activeView ?? 'open';
$myAssignedOnly = $myAssignedOnly ?? false;
?>
<?php
$listTitle = t('Handovers');
ob_start();
?>
<?php if ($canManage): ?>
  <button type="button" class="danger outline small" data-handovers-bulk="delete" hidden>
    <i class="bi bi-trash3-fill"></i> <?php e(t('Delete')); ?>
  </button>
<?php endif; ?>
<?php if ($canCreate): ?>
  <a role="button" class="app-action-success" href="<?php e(requestPathWithReturnTarget('helpdesk/handovers/create', \MintyPHP\Http\Request::pathWithQuery())); ?>">
    <i class="bi bi-plus"></i> <?php e(t('New handover')); ?>
  </a>
<?php endif; ?>
<?php
$listTitleActionsHtml = ob_get_clean();
require templatePath('partials/app-list-titlebar.phtml');
?>

<div class="app-tabs-nav" style="margin-bottom: 12px;">
  <a
    href="<?php e(lurl('helpdesk/handovers') . '?view=active'); ?>"
    role="button"
    class="<?php e($activeView === 'active' ? 'primary small' : 'secondary outline small'); ?>"
  ><?php e(t('In progress')); ?></a>
  <a
    href="<?php e(lurl('helpdesk/handovers') . '?view=done'); ?>"
    role="button"
    class="<?php e($activeView === 'done' ? 'primary small' : 'secondary outline small'); ?>"
  ><?php e(t('Done')); ?></a>
</div>

<?php
$filterUiNamespace = 'helpdesk-handovers';
require templatePath('partials/app-list-filters.phtml');
?>
<div class="app-list-table">
  <div id="helpdesk-handovers-grid"></div>
</div>

<script src="<?php e(assetVersion('vendor/gridjs/gridjs.umd.js')); ?>"></script>
<?php if ($canManage): ?>
  <script src="<?php e(assetVersion('vendor/gridjs/plugins/selection/selection.umd.js')); ?>"></script>
<?php endif; ?>
<script type="application/json" id="page-config-helpdesk-handovers"><?php gridJsonForJs([
    'dataUrl' => lurl('helpdesk/handovers-data') . '?view=' . rawurlencode($activeView ?? 'active'),
    'gridLang' => gridLang(),
    'gridSearch' => $searchConfig,
    'filterSchema' => $clientFilterSchema,
    'filterChipMeta' => $filterChipMeta,
    'editBaseUrl' => lurl('helpdesk/handovers/edit/'),
    'canManage' => $canManage,
    'activeView' => $activeView,
    'myAssignedOnly' => $myAssignedOnly,
    'bulkUrl' => $canManage ? lurl('helpdesk/handovers/bulk/') : '',
    'csrfKey' => $csrfKey ?? '',
    'csrfToken' => $csrfToken ?? '',
    'labels' => [
        'domain' => t('Domain'),
        'status' => t('Status'),
        'debitorName' => t('Customer'),
        'productDisplay' => t('Software product'),
        'assignedTo' => t('Assigned to'),
        'dueDate' => t('Due date'),
        'createdAt' => t('Created'),
        'createdBy' => t('Created by'),
        'selectAll' => t('Select all'),
        'bulkDeleteConfirm' => t('Delete selected handovers?'),
        'bulkDeleteSuccess' => t('%d handover(s) deleted'),
        'bulkDeleteError' => t('Failed to delete handovers'),
    ],
]); ?></script>
<script type="module" src="<?php e(assetVersion('modules/helpdesk/js/pages/helpdesk-handovers-index.js')); ?>"></script>
