import type { State } from '../state'; import type { SectionOptionType } from '../types'; type Props = { data: SectionOptionType[]; scrollToSelectedOption?: boolean; } & Pick, 'selectedOption'>; export const getSectionLocation = ({ data, selectedOption, scrollToSelectedOption, }: Props) => { let indexes = { sectionIndex: 0, itemIndex: 0, }; if (scrollToSelectedOption && selectedOption && 'section' in selectedOption) { const { value, section } = selectedOption; const sectionItem = data.find((item) => item.title === section?.title); if (sectionItem) { indexes = { sectionIndex: data.findIndex((item) => item.title === sectionItem.title), itemIndex: sectionItem?.data.findIndex((item) => item.value === value), }; } } return indexes; };