<script lang="ts">
import { Component } from 'vue-property-decorator';
import get from 'lodash/get';

import DropdownEnumSelect from '../../DropdownEnumSelect.vue';

@Component({})
export default class DropdownEnumSelectEx extends DropdownEnumSelect {
  get selectedTitle() {
    const selected = this.options.find((e) => e.value === this.valueId);
    return (selected && selected.label) || this.defaultTitle;
  }

  get options() {
    const enumVar = this.fieldNode && this.fieldNode.enum;
    if (enumVar) {
      return [
        ...enumVar
          .filter((item) => get(this, item.key, false))
          .map((item) => {
            return {
              value: item.value,
              label: item.value,
            };
          }),
      ];
    }

    console.error(
      'empty options for enum dropdown',
      this.fieldNode.name,
      this.value,
      this.fieldNode
    );

    return [];
  }

  changeHandler(value, inputEvents) {
    inputEvents.input(value?.value);
  }
}
</script>
