import type { PropertyValues } from 'lit'
import { LitElement, css, html } from 'lit'
import { property, query } from 'lit/decorators.js'
import { classMap } from 'lit/directives/class-map.js'
import type { Options } from 'simplebar'
import SimpleBar from 'simplebar'
import simpleBar_css from 'simplebar/dist/simplebar.css'
import type { DirectiveClass, DirectiveResult } from 'lit/directive'
import { customElementIfNotExist } from '../../utils/customElementIfNotExist'
import { dispatchCustomEvent } from '../../utils/dispatchCustomEvent'
import { debounce } from '../../utils/debounce'
import styles_css from './styles.pcss'
import vars_css from './vars.pcss'
declare global {
interface HTMLElementTagNameMap {
'us-scroll-layout': ScrollLayout
}
}
@customElementIfNotExist('us-scroll-layout')
export class ScrollLayout extends LitElement {
static styles = [
css([vars_css] as TemplateStringsArray | any),
css([styles_css] as TemplateStringsArray | any),
css([simpleBar_css] as TemplateStringsArray | any),
]
@property() ariaLabel = ''
@property({ type: Object }) options = {} as Options
@property({ type: Boolean }) innactive = false
@property({ type: Boolean }) observeEvent = false
@property({ type: Boolean }) fullHeight = false
@query('[data-simplebar]') simpleBarEl!: HTMLDivElement
simpleBar!: SimpleBar
handleSimpleBarScrollEventBinded = this.handleSimpleBarScrollEvent.bind(this)
handleScrollEventDebounced = debounce(() => dispatchCustomEvent('handleScrollEvent', null, this, false, false), 100, false)
firstUpdated() {
this.initSimpleBar()
}
async updated(changedProperties: PropertyValues) {
if (changedProperties.has('innactive')) {
if (this.innactive)
this.disposeSimpleBar()
else
await this.reInitSimpleBar()
}
}
disconnectedCallback() {
this.disposeSimpleBar()
super.disconnectedCallback()
}
render() {
if (this.innactive)
return html`