import { defineStore } from "pinia";
import { ref } from "vue";

export const useAutoflowStore = defineStore("autoflowStore", () => {
  // 초기값 복원
  const storedId = localStorage.getItem("projectId");
  const projectId = ref<number | null>(storedId ? Number(storedId) : null);

  const projectName = ref<string>(localStorage.getItem("projectName") || "");

  const setProjectId = (id: number) => {
    projectId.value = id;
    localStorage.setItem("projectId", String(id));
  };

  const clearProjectId = () => {
    projectId.value = null;
    localStorage.removeItem("projectId");
  };

  const setProjectName = (name: string) => {
    projectName.value = name;
    localStorage.setItem("projectName", name);
  };

  const clearProjectName = () => {
    projectName.value = "";
    localStorage.removeItem("projectName");
  };

  return {
    projectId,
    projectName,
    setProjectId,
    clearProjectId,
    setProjectName,
    clearProjectName,
  };
});
