import React, { useContext, useMemo } from "react";
import classNames from "classnames";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const CalendarDay = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("calendar", prefixCls);
  const {
    item,
    index,
    color,
    offset,
    rowHeight
  } = props;
  const calcStyle = useMemo(() => {
    const style = {
      height: rowHeight
    };
    if (item.type === "placeholder") {
      style.width = "100%";
      return style;
    }
    if (index === 0) {
      style.marginLeft = `${100 * offset / 7}%`;
    }
    if (color) {
      switch (item.type) {
        case "end":
        case "start":
        case "start-end":
        case "multiple-middle":
        case "multiple-selected":
          style.background = color;
          break;
        case "middle":
          style.color = color;
          break;
        default:
          break;
      }
    }
    return style;
  }, [item, index, color, offset, rowHeight]);
  const onClick = () => {
    var _a;
    if (props.item.type !== "disabled") {
      (_a = props.onClick) == null ? void 0 : _a.call(props, item);
    }
  };
  const renderTopInfo = () => {
    const {
      topInfo
    } = props.item;
    return topInfo || props.topInfoRender ? /* @__PURE__ */ React.createElement("div", {
      key: String(index),
      className: classNames(bem("top-info"))
    }, props.topInfoRender ? props.topInfoRender(props.item) : topInfo) : null;
  };
  const renderBottomInfo = () => {
    const {
      bottomInfo
    } = props.item;
    return bottomInfo || props.bottomInfoRender ? /* @__PURE__ */ React.createElement("div", {
      key: String(index),
      className: classNames(bem("bottom-info"))
    }, props.bottomInfoRender ? props.bottomInfoRender(props.item) : bottomInfo) : null;
  };
  const renderContent = () => {
    const {
      type: type2,
      text
    } = item;
    const Nodes = [renderTopInfo(), text, renderBottomInfo()];
    if (type2 === "selected") {
      return /* @__PURE__ */ React.createElement("div", {
        className: classNames(bem("selected-day")),
        style: {
          width: rowHeight,
          height: rowHeight,
          background: color
        }
      }, Nodes);
    }
    return Nodes;
  };
  const {
    type,
    className
  } = props.item;
  return type === "placeholder" ? /* @__PURE__ */ React.createElement("div", {
    key: String(index),
    className: classNames(bem("day")),
    style: calcStyle
  }) : /* @__PURE__ */ React.createElement("div", {
    role: "gridcell",
    style: calcStyle,
    className: classNames(bem("day", type), className),
    tabIndex: type === "disabled" ? void 0 : -1,
    onClick
  }, renderContent());
};
CalendarDay.defaultProps = {
  offset: 0
};
var stdin_default = CalendarDay;
export {
  stdin_default as default
};
