import React, { useRef, useState } from "react";
import { ControlIcon, KebabIcon, TrashIcon } from "@/assets/svgs";
import { LazyLoad } from "@/components/LazyLoad";
import { GlobalContext, setGLobalProperty } from "@/context/Global";
import { workflowConfig } from "@/utils/templates/api/workflow";
import { StringCaser } from "@/utils/utils";
import { DropdownOptions } from "@/components/DropdownOptions";
// import { RouteIfControlModal } from "./RouteIfControlModal";

const RouteSwitchControl = ({
  onDeleteWorkflowData,
  index,
  workflow,
  segment,
  parentId,
}) => {
  const {
    dispatch: globalDispatch,
    state: { selectedRoute },
  } = React.useContext(GlobalContext);
  const containerRef = useRef(null);

  const dropdownOptions = [
    {
      action: () => onDeleteWorkflowData(workflow?.id, segment, parentId),
      icon: <TrashIcon />,
    },
  ];
  const [open, setOpen] = useState(false);

  const onToggleModal = (value, e) => {
    if (value && e && e.target.id === "control") {
      setOpen(true);
    } else if (!value && open) {
      setOpen(false);
    }
  };
  return (
    <div
      ref={containerRef}
      className="group relative h-[4.3438rem] max-h-[4.3375rem] min-h-[4.3438rem] w-[16.25rem] "
    >
      <div
        onClick={(e) => onToggleModal(true, e)}
        id={`control`}
        className="relative flex h-[4.3438rem] max-h-[4.3375rem] min-h-[4.3438rem] w-[16.25rem] cursor-pointer flex-col gap-1 rounded-lg border border-solid border-primaryBlue bg-white p-5 px-3 py-2 shadow-md shadow-primaryBlue transition ease-in-out"
      >
        <div className={"flex h-7 w-full gap-3"}>
          <div className="flex grow items-center justify-start gap-2">
            <span className=" h-5 max-h-5 rounded-md bg-primaryBlue px-2 py-1 text-[.725rem] leading-snug tracking-widest text-white">
              {/* {selectedRoute?.method && selectedRoute?.method} */}
            </span>
            <span>switch control</span>
          </div>

          <LazyLoad>
            <DropdownOptions options={dropdownOptions} />
          </LazyLoad>
        </div>
        <div className={"flex gap-3"}>
          {/* <span className=" ">{selectedRoute?.name || "New Api Route"}</span> */}
        </div>
      </div>
      <div>
        {/* <LazyLoad count={5}>
          <RouteSwitchControlModal
            open={open}
            onToggleModal={onToggleModal}
            parentRef={containerRef}
          />
        </LazyLoad> */}
      </div>
    </div>
  );
};

export default RouteSwitchControl;
