import {useEffect, useState} from "react";
import DoneIcon from '@mui/icons-material/Done';

const Items = ({data}) => {
    const [result, setResult] = useState([])

    useEffect(() => {
        let arr = []
        for (let i = 0; i < 6; i++) {
            if (data[i]) {
                let _item = {}
                _item.name = data[i].name
                _item.city_name = data[i].city_name
                _item.tanafos_period = data[i].tanafos_period
                switch (data[i].vehicle_type) {
                    case 'اتوبوس':
                        _item.vehicle_num = 4
                        break;
                    case 'مینی بوس':
                        _item.vehicle_num = 2
                        break;
                    default:
                        _item.vehicle_num = 0
                        break;
                }
                arr.push(_item)

            } else {
                arr.push(null)
            }
        }
        setResult(arr)
    }, []);

    return (<>
            {result.map((item, index) => (<tr key={index}>
                <td style={{minHeight: 21, border: '1px solid'}}>{index + 1}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item?.name || (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item ? (<>بازسازی ناوگان
                    مسافری</>) : (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item ? (
                    <DoneIcon fontSize={'inherit'}/>) : (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item ? (
                    <DoneIcon fontSize={'inherit'}/>) : (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item?.city_name || (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item?.vehicle_num || (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>&nbsp;</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item ? (<>کارآفرینی امید</>) : (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item ? (<>15/2</>) : (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item?.tanafos_period || (<>&nbsp;</>)}</td>
                <td style={{minHeight: 21, border: '1px solid'}}>{item ? (<>60</>) : (<>&nbsp;</>)}</td>
            </tr>))}
        </>

    )
}
export default Items