/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

import { __assign } from 'tslib';
import React__default from 'react';
import { themeable } from 'amis-core';
import TimelineItem, { getAlignByDirection, TimelineTimeComponent, TimelineContentComponent, TimelineLineComponent } from './TimelineItem.js';

var DirectionMode;
(function (DirectionMode) {
    DirectionMode["left"] = "left";
    DirectionMode["right"] = "right";
    DirectionMode["top"] = "top";
    DirectionMode["bottom"] = "bottom";
    DirectionMode["alternate"] = "alternate";
})(DirectionMode || (DirectionMode = {}));
function Timeline(props) {
    var items = props.items, style = props.style, cx = props.classnames, className = props.className, iconClassName = props.iconClassName, timeClassName = props.timeClassName, titleClassName = props.titleClassName, detailClassName = props.detailClassName, _a = props.direction, direction = _a === void 0 ? 'vertical' : _a, _b = props.reverse, reverse = _b === void 0 ? false : _b;
    var _c = props.mode, mode = _c === void 0 ? DirectionMode.right : _c;
    var timelineDatasource = items === null || items === void 0 ? void 0 : items.slice();
    reverse && (timelineDatasource === null || timelineDatasource === void 0 ? void 0 : timelineDatasource.reverse());
    // 分成水平和垂直两种模式渲染
    if (direction === 'horizontal') {
        if ([DirectionMode.right, DirectionMode.left].includes(mode)) {
            mode = DirectionMode.top;
        }
        // alternate模式下，交替生成时间和内容
        var isReverseScenario_1 = function (index, isAlternate) {
            return isAlternate ? index % 2 === 0 : false;
        };
        return (React__default.createElement("div", { className: cx('Timeline', "Timeline-".concat(direction), "Timeline-".concat(mode), className), style: style },
            React__default.createElement("div", { className: cx('Timeline-first-line') }, timelineDatasource === null || timelineDatasource === void 0 ? void 0 : timelineDatasource.map(function (item, index) {
                var _a;
                // 内容区偏移
                var align = getAlignByDirection(direction, item.align);
                return (React__default.createElement("div", { className: cx('TimelineItem-content', (_a = {},
                        _a["TimelineItem-content-align--".concat(align)] = !!align,
                        _a)) }, isReverseScenario_1(index, mode === DirectionMode.alternate) ||
                    mode === DirectionMode.top ? (React__default.createElement(TimelineTimeComponent, __assign({ key: "TimelineItem-".concat(index) }, item))) : (React__default.createElement("div", { className: cx('Timeline-inner-content-wrapper') },
                    React__default.createElement(TimelineContentComponent, __assign({ key: "TimelineItem-".concat(index) }, item))))));
            })),
            React__default.createElement("div", { className: cx('Timeline-line') }, timelineDatasource === null || timelineDatasource === void 0 ? void 0 : timelineDatasource.map(function (item, index) { return (React__default.createElement(TimelineLineComponent, __assign({ key: "TimelineItem-".concat(index) }, item, { direction: direction }))); })),
            React__default.createElement("div", { className: cx('Timeline-second-line') }, timelineDatasource === null || timelineDatasource === void 0 ? void 0 : timelineDatasource.map(function (item, index) {
                var _a;
                // 内容区偏移
                var align = getAlignByDirection(direction, item.align);
                return (React__default.createElement("div", { className: cx('TimelineItem-content', (_a = {},
                        _a["TimelineItem-content-align--".concat(align)] = !!align,
                        _a)) }, isReverseScenario_1(index, mode === DirectionMode.alternate) ||
                    mode === DirectionMode.top ? (React__default.createElement("div", { className: cx('Timeline-inner-content-wrapper') },
                    React__default.createElement(TimelineContentComponent, __assign({ key: "TimelineItem-".concat(index) }, item)))) : (React__default.createElement(TimelineTimeComponent, __assign({ key: "TimelineItem-".concat(index) }, item)))));
            }))));
    }
    return (React__default.createElement("div", { className: cx('Timeline', "Timeline-".concat(direction), "Timeline-".concat(mode), className), style: style }, timelineDatasource === null || timelineDatasource === void 0 ? void 0 : timelineDatasource.map(function (item, index) { return (React__default.createElement(TimelineItem, __assign({}, item, { key: "TimelineItem-".concat(index), iconClassName: item.iconClassName || iconClassName, timeClassName: item.timeClassName || timeClassName, titleClassName: item.titleClassName || titleClassName, detailClassName: item.detailClassName || detailClassName, direction: direction }))); })));
}
var Timeline$1 = themeable(Timeline);

export { DirectionMode, Timeline, Timeline$1 as default };
