"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index_esm = require("../../../@vant/use/dist/index.esm.js");
const useSyncPropRef = require("../composables/use-sync-prop-ref.js");
const index$1 = require("../tab/index.js");
const index = require("../tabs/index.js");
const PickerToolbar = require("../picker/PickerToolbar.js");
const basic = require("../utils/basic.js");
const create = require("../utils/create.js");
const props = require("../utils/props.js");
const [name, bem] = create.createNamespace("picker-group");
const PICKER_GROUP_KEY = Symbol(name);
const pickerGroupProps = basic.extend({
  tabs: props.makeArrayProp(),
  activeTab: props.makeNumericProp(0),
  nextStepText: String,
  showToolbar: props.truthProp
}, PickerToolbar.pickerToolbarProps);
var stdin_default = Vue.defineComponent({
  name,
  props: pickerGroupProps,
  emits: ["confirm", "cancel", "update:activeTab"],
  setup(props2, {
    emit,
    slots
  }) {
    const activeTab = useSyncPropRef.useSyncPropRef(() => props2.activeTab, (value) => emit("update:activeTab", value));
    const {
      children,
      linkChildren
    } = index_esm.useChildren(PICKER_GROUP_KEY);
    linkChildren();
    const showNextButton = () => +activeTab.value < props2.tabs.length - 1 && props2.nextStepText;
    const onConfirm = () => {
      if (showNextButton()) {
        activeTab.value = +activeTab.value + 1;
      } else {
        emit("confirm", children.map((item) => item.confirm()));
      }
    };
    const onCancel = () => emit("cancel");
    return () => {
      var _a, _b;
      let childNodes = (_b = (_a = slots.default) == null ? void 0 : _a.call(slots)) == null ? void 0 : _b.filter((node) => node.type !== Vue.Comment).map((node) => {
        if (node.type === Vue.Fragment) {
          return node.children;
        }
        return node;
      });
      if (childNodes) {
        childNodes = basic.flat(childNodes);
      }
      const confirmButtonText = showNextButton() ? props2.nextStepText : props2.confirmButtonText;
      return Vue.createVNode("div", {
        "class": bem()
      }, [props2.showToolbar ? Vue.createVNode(PickerToolbar.default, {
        "title": props2.title,
        "cancelButtonText": props2.cancelButtonText,
        "confirmButtonText": confirmButtonText,
        "onConfirm": onConfirm,
        "onCancel": onCancel
      }, basic.pick(slots, PickerToolbar.pickerToolbarSlots)) : null, Vue.createVNode(index.Tabs, {
        "active": activeTab.value,
        "onUpdate:active": ($event) => activeTab.value = $event,
        "class": bem("tabs"),
        "shrink": true,
        "animated": true,
        "lazyRender": false
      }, {
        default: () => [props2.tabs.map((title, index2) => Vue.createVNode(index$1.Tab, {
          "title": title,
          "titleClass": bem("tab-title")
        }, {
          default: () => [childNodes == null ? void 0 : childNodes[index2]]
        }))]
      })]);
    };
  }
});
exports.PICKER_GROUP_KEY = PICKER_GROUP_KEY;
exports.default = stdin_default;
exports.pickerGroupProps = pickerGroupProps;
