import { defineComponent, computed, onMounted, resolveComponent, createElementBlock, openBlock, normalizeClass, unref, createVNode, createCommentVNode, normalizeStyle, withCtx } from 'vue';
import '../../../utils/index.mjs';
import { sortSelectorProps } from './sort-selector.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';
import { addUnit } from '../../../utils/add-unit.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlSortSelector" },
  __name: "sort-selector",
  props: sortSelectorProps,
  emits: ["change", "update:selectValue", "update:sortValue"],
  setup(__props, { emit: __emit }) {
    const bem = createNamespace("sort-selector");
    const props = __props;
    const emits = __emit;
    const selectValue = computed({
      get: () => props.selectValue || props.options?.[0]?.value || null,
      set: (val) => {
        emits("update:selectValue", val);
      }
    });
    const sortValue = 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);
    };
    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 = resolveComponent("ll-select");
      const _component_ll_icon_base = resolveComponent("ll-icon-base");
      const _component_ll_button = resolveComponent("ll-button");
      return openBlock(), createElementBlock(
        "div",
        {
          class: normalizeClass([unref(bem).b()])
        },
        [
          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: normalizeStyle({
              minWidth: unref(addUnit)(_ctx.minWidth),
              maxWidth: _ctx.maxWidth ? unref(addUnit)(_ctx.maxWidth) : void 0
            }),
            options: _ctx.options,
            "field-names": _ctx.fieldNames,
            class: normalizeClass(unref(bem).e("select-content")),
            onSelect: handleSelect
          }, null, 8, ["value", "size", "style", "options", "field-names", "class"]),
          createCommentVNode(" \u6392\u5E8F "),
          createVNode(_component_ll_button, {
            class: normalizeClass([unref(bem).e("sort-btn")]),
            type: "text",
            size: _ctx.size || _ctx.extendSize,
            onClick: handleSort
          }, {
            icon: withCtx(() => [
              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 */
      );
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=sort-selector.vue2.mjs.map
