import { j as n } from "../../node_modules/react/jsx-runtime.mjs";
import { useState as h } from "react";
import { useImmer as B } from "../../node_modules/use-immer/dist/use-immer.module.mjs";
import { BitzPickDrawer as I } from "../BitzDrawer/index.mjs";
import N from "../../node_modules/antd/es/input/index.mjs";
import g from "../../node_modules/@ant-design/icons/es/icons/DownOutlined.mjs";
import K from "../../node_modules/antd/es/tabs/index.mjs";
import M from "../../node_modules/antd/es/radio/index.mjs";
const r = { label: "请选择", key: "", value: "" }, O = (t) => {
  var f;
  const [v, m] = h(((f = t.defaultValue) == null ? void 0 : f.join(" / ")) || ""), [x, d] = h(!1), [o, b] = B([{ ...r, children: t.options }]), [u, i] = h(r.label), j = () => {
    d(!1), b([{ ...r, children: t.options }]), i(r.label);
  }, k = () => {
    var s;
    const l = o.slice(1), a = l.map((c) => ({
      label: c.label,
      value: c.value
    })), e = l.map((c) => c.key);
    (s = t.onChange) == null || s.call(t, e, a), d(!1), m(e.join(" / "));
  }, C = (l) => {
    b((a) => {
      const e = o.at(-1), s = a.at(-1);
      if (e) {
        const c = e.children, y = e.label;
        if (c != null && c.find((z) => z.label === y)) {
          s.label = l.label, s.key = l.label, i(l.label);
          return;
        }
      }
      a.push({
        key: l.label,
        label: l.label,
        value: l.label,
        children: l.children ? l.children : s.children
      }), i(l.label);
    });
  }, p = (l) => {
    i(l);
    const a = o.slice(0, o.findIndex((e) => e.label === l) + 1);
    b(a);
  };
  return /* @__PURE__ */ n.jsxs("div", { className: "bitzCascaderMobileBlock", children: [
    /* @__PURE__ */ n.jsx(
      N,
      {
        placeholder: t.placeholder,
        onClick: () => d(!0),
        value: v,
        suffix: /* @__PURE__ */ n.jsx(g, {})
      }
    ),
    /* @__PURE__ */ n.jsx(
      I,
      {
        open: x,
        handleCancel: j,
        handleOk: k,
        children: /* @__PURE__ */ n.jsx(
          K,
          {
            defaultActiveKey: u,
            activeKey: u,
            items: o.map((l) => {
              var a;
              return {
                key: l.label,
                label: l.label,
                children: (a = l.children) == null ? void 0 : a.map((e, s) => /* @__PURE__ */ n.jsxs(
                  "div",
                  {
                    className: "item",
                    onClick: () => C(e),
                    children: [
                      /* @__PURE__ */ n.jsx("span", { children: e.label }),
                      /* @__PURE__ */ n.jsx("span", { children: e.label === u ? /* @__PURE__ */ n.jsx(M, { checked: !0 }) : "" })
                    ]
                  },
                  s
                ))
              };
            }),
            onChange: p
          }
        )
      }
    )
  ] });
}, T = O;
export {
  T as default
};
