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

const useOptionStore = defineStore('optionStore', () => {
  const globalOption = ref();

  function mapOption(value: string) {
    for (const category in globalOption.value) {
      if (globalOption.value.hasOwnProperty(category)) {
        const option = globalOption.value[category].find(
          (opt: { value: string }) => opt.value === value,
        );
        if (option) return option.label;
      }
    }
    return value;
  }

  return {
    globalOption,

    mapOption,
  };
});

export default useOptionStore;
