import { useEffect, useState } from 'react'
import styled from '@emotion/styled'
import { PlusCircleIcon } from '@heroicons/react/outline'
import useMangoGroupConfig from '../hooks/useMangoGroupConfig'
import useMangoStore from '../stores/useMangoStore'
import MarketMenuItem from './MarketMenuItem'
import { LinkButton } from './Button'
import MarketsModal from './MarketsModal'
import useLocalStorageState from '../hooks/useLocalStorageState'
const StyledMarketSelectWrapper = styled.div`
-ms-overflow-style: none;
scrollbar-width: none;
::-webkit-scrollbar {
display: none;
}
`
const StyledArrow = styled.div`
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
padding-right: 0.5rem;
`
const MarketSelect = () => {
const [showMarketsModal, setShowMarketsModal] = useState(false)
const [hiddenMarkets] = useLocalStorageState('hiddenMarkets', [])
const [sortedMarkets, setSortedMarkets] = useState([])
const groupConfig = useMangoGroupConfig()
const marketConfig = useMangoStore((s) => s.selectedMarket.config)
const baseSymbol = marketConfig.baseSymbol
const isPerpMarket = marketConfig.kind === 'perp'
useEffect(() => {
const markets = []
const allMarkets = [...groupConfig.spotMarkets, ...groupConfig.perpMarkets]
allMarkets.forEach((market) => {
const base = market.name.slice(0, -5)
const found = markets.find((b) => b.baseAsset === base)
if (!found) {
markets.push({ baseAsset: base, markets: [market] })
} else {
found.markets.push(market)
}
})
setSortedMarkets(markets)
}, [groupConfig])
return (
<>