import { FormItem } from "./types";

export function createDefaultData(formItems: FormItem[]) {
  const data: Record<string, any> = {};

  for (const item of formItems) {
    data[item.field] = "";
  }

  return data;
}

export function transformDetailData(
  formItems: FormItem[],
  data: Record<string, string>,
  transform?: Record<string, string>
) {
  const detail: Record<string, any> = {};

  for (let i = 0; i < formItems.length; i++) {
    let target = "";
    const { field: source } = formItems[i];

    target = transform && transform[source] ? transform[source] : source;

    detail[source] = data[target];
  }

  return detail;
}
