// import { BookIcon } from '@sanity/icons' import { format, parseISO } from 'date-fns' import { TiCalendarOutline } from 'react-icons/ti' import { defineField, defineType } from 'sanity' import authorType from '../author' export default defineType({ name: 'weddingpackage', title: 'Wedding Main Page', icon: TiCalendarOutline, type: 'document', fields: [ defineField({ name: 'title', title: 'Title', type: 'string', validation: (rule) => rule.required(), }), defineField({ name: 'content', title: 'Content Wedding', type: 'array', of: [{ type: 'block', styles: [ { title: 'Normal', value: 'normal' }, { title: 'H1', value: 'h1' }, { title: 'H2', value: 'h2' }, { title: 'H3', value: 'h3' }, { title: 'H4', value: 'h4' }, { title: 'H5', value: 'h5' }, { title: 'H6', value: 'h6' }, { title: 'ul', value: 'ul' }, { title: 'ol', value: 'ol' }, { title: 'Quote', value: 'blockquote' }, ], marks: { decorators: [ { title: 'Strong', value: 'strong' }, { title: 'Emphasis', value: 'em' }, ], annotations: [ { name: 'link', type: 'object', title: 'URL', fields: [ { title: 'URL', name: 'href', type: 'url', }, ], }, ], }, }], }), defineField({ name: 'fileWedding', title: 'File Wedding', type: 'file', options: { accept: 'application/pdf', storeOriginalFilename: true }, validation: (rule) => rule.required() }), defineField({ name: 'date', title: 'Date', type: 'datetime', initialValue: () => new Date().toISOString(), }), defineField({ name: 'author', title: 'Author', type: 'reference', to: [{ type: authorType.name }], }), ], preview: { select: { title: 'title', author: 'author.name', date: 'date', media: 'coverImage', }, prepare({ title, media, author, date }) { const subtitles = [ author && `by ${author}`, date && `on ${format(parseISO(date), 'LLL d, yyyy')}`, ].filter(Boolean) return { title, media, subtitle: subtitles.join(' ') } }, }, })