// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { CssLength } from '@breadstone/mosaik-themes';
import { RendererServiceLocator } from '../../../../Dom/Renderer';
import { ScrollerServiceLocator } from '../../../../Dom/Scroller';
import { IntlController } from '../../../../Intl/IntlController';
import { Appearanceable } from '../../../Behaviors/Appearanceable';
import { Dimensionable } from '../../../Behaviors/Dimensionable';
import { Slottable } from '../../../Behaviors/Slottable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Variantable } from '../../../Behaviors/Variantable';
import { addInheritanceProviderController } from '../../../Controllers/InheritanceProviderController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { ChatBegin } from '../../../Types/ChatBegin';
import { CustomElement } from '../../Abstracts/CustomElement';
import { BackTopElement } from '../../Misc/BackTop/BackTopElement';
import { chatElementTemplate } from './ChatElementTemplate';
import { ChatHeaderElement } from './ChatHeaderElement';
import { CHAT_INHERITANCE_CONTEXT } from './ChatInheritanceContext';
import { ChatInputElement } from './ChatInputElement';
import { ChatMessageDividerElement } from './ChatMessageDividerElement';
import { ChatMessageElement } from './ChatMessageElement';
import { ChatElementIntl } from './Intl/ChatElementIntl';
import { chatElementCosmopolitanStyle } from './Themes/ChatElement.Cosmopolitan';
import { chatElementJoyStyle } from './Themes/ChatElement.Joy';
import { chatElementMemphisStyle } from './Themes/ChatElement.Memphis';
// #endregion
/**
 * Chat - A user interface component for real-time messaging and communication.
 *
 * @description
 * The Chat component provides a platform for users to engage in real-time text-based conversations.
 * It typically includes features such as sending and receiving messages, user avatars, timestamps, and more.
 * Chat components are commonly used in messaging applications, social media platforms, and customer support systems.
 *
 * @element mosaik-chat
 * @category Media
 *
 * @slot empty - Slot for empty state content.
 * @slot header - Slot for chat header content.
 * @slot input - Slot for chat input element.
 * @slot message - Slot for chat message elements.
 *
 * @csspart empty - The empty part.
 * @csspart footer - The footer part.
 * @csspart messages - The messages part.
 * @csspart messagesWrapper - The messagesWrapper part.
 *
 * @cssprop {String} --chat-background-color - The background color CSS custom property.
 * @cssprop {String} --chat-border-color - The border color CSS custom property.
 * @cssprop {String} --chat-border-radius - The border radius CSS custom property.
 * @cssprop {String} --chat-border-style - The border style CSS custom property.
 * @cssprop {String} --chat-border-width - The border width CSS custom property.
 * @cssprop {String} --chat-font-family - The font family CSS custom property.
 * @cssprop {String} --chat-font-letter-spacing - The font letter spacing CSS custom property.
 * @cssprop {String} --chat-font-line-height - The font line height CSS custom property.
 * @cssprop {String} --chat-font-size - The font size CSS custom property.
 * @cssprop {String} --chat-font-text-decoration - The font text decoration CSS custom property.
 * @cssprop {String} --chat-font-text-transform - The font text transform CSS custom property.
 * @cssprop {String} --chat-font-weight - The font weight CSS custom property.
 * @cssprop {String} --chat-foreground-color - The foreground color CSS custom property.
 * @cssprop {String} --chat-gap - The gap CSS custom property.
 * @cssprop {String} --chat-line-thickness - The line thickness CSS custom property.
 * @cssprop {String} --chat-padding-bottom - The padding bottom CSS custom property.
 * @cssprop {String} --chat-padding-left - The padding left CSS custom property.
 * @cssprop {String} --chat-padding-right - The padding right CSS custom property.
 * @cssprop {String} --chat-padding-top - The padding top CSS custom property.
 * @cssprop {String} --chat-shadow - The shadow CSS custom property.
 * @cssprop {String} --chat-shadow-blur - The shadow blur CSS custom property.
 * @cssprop {String} --chat-shadow-color - The shadow color CSS custom property.
 * @cssprop {String} --chat-shadow-offset-x - The shadow offset x CSS custom property.
 * @cssprop {String} --chat-shadow-offset-y - The shadow offset y CSS custom property.
 * @cssprop {String} --chat-shadow-spread - The shadow spread CSS custom property.
 * @cssprop {String} --chat-transition-duration - The transition duration CSS custom property.
 * @cssprop {String} --chat-transition-mode - The transition mode CSS custom property.
 * @cssprop {String} --chat-transition-property - The transition property CSS custom property.
 * @cssprop {String} --chat-translate - The translate CSS custom property.
 *
 * @dependency mosaik-back-top - The Back Top element.
 *
 * @example
 * Basic chat:
 * ```html
 * <mosaik-chat></mosaik-chat>
 * ```
 *
 * @example
 * Chat with scroll-to-end enabled and a variant:
 * ```html
 * <mosaik-chat variant="primary" scroll-to-end></mosaik-chat>
 * ```
 *
 * @public
 */
