<?php
use MintyPHP\Router;
use MintyPHP\Http\Request;

$canCreateTenants = (bool) ($canCreateTenants ?? false);
$toolbarFilterSchema = is_array($toolbarFilterSchema ?? null) ? $toolbarFilterSchema : [];
$searchToolbarFilterSchema = is_array($searchToolbarFilterSchema ?? null) ? $searchToolbarFilterSchema : [];
$drawerToolbarFilterSchema = is_array($drawerToolbarFilterSchema ?? null) ? $drawerToolbarFilterSchema : [];
$toolbarFilterState = is_array($toolbarFilterState ?? null) ? $toolbarFilterState : [];
$filterChipMeta = is_array($filterChipMeta ?? null) ? $filterChipMeta : [];
$clientFilterSchema = is_array($clientFilterSchema ?? null) ? $clientFilterSchema : [];
$searchConfig = is_array($searchConfig ?? null) ? $searchConfig : null;
?>
<?php
$breadcrumbs = [
  ['label' => t('Home'), 'path' => 'admin'],
  ['label' => t('Tenants')],
];
require templatePath('partials/app-breadcrumb.phtml');
?>
<?php
$listTitle = t('Tenants');
ob_start();
?>
<?php if ($canCreateTenants): ?>
  <a role="button" class="app-action-success" href="<?php e(requestPathWithReturnTarget('admin/tenants/create', Request::pathWithQuery())); ?>">
    <i class="bi bi-plus"></i> <?php e(t('Create tenant')); ?>
  </a>
<?php endif; ?>
<?php
$listTitleActionsHtml = ob_get_clean();
require templatePath('partials/app-list-titlebar.phtml');
?>
<?php
$filterUiNamespace = 'tenants';
require templatePath('partials/app-list-filters.phtml');
?>
<div class="app-list-table">
  <div id="tenants-grid"></div>
</div>

<?php
$gridLang = json_decode(appBufferValue('grid_lang'), true);
if (!is_array($gridLang)) {
  $gridLang = [];
}
$pageConfig = [
  'gridSearch' => $searchConfig,
  'filterSchema' => $clientFilterSchema,
  'filterChipMeta' => $filterChipMeta,
  'gridLang' => $gridLang,
  'labels' => [
    'avatar' => t('Avatar'),
    'description' => t('Description'),
    'status' => t('Status'),
    'theme' => t('Theme'),
    'sso' => t('SSO'),
    'activeUsers' => t('Active users'),
    'inactiveUsers' => t('Inactive users'),
    'created' => t('Created'),
    'active' => t('Active'),
    'default' => t('Default'),
    'microsoftOnly' => t('Microsoft only'),
    'inactive' => t('Inactive'),
  ],
];
?>
<script src="<?php e(assetVersion('vendor/gridjs/gridjs.umd.js')); ?>"></script>
<script type="application/json" id="page-config-admin-tenants-index"><?php gridJsonForJs($pageConfig); ?></script>
<script type="module" src="<?php e(assetVersion('js/pages/admin-tenants-index.js')); ?>"></script>
