import React, { useState, useCallback, useMemo, useEffect } from 'react'; import SectionTab from 'common/section-tab'; import { PageSwitch, Page } from 'common/page-switch'; import { LayerComponent, EditorWrapper } from 'common/styles'; import { editorComponents } from 'components/editor'; import { symbolTabs, circleTabs, lineTabs, fillTabs, heatmapTabs, } from './constants'; import type { LayerType } from '../types/map'; import type { ITab } from './constants'; interface IProps { type: LayerType; } const tabsComponent = { symbol: symbolTabs, circle: circleTabs, heatmap: heatmapTabs, cluster: symbolTabs, line: lineTabs, fill: fillTabs, }; const InnerTabs = ({ type }: IProps) => { const tabs = useMemo(() => { return tabsComponent[type]; }, [type]); const currTab = tabs?.map((t) => t.id); type PageIds = typeof currTab[number]; const [activePageId, setActivePageId] = useState( // @ts-ignore line (tabs?.filter((i: ITab) => !i.disabled) as ITab[])?.[0] ?.id ); const changeTab = useCallback( (id: string) => { // @ts-ignore line return !(tabs.find((i: ITab) => i.id === id) as ITab) ?.disabled ? setActivePageId(id as PageIds) : undefined; }, [tabs] ); useEffect(() => { setActivePageId( // @ts-ignore line (tabs?.filter((i: ITab) => !i.disabled) as ITab[])?.[0] ?.id ); }, [type]); return ( {tabs?.map((tab) => ( {editorComponents?.[tab?.id]} ))} ); }; export default InnerTabs;