import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import React, { useCallback, useMemo } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { ComponentDefaults } from "../../utils/typings";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    activeDate: '',
    activeTime: [],
    options: [],
    optionKey: {
        valueKey: 'value',
        textKey: 'text',
        childrenKey: 'children'
    },
    onSelect: function() {}
});
export var TimeDetail = function(props) {
    var _$_object_spread = _object_spread({}, defaultProps, props), options = _$_object_spread.options, optionKey = _$_object_spread.optionKey, className = _$_object_spread.className, activeDate = _$_object_spread.activeDate, activeTime = _$_object_spread.activeTime, onSelect = _$_object_spread.onSelect;
    var classPrefix = 'nut-timedetail';
    var timeList = useMemo(function() {
        return (options === null || options === void 0 ? void 0 : options.find(function(item) {
            return item[optionKey.valueKey] === activeDate;
        })) || _define_property({}, optionKey.childrenKey, []);
    }, [
        options,
        optionKey,
        activeDate
    ]);
    var isActive = useCallback(function(timeKey) {
        var date = activeTime.find(function(item) {
            return item[optionKey.valueKey] === activeDate;
        });
        if (date === null || date === void 0 ? void 0 : date[optionKey.childrenKey]) {
            var time = date === null || date === void 0 ? void 0 : date[optionKey.childrenKey].find(function(time) {
                return time[optionKey.valueKey] === timeKey;
            });
            return time;
        }
        return false;
    }, [
        activeTime,
        optionKey,
        activeDate
    ]);
    return /*#__PURE__*/ React.createElement(View, {
        className: classNames(classPrefix, className)
    }, timeList[optionKey.childrenKey].map(function(item) {
        return /*#__PURE__*/ React.createElement(View, {
            className: classNames("".concat(classPrefix, "-item"), {
                active: isActive(item[optionKey.valueKey])
            }),
            key: item[optionKey.valueKey],
            onClick: function() {
                return onSelect(item);
            }
        }, item[optionKey.textKey]);
    }));
};
TimeDetail.displayName = 'NutTimeDetail';
