export * from './http'
export * from './auth'
export * from './dict'
export * from './feedback'
export * from './i18n'
export * from './store'
export * from './theme'
export * from './page'
export * from './core.plugin'

export interface RoutePathMap {}
export interface RouteNameMap {}

declare module 'vue-router' {
    interface RouteMeta {
        /**
         * 需要登录才可访问
         * @default true
         */
        requiresLogin?: boolean

        /**
         * 需要有页面权限才可访问，当 requiresLogin = false 时忽略
         * 为字符串时（如 sys:user:save），比对权限 action，支持多个 , 拼接
         * @default true
         */
        requiresAuth?: boolean | string | string[]

        /**
         * 左侧激活的菜单路径
         */
        activedModule?: (string & {}) | keyof RoutePathMap

        /**
         * 左侧激活的菜单名称
         */
        activedModuleName?: (string & {}) | keyof RouteNameMap

        /**
         * 多页签的key
         *
         * - 'path': 根据路由路径缓存
         * - 'path&query': 根据路径 path 和查询字符串 search 缓存（不包括 hash）
         * - 'route': 根据路由名称 name 缓存
         * - 'route&query': 根据路由名称 name 和查询字符串 search 缓存（不包括 hash）
         * - string: 以此为 key 进行缓存
         * @default =keepAlive
         */
        tabKey?: 'path' | 'path&query' | 'route' | 'route&query' | (string & {})
        /**
         * 是否无 DOM 包裹，仅由子路由渲染
         *
         * 嵌套子路由时，给于此标志
         * @default false
         */
        abstract?: boolean

        /**
         * 是否缓存（仅对一级路由生效）
         *
         * 嵌套子路由时，配合 abstract: true 使用
         * 建议不使用嵌套路由，把嵌套子路由改为自行处理 path 参数渲染对应组件
         * - false: 不缓存
         * - 'path': 根据路由路径缓存
         * - 'path&query': 根据路径 path 和查询字符串 search 缓存（不包括 hash）
         * - 'route': 根据路由名称 name 缓存
         * - 'route&query': 根据路由名称 name 和查询字符串 search 缓存（不包括 hash）
         * - string: 以此为 key 进行缓存
         * @default 'path'
         */
        keepAlive?: false | 'path' | 'path&query' | 'route' | 'route&query' | (string & {})
    }

    interface Router {
        readonly base: string
    }

    interface RouteLocationNormalized {
        __DT_ROUTE_ERROR?: 'LOAD_FAILURED' | '403' | false
    }
}

declare module 'pinia' {
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    interface DefineStoreOptionsBase<S extends StateTree, Store> {
        persist?: false | import('./store').PersistOptions<S>
    }

    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    interface PiniaCustomProperties<Id, S, G, A> {
        $clear(): void
    }
}

declare module 'vue' {
    export interface ComponentCustomProperties {
        $can: import('./auth').CanFn

        $page: {
            title: string | undefined
        }

        $file: (id: string, credentials?: boolean) => string
        $preview: (id: string, credentials?: boolean) => string

        vSpin: import('./core.plugin').SpinDirective
        vTooltip: import('./core.plugin').TooltipDirective
    }
}

import { LocaleMsg } from '../locales'
declare module '@ithinkdt/common' {
    /**
     * 定义全局翻译消息类型
     */
    interface GlobalMessage extends LocaleMsg {}
}

declare global {
    interface BaseEntity {
        id?: string | number

        createDate?: number | Date

        createUser?: string

        updateDate?: number | Date

        updateUser?: string
    }

    type RequiredId<T extends { id?: string }> = T & { id: string }

    type OmitId<T extends {}> = Omit<T, 'id'> | (Omit<T, 'id'> & { id?: undefined })
}
