import virtual from 'doom-@api-virtual';
import { last, upperFirst } from 'es-toolkit';
import { get } from 'es-toolkit/compat';
export const modelName = (ref) => {
    const lastPart = last(ref.split('.'));
    return upperFirst(lastPart.startsWith('#') ? lastPart.slice(1) : lastPart);
};
export const resolveRef = (openapi, ref) => {
    if (!ref.startsWith('#/')) {
        ref = `#/components/schemas/${ref}`;
    }
    return get(openapi, ref.slice(2).split('/'));
};
const DEFAULT_COMMON_REFS = {
    'v1alpha1.ListMeta': 'common-definitions/list-meta/#ListMeta',
    'v1.ObjectMeta': 'common-definitions/object-meta/#ObjectMeta',
};
const K8S_DOC_PREFIX = 'https://kubernetes.io/docs/reference/kubernetes-api/';
export const COMMON_REFS = {
    ...Object.fromEntries(Object.entries(DEFAULT_COMMON_REFS).map(([key, value]) => [
        key,
        `${K8S_DOC_PREFIX}${value}`,
    ])),
    ...virtual.references,
};
export const omitRoutePathRefs = (routePath) => Object.fromEntries(Object.entries(COMMON_REFS).filter(([, value]) => routePath !== value.split('#')[0]));
export const CJK_PATTERN = /\p{sc=Han}/u;
export const handleCJKWhitespaces = (text) => {
    if (!text) {
        return '';
    }
    text = text.at(0)?.match(CJK_PATTERN) ? text : ` ${text}`;
    return text.at(-1)?.match(CJK_PATTERN) ? text : `${text} `;
};
