"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
  __name: "index",
  props: {
    // 字段名称，用于表单校验
    name: {
      type: String,
      required: true
    },
    // 显示标签
    label: {
      type: String,
      required: true
    },
    // 按钮的值
    value: {
      type: [String, Number],
      required: true
    },
    // 宽度设置
    width: {
      type: String,
      default: ""
    },
    // v-model 绑定的值
    modelValue: {
      type: [String, Number, Array],
      default: ""
    },
    // 是否多选模式
    multiple: {
      type: Boolean,
      default: false
    },
    // 是否禁用
    disabled: {
      type: Boolean,
      default: false
    }
  },
  emits: ["update:modelValue", "change"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const validateField = common_vendor.inject("validateField", () => {
    });
    const parseModelValue = (val) => {
      if (!val)
        return [];
      if (Array.isArray(val)) {
        return val.map((v) => v.toString());
      }
      const cleanValue = val.toString().replace(/^,+/, "");
      if (cleanValue.includes("|")) {
        return cleanValue.split("|");
      }
      if (cleanValue.includes(",")) {
        return cleanValue.split(",");
      }
      return cleanValue ? [cleanValue] : [];
    };
    const isChecked = common_vendor.computed(() => {
      if (props.multiple) {
        const currentValue = parseModelValue(props.modelValue);
        return currentValue.includes(props.value.toString());
      }
      return props.modelValue === props.value;
    });
    const toggleSelect = () => {
      if (props.disabled)
        return;
      if (props.multiple) {
        const currentValue = parseModelValue(props.modelValue);
        const index = currentValue.indexOf(props.value.toString());
        let newValue;
        if (index === -1) {
          newValue = [...currentValue, props.value.toString()];
        } else {
          newValue = currentValue.filter((v) => v !== props.value.toString());
        }
        const emitValue = newValue.join(",");
        emit("update:modelValue", emitValue);
        emit("change", emitValue, newValue);
      } else {
        emit("update:modelValue", props.value);
        emit("change", props.value);
      }
      common_vendor.nextTick$1(() => {
        if (props.name) {
          validateField(props.name);
        }
      });
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.t(__props.label),
        b: common_vendor.n(isChecked.value ? "form-icon-onoffbutton-checked" : "form-icon-onoffbutton-unchecked"),
        c: isChecked.value ? 1 : "",
        d: __props.disabled ? 1 : "",
        e: common_vendor.o(toggleSelect),
        f: common_vendor.gei(_ctx, "")
      };
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b253cbc5"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/components/SsOnoffButton/index.js.map
