import { computed, inject, provide, type InjectionKey } from 'vue' import { useConfigStore } from '@/store/configStore' import { getProjectBaleLink, getProjectSupportPhoneLink, } from '@/utils/config' import { getRulesBlocks, getRulesTitle, type RulesBlock } from '../rulesContent' export interface RulesPageContext { config: ReturnType nameProject: ReturnType> rulesTitle: ReturnType> rulesBlocks: ReturnType> getProjectSupportPhoneLink: typeof getProjectSupportPhoneLink getProjectBaleLink: typeof getProjectBaleLink } export const RULES_PAGE_CONTEXT_KEY: InjectionKey = Symbol('rulesPageContext') export function useRulesPage() { const config = useConfigStore() const nameProject = computed( () => config.config?.name_fa || config.config?.name || 'بورس مس', ) const rulesTitle = computed(() => getRulesTitle(nameProject.value, true)) const rulesBlocks = computed(() => getRulesBlocks(nameProject.value, true)) const context: RulesPageContext = { config, nameProject, rulesTitle, rulesBlocks, getProjectSupportPhoneLink, getProjectBaleLink, } provide(RULES_PAGE_CONTEXT_KEY, context) return context } export function useRulesPageContext() { const context = inject(RULES_PAGE_CONTEXT_KEY) if (!context) { throw new Error('useRulesPageContext must be used within a page that calls useRulesPage()') } return context }