import React, { useState } from "react";
import { ControlIcon, KebabIcon, TrashIcon } from "@/assets/svgs";
import { LazyLoad } from "@/components/LazyLoad";
import { GlobalContext } from "@/context/Global";
import { WorkflowTypes } from "@/utils/constants";
import { RouteConfiguration } from "../RouteConfiguration";
import { RouteIfControl } from "../RouteIfControl";
import { WorkflowWrapper } from "../WorkflowWrapper";

const RouteEditorWorkflow = ({
  workflow,
  index,
  totalFlow,
  setWorkflowData,
  onDeleteWorkflowData,
  addNewCondition,
  addVariable,
  variables,
  onSave,
  updateWorkflow,
  updateRouteConfig,
  segment = null,
  parentId = null,
}) => {
  const {
    dispatch: globalDispatch,
    state: { selectedRoute },
  } = React.useContext(GlobalContext);

  return (
    <>
      {workflow?.name === WorkflowTypes.APIRoute ? (
        <RouteConfiguration
          setWorkflowData={setWorkflowData}
          index={index}
          totalFlow={totalFlow}
          workflow={workflow}
          variables={variables}
          onSave={onSave}
          updateWorkflow={updateWorkflow}
          updateRouteConfig={updateRouteConfig}
        />
      ) : null}

      {workflow?.name === WorkflowTypes.IfControl ? (
        <RouteIfControl
          index={index}
          workflow={workflow}
          totalFlow={totalFlow}
          setWorkflowData={setWorkflowData}
          onDeleteWorkflowData={onDeleteWorkflowData}
          addNewCondition={addNewCondition}
          segment={segment}
          parentId={parentId}
          addVariable={addVariable}
          variables={variables}
          onSave={onSave}
          updateWorkflow={updateWorkflow}
        />
      ) : null}

      {![WorkflowTypes.APIRoute, WorkflowTypes.IfControl].includes(
        workflow?.name
      ) ? (
        <WorkflowWrapper
          segment={segment}
          parentId={parentId}
          onDeleteWorkflowData={onDeleteWorkflowData}
          setWorkflowData={setWorkflowData}
          index={index}
          workflow={workflow}
          addVariable={addVariable}
          totalFlow={totalFlow}
          variables={variables}
          onSave={onSave}
          updateWorkflow={updateWorkflow}
        />
      ) : null}
    </>
  );
};

export default RouteEditorWorkflow;
