---
import SingleLayout from '@layouts/SingleLayout.astro'
import { getConfig } from '@libs/config'
import { getData } from '@libs/data'

function getVersionsSortedDesc<TKey extends string, TVersions extends Record<TKey, string>>(
  versions: TVersions[],
  orderBy: TKey
) {
  return [...versions].sort((versionA, versionB) => {
    return versionB[orderBy].localeCompare(versionA[orderBy])
  })
}
---

<SingleLayout
  title="Versions"
  description="An appendix of hosted documentation for nearly every release of Bootstrap, from v1 through v5."
>
  
    {
      getVersionsSortedDesc(getData('docs-versions'), 'group').map((docsVersion) => {
        return (

{docsVersion.group}
            
{docsVersion.description}
            
              {docsVersion.versions
                .slice()
                .sort((a, b) => b.localeCompare(a))
                .map((version) => {
                  const isCurrentVersion = version === getConfig().docs_version

                  return (
                    <a
                      class:list={[
                        'list-group-item list-group-item-action py-2 text-primary',
                        isCurrentVersion && 'd-flex justify-content-between align-items-center'
                      ]}
                      href={`${docsVersion.baseurl}/${version}/`}
                    >
                      {version}
                      {isCurrentVersion && <span class="badge text-bg-primary">Latest</span>}
                    </a>
                  )
                })}
            </div>
          </div>
        )
      })
    }
  
</SingleLayout>
