'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../locale/index.cjs');
require('../../locale-provider/index.cjs');
var index$1 = require('../../grid/index.cjs');
var index = require('../../tooltip/index.cjs');
var context = require('./context.cjs');
var useLocaleReceiver = require('../../locale-provider/src/useLocaleReceiver.cjs');
var _class = require('../../../utils/dom/class.cjs');
var en_US = require('../../../locale/lang/en_US.cjs');

const FormItemLabel = (props, {
  slots,
  emit,
  attrs
}) => {
  var _a, _b, _c, _d, _e;
  const {
    prefixCls,
    htmlFor,
    labelCol,
    labelAlign,
    colon,
    required,
    requiredMark
  } = {
    ...props,
    ...attrs
  };
  const [formLocale] = useLocaleReceiver.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 = _class.classNames(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*$/, "");
  if (props.tooltip || slots.tooltip) {
    const tooltipNode = vue.createVNode("span", {
      "class": `${prefixCls}-item-tooltip`
    }, [vue.createVNode(index.Tooltip, {
      "title": props.tooltip
    }, {
      default: () => [vue.createVNode(iconsVue.QuestionCircleOutlined, null, null)]
    })]);
    labelChildren = vue.createVNode(vue.Fragment, null, [labelChildren, slots.tooltip ? (_c = slots.tooltip) == null ? void 0 : _c.call(slots, {
      class: `${prefixCls}-item-tooltip`
    }) : tooltipNode]);
  }
  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 = _class.classNames({
    [`${prefixCls}-item-required`]: required,
    [`${prefixCls}-item-required-mark-optional`]: requiredMark === "optional",
    [`${prefixCls}-item-no-colon`]: !computedColon
  });
  return vue.createVNode(index$1.Col, {
    ...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.cjs.map
