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

/** 设置targetTenantId */
export const useTargetTenantIdStore = defineStore(
  'targetTenantId',
  () => {
    const targetTenantId = ref<number | null>(null);

    function clear() {
      targetTenantId.value = null;
    }

    function setValue(newVal: number) {
      targetTenantId.value = newVal;
    }

    function getValue() {
      return targetTenantId.value;
    }

    function getStringValue(): string {
      return targetTenantId.value === null ? '' : String(targetTenantId.value);
    }

    return { setValue, getValue, clear, targetTenantId, getStringValue };
  },
  {
    persist: {
      storage: sessionStorage,
    },
  },
);
