'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../directives/index.cjs');
var vueTypes = require('../../../utils/vue/vueTypes.cjs');
var KeyCode = require('../../../utils/KeyCode.cjs');
var index = require('../../../directives/ant-input/index.cjs');

var Options = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  props: {
    disabled: {
      type: Boolean,
      default: void 0
    },
    changeSize: Function,
    quickGo: Function,
    selectComponentClass: vueTypes.default.any,
    current: Number,
    pageSizeOptions: vueTypes.default.array.def(["10", "20", "50", "100"]),
    pageSize: Number,
    buildOptionText: Function,
    locale: vueTypes.default.object,
    rootPrefixCls: String,
    selectPrefixCls: String,
    goButton: vueTypes.default.any
  },
  setup(props) {
    const goInputText = vue.ref("");
    const validValue = vue.computed(() => {
      return !goInputText.value || Number.isNaN(goInputText.value) ? void 0 : Number(goInputText.value);
    });
    const defaultBuildOptionText = (opt) => {
      return `${opt.value} ${props.locale.items_per_page}`;
    };
    const handleChange = (e) => {
      const {
        value,
        composing
      } = e.target;
      if (e.isComposing || composing || goInputText.value === value)
        return;
      goInputText.value = value;
    };
    const handleBlur = (e) => {
      const {
        goButton,
        quickGo,
        rootPrefixCls
      } = props;
      if (goButton || goInputText.value === "")
        return;
      if (e.relatedTarget && (e.relatedTarget.className.includes(`${rootPrefixCls}-item-link`) || e.relatedTarget.className.includes(`${rootPrefixCls}-item`))) {
        goInputText.value = "";
      } else {
        quickGo(validValue.value);
        goInputText.value = "";
      }
    };
    const go = (e) => {
      if (goInputText.value === "")
        return;
      if (e.keyCode === KeyCode.KeyCode.ENTER || e.type === "click") {
        props.quickGo(validValue.value);
        goInputText.value = "";
      }
    };
    const pageSizeOptions = vue.computed(() => {
      const {
        pageSize,
        pageSizeOptions: pageSizeOptions2
      } = props;
      if (pageSizeOptions2.some((option) => option.toString() === pageSize.toString()))
        return pageSizeOptions2;
      return pageSizeOptions2.concat([pageSize.toString()]).sort((a, b) => {
        const numberA = Number.isNaN(Number(a)) ? 0 : Number(a);
        const numberB = Number.isNaN(Number(b)) ? 0 : Number(b);
        return numberA - numberB;
      });
    });
    return () => {
      const {
        rootPrefixCls,
        locale,
        changeSize,
        quickGo,
        goButton,
        selectComponentClass: Select,
        selectPrefixCls,
        pageSize,
        disabled
      } = props;
      const prefixCls = `${rootPrefixCls}-options`;
      let changeSelect = null;
      let goInput = null;
      let gotoButton = null;
      if (!changeSize && !quickGo)
        return null;
      if (changeSize && Select) {
        const buildOptionText = props.buildOptionText || defaultBuildOptionText;
        const options = pageSizeOptions.value.map((opt, i) => {
          return vue.createVNode(Select.Option, {
            "key": i,
            "value": opt
          }, {
            default: () => [buildOptionText({
              value: opt
            })]
          });
        });
        changeSelect = vue.createVNode(Select, {
          "disabled": disabled,
          "prefixCls": selectPrefixCls,
          "showSearch": false,
          "class": `${prefixCls}-size-changer`,
          "optionLabelProp": "children",
          "value": (pageSize || pageSizeOptions.value[0]).toString(),
          "onChange": (value) => changeSize(Number(value)),
          "getPopupContainer": (triggerNode) => triggerNode.parentNode
        }, {
          default: () => [options]
        });
      }
      if (quickGo) {
        if (goButton) {
          gotoButton = typeof goButton === "boolean" ? vue.createVNode("button", {
            "type": "button",
            "onClick": go,
            "onKeyup": go,
            "disabled": disabled,
            "class": `${prefixCls}-quick-jumper-button`
          }, [locale.jump_to_confirm]) : vue.createVNode("span", {
            "onClick": go,
            "onKeyup": go
          }, [goButton]);
        }
        goInput = vue.createVNode("div", {
          "class": `${prefixCls}-quick-jumper`
        }, [locale.jump_to, vue.withDirectives(vue.createVNode("input", {
          "disabled": disabled,
          "type": "text",
          "value": goInputText.value,
          "onInput": handleChange,
          "onChange": handleChange,
          "onKeyup": go,
          "onBlur": handleBlur
        }, null), [[index.antInputDirective]]), locale.page, gotoButton]);
      }
      return vue.createVNode("li", {
        "class": `${prefixCls}`
      }, [changeSelect, goInput]);
    };
  }
});

exports.default = Options;
//# sourceMappingURL=Options.cjs.map
