
import { Swiper, SwiperItem, Image } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { getImgURL } from '@/utils/image'
import nav2Target from '@/utils/nav2Target'
import './index.scss'

export default function Banner (props) {
  const { List = [] } = props
  
  const redirectTo = ({ targetId, contentType, buildingId } = {})=> {
    switch (contentType) {
      // 项目
      case 'project':
        Taro.navigateTo({
          url: '/pages/index/buildingDetail/index?id=' + buildingId
        })
        return;

      // 活动
      case 'activity':
        Taro.navigateTo({
          url: '/pages/index/activityDetail/index?id=' + targetId
        })
        return;

      // 资讯
      case 'news':
        Taro.navigateTo({
          url: '/pages/index/newsDetail/index?id=' + targetId
        })
        return;

      // live
      case 'live':
        Taro.navigateTo({
          url: '/pages/video/liveDetail/index?id=' + targetId
        })
        return;


      // 其他
      case 'others':
      default:
        
        return;
    }
  }

  const handleBannerClick = (item) => {
    if (item.contentType && item.contentType != "nothing") {
      nav2Target(item)
    } 
  }
  return (
    <view className='components Banner'>
      <Swiper autoplay interval={2000} indicator-dots>
        {
          List.map((item, index) => (
            <SwiperItem key={`Banner-${index}`}>
              <view className='swiper-item'>
                <Image mode='aspectFill' className='centerLabel' onClick={()=>handleBannerClick(item)} src={getImgURL(item.image)} />
              </view>
            </SwiperItem>
          ))
        }
      </Swiper>
    </view>
  )
}
