| 1 |
import { useLabelsStore } from '@/stores/labels' |
| 2 |
import { getActivePinia } from 'pinia' |
| 3 |
|
| 4 |
/** |
| 5 |
* Composable function to provide easy access to labels throughout the application |
| 6 |
* @returns Object with getLabel function and allLabels getter |
| 7 |
*/ |
| 8 |
export function useLabels() { |
| 9 |
// Check if Pinia is available |
| 10 |
if (!getActivePinia()) { |
| 11 |
//console.warn('Pinia is not initialized. Labels will not be available.') |
| 12 |
return { |
| 13 |
getLabel: (key: string, fallback: string = '') => fallback || key, |
| 14 |
allLabels: {}, |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
const labelsStore = useLabelsStore() |
| 19 |
|
| 20 |
/** |
| 21 |
* Get a label by key with optional fallback value |
| 22 |
* @param key The label key to retrieve |
| 23 |
* @param fallback Optional fallback text if label doesn't exist |
| 24 |
* @returns The label string or fallback value |
| 25 |
*/ |
| 26 |
const getLabel = (key: string, fallback: string = ''): string => { |
| 27 |
return labelsStore.getLabel(key, fallback) |
| 28 |
} |
| 29 |
|
| 30 |
return { |
| 31 |
getLabel, |
| 32 |
allLabels: labelsStore.allLabels, |
| 33 |
} |
| 34 |
} |
| 35 |
|