'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var en_US = require('../locale/lang/en_US.js');
var classNames = require('../_util/classNames.js');
var LocaleReceiver = require('../locale-provider/LocaleReceiver.js');
var Col = require('../grid/Col.js');
var context = require('./context.js');

const FormItemLabel = (props, {
  slots,
  emit,
  attrs
}) => {
  var _a, _b, _c, _d, _e;
  const {
    prefixCls,
    htmlFor,
    labelCol,
    labelAlign,
    colon,
    required,
    requiredMark
  } = {
    ...props,
    ...attrs
  };
  const [formLocale] = LocaleReceiver.useLocaleReceiver("Form");
  const label = (_b = props.label) != null ? _b : (_a = slots.label) == null ? void 0 : _a.call(slots);
  if (!label)
    return null;
  const {
    vertical,
    labelAlign: contextLabelAlign,
    labelCol: contextLabelCol,
    labelWrap,
    colon: contextColon
  } = context.useInjectForm();
  const mergedLabelCol = labelCol || (contextLabelCol == null ? void 0 : contextLabelCol.value) || {};
  const mergedLabelAlign = labelAlign || (contextLabelAlign == null ? void 0 : contextLabelAlign.value);
  const labelClsBasic = `${prefixCls}-item-label`;
  const labelColClassName = classNames.default(labelClsBasic, mergedLabelAlign === "left" && `${labelClsBasic}-left`, mergedLabelCol.class, {
    [`${labelClsBasic}-wrap`]: !!labelWrap.value
  });
  let labelChildren = label;
  const computedColon = colon === true || (contextColon == null ? void 0 : contextColon.value) !== false && colon !== false;
  const haveColon = computedColon && !vertical.value;
  if (haveColon && typeof label === "string" && label.trim() !== "")
    labelChildren = label.replace(/[:|：]\s*$/, "");
  labelChildren = vue.createVNode(vue.Fragment, null, [labelChildren, (_c = slots.tooltip) == null ? void 0 : _c.call(slots, {
    class: `${prefixCls}-item-tooltip`
  })]);
  if (requiredMark === "optional" && !required) {
    labelChildren = vue.createVNode(vue.Fragment, null, [labelChildren, vue.createVNode("span", {
      "class": `${prefixCls}-item-optional`
    }, [((_d = formLocale.value) == null ? void 0 : _d.optional) || ((_e = en_US.default.Form) == null ? void 0 : _e.optional)])]);
  }
  const labelClassName = classNames.default({
    [`${prefixCls}-item-required`]: required,
    [`${prefixCls}-item-required-mark-optional`]: requiredMark === "optional",
    [`${prefixCls}-item-no-colon`]: !computedColon
  });
  return vue.createVNode(Col.default, vue.mergeProps(mergedLabelCol, {
    "class": labelColClassName
  }), {
    default: () => [vue.createVNode("label", {
      "for": htmlFor,
      "class": labelClassName,
      "title": typeof label === "string" ? label : "",
      "onClick": (e) => emit("click", e)
    }, [labelChildren])]
  });
};
FormItemLabel.displayName = "FormItemLabel";
FormItemLabel.inheritAttrs = false;

exports.default = FormItemLabel;
//# sourceMappingURL=FormItemLabel.js.map
