'use strict';

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

var vue = require('vue');
require('../../../utils/index.js');
var sortSelector = require('./sort-selector.js');
var createNamespace = require('../../../utils/create-namespace.js');
var addUnit = require('../../../utils/add-unit.js');

"use strict";
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "LlSortSelector" },
  __name: "sort-selector",
  props: sortSelector.sortSelectorProps,
  emits: ["change", "update:selectValue", "update:sortValue"],
  setup(__props, { emit: __emit }) {
    const bem = createNamespace.createNamespace("sort-selector");
    const props = __props;
    const emits = __emit;
    const selectValue = vue.computed({
      get: () => props.selectValue || props.options?.[0]?.value || null,
      set: (val) => {
        emits("update:selectValue", val);
      }
    });
    const sortValue = vue.computed({
      get: () => props.sortValue || props.options?.[0]?.orderBy || "asc",
      set: (val) => {
        emits("update:sortValue", val);
      }
    });
    const handleSelect = (value, option) => {
      const newSelectVal = value;
      const newSortVal = option.orderBy || "asc";
      selectValue.value = newSelectVal;
      sortValue.value = newSortVal;
      emits("change", newSelectVal, newSortVal);
    };
    const handleSort = () => {
      const newSortVal = sortValue.value === "asc" ? "desc" : "asc";
      sortValue.value = newSortVal;
      emits("change", selectValue.value, newSortVal);
    };
    vue.onMounted(() => {
      if (!props.selectValue && props.options?.length > 0) {
        emits("update:selectValue", props.options[0]?.value || "");
      }
      if (!props.sortValue) {
        emits("update:sortValue", props.options[0]?.orderBy || "asc");
      }
    });
    return (_ctx, _cache) => {
      const _component_ll_select = vue.resolveComponent("ll-select");
      const _component_ll_icon_base = vue.resolveComponent("ll-icon-base");
      const _component_ll_button = vue.resolveComponent("ll-button");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass([vue.unref(bem).b()])
        },
        [
          vue.createVNode(_component_ll_select, {
            value: selectValue.value,
            "onUpdate:value": _cache[0] || (_cache[0] = ($event) => selectValue.value = $event),
            size: _ctx.size || _ctx.extendSize,
            placeholder: "\u8BF7\u9009\u62E9",
            style: vue.normalizeStyle({
              minWidth: vue.unref(addUnit.addUnit)(_ctx.minWidth),
              maxWidth: _ctx.maxWidth ? vue.unref(addUnit.addUnit)(_ctx.maxWidth) : void 0
            }),
            options: _ctx.options,
            "field-names": _ctx.fieldNames,
            class: vue.normalizeClass(vue.unref(bem).e("select-content")),
            onSelect: handleSelect
          }, null, 8, ["value", "size", "style", "options", "field-names", "class"]),
          vue.createCommentVNode(" \u6392\u5E8F "),
          vue.createVNode(_component_ll_button, {
            class: vue.normalizeClass([vue.unref(bem).e("sort-btn")]),
            type: "text",
            size: _ctx.size || _ctx.extendSize,
            onClick: handleSort
          }, {
            icon: vue.withCtx(() => [
              vue.createVNode(_component_ll_icon_base, {
                arrow: true,
                "is-white-bg": false,
                "is-show-container": false,
                "tooltip-title": sortValue.value === "asc" ? _ctx.ascText || "\u5347\u5E8F" : _ctx.descText || "\u964D\u5E8F",
                "icon-name": sortValue.value === "asc" ? "icon-ascending" : "icon-descending"
              }, null, 8, ["tooltip-title", "icon-name"])
            ]),
            _: 1
            /* STABLE */
          }, 8, ["class", "size"])
        ],
        2
        /* CLASS */
      );
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=sort-selector.vue2.js.map
