import { createVNode, Fragment } from 'vue';
import { QuestionCircleOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../locale/index.mjs';
import '../../locale-provider/index.mjs';
import { Col } from '../../grid/index.mjs';
import { Tooltip } from '../../tooltip/index.mjs';
import { useInjectForm } from './context.mjs';
import { useLocaleReceiver } from '../../locale-provider/src/useLocaleReceiver.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import localeValues from '../../../locale/lang/en_US.mjs';

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("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
  } = 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(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 = createVNode("span", {
      "class": `${prefixCls}-item-tooltip`
    }, [createVNode(Tooltip, {
      "title": props.tooltip
    }, {
      default: () => [createVNode(QuestionCircleOutlined, null, null)]
    })]);
    labelChildren = createVNode(Fragment, null, [labelChildren, slots.tooltip ? (_c = slots.tooltip) == null ? void 0 : _c.call(slots, {
      class: `${prefixCls}-item-tooltip`
    }) : tooltipNode]);
  }
  if (requiredMark === "optional" && !required) {
    labelChildren = createVNode(Fragment, null, [labelChildren, createVNode("span", {
      "class": `${prefixCls}-item-optional`
    }, [((_d = formLocale.value) == null ? void 0 : _d.optional) || ((_e = localeValues.Form) == null ? void 0 : _e.optional)])]);
  }
  const labelClassName = classNames({
    [`${prefixCls}-item-required`]: required,
    [`${prefixCls}-item-required-mark-optional`]: requiredMark === "optional",
    [`${prefixCls}-item-no-colon`]: !computedColon
  });
  return createVNode(Col, {
    ...mergedLabelCol,
    "class": labelColClassName
  }, {
    default: () => [createVNode("label", {
      "for": htmlFor,
      "class": labelClassName,
      "title": typeof label === "string" ? label : "",
      "onClick": (e) => emit("click", e)
    }, [labelChildren])]
  });
};
FormItemLabel.displayName = "FormItemLabel";
FormItemLabel.inheritAttrs = false;

export { FormItemLabel as default };
//# sourceMappingURL=FormItemLabel.mjs.map
