import { resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
import { defineComponent } from "vue";
import { mergeProps } from "@vue/runtime-core";
import List from '../virtual-list';
import { getLabel } from "./utils";
export default defineComponent({
  name: 'x-option-list',
  props: {
    prefixCls: String,
    options: Array,
    values: Set,
    height: Number,
    virtualScroll: Boolean,
    onSelect: Function
  },
  slots: ['label'],

  setup(props, {
    attrs,
    slots
  }) {
    const {
      prefixCls
    } = props;
    const optionPrefixCls = `${prefixCls}-option`;

    const item = (...args) => {
      var _slots$default;

      const {
        item: option,
        index
      } = args[0];
      let label = (_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots, ...args);
      if (label === undefined) label = getLabel(option);
      if (slots.label) label = slots.label({
        option,
        label,
        index
      });
      const selected = props.values.has(option.value);
      let itemProps = {
        class: [optionPrefixCls, {
          [`${optionPrefixCls}-selected`]: selected,
          [`${optionPrefixCls}-disabled`]: option.disabled
        }],
        onClick: () => props.onSelect(option)
      };
      itemProps = mergeProps(itemProps, option);
      return _createVNode("div", itemProps, [_createVNode("div", {
        "class": `${optionPrefixCls}-content`
      }, [label])]);
    };

    return () => {
      const a = {
        default: item
      };
      return _createVNode(List, {
        "virtual": props.virtualScroll,
        "data": props.options,
        "itemKey": "value"
      }, a);
    };
  }

});