import React from "react";
import CreateRole from "./CreateRole";
import EditRole from "./EditRole";
import CreateJobRole from "./CreateJobRole";
import EditJobRole from "./EditJobRole";
import CreateWorkCategory from "./CreateWorkCategory";
import EditWorkCategory from "./EditWorkCategory";
import CreateCategory from "./CreateContactCategory";
import CreateContactTag from "./CreateContactTag";
import EditContactCategory from "./EditContactCategory";
import EditContactTag from "./EditContactTag";
import ManageExpenseType from "./ManageExpenseType";
import ManagePaymentMode from "./ManagePaymentMode";
import ManageExpenseStatus from "./ManageExpenseStatus";
import ManageDocumentCategory from "./ManageDocumentCategory";
import ManageDocumentType from "./ManageDocumentType";
import ManageServices from "./Services/ManageServices";
import ServiceGroups from "./Services/ServicesGroups";
import ManagePaymentHead from "./paymentAdjustmentHead/ManagePaymentHead";
import RequisitionStatus from "./InventoryManagement/RequisitionStatus";
import PurchaseOrderStatus from "./InventoryManagement/PurchaseOrderStatus";
import ProductCategory from "./InventoryManagement/ProductCategory";

const MasterModal = ({ modaldata, closeModal }) => {
  if (!modaldata?.modalType || modaldata.modalType === "delete") {
    return null;
  }

  const { modalType, item, masterType } = modaldata;

  const modalComponents = {
    "Application Role": (
      <CreateRole masmodalType={masterType} onClose={closeModal} />
    ),
    "Edit-Application Role": (
      <EditRole master={modaldata} onClose={closeModal} />
    ),
    "Job Role": <CreateJobRole onClose={closeModal} />,
    "Edit-Job Role": <EditJobRole data={item} onClose={closeModal} />,
    "Work Category": <CreateWorkCategory onClose={closeModal} />,
    "Edit-Work Category": <EditWorkCategory data={item} onClose={closeModal} />,
    "Contact Category": <CreateCategory data={item} onClose={closeModal} />,
    "Edit-Contact Category": (
      <EditContactCategory data={item} onClose={closeModal} />
    ),
    "Contact Tag": <CreateContactTag data={item} onClose={closeModal} />,
    "Edit-Contact Tag": <EditContactTag data={item} onClose={closeModal} />,
    "Expense Type": <ManageExpenseType onClose={closeModal} />,
    "Edit-Expense Type": <ManageExpenseType data={item} onClose={closeModal} />,
    "Payment Mode": <ManagePaymentMode onClose={closeModal} />,
    "Edit-Payment Mode": <ManagePaymentMode data={item} onClose={closeModal} />,
    "Expense Status": <ManageExpenseStatus onClose={closeModal} />,
    "Edit-Expense Status": (
      <ManageExpenseStatus data={item} onClose={closeModal} />
    ),
    "Document Category": <ManageDocumentCategory onClose={closeModal} />,
    "Edit-Document Category": (
      <ManageDocumentCategory data={item} onClose={closeModal} />
    ),
    "Document Type": <ManageDocumentType onClose={closeModal} />,
    "Edit-Document Type": (
      <ManageDocumentType data={item} onClose={closeModal} />
    ),
    Services: <ManageServices onClose={closeModal} />,
    "Edit-Services": <ManageServices data={item} onClose={closeModal} />,
    "Manage-Services": <ServiceGroups service={item} onClose={closeModal} />,
    "Payment Adjustment Head": <ManagePaymentHead onClose={closeModal} />,
    "Edit-Payment Adjustment Head": <ManagePaymentHead data={item} onClose={closeModal} />,

    "Requisition Status": <RequisitionStatus onClose={closeModal} />,
    "Edit-Requisition Status": (
      <RequisitionStatus data={item} onClose={closeModal} />
    ),
    "Purchase Order Status": <PurchaseOrderStatus onClose={closeModal} />,
    "Edit-Purchase Order Status": (
      <PurchaseOrderStatus data={item} onClose={closeModal} />
    ),
    "Product Category": <ProductCategory onClose={closeModal} />,
    "Edit-Product Category": (
      <ProductCategory data={item} onClose={closeModal} />
    ),
  };

  return (
    <div className="p-2 p-md-1">
      <div className="text-center">
        <p className="fs-5 fw-semibold">{`${(masterType, " ", modalType)}`}</p>
      </div>
      {modalComponents[modalType] || null}
    </div>
  );
};

export default MasterModal;
