import React from 'react'
import Taro, { useRouter } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { AtList, AtListItem } from "taro-ui"
import './index.scss'

const roadCode = [
  { title: "八一乡", value: "360121206000" },
  { title: "东新乡", value: "360121205000" },
  { title: "富山乡", value: "360121204000" },
  { title: "冈上镇", value: "360121107000" },
  { title: "广福镇", value: "360121108000" },
  { title: "黄马乡", value: "360121203000" },
  { title: "蒋巷镇", value: "360121105000" },
  { title: "金湖管理处", value: "330052" },
  { title: "泾口乡", value: "360121200000" },
  { title: "莲塘镇", value: "360121100000" },
  { title: "南新乡", value: "360121201000" },
  { title: "三江镇", value: "360121102000" },
  { title: "塔城乡", value: "360121202000" },
  { title: "塘南镇", value: "360121103000" },
  { title: "武阳镇", value: "360121106000" },
  { title: "向塘镇", value: "360121101000" },
  { title: "银三角管委会", value: "360121471000" },
  { title: "幽兰镇", value: "360121104000" },
]

function Index() {
  const { detail } = useRouter().params
  const detailItem = detail ? JSON.parse(decodeURIComponent(detail)) : null

  let townshipCode = ''
  const targetValue = detailItem?.road?.townshipCode ?? ''
  const foundItem = roadCode.find(item => item.value === targetValue)
  if (foundItem) {
    townshipCode = foundItem.title
  } else {
    townshipCode = "--"
  }

  return (
    <View className='page'>
      <AtList>
        <AtListItem title='所属乡镇' extraText={townshipCode} />
        <AtListItem title='所属行政村' extraText={detailItem.road?.village?.name || '--'} />
        <AtListItem title='道路名称' extraText={detailItem.road?.routeName || '--'} />
        <AtListItem title='道路代码' extraText={detailItem.road?.routeCode || '--'} />
        <AtListItem title='起点桩号' extraText={detailItem.road?.startStation || '--'} />
        <AtListItem title='止点桩号' extraText={detailItem.road?.stopStation || '--'} />
        <AtListItem title='技术等级' extraText={detailItem.road?.technicalLevel || '--'} />
        <AtListItem title='路面类型' extraText={detailItem.road?.pavementType || '--'} />
        <AtListItem title='路面宽度' extraText={detailItem.road?.pavementWidth || '--'} />
        <AtListItem title='路基宽度' extraText={detailItem.road?.subgradeWidth || '--'} />
        <AtListItem title='桩号里程' extraText={detailItem.road?.chainageMileage || '--'} />
        <AtListItem title='养护次数（次）' extraText={detailItem.maintenanceCount} />
      </AtList>
    </View>
  )
}

export default Index