<template>
    <view
        @tap="rowClicked(msg.globalMsg)"
        class="tableRow flex"
        :class="msg.globalMsg.isFinished ? 'mocp-bg-fill-4' : ''"
    >
        <view
            v-for="(item, index) of msg.filterMsg"
            :key="index"
            class="rowItem u-line-1 text-center"
            :style="{flex: item.flex}"
        >
            <global-flight-no
                v-if="item.key === 'flightNo'"
                :flightNo="item.data"
                :airline="item.airlineCode"
                :flex="item.flex"
            />

            <RenderTime
                v-else-if="item.key === 'time'"
                :item="msg.globalMsg"
            />

            <view
                v-else-if="item.key == 'status'"
                :class="item.color">
                {{ item.data }}
            </view>

            <text v-else>{{ item.data }}</text>
        </view>
    </view>
</template>

<script setup>
import { ref, computed } from 'vue'
import { storeToRefs } from 'pinia'
import Day from 'mocp/utils/dayjs'
import useFlightSupportStore from 'mocp/store/flight-support'
import { decideReleaseStatus } from '../utils/currentInBoundMode'
import GlobalFlightNo from 'mocp/components/global-flight-no/global-flight-no.vue'
import RenderTime from '../components/RenderTime.vue'
import { fightListPlanTime } from 'mocp/utils/getFlightList'
import { rowClicked } from '../utils/jumpSlingleFlight'
import { currentInBoundModeForFlightTablePage, allInBoundMode } from '../utils/currentInBoundMode'

const flightSupportStore = useFlightSupportStore()
const {listTab} = storeToRefs(flightSupportStore)


const ps = defineProps({
    item: {
        type: Object,
        default: () => ({})
    }
})

// 组装列表数据
const msg = computed(() => {
    const isCurrentIn = currentInBoundModeForFlightTablePage.value + 1 == allInBoundMode.In
    const filterListTab = listTab.value.filter(item => !!item.selected)
    const filterMsg = filterListTab.map(item => {
        const defaultObj = {
            key: item.key,
            flex: item.flex,
            data: ps.item[item.key]
        }
        // 航班号
        if (item.key == 'flightNo') {
            return {
                ...defaultObj,
                airlineCode: ps.item['airlineCode']
            }
        }
        // 出发地
        if (item.key == 'depStn') {
            console.log()
            return {
                ...defaultObj,
                data: isCurrentIn ?
                    ps.item.depStn :
                    ps.item.arrStn
            }
        }
        // 计划
        if (fightListPlanTime.includes(item.key)) {
            console.log()
            return {
                ...defaultObj,
                data: isCurrentIn ?
                    Day(ps.item.staChn).format('HH:mm') :
                    Day(ps.item.stdChn).format('HH:mm')
            }
        }
        // 状态
        if (item.key == 'status') {
            return {
                ...defaultObj,
                ...decideReleaseStatus(ps.item)
            }
        }
        // 特殊任务
        if (item.key == 'isSpecialTask') {
            const current = ps.item
            console.log(current)
            return {
                ...defaultObj,
                data: current.isVip || current.isHighlandFlights || current.fltType === 'I' ? '特殊' : ''
            }
        }
        return {
            ...defaultObj
        }
    })
    return {
        globalMsg: ps.item,
        filterMsg
    }
})

</script>
<style lang="scss" scoped>
@import '../constants/flightSupportList';
</style>
