<?php
$searchToolbarFilterSchema = is_array($searchToolbarFilterSchema ?? null) ? $searchToolbarFilterSchema : [];
$drawerToolbarFilterSchema = is_array($drawerToolbarFilterSchema ?? null) ? $drawerToolbarFilterSchema : [];
$toolbarFilterState = is_array($toolbarFilterState ?? null) ? $toolbarFilterState : [];
$toolbarOptionSets = is_array($toolbarOptionSets ?? null) ? $toolbarOptionSets : [];
$filterUiNamespace = strtolower(trim((string) ($filterUiNamespace ?? 'list')));
$filterUiNamespace = preg_replace('/[^a-z0-9_-]+/', '-', $filterUiNamespace) ?: 'list';
$toolbarId = trim((string) ($filterToolbarId ?? ($filterUiNamespace . '-toolbar')));
$drawerToolbarId = trim((string) ($filterDrawerToolbarId ?? ($filterUiNamespace . '-drawer-toolbar')));
$drawerTitleId = trim((string) ($filterDrawerTitleId ?? ($filterUiNamespace . '-filter-drawer-title')));
$filterLabel = trim((string) ($filterLabel ?? t('Filter')));
$filterCloseLabel = trim((string) ($filterCloseLabel ?? t('Close filters')));
$filterApplyLabel = trim((string) ($filterApplyLabel ?? t('Apply filters')));
$filterChipsClearAllLabel = trim((string) ($filterChipsClearAllLabel ?? t('Clear all filters')));
$filterChipsRemoveLabel = trim((string) ($filterChipsRemoveLabel ?? t('Remove filter')));
$filterLiveAppliedMessage = trim((string) ($filterLiveAppliedMessage ?? t('Filters applied')));
$filterLiveRemovedMessage = trim((string) ($filterLiveRemovedMessage ?? t('Filter removed')));
$filterLiveClearedMessage = trim((string) ($filterLiveClearedMessage ?? t('All filters cleared')));

if ($toolbarId === '') {
    $toolbarId = $filterUiNamespace . '-toolbar';
}
if ($drawerToolbarId === '') {
    $drawerToolbarId = $filterUiNamespace . '-drawer-toolbar';
}
if ($drawerTitleId === '') {
    $drawerTitleId = $filterUiNamespace . '-filter-drawer-title';
}
if ($filterLabel === '') {
    $filterLabel = t('Filter');
}
if ($filterCloseLabel === '') {
    $filterCloseLabel = t('Close filters');
}
if ($filterApplyLabel === '') {
    $filterApplyLabel = t('Apply filters');
}
if ($filterChipsClearAllLabel === '') {
    $filterChipsClearAllLabel = t('Clear all filters');
}
if ($filterChipsRemoveLabel === '') {
    $filterChipsRemoveLabel = t('Remove filter');
}
if ($filterLiveAppliedMessage === '') {
    $filterLiveAppliedMessage = t('Filters applied');
}
if ($filterLiveRemovedMessage === '') {
    $filterLiveRemovedMessage = t('Filter removed');
}
if ($filterLiveClearedMessage === '') {
    $filterLiveClearedMessage = t('All filters cleared');
}
?>
<div class="app-list-toolbar" id="<?php e($toolbarId); ?>">
  <?php renderGridFilterToolbar($searchToolbarFilterSchema, $toolbarFilterState, $toolbarOptionSets); ?>
  <button
    type="button"
    class="outline secondary icon-button"
    data-filter-drawer-open
    data-tooltip="<?php e($filterLabel); ?>"
    data-tooltip-pos="top"
    aria-label="<?php e($filterLabel); ?>"
    aria-expanded="false"
  >
    <i class="bi bi-funnel"></i> <?php e($filterLabel); ?>
  </button>
</div>
<div
  class="app-active-filters"
  data-active-filter-chips
  data-filter-chips-clear-all-label="<?php e($filterChipsClearAllLabel); ?>"
  data-filter-chips-remove-label="<?php e($filterChipsRemoveLabel); ?>"
></div>
<p
  class="app-visually-hidden"
  data-filter-live-region
  data-filter-live-applied-message="<?php e($filterLiveAppliedMessage); ?>"
  data-filter-live-removed-message="<?php e($filterLiveRemovedMessage); ?>"
  data-filter-live-cleared-message="<?php e($filterLiveClearedMessage); ?>"
  aria-live="polite"
  aria-atomic="true"
></p>
<div
  class="app-filter-drawer"
  data-filter-drawer
  role="dialog"
  aria-modal="true"
  aria-hidden="true"
  aria-labelledby="<?php e($drawerTitleId); ?>"
  hidden
>
  <aside class="app-filter-drawer-panel" data-filter-drawer-panel>
    <header class="app-filter-drawer-header">
      <h2 id="<?php e($drawerTitleId); ?>"><?php e($filterLabel); ?></h2>
      <button
        type="button"
        class="transparent icon-button"
        data-filter-drawer-close
        aria-label="<?php e($filterCloseLabel); ?>"
      >
        <i class="bi bi-x-lg"></i>
      </button>
    </header>
    <div class="app-filter-drawer-body">
      <div class="app-list-toolbar" id="<?php e($drawerToolbarId); ?>">
        <?php renderGridFilterToolbar($drawerToolbarFilterSchema, $toolbarFilterState, $toolbarOptionSets); ?>
      </div>
    </div>
    <footer class="app-filter-drawer-footer">
      <button type="button" class="primary" data-filter-drawer-apply>
        <?php e($filterApplyLabel); ?>
      </button>
    </footer>
  </aside>
</div>
