import { __decorate } from "tslib";
import { html, nothing } from "lit";
import { queryAsync, state } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { when } from 'lit/directives/when.js';
import elementStyles from './Checkbox.styles.js';
import CheckedElement from "./CheckedElement.js";
import { check, checkIndeterminate } from '../icons/Icons.js';
import { ripple } from "../effects/rippleDirective.js";
import '../../define/ui/ui-ripple.js';
export default class CheckboxElement extends CheckedElement {
    constructor() {
        super(...arguments);
        this.showRipple = false;
        this.getRipple = () => {
            this.showRipple = true;
            return this.ripple;
        };
        this.renderRipple = () => {
            const { disabled } = this;
            return html `<ui-ripple class="ripple" unbounded ?disabled="${disabled}"></ui-ripple>`;
        };
    }
    static get styles() {
        return elementStyles;
    }
    get _icon() {
        const { indeterminate, checked } = this;
        if (indeterminate) {
            return checkIndeterminate;
        }
        if (checked) {
            return check;
        }
        return nothing;
    }
    async handleFocus() {
        const _ripple = await this.getRipple();
        _ripple?.beginFocus();
    }
    async handleBlur() {
        const _ripple = await this.getRipple();
        _ripple?.endFocus();
    }
    async handleKeyDown(e) {
        super.handleKeyDown(e);
        if (['Space'].includes(e.code)) {
            const _ripple = await this.getRipple();
            _ripple?.beginPress();
        }
    }
    async handleKeyUp(e) {
        super.handleKeyUp(e);
        if (['Space'].includes(e.code)) {
            const _ripple = await this.getRipple();
            _ripple?.endPress();
        }
    }
    render() {
        const { pressed = false } = this;
        const containerClasses = classMap({
            surface: true,
            pressed,
        });
        return html `
    <div class="${containerClasses}" ${ripple(this.getRipple)}>
      <div class="container"></div>
      <div class="state"></div>
      ${when(this.showRipple, this.renderRipple)}
      <div class="icon">${this._icon}</div>
    </div>
    `;
    }
}
__decorate([
    queryAsync('ui-ripple')
], CheckboxElement.prototype, "ripple", void 0);
__decorate([
    state()
], CheckboxElement.prototype, "showRipple", void 0);
//# sourceMappingURL=CheckboxElement.js.map