<template>
    <view class="cu-timeline">
        <view class="item"
            :style="{ '--color': '#0396FF', '--gap': gap, '--left': leftWidth }" v-if="showInit">
            <view class="left" v-if="showLeft">
                <slot name="left"></slot>
            </view>
            <view class="line">
                <view class="svg">
                    <i class="my my-start" style="width: 16px;height: 16px;"></i>
                </view>
            </view>
            <view class="right">
                <slot name="right"></slot>
            </view>
        </view>
        <view v-for="(item, index) in dataList" :key="index" class="item"
            :style="{ '--color': item.color || '#0396FF', '--bgcolor': item.color ? item.color + '1a' : '#0396FF1a', '--gap': gap, '--left': leftWidth }">
            <view class="left" v-if="showLeft">
                <slot name="left" :item="item"></slot>
            </view>
            <view class="line">
                <view class="svg">
                    <slot name="dot" :item="item"></slot>
                </view>
            </view>
            <view class="right">
                <slot name="right" :item="item"></slot>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    props: {
        dataList: {
            type: Array,
            default: () => []
        },
        showInit: {
            type: Boolean,
            default: true
        },
        showLeft: {
            type: Boolean,
            default: true
        },
        leftWidth: {
            type: String,
            default: '150rpx'
        },
        gap: {
            type: String,
            default: '20rpx'
        }
    },
    data() {
        return {

        }
    }
};
</script>

<style lang="scss" scoped>
.cu-timeline {
    position: relative;
    padding: 10rpx;
    display: flex;
    flex-direction: column;

    .item {
        display: flex;
        justify-content: center;
    }

    .left {
        font-size: 13px;
        width: 150px;
        overflow: hidden;
        margin-bottom: var(--gap);
        text-align: right;
        white-space: pre-wrap;
        word-wrap: break-word;
        word-break: break-all;
        flex-shrink: 0;
        margin-right: 10px;
    }

    .line {
        margin: 2px 10px 0px 10px;
        width: 2px;
        background: #eeeeee;
        position: relative;
        flex-shrink: 0;
        flex-grow: 0;

        .svg {
            position: absolute;
            top: 0px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            justify-content: center;
            align-items: center;
            width: 16px;
            height: 16px;
            // background: var(--color);
            // box-shadow: 0 0 3px 1px var(--color);
            // border-radius: 50%;
        }
        .dot {
            position: absolute;
            top: 0px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            justify-content: center;
            align-items: center;
            width: 8px;
            height: 8px;
            background: var(--color);
            box-shadow: 0 0 3px 1px var(--color);
            border-radius: 50%;
        }
    }

    .right {
        flex: 1;
        margin-bottom: var(--gap);
        margin-left: 10px;
        font-size: 13px;


    }

    .item:last-child {
        .line {
            background: transparent;
        }
    }
}
</style>