import { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState';
export const linkValidation = (props, sanitizedFieldsWithoutText) => {
  return async ({
    node,
    validation: {
      options: {
        id,
        collectionSlug,
        operation,
        preferences,
        req
      }
    }
  }) => {
    /**
    * Run fieldSchemasToFormState as that properly validates link fields and link sub-fields
    */
    const result = await fieldSchemasToFormState({
      id,
      collectionSlug,
      data: node.fields,
      fields: sanitizedFieldsWithoutText,
      fieldSchemaMap: undefined,
      operation: operation === 'create' || operation === 'update' ? operation : 'update',
      permissions: {},
      preferences,
      renderAllFields: false,
      req,
      schemaPath: ''
    });
    let errorPaths = [];
    for (const fieldKey in result) {
      if (result[fieldKey].errorPaths) {
        errorPaths = errorPaths.concat(result[fieldKey].errorPaths);
      }
    }
    if (errorPaths.length) {
      return 'The following fields are invalid: ' + errorPaths.join(', ');
    }
    return true;
  };
};
//# sourceMappingURL=validate.js.map