import { toastController } from "@ionic/core";
import valueToPath from "./valueToPath";
export default async function importUsersFromData(fireenjin, results) {
  for (const data of results) {
    let userData = {
      tags: ["csvImport"],
    };
    const columnKeys = Object.keys(data);
    for (const columnKey of columnKeys) {
      userData = valueToPath(columnKey, ["firstName", "lastName", "email", "phone", "address", "name"].includes(columnKey)
        ? data[columnKey] === "TRUE"
        : data[columnKey], userData);
      if (columnKey === "name") {
        const nameParts = data[columnKey].split(" ");
        if (nameParts[0]) {
          userData.firstName = nameParts[0];
        }
        if (nameParts[1]) {
          userData.lastName = nameParts[1];
        }
      }
    }
    await fireenjin.sdk.addUser({
      data: {
        address: {
          full: userData.address,
        },
        firstName: userData.firstName ? userData.firstName : null,
        lastName: userData.lastName ? userData.lastName : null,
        phone: userData.phone ? userData.phone : null,
        email: userData.email ? userData.email : null,
        tags: userData.tags ? userData.tags : [],
      },
    });
  }
  (await toastController.create({
    message: `Successfully imported ${(results === null || results === void 0 ? void 0 : results.length) || 0} records.`,
    duration: 3000,
  })).present();
}
//# sourceMappingURL=importUsersFromData.js.map