import { ComponentSchema, fields } from '@keystatic/core';
import type { ContentComponent } from '@keystatic/core/content-components';

import { createContentField } from './content';
import { createPathField } from './path';
import { createMetaField } from './meta';

export const createArticleField = (
  imageSubfolder: string,
  defaultPath: string = '',
  additionalComponents?: Record<string, ContentComponent>
) => ({
  title: fields.slug({ name: { label: 'Title' } }),
  summary: fields.text({
    label: 'Summary',
    multiline: true,
  }),
  path: createPathField(defaultPath),
  cover: fields.object({
    src: fields.image({
      label: 'Cover Image',
      directory: `public/images/covers/${imageSubfolder}`,
      publicPath: `/image/covers/${imageSubfolder}`,
    }),
    alt: fields.text({ label: 'Alt' }),
    caption: fields.text({
      label: 'Caption',
      multiline: true,
    }),
    showInHeader: fields.checkbox({
      label: 'Show in Header',
      defaultValue: false,
    }),
  }),
  meta: createMetaField(),
  content: createContentField(imageSubfolder, additionalComponents),
});