let ChatElement = class ChatElement extends Themeable(Dimensionable(Appearanceable(Variantable(Slottable(CustomElement))))) {
    // #region Fields
    _intl;
    _provider = addInheritanceProviderController(this, {
        context: CHAT_INHERITANCE_CONTEXT,
        values: () => ({
            variant: this.variant,
            appearance: this.appearance
        })
    });
    _scrollToEnd;
    _begin;
    _inputElement;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._intl = new IntlController(this, {
            factory: () => new ChatElementIntl()
        });
        this._scrollToEnd = false;
        this._begin = ChatBegin.Start;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-chat';
    }
    /**
     * Gets or sets the `scrollToEnd` property.
     * If `true`, in order to `begin` property, the chat will scroll to top or bottom of the chat messages.
     *
     * @public
     * @attr
     */
    get scrollToEnd() {
        return this._scrollToEnd;
    }
    set scrollToEnd(value) {
        if (this._scrollToEnd !== value) {
            this._scrollToEnd = value;
            this.requestUpdate('scrollToEnd');
        }
    }
    /**
     * Gets or sets the `begin` property.
     *
     * @public
     */
    get begin() {
        return this._begin;
    }
    set begin(value) {
        if (this._begin !== value) {
            this._begin = value;
            this.requestUpdate('begin');
        }
    }
    /**
     * Gets or sets the `intl` property.
     *
     * @public
     */
    get intl() {
        return this._intl.intl;
    }
    set intl(value) {
        this._intl.provide(value);
    }
    /**
     * Returns the `input` property.
     *
     * @private
     * @readonly
     */
    get inputElement() {
        return this._inputElement;
    }
    // #endregion
    // #region Methods
    onSlotChanges(slotName) {
        super.onSlotChanges(slotName);
        if (slotName === 'input') {
            // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
            this._inputElement = this.getSlotAssignmentsOf('input', ChatInputElement).at(0);
            this._inputElement.dir = this.dir;
            this._inputElement.variant = this.variant;
            this._inputElement.placeholder = this.intl.inputPlaceholder;
        }
        if (slotName === 'message') {
            if (this.begin === ChatBegin.End) {
                if (this._scrollToEnd) {
                    ScrollerServiceLocator.current.scrollToBottom(this.getTemplatePart('messages'), {
                        behavior: 'smooth'
                    });
                }
            }
        }
    }
    /**
     * @protected
     */
    onWidthPropertyChanged(_prev, next) {
        RendererServiceLocator.current.setStyle(this, 'min-width', next);
        RendererServiceLocator.current.setStyle(this, 'width', next);
    }
    /**
     * @protected
     */
    onHeightPropertyChanged(_prev, next) {
        RendererServiceLocator.current.setStyle(this, 'min-height', next);
        RendererServiceLocator.current.setStyle(this, 'height', next);
    }
};
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], ChatElement.prototype, "scrollToEnd", null);
__decorate([
    Property({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], ChatElement.prototype, "begin", null);
__decorate([
    Property({ type: Object }),
    __metadata("design:type", ChatElementIntl),
    __metadata("design:paramtypes", [ChatElementIntl])
], ChatElement.prototype, "intl", null);
__decorate([
    Watch('width'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", void 0)
], ChatElement.prototype, "onWidthPropertyChanged", null);
__decorate([
    Watch('height'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", void 0)
], ChatElement.prototype, "onHeightPropertyChanged", null);
ChatElement = __decorate([
    Component({
        selector: 'mosaik-chat',
        template: chatElementTemplate,
        themes: {
            joy: chatElementJoyStyle,
            memphis: chatElementMemphisStyle,
            cosmopolitan: chatElementCosmopolitanStyle
        },
        host: {
            role: 'list'
        },
        imports: [
            ChatHeaderElement,
            ChatMessageElement,
            ChatMessageDividerElement,
            ChatInputElement,
            BackTopElement
        ]
    }),
    __metadata("design:paramtypes", [])
], ChatElement);
export { ChatElement };
//# sourceMappingURL=ChatElement.js.map