/**
 * DevExtreme (esm/renovation/ui/scheduler/appointment/overflow_indicator/layout.js)
 * Version: 23.2.4 (build 24056-0112)
 * Build date: Sun Feb 25 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
var _excluded = ["groups", "overflowIndicatorTemplate", "viewModel"];
import {
    createVNode,
    createComponentVNode,
    normalizeProps
} from "inferno";
import {
    InfernoEffect,
    InfernoComponent
} from "@devextreme/runtime/inferno";
import {
    normalizeStyles
} from "@devextreme/runtime/inferno";
import {
    combineClasses
} from "../../../../utils/combine_classes";
import {
    Button
} from "../../../button";
import {
    getIndicatorColor,
    getOverflowIndicatorStyles
} from "./utils";
import messageLocalization from "../../../../../localization/message";
import {
    AppointmentsContext
} from "../../appointments_context";
import {
    mergeStylesWithColor
} from "../utils";
export var viewFunction = _ref => {
    var {
        classes: classes,
        data: data,
        props: {
            overflowIndicatorTemplate: OverflowIndicatorTemplate
        },
        styles: styles,
        text: text
    } = _ref;
    return createComponentVNode(2, Button, {
        style: normalizeStyles(styles),
        className: classes,
        type: "default",
        stylingMode: "contained",
        children: OverflowIndicatorTemplate ? OverflowIndicatorTemplate({
            data: data
        }) : createVNode(1, "span", null, text, 0)
    })
};
export var OverflowIndicatorProps = {};
var getTemplate = TemplateProp => TemplateProp && (TemplateProp.defaultProps ? props => normalizeProps(createComponentVNode(2, TemplateProp, _extends({}, props))) : TemplateProp);
export class OverflowIndicator extends InfernoComponent {
    constructor(props) {
        super(props);
        this.state = {
            color: void 0
        };
        this.updateStylesEffect = this.updateStylesEffect.bind(this)
    }
    get appointmentsContextValue() {
        if (this.context[AppointmentsContext.id]) {
            return this.context[AppointmentsContext.id]
        }
        return AppointmentsContext.defaultValue
    }
    createEffects() {
        return [new InfernoEffect(this.updateStylesEffect, [this.props.groups, this.props.viewModel, this.appointmentsContextValue])]
    }
    updateEffects() {
        var _this$_effects$;
        null === (_this$_effects$ = this._effects[0]) || void 0 === _this$_effects$ ? void 0 : _this$_effects$.update([this.props.groups, this.props.viewModel, this.appointmentsContextValue])
    }
    updateStylesEffect() {
        var {
            groups: groups,
            viewModel: viewModel
        } = this.props;
        getIndicatorColor(this.appointmentsContextValue, viewModel, groups).then(color => {
            this.setState(__state_argument => ({
                color: color
            }))
        })
    }
    get data() {
        return {
            appointmentCount: this.props.viewModel.items.settings.length,
            isCompact: this.props.viewModel.isCompact
        }
    }
    get text() {
        var {
            isCompact: isCompact
        } = this.props.viewModel;
        var {
            appointmentCount: appointmentCount
        } = this.data;
        if (isCompact) {
            return "".concat(appointmentCount)
        }
        var formatter = messageLocalization.getFormatter("dxScheduler-moreAppointments");
        return formatter(appointmentCount)
    }
    get appointmentStyles() {
        return getOverflowIndicatorStyles(this.props.viewModel)
    }
    get styles() {
        return mergeStylesWithColor(this.state.color, this.appointmentStyles)
    }
    get classes() {
        return combineClasses({
            "dx-scheduler-appointment-collector": true,
            "dx-scheduler-appointment-collector-compact": this.data.isCompact
        })
    }
    get restAttributes() {
        var _this$props = this.props,
            restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
        return restProps
    }
    render() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props, {
                overflowIndicatorTemplate: getTemplate(props.overflowIndicatorTemplate)
            }),
            color: this.state.color,
            appointmentsContextValue: this.appointmentsContextValue,
            data: this.data,
            text: this.text,
            appointmentStyles: this.appointmentStyles,
            styles: this.styles,
            classes: this.classes,
            restAttributes: this.restAttributes
        })
    }
}
OverflowIndicator.defaultProps = OverflowIndicatorProps;
