import Kmcomponent, { type KmcomponentProperties } from './kmcomponent';
import { Loading } from '../../loading/loading';
const string = (value = '', select?: string[]) => ({ type: 'string' as const, default: value, select });
const escape = (value: unknown) => String(value).replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]!);
/** Reactive Loading wrapper. Styles and behavior belong to the existing Loading component. */
export default class CrazyLoading extends Kmcomponent {
static properties: KmcomponentProperties = {
active: { type: 'boolean', default: true, reflect: true },
size: { ...string('normal', ['small', 'normal', 'large']), reflect: true },
label: string('Loading…'),
'complete-label': string('Ready'),
'aria-label': string(),
image: string(),
'icon-text': string(),
'icon-class': string('material-icons'),
};
get isActive(): boolean { return this.getProperty('active') as boolean; }
/** Show the ring. Await updateComplete when reading the rendered status. */
start(label?: string): void {
if (label !== undefined) this.setProperty('label', label);
this.setProperty('active', true);
}
/** Hide the ring while retaining the logo or projected content. */
stop(label?: string): void {
if (label !== undefined) this.setProperty('complete-label', label);
this.setProperty('active', false);
}
render(): string {
const a = this.prepareContext().attributes;
const content = a.image
? ``
: a['icon-text'] ? `${escape(a['icon-text'])}` : '';
return `