<script lang="ts">
  let {
    rail,
    children
  }: {
    rail: () => unknown;
    children: () => unknown;
  } = $props();
</script>

<div class="secondary-rail-layout">
  <aside class="secondary-rail-layout-nav">
    {@render rail()}
  </aside>

  <div class="secondary-rail-layout-panel">
    <div class="secondary-rail-layout-content">
      {@render children()}
    </div>
  </div>
</div>

<style>
  .secondary-rail-layout {
    margin: calc(var(--content-padding, 0rem) * -1);
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    align-items: stretch;
    flex: 1;
    height: calc(100% + (var(--content-padding, 0rem) * 2));
    min-height: calc(100% + (var(--content-padding, 0rem) * 2));
    overflow: clip;
  }

  .secondary-rail-layout-nav,
  .secondary-rail-layout-panel {
    min-width: 0;
    min-height: 0;
  }

  .secondary-rail-layout-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--panel);
  }

  .secondary-rail-layout-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
  }

  .secondary-rail-layout-content > :global(*) {
    flex: 1 0 auto;
    min-height: 100%;
  }

  @media (max-width: 980px) {
    .secondary-rail-layout {
      grid-template-columns: 1fr;
      flex: none;
      height: auto;
      min-height: auto;
      max-height: none;
    }

    .secondary-rail-layout-nav {
      border-bottom: 1px solid var(--line);
    }

    .secondary-rail-layout-content {
      height: auto;
    }
  }
</style>
