import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useCallback } from 'react';
import { useAtomValue } from 'jotai';
import { DownloadIcon } from '@redocly/theme/icons/DownloadIcon/DownloadIcon';
import { getPathPrefix, combineUrls } from '@redocly/theme/core/openapi';
import { Button } from '@redocly/theme/components/Button/Button';
import { DocumentIcon } from '@redocly/theme/icons/DocumentIcon/DocumentIcon';
import { JsonIcon } from '@redocly/theme/icons/JsonIcon/JsonIcon';
import { FileIcon } from '@redocly/theme/icons/FileIcon/FileIcon';
import { useDownloadInfo } from './useDownloadInfo.js';
import { globalStoreAtom } from '../../jotai/store.js';
import { useTelemetry } from '../../hooks/index.js';
import { styled } from '../../styled-components.js';
function DownloadSpecificationComponent() {
    const telemetry = useTelemetry();
    const { options } = useAtomValue(globalStoreAtom);
    const pathPrefix = getPathPrefix();
    const downloadObjects = useDownloadInfo({
        downloadUrls: options.downloadUrls,
    });
    const renderIcon = useCallback((iconType) => {
        switch (iconType) {
            case 'yaml':
                return _jsx(DocumentIcon, {});
            case 'json':
                return _jsx(JsonIcon, {});
            default:
                return _jsx(FileIcon, {});
        }
    }, []);
    if (!downloadObjects) {
        return _jsx(_Fragment, {});
    }
    return (_jsx(Wrapper, { children: (downloadObjects || []).map(({ title, url, iconType }) => {
            const downloadUrl = pathPrefix ? combineUrls(pathPrefix, url) : url;
            return (_jsxs(Card, { onClick: () => telemetry.send({ type: 'openapi_docs.download_definition.clicked' }), children: [_jsxs(FileName, { children: [renderIcon(iconType), _jsx("a", { href: downloadUrl, target: "_blank", download: true, rel: "noreferrer", children: title })] }), _jsx("a", { href: downloadUrl, target: "_blank", download: true, rel: "noreferrer", children: _jsx(Button, { variant: "text", size: "small", icon: _jsx(DownloadIcon, {}) }) })] }, title));
        }) }));
}
export const DownloadSpecification = memo(DownloadSpecificationComponent);
const Card = styled.div `
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;

  border-bottom: 1px solid var(--border-color-secondary);
  padding-bottom: var(--spacing-sm);
  :last-of-type {
    padding-bottom: 0px;
    border-bottom: none;
  }
`;
const FileName = styled.span `
  display: flex;
  width: calc(100% - 25px);
  gap: var(--spacing-xs);
  align-items: center;

  svg {
    flex-shrink: 0;
  }
  a {
    width: 100%;
    color: var(--text-color-primary);
    word-break: break-word;
    text-decoration: none;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
`;
const Wrapper = styled.div `
  display: flex;
  align-items: center;
  align-self: flex-start;
  justify-content: space-between;
  flex-direction: column;
  gap: var(--spacing-sm);
  font-size: var(--font-size-base);
`;
//# sourceMappingURL=DownloadSpecification.js.map