import React, { isValidElement, useContext } from "react";
import classnames from "classnames";
import Icon from "../icon";
import { isDef } from "../utils";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const Cell = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("cell", prefixCls);
  const renderLabel = () => {
    const showLabel = isDef(props.label);
    if (showLabel) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("label"), props.labelClass)
      }, props.label);
    }
    return null;
  };
  const renderTitle = () => {
    if (isDef(props.title)) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("title"), props.titleClass),
        style: props.titleStyle
      }, props.title, renderLabel());
    }
    return null;
  };
  const renderValue = () => {
    const hasTitle = isDef(props.title);
    const hasValue = props.children || isDef(props.value);
    if (hasValue) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("value", {
          alone: !hasTitle
        }), props.valueClass)
      }, props.children ? props.children : /* @__PURE__ */ React.createElement("span", null, props.value));
    }
    return null;
  };
  const renderLeftIcon = () => {
    if (typeof props.icon === "string") {
      return /* @__PURE__ */ React.createElement(Icon, {
        name: props.icon,
        className: classnames(bem("left-icon")),
        classPrefix: props.iconPrefix
      });
    }
    if (/* @__PURE__ */ isValidElement(props.icon)) {
      return props.icon;
    }
    return null;
  };
  const renderRightIcon = () => {
    if (props.rightIcon) {
      return props.rightIcon;
    }
    if (props.isLink) {
      const name = props.arrowDirection ? `arrow-${props.arrowDirection}` : "arrow";
      return /* @__PURE__ */ React.createElement(Icon, {
        name,
        className: classnames(bem("right-icon"))
      });
    }
    return null;
  };
  const {
    className,
    style,
    size,
    center,
    border = true,
    isLink,
    required,
    onClick
  } = props;
  const clickable = isLink || props.clickable;
  const classes = {
    center,
    required,
    clickable,
    borderless: !border
  };
  if (size) {
    classes[size] = !!size;
  }
  return /* @__PURE__ */ React.createElement("div", {
    style,
    className: classnames(bem(classes), className),
    role: clickable ? "button" : void 0,
    onClick
  }, renderLeftIcon(), renderTitle(), renderValue(), renderRightIcon(), props.extra);
};
var stdin_default = Cell;
export {
  stdin_default as default
};
