import * as Yup from "yup";

import dayjs from "dayjs";
import { BranchRole, showAdmin } from "../../../types/App";

export const getInitialValues = (objectToEdit: showAdmin | any): any => {
  console.log(objectToEdit, "");

  const selects =
    objectToEdit?.branches?.map((item: BranchRole, index: number) => {
      return { branch: item?.branch?.id, role: item?.role?.id };
    }) ?? [];

  return {
    id: objectToEdit?.user?.id ?? null,
    username: objectToEdit?.user?.username ?? null,
    email: objectToEdit?.user?.email ?? null,
    type: objectToEdit?.user?.type ?? null,
    status: objectToEdit?.user?.status === "active" ? true : false,
    selects: selects,
    password: null,
  };
};

export const getValidationSchema = () => {
  return Yup.object().shape({
    username: Yup.string().required("validation.required"),
    password: Yup.string()
      .required("validation.required")
      .min(8, "validation.Password_must_be_at_least_8_characters_long"),
    type: Yup.string().required("validation.required"),
  });
};

export const getEditValidationSchema = () => {
  // validate input
  return Yup.object().shape({
    username: Yup.string().required("validation.required"),
    type: Yup.string().required("validation.required"),
    // branch_id: Yup.array().required("validation.required"),
    // roles: Yup.string().required("validation.required"),
  });
};
