import control from "images/icons/control.svg";
import controlOff from "images/icons/HandOff.svg";

import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

import { Button } from "components/shared/Button/Button";


export const ControlButton: React.FC<any> = ({ onClick, isSidebarWide }) => {
  const { t } = useTranslation();

  const [active, setActive] = useState(false);
  const [button, setButton] = useState({
    icon: control,
    active: "request-control-btn",
    inactive: "request-control-btn-disable",
    type: "control",
  });

  useEffect(() => {
    setButton({ ...button, icon: active ? control : controlOff });
  }, [active]);

  function handleClick() {
    onClick();
    setActive((prev) => !prev);
  }

  return (
    <div
      onClick={handleClick}
      className="toolbar-button-area"
    >
      <Button
        isSidebarWide={isSidebarWide}
        button={button}
        active={active}
      ></Button>
    </div>
  );
};
