'use strict';

function createFillBlogFormHandler(formRef, successMessage) {
  return async ({
    title,
    content,
    excerpt,
    tags
  }) => {
    const form = formRef.current;
    if (!form) return { success: false, message: "Form not ready" };
    if (title !== void 0)
      form.setValue("title", title, { shouldValidate: true });
    if (content !== void 0)
      form.setValue("content", content, { shouldValidate: true });
    if (excerpt !== void 0) form.setValue("excerpt", excerpt);
    if (tags !== void 0)
      form.setValue(
        "tags",
        tags.map((name) => ({ name }))
      );
    return { success: true, message: successMessage };
  };
}

exports.createFillBlogFormHandler = createFillBlogFormHandler;
