// #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 { RendererServiceLocator } from '../../../../Dom/Renderer';
import { Attachable } from '../../../Behaviors/Attachable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Variantable } from '../../../Behaviors/Variantable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { rippleElementTemplate } from './RippleElementTemplate';
import { rippleElementJoyStyle } from './Themes/RippleElement.Joy';
import { rippleElementRetroStyle } from './Themes/RippleElement.Retro';
import { rippleElementCosmopolitanStyle } from './Themes/RippleElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
import { on } from '@breadstone/mosaik-elements';
import { CssTime } from '@breadstone/mosaik-themes';
// #endregion
/**
 * Ripple - An interactive visual effect component that creates expanding circular animations on user interaction.
 *
 * Provides tactile feedback through animated ripple effects that emanate from the point of user interaction.
 * Enhances user experience by giving immediate visual confirmation of clicks, taps, or other interactions
 * with a Material Design-inspired expanding circle animation.
 *
 * @name RippleElement
 * @element mosaik-ripple
 * @category Effects
 *
 * @slot - Default content area (typically empty as ripple is a visual effect overlay)
 *
 * @csspart ripple - Main ripple effect container
 * @csspart animation - Individual ripple animation elements
 *
 * @cssprop --ripple-background-color - Background color for the ripple effect
 * @cssprop --ripple-opacity - Opacity level for the ripple animation
 * @cssprop --ripple-duration - Animation duration for the ripple effect
 * @cssprop --ripple-scale - Maximum scale factor for the ripple expansion
 * @cssprop --ripple-easing - Easing function for the ripple animation
 *
 * @dependency CssTime - For handling CSS time values and animation timing
 *
 * @example
 * ```html
 * <!-- Basic button with ripple effect -->
 * <mosaik-button>
 *   <mosaik-ripple></mosaik-ripple>
 *   Click Me
 * </mosaik-button>
 *
 * <!-- Card with ripple feedback -->
 * <mosaik-card clickable="true">
 *   <mosaik-ripple></mosaik-ripple>
 *   <mosaik-text slot="header">Interactive Card</mosaik-text>
 *   <mosaik-text>Click anywhere on this card</mosaik-text>
 * </mosaik-card>
 *
 * <!-- Custom ripple attached to external element -->
 * <div id="custom-element" class="interactive-area">
 *   <mosaik-ripple for="custom-element"></mosaik-ripple>
 *   Custom Interactive Area
 * </div>
 *
 * <!-- Ripple with custom styling -->
 * <mosaik-button appearance="primary">
 *   <mosaik-ripple style="--ripple-background-color: rgba(255,255,255,0.3); --ripple-duration: 600ms;"></mosaik-ripple>
 *   Primary Button
 * </mosaik-button>
 *
 * <!-- Disabled ripple (no animation) -->
 * <mosaik-button disabled="true">
 *   <mosaik-ripple disabled="true"></mosaik-ripple>
 *   Disabled Button
 * </mosaik-button>
 * ```
 *
 * @public
 */
let RippleElement = class RippleElement extends Themeable(Variantable(Disableable(Attachable(CustomElement)))) {
    // #region Fields
    _mouseDownSubscription;
    _centered;
    _duration;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._centered = false;
        this._duration = 400;
        this._mouseDownSubscription = null;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link is}` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-ripple';
    }
    /**
     * Gets or sets the `centered` property.
     *
     * @public
     * @attr
     */
    get centered() {
        return this._centered;
    }
    set centered(value) {
        if (this._centered !== value) {
            this._centered = value;
            this.requestUpdate('centered');
        }
    }
    /**
     * Gets or sets the `duration` property.
     *
     * @public
     * @attr
     */
    get duration() {
        return this._duration;
    }
    set duration(value) {
        if (this._duration !== value) {
            this._duration = value;
            this.requestUpdate('duration');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    disconnectedCallback() {
        super.disconnectedCallback();
        if (this.control && this._mouseDownSubscription) {
            this._mouseDownSubscription.dispose();
        }
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        if (this.control) {
            this._mouseDownSubscription = on(this.control, 'mousedown', (e) => this.onMouseDown(e));
        }
    }
    /**
     * @private
     */
    onMouseDown(event) {
        const element = RendererServiceLocator.current.createElement('span');
        RendererServiceLocator.current.setAttribute(element, 'part', 'ripple');
        const dimension = this.getDimensions(event.clientX, event.clientY);
        if (this._centered) {
            dimension.top = 0;
            dimension.left = 0;
        }
        const styles = {
            width: `${dimension.radius}px`,
            height: `${dimension.radius}px`,
            top: `${dimension.top}px`,
            left: `${dimension.left}px`
        };
        const frames = [
            {
                opacity: 0.5,
                transform: 'scale(.3)'
            },
            {
                opacity: 0,
                transform: 'scale(2)'
            }
        ];
        const opts = {
            duration: this._duration,
            fill: 'forwards',
            easing: 'linear'
        };
        Object.assign(element.style, styles);
        this.shadowRoot?.appendChild(element);
        void element.animate(frames, opts).finished.then(() => element.remove());
    }
    /**
     * @private
     */
    getDimensions(x, y) {
        const rect = this.getBoundingClientRect();
        const radius = Math.max(rect.width, rect.height);
        const left = Math.round(x - rect.left - radius / 2);
        const top = Math.round(y - rect.top - radius / 2);
        return {
            radius,
            top: top,
            left: left
        };
    }
};
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], RippleElement.prototype, "centered", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], RippleElement.prototype, "duration", null);
RippleElement = __decorate([
    Component({
        selector: 'mosaik-ripple',
        template: rippleElementTemplate,
        themes: {
            joy: rippleElementJoyStyle,
            retro: rippleElementRetroStyle,
            cosmopolitan: rippleElementCosmopolitanStyle
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], RippleElement);
export { RippleElement };
//# sourceMappingURL=RippleElement.js.map