"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TimeDetail", {
    enumerable: true,
    get: function() {
        return TimeDetail;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _define_property = require("@swc/helpers/_/_define_property");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _components = require("@tarojs/components");
var _typings = require("../../utils/typings");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    activeDate: '',
    activeTime: [],
    options: [],
    optionKey: {
        valueKey: 'value',
        textKey: 'text',
        childrenKey: 'children'
    },
    onSelect: function onSelect() {}
});
var TimeDetail = function TimeDetail(props) {
    var _$_object_spread = (0, _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 = (0, _react.useMemo)(function() {
        return (options === null || options === void 0 ? void 0 : options.find(function(item) {
            return item[optionKey.valueKey] === activeDate;
        })) || (0, _define_property._)({}, optionKey.childrenKey, []);
    }, [
        options,
        optionKey,
        activeDate
    ]);
    var isActive = (0, _react.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.default.createElement(_components.View, {
        className: (0, _classnames.default)(classPrefix, className)
    }, timeList[optionKey.childrenKey].map(function(item) {
        return /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: (0, _classnames.default)("".concat(classPrefix, "-item"), {
                active: isActive(item[optionKey.valueKey])
            }),
            key: item[optionKey.valueKey],
            onClick: function onClick() {
                return onSelect(item);
            }
        }, item[optionKey.textKey]);
    }));
};
TimeDetail.displayName = 'NutTimeDetail';
