@php
  $configData = Helper::appClasses();
  $ownerHomeRoute = \Illuminate\Support\Facades\Auth::check()
    ? \App\Support\Authorization\PermissionCatalog::firstAccessibleRouteFor(\Illuminate\Support\Facades\Auth::user())
    : route('owner.dashboard');
  $canCatalogs = auth()->user()?->can('owner.packages.view')
    || auth()->user()?->can('owner.gifts.view')
    || auth()->user()?->can('owner.artists.view')
    || auth()->user()?->can('owner.other_costs.view');
  $canSettings = auth()->user()?->can('owner.settings_general.view')
    || auth()->user()?->can('owner.team.view')
    || auth()->user()?->can('owner.roles.view')
    || auth()->user()?->can('owner.payments.view')
    || auth()->user()?->can('owner.quote_rules.view');
@endphp

<aside id="layout-menu" class="layout-menu menu-vertical menu" @foreach ($configData['menuAttributes'] as $attribute => $value) {{ $attribute }}="{{ $value }}" @endforeach>
  <div class="app-brand demo">
    <a href="{{ $ownerHomeRoute }}" class="app-brand-link">
      <span class="app-brand-logo demo">@include('_partials.macros')</span>
      <span class="app-brand-text demo menu-text fw-bold ms-3">Propietario</span>
    </a>

    <a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large ms-auto">
      <i class="icon-base ti menu-toggle-icon d-none d-xl-block"></i>
      <i class="icon-base ti tabler-x d-block d-xl-none"></i>
    </a>
  </div>

  <div class="menu-inner-shadow"></div>

  <ul class="menu-inner py-1">
    @can('owner.dashboard.view')
    <li class="menu-item {{ request()->routeIs('owner.dashboard') ? 'active' : '' }}">
      <a href="{{ route('owner.dashboard') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-smart-home"></i>
        <div>Dashboard</div>
      </a>
    </li>
    @endcan

    @can('owner.serenatas.view')
    <li class="menu-item {{ request()->routeIs('owner.serenatas.*') && !request()->routeIs('owner.serenatas.planner*') ? 'active' : '' }}">
      <a href="{{ route('owner.serenatas.index') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-music"></i>
        <div>Serenatas</div>
      </a>
    </li>
    @endcan

    @can('owner.planner.view')
    <li class="menu-item {{ request()->routeIs('owner.serenatas.planner*') ? 'active' : '' }}">
      <a href="{{ route('owner.serenatas.planner') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-route"></i>
        <div>Planificador</div>
      </a>
    </li>
    @endcan

    @can('owner.clients.view')
    <li class="menu-item {{ request()->routeIs('owner.clients.*') ? 'active' : '' }}">
      <a href="{{ route('owner.clients.index') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-users-group"></i>
        <div>Clientes</div>
      </a>
    </li>
    @endcan

    @can('owner.quotes.view')
    <li class="menu-item {{ request()->routeIs('owner.quotes.calculator*') ? 'active' : '' }}">
      <a href="{{ route('owner.quotes.calculator') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-calculator"></i>
        <div>Cotizador</div>
      </a>
    </li>
    @endcan

    @can('owner.reports.view')
    <li class="menu-item {{ request()->routeIs('owner.reports.*') ? 'active' : '' }}">
      <a href="{{ route('owner.reports.index') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-report-money"></i>
        <div>Reportes</div>
      </a>
    </li>
    @endcan

    @if (auth()->user()?->can('owner.external_partners.view') || auth()->user()?->can('owner.mariachi_groups.view') || $canCatalogs || $canSettings)
    <li class="menu-item pe-none">
      <div class="menu-link py-2">
        <div class="w-100 border-top"></div>
      </div>
    </li>
    @endif

    @can('owner.external_partners.view')
    <li class="menu-item {{ request()->routeIs('owner.settings.external-partners*') ? 'active' : '' }}">
      <a href="{{ route('owner.settings.external-partners') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-users-group"></i>
        <div>Externos (Cedidas)</div>
      </a>
    </li>
    @endcan

    @can('owner.mariachi_groups.view')
    <li class="menu-item {{ request()->routeIs('owner.settings.mariachi-groups*') ? 'active' : '' }}">
      <a href="{{ route('owner.settings.mariachi-groups') }}" class="menu-link">
        <i class="menu-icon icon-base ti tabler-music"></i>
        <div>Grupos Mariachi</div>
      </a>
    </li>
    @endcan

    @if ($canSettings)
    <li class="menu-item {{ request()->routeIs('owner.settings.index') || request()->routeIs('owner.settings.team*') || request()->routeIs('owner.settings.roles*') || request()->routeIs('owner.settings.payments*') || request()->routeIs('owner.settings.quote-rules*') ? 'active open' : '' }}">
      <a href="javascript:void(0);" class="menu-link menu-toggle">
        <i class="menu-icon icon-base ti tabler-settings"></i>
        <div>Configuración</div>
      </a>
      <ul class="menu-sub">
        @can('owner.settings_general.view')
        <li class="menu-item {{ request()->routeIs('owner.settings.index') ? 'active' : '' }}">
          <a href="{{ route('owner.settings.index') }}" class="menu-link">
            <div>General</div>
          </a>
        </li>
        @endcan
        @can('owner.team.view')
        <li class="menu-item {{ request()->routeIs('owner.settings.team') ? 'active' : '' }}">
          <a href="{{ route('owner.settings.team') }}" class="menu-link">
            <div>Equipo</div>
          </a>
        </li>
        @endcan
        @can('owner.roles.view')
        <li class="menu-item {{ request()->routeIs('owner.settings.roles') ? 'active' : '' }}">
          <a href="{{ route('owner.settings.roles') }}" class="menu-link">
            <div>Roles</div>
          </a>
        </li>
        @endcan
        @can('owner.payments.view')
        <li class="menu-item {{ request()->routeIs('owner.settings.payments*') ? 'active' : '' }}">
          <a href="{{ route('owner.settings.payments') }}" class="menu-link">
            <div>Pagos</div>
          </a>
        </li>
        @endcan
        @can('owner.quote_rules.view')
        <li class="menu-item {{ request()->routeIs('owner.settings.quote-rules*') ? 'active' : '' }}">
          <a href="{{ route('owner.settings.quote-rules') }}" class="menu-link">
            <div>Reglas de cotizador</div>
          </a>
        </li>
        @endcan
      </ul>
    </li>
    @endif
  </ul>
</aside>
