File size: 1,430 Bytes
c10f8f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {
  PanelLeftClose,
  PanelLeftOpen,
  Eye,
  MessageCircleCode,
} from "lucide-react";
import classNames from "classnames";

import { Button } from "@/components/ui/button";
import { useEditor } from "@/hooks/useEditor";

const TABS = [
  {
    value: "chat",
    label: "Chat",
    icon: MessageCircleCode,
  },
  {
    value: "preview",
    label: "Preview",
    icon: Eye,
  },
];

export const SwitchTab = ({ isMobile = false }: { isMobile?: boolean }) => {
  const { currentTab, setCurrentTab } = useEditor();

  if (isMobile) {
    return (
      <div className="flex items-center justify-center gap-1 bg-neutral-900 rounded-full p-1">
        {TABS.map((item) => (
          <Button
            key={item.value}
            variant={currentTab === item.value ? "default" : "ghost"}
            className={classNames("", {
              "opacity-60": currentTab !== item.value,
            })}
            size="sm"
            onClick={() => setCurrentTab(item.value)}
          >
            <item.icon className="size-4" />
            <span className="inline">{item.label}</span>
          </Button>
        ))}
      </div>
    );
  }
  return (
    <Button
      variant="ghost"
      size="iconXs"
      className="max-lg:hidden"
      onClick={() => setCurrentTab(currentTab === "chat" ? "preview" : "chat")}
    >
      {currentTab === "chat" ? <PanelLeftClose /> : <PanelLeftOpen />}
    </Button>
  );
};