import cx from 'clsx';
import { ReactNode, useState } from 'react';
import { Sails } from 'sails-js';
import { getPreformattedText } from '@/shared/helpers';
import { PreformattedBlock } from '@/shared/ui';
import ArrowSVG from '../../assets/arrow.svg?react';
import {
ISailsCtorFuncParams,
ISailsFuncArg,
SailsServiceEvent,
SailsServiceFunc,
SailsServiceQuery,
} from '../../types';
import styles from './sails-preview.module.scss';
type Props = {
value: Sails;
};
function Accordion({ heading, children }: { heading: string; children: ReactNode }) {
const [isOpen, setIsOpen] = useState(true);
const toggle = () => setIsOpen((prevValue) => !prevValue);
return (
{isOpen && children}
);
}
function SailsPreview({ value }: Props) {
const { scaleCodecTypes, ctors, services } = value;
const getArgs = (args: ISailsFuncArg[]) => args.map(({ name, type }) => `${name}: ${type}`).join(', ');
const getReturnType = (type: unknown) => JSON.stringify(type).replace(/"/g, '');
const getFunction = (name: string, returnType?: string, args?: ISailsFuncArg[]) =>
`${name}: (${args ? getArgs(args) : ''}) => ${returnType}`;
const getConstructorFunction = (name: string, { args }: ISailsCtorFuncParams) => getFunction(name, 'void', args);
const getServiceFunction = (name: string, { args, returnType }: SailsServiceFunc | SailsServiceQuery) =>
getFunction(name, getReturnType(returnType), args);
const getEventFunction = (name: string, { type }: SailsServiceEvent) => getFunction(name, getReturnType(type));
const getFunctions = (funcs: Record, getFunc: (name: string, func: T) => string) =>
Object.entries(funcs)
.map(([name, func]) => getFunc(name, func))
.join('\n');
const serviceEntries = Object.entries(services);
const renderServices = () =>
serviceEntries.map(([name, { functions, queries, events }]) => (
));
return (
);
}
export { SailsPreview };