"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const Grid = require("../grid/Grid.js");
const index_esm = require("../../../@vant/use/dist/index.esm.js");
const useRoute = require("../composables/use-route.js");
const index$1 = require("../icon/index.js");
const index = require("../badge/index.js");
const constant = require("../utils/constant.js");
const basic = require("../utils/basic.js");
const create = require("../utils/create.js");
const format = require("../utils/format.js");
const props = require("../utils/props.js");
const [name, bem] = create.createNamespace("grid-item");
const gridItemProps = basic.extend({}, useRoute.routeProps, {
  dot: Boolean,
  text: String,
  icon: String,
  badge: props.numericProp,
  iconColor: String,
  iconPrefix: String,
  badgeProps: Object
});
var stdin_default = Vue.defineComponent({
  name,
  props: gridItemProps,
  setup(props2, {
    slots
  }) {
    const {
      parent,
      index: index$2
    } = index_esm.useParent(Grid.GRID_KEY);
    const route = useRoute.useRoute();
    if (!parent) {
      return;
    }
    const rootStyle = Vue.computed(() => {
      const {
        square,
        gutter,
        columnNum
      } = parent.props;
      const percent = `${100 / +columnNum}%`;
      const style = {
        flexBasis: percent
      };
      if (square) {
        style.paddingTop = percent;
      } else if (gutter) {
        const gutterValue = format.addUnit(gutter);
        style.paddingRight = gutterValue;
        if (index$2.value >= +columnNum) {
          style.marginTop = gutterValue;
        }
      }
      return style;
    });
    const contentStyle = Vue.computed(() => {
      const {
        square,
        gutter
      } = parent.props;
      if (square && gutter) {
        const gutterValue = format.addUnit(gutter);
        return {
          right: gutterValue,
          bottom: gutterValue,
          height: "auto"
        };
      }
    });
    const renderIcon = () => {
      if (slots.icon) {
        return Vue.createVNode(index.Badge, Vue.mergeProps({
          "dot": props2.dot,
          "content": props2.badge
        }, props2.badgeProps), {
          default: slots.icon
        });
      }
      if (props2.icon) {
        return Vue.createVNode(index$1.Icon, {
          "dot": props2.dot,
          "name": props2.icon,
          "size": parent.props.iconSize,
          "badge": props2.badge,
          "class": bem("icon"),
          "color": props2.iconColor,
          "badgeProps": props2.badgeProps,
          "classPrefix": props2.iconPrefix
        }, null);
      }
    };
    const renderText = () => {
      if (slots.text) {
        return slots.text();
      }
      if (props2.text) {
        return Vue.createVNode("span", {
          "class": bem("text")
        }, [props2.text]);
      }
    };
    const renderContent = () => {
      if (slots.default) {
        return slots.default();
      }
      return [renderIcon(), renderText()];
    };
    return () => {
      const {
        center,
        border,
        square,
        gutter,
        reverse,
        direction,
        clickable
      } = parent.props;
      const classes = [bem("content", [direction, {
        center,
        square,
        reverse,
        clickable,
        surround: border && gutter
      }]), {
        [constant.BORDER]: border
      }];
      return Vue.createVNode("div", {
        "class": [bem({
          square
        })],
        "style": rootStyle.value
      }, [Vue.createVNode("div", {
        "role": clickable ? "button" : void 0,
        "class": classes,
        "style": contentStyle.value,
        "tabindex": clickable ? 0 : void 0,
        "onClick": route
      }, [renderContent()])]);
    };
  }
});
exports.default = stdin_default;
exports.gridItemProps = gridItemProps;
