import React from "react"
import * as antd from "antd"
import { Translation } from "react-i18next"
import useUrlQueryActiveKey from "hooks/useUrlQueryActiveKey"
import { Icons, createIconRender } from "components/Icons"
import UseTopBar from "hooks/useTopBar"
import {
composedSettingsByGroups as settingsGroups,
composedTabs,
} from "schemas/settings"
import menuGroupsDecorators from "schemas/settingsMenuGroupsDecorators"
import SettingTab from "./components/SettingTab"
import "./index.mobile.less"
const SettingsHeader = ({
activeKey,
back = () => { }
} = {}) => {
const currentTab = composedTabs[activeKey]
return
{
activeKey && }
onClick={back}
size="large"
type="ghost"
/>
}
{
createIconRender(currentTab?.icon ?? "Settings")
}
{(t) => t(currentTab?.label ?? activeKey ?? "Settings")}
}
export default (props) => {
let lastKey = null
const [activeKey, setActiveKey] = useUrlQueryActiveKey({
queryKey: "tab",
defaultKey: null,
})
const handleTabChange = (key) => {
// star page transition using new chrome transition api
if (document.startViewTransition) {
return document.startViewTransition(() => {
changeTab(key)
})
}
return changeTab(key)
}
const goBack = () => {
handleTabChange(lastKey)
}
const changeTab = (key) => {
lastKey = key
setActiveKey(key)
// scroll to top
app.layout.scrollTo({
top: 0,
})
}
return
{
!activeKey && settingsGroups.map((entry) => {
const groupDecorator = menuGroupsDecorators[entry.group]
return
{(t) => t(groupDecorator?.label ?? entry.group)}
{
entry.groupModule.map((settingsModule, index) => {
return
{
handleTabChange(settingsModule.id)
}}
>
{(t) => t(settingsModule.label)}
})
}
})
}
{
activeKey &&
}
}