import { computed } from 'vue';
import { useStore } from 'vuex';

export function useGamaProp(gamaName: string, propCode?: string) {
  const store = useStore();
  const gamas = computed(() => store.getters['gamas/gamasFlat']);
  const gama = computed(() => gamas.value.find((gama) => gama.NOMBRE === gamaName));
  const prop = computed(() => gama.value?.PROPS.find((prop) => prop.code === propCode) || null);
  const options = computed(() => prop.value?.options || []);
  const getLabel = (rawValue: string) => {
    const value = options.value.find((option) => option.value === rawValue);
    return value ? value.label : rawValue;
  };
  return { prop, getLabel, options };
}
