'use strict';

var config = require('fumadocs-mdx/config');
var schemas = require('../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js');

// Reusable schema for date
const createDateSchema = () => schemas.preprocess((arg) => {
    if (arg instanceof Date) {
        // Format Date object to YYYY-MM-DD string
        const year = arg.getFullYear();
        const month = (arg.getMonth() + 1).toString().padStart(2, '0');
        const day = arg.getDate().toString().padStart(2, '0');
        return `${year}-${month}-${day}`;
    }
    if (typeof arg === 'string') {
        return arg.trim();
    }
    // For other types or null/undefined, let the subsequent string validation handle it
    return arg;
}, schemas.string()
    .regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format or a valid Date object")
    .refine((val) => !isNaN(new Date(val).getTime()), 'Invalid date!'));
// common docs frontmatter  schema
// @ts-ignore
const createCommonDocsSchema = () => config.frontmatterSchema
    .extend({
    date: createDateSchema(),
    author: schemas.string().optional(),
    keywords: schemas.array(schemas.string()).optional(),
});
// common meta schema
// @ts-ignore
const createCommonMetaSchema = () => config.metaSchema.extend({});
const remarkInstallOptions = {
    persist: {
        id: 'package-manager',
    },
};

exports.createCommonDocsSchema = createCommonDocsSchema;
exports.createCommonMetaSchema = createCommonMetaSchema;
exports.createDateSchema = createDateSchema;
exports.remarkInstallOptions = remarkInstallOptions;
