import { isVNode as ie, defineComponent as ce, useSlots as ue, ref as pe, shallowRef as w, computed as R, unref as a, watch as M, createVNode as o, Fragment as _, openBlock as p, createBlock as x, mergeProps as de, withCtx as I, resolveDynamicComponent as T, createElementBlock as fe, renderList as me, normalizeStyle as he } from "vue";
import { Col as F, Flex as k, Button as q, Row as ge } from "@aplus-frontend/antdv";
import { isArray as xe, isBoolean as ye, omit as ve } from "lodash-unified";
import { floorWith as H } from "../../utils/format.mjs";
import { useDevWarning as Se } from "../../utils/warning.mjs";
import "../../config-provider/index.mjs";
import "../../utils/index.mjs";
import "../ap-form.vue.mjs";
import "../item/index.vue2.mjs";
import { genRealChildren as G } from "../item-group/helper.mjs";
import Ce from "../style/search-form.mjs";
import "./components/popover-filter.vue.mjs";
import "./components/popover-sorter/index.vue.mjs";
import { getTargetNode as we } from "./hooks/use-collapse-input-count.mjs";
import { useCountPerRow as Re } from "./hooks/use-count-per-row.mjs";
import { useSorter as _e } from "./hooks/use-sorter.mjs";
import { execFunc as J, diffFormItem as Fe } from "./utils.mjs";
import { useNamespace as be } from "../../config-provider/hooks/use-namespace.mjs";
import { useLocale as Ae } from "../../config-provider/hooks/use-locale.mjs";
import { isDef as K } from "../../utils/is.mjs";
import Q from "../item/index.vue.mjs";
import Be from "./components/popover-filter.vue2.mjs";
import Ne from "./components/popover-sorter/index.vue2.mjs";
import Ie from "../ap-form.vue2.mjs";
function Te(d) {
  return typeof d == "function" || Object.prototype.toString.call(d) === "[object Object]" && !ie(d);
}
const r = 100, nt = /* @__PURE__ */ ce({
  name: "ApFormSearchForm",
  __name: "index",
  props: {
    layout: {
      default: "horizontal"
    },
    labelCol: {},
    wrapperCol: {},
    colon: {
      type: Boolean,
      default: !0
    },
    labelAlign: {
      default: "right"
    },
    labelWrap: {
      type: Boolean
    },
    prefixCls: {},
    requiredMark: {},
    hideRequiredMark: {
      type: Boolean,
      default: !1
    },
    rules: {},
    validateMessages: {},
    validateOnRuleChange: {
      type: Boolean,
      default: !0
    },
    scrollToFirstError: {},
    onSubmit: {},
    name: {},
    validateTrigger: {
      default: "change"
    },
    size: {},
    disabled: {
      type: Boolean
    },
    onFieldsChange: {},
    onFinish: {},
    onFinishFailed: {},
    onValidate: {},
    variant: {},
    initialValues: {},
    onValuesChange: {},
    syncToUrl: {
      type: [Boolean, Function]
    },
    syncToUrlPriority: {
      type: Boolean
    },
    autoFocusFirstInput: {
      type: Boolean
    },
    collapse: {
      type: Boolean,
      default: void 0
    },
    defaultCollapse: {
      type: Boolean,
      default: !0
    },
    "onUpdate:collapse": {},
    searchText: {},
    resetText: {},
    onReset: {},
    customReset: {
      type: Boolean,
      default: !1
    },
    extraInAction: {
      type: Boolean,
      default: !1
    },
    forceExpand: {
      type: Boolean,
      default: !1
    },
    countPerRow: {
      default: 5
    },
    submitLoading: {
      type: Boolean
    },
    maxRows: {
      default: 2
    },
    sortable: {
      type: Boolean,
      default: !0
    },
    resizeTarget: {},
    resize: {},
    loadingDelay: {
      default: 300
    }
  },
  setup(d, {
    expose: X
  }) {
    const y = ue(), t = d;
    Se("SearchForm").deprecated(typeof t.resizeTarget < "u", "resizeTarget", "resize.target");
    const Y = Ce("ap-form-search-form"), {
      b: f
    } = be("ap-form-search-form"), {
      t: P
    } = Ae(), v = pe(), E = w(), Z = Re(t, E), W = w();
    function z() {
      const e = v.value?.getFieldsValueTransformed(!0);
      J(t.onSubmit, e);
    }
    function ee() {
      t.customReset || v.value?.resetFields?.(), J(t.onReset);
    }
    const te = (e) => K(e) ? (xe(e) ? e : [e]).join("") : Date.now();
    let O = [];
    const m = w(G(y.default())), c = w(y.extra?.()), L = R(() => H(r / a(Z), 4)), {
      items: b,
      sorted: $,
      handleClickConfirm: A
    } = _e(m);
    M(() => y.default(), (e) => {
      O = m.value, m.value = Fe(O, G(e)), $.value = !1;
    }), M(() => y.extra?.(), (e) => {
      c.value = e;
    });
    function oe(e) {
      return H(e * (r / 24), 4);
    }
    const n = R(() => {
      const e = m.value, u = [], l = [], g = [], s = a(L);
      let S = 0, B = 0;
      const le = r * t.maxRows - s * (a(c) && !t.extraInAction ? 2 : 1);
      e.forEach((N) => {
        const D = we(N);
        if (!D)
          return;
        const i = D.props;
        if (ye(i.hidden) ? !!i.hidden : K(i.hidden))
          u.push(N);
        else {
          let C = i.span ? oe(i.span) : s;
          const V = {
            node: N,
            span: C,
            key: `ApFormSearchFormItem-${te(i.name)}-${i._signal}`
          }, U = r - S % r;
          U < C && (C += U), S += C, S > le ? l.push(V) : (B = S, g.push(V));
        }
      });
      const j = r - (B + s) % r, re = Math.ceil(B) % r < s, se = j < s ? r : j;
      return {
        hideNode: o(_, null, [u]),
        nodes: g,
        collapseNodes: l,
        extraSpan: se,
        lastRowOnlyIncludeActionAndExtra: re
      };
    }), h = (e) => `${e}%`, ae = R(() => {
      let e;
      const u = n.value.collapseNodes.length || t.sortable && m.value.length, l = o(F, {
        flex: h(a(L)),
        key: "actionWrapper"
      }, {
        default: () => [o(Q, null, {
          default: () => [o(k, {
            wrap: "wrap",
            justify: n.value.lastRowOnlyIncludeActionAndExtra && !(a(c) && t.extraInAction) ? "flex-end" : "space-between"
          }, {
            default: () => [o(k, {
              gap: 8,
              wrap: "wrap"
            }, {
              default: () => [u ? o("div", {
                class: f("column-setting-trigger-wrapper")
              }, [n.value.collapseNodes.length ? o(Be, {
                onSubmit: z,
                config: n.value.collapseNodes,
                submitLoading: t.submitLoading
              }, null) : null, t.sortable && b.value.length ? o(Ne, {
                ref: W,
                items: b.value,
                onClickConfirm: A,
                sorted: $.value
              }, null) : null]) : null, o(q, {
                type: "primary",
                onClick: z,
                loading: t.submitLoading ? {
                  delay: t.loadingDelay
                } : !1,
                htmlType: "submit",
                class: f("action-btn")
              }, {
                default: () => [t.searchText || P("ap.apForm.search.search")]
              }), o(q, {
                onClick: ee,
                type: "text",
                class: [f("action-btn"), f("action-btn-reset")]
              }, {
                default: () => [t.resetText || P("ap.apForm.search.reset")]
              })]
            }), t.extraInAction ? a(c) : null]
          })]
        })]
      }), g = !t.extraInAction && a(c) ? o(F, {
        flex: h(n.value.extraSpan),
        key: "extraNode"
      }, {
        default: () => [o(Q, null, {
          default: () => [o(k, {
            justify: n.value.extraSpan === r || n.value.lastRowOnlyIncludeActionAndExtra ? "start" : "flex-end"
          }, Te(e = a(c)) ? e : {
            default: () => [e]
          })]
        })]
      }) : null, s = o(F, {
        flex: h(n.value.extraSpan)
      }, null);
      return n.value.lastRowOnlyIncludeActionAndExtra ? o(_, null, [g || s, l]) : o(_, null, [l, g]);
    });
    function ne() {
      const e = W.value?.getCachedList();
      A(e);
    }
    return X({
      apForm: R(() => a(v)),
      getSorterItems: () => b.value,
      setSorterItems: A,
      resetSorterItems: ne
    }), (e, u) => (p(), x(Ie, de({
      ref_key: "apForm",
      ref: v,
      class: [a(f)(), a(Y)]
    }, a(ve)(t, ["collapse", "defaultCollapse", "onUpdate:collapse", "searchText", "resetText", "onSubmit", "onReset", "extraInAction", "forceExpand", "countPerRow"])), {
      default: I(() => [(p(), x(T(n.value.hideNode))), o(a(ge), {
        ref_key: "contentWrapperRef",
        ref: E,
        gutter: 8
      }, {
        default: I(() => [(p(!0), fe(_, null, me(n.value.nodes, (l) => (p(), x(a(F), {
          key: l.key,
          flex: h(l.span),
          style: he({
            maxWidth: h(l.span)
          })
        }, {
          default: I(() => [(p(), x(T(l.node)))]),
          _: 2
        }, 1032, ["flex", "style"]))), 128)), (p(), x(T(ae.value)))]),
        _: 1
      }, 512)]),
      _: 1
    }, 16, ["class"]));
  }
});
export {
  nt as default
};
