import { matchMedia } from "@/utils";

export const useLayoutStore = defineStore("layout", () => {
  // 侧边栏状态
  const hiddenLeftSidebar = ref(false);
  // 简洁按钮
  const simpleMode = ref(false);

  const handleResize = () => {
    matchMedia(
      "sm",
      () => {
        hiddenLeftSidebar.value = true;
      },
      () => {
        hiddenLeftSidebar.value = false;
      }
    );
    matchMedia(
      "536",
      () => {
        simpleMode.value = true;
      },
      () => {
        simpleMode.value = false;
      }
    );
  };

  const toggleLeftSidebar = () => {
    hiddenLeftSidebar.value = !hiddenLeftSidebar.value;
  };

  window.addEventListener("resize", handleResize);

  onMounted(() => {
    handleResize();
  });

  onUnmounted(() => {
    window.removeEventListener("resize", handleResize);
  });
  return { hiddenLeftSidebar, toggleLeftSidebar, simpleMode };
});
