/* eslint-disable class-methods-use-this */
import { html, css, nothing } from '@lion/core';
import { ObserverMixin } from '@lion/core/src/ObserverMixin.js';
import { FormatMixin } from '@lion/field';
export const ChoiceInputMixin = superclass =>
// eslint-disable-next-line
class ChoiceInputMixin extends FormatMixin(ObserverMixin(superclass)) {
get delegations() {
return {
...super.delegations,
target: () => this.inputElement,
properties: [...super.delegations.properties, 'checked'],
attributes: [...super.delegations.attributes, 'checked'],
};
}
get events() {
return {
...super.events,
_toggleChecked: [() => this, 'user-input-changed'],
};
}
static get syncObservers() {
return {
...super.syncObservers,
_syncModelValueToChecked: ['modelValue'],
};
}
static get asyncObservers() {
return {
...super.asyncObservers,
_reflectCheckedToCssClass: ['modelValue'],
};
}
get choiceChecked() {
return this.modelValue.checked;
}
set choiceChecked(checked) {
if (this.modelValue.checked !== checked) {
this.modelValue = { value: this.modelValue.value, checked };
}
}
get choiceValue() {
return this.modelValue.value;
}
set choiceValue(value) {
if (this.modelValue.value !== value) {
this.modelValue = { value, checked: this.modelValue.checked };
}
}
constructor() {
super();
this.modelValue = { value: '', checked: false };
}
/**
* @override
* Override InteractionStateMixin
* 'prefilled' should be false when modelValue is { checked: false }, which would return
* true in original method (since non-empty objects are considered prefilled by default).
*/
static _isPrefilled(modelValue) {
return modelValue.checked;
}
static get styles() {
return [
css`
:host {
display: flex;
}
.choice-field__graphic-container {
display: none;
}
`,
];
}
render() {
return html`