import { computed } from 'vue'; import { useI18n } from '@/locales/helpers.ts'; import { useSettingsStore } from '@/stores/setting.ts'; import type { TypeAndDisplayName } from '@/core/base.ts'; import { type LocalizedDateRange, DateRangeScene } from '@/core/datetime.ts'; import { StatisticsAnalysisType } from '@/core/statistics.ts'; export function useStatisticsSettingPageBase() { const { getAllDateRanges, getAllTimezoneTypesUsedForStatistics, getAllCategoricalChartTypes, getAllTrendChartTypes, getAllStatisticsChartDataTypes, getAllStatisticsSortingTypes } = useI18n(); const settingsStore = useSettingsStore(); const allChartDataTypes = computed(() => getAllStatisticsChartDataTypes(StatisticsAnalysisType.CategoricalAnalysis)); const allTimezoneTypesUsedForStatistics = computed(() => getAllTimezoneTypesUsedForStatistics()); const allSortingTypes = computed(() => getAllStatisticsSortingTypes()); const allCategoricalChartTypes = computed(() => getAllCategoricalChartTypes()); const allCategoricalChartDateRanges = computed(() => getAllDateRanges(DateRangeScene.Normal, false)); const allTrendChartTypes = computed(() => getAllTrendChartTypes()); const allTrendChartDateRanges = computed(() => getAllDateRanges(DateRangeScene.TrendAnalysis, false)); const defaultChartDataType = computed({ get: () => settingsStore.appSettings.statistics.defaultChartDataType, set: (value: number) => settingsStore.setStatisticsDefaultChartDataType(value) }); const defaultTimezoneType = computed({ get: () => settingsStore.appSettings.statistics.defaultTimezoneType, set: (value: number) => settingsStore.setStatisticsDefaultTimezoneType(value) }); const defaultSortingType = computed({ get: () => settingsStore.appSettings.statistics.defaultSortingType, set: (value: number) => settingsStore.setStatisticsSortingType(value) }); const defaultCategoricalChartType = computed({ get: () => settingsStore.appSettings.statistics.defaultCategoricalChartType, set: (value: number) => settingsStore.setStatisticsDefaultCategoricalChartType(value) }); const defaultCategoricalChartDateRange = computed({ get: () => settingsStore.appSettings.statistics.defaultCategoricalChartDataRangeType, set: (value: number) => settingsStore.setStatisticsDefaultCategoricalChartDateRange(value) }); const defaultTrendChartType = computed({ get: () => settingsStore.appSettings.statistics.defaultTrendChartType, set: (value: number) => settingsStore.setStatisticsDefaultTrendChartType(value) }); const defaultTrendChartDateRange = computed({ get: () => settingsStore.appSettings.statistics.defaultTrendChartDataRangeType, set: (value: number) => settingsStore.setStatisticsDefaultTrendChartDateRange(value) }); return { // computed states allChartDataTypes, allTimezoneTypesUsedForStatistics, allSortingTypes, allCategoricalChartTypes, allCategoricalChartDateRanges, allTrendChartTypes, allTrendChartDateRanges, defaultChartDataType, defaultTimezoneType, defaultSortingType, defaultCategoricalChartType, defaultCategoricalChartDateRange, defaultTrendChartType, defaultTrendChartDateRange }; }