<template>
  <view :class="gridClass" :style="gridStyle">
    <slot></slot>
  </view>
</template>

<script lang="ts">
import { defineComponent as _defineComponent } from "vue";
import { computed, provide, reactive, toRef } from "vue";
import { splitUnit, classNames, stringifyStyle, createBem } from "../utils";
import { gridProps, gridSymbol } from "./common";
const __default__ = {
  options: {
    virtualHost: true,
    styleIsolation: "shared"
  }
};
export default /* @__PURE__ */ _defineComponent({
  ...__default__,
  __name: "grid",
  props: gridProps,
  setup(__props, { expose: __expose }) {
    __expose();
    const props = __props;
    const bem = createBem("grid");
    const gutter = computed(() => {
      if (props.gap) {
        const result = splitUnit(props.gap);
        return [result[0] / 2, result[1] || "rpx"];
      }
      return [0, "rpx"];
    });
    provide(
      gridSymbol,
      reactive({
        columns: toRef(props, "columns"),
        gap: toRef(props, "gap"),
        gutter
      })
    );
    const gridClass = computed(() => {
      return classNames(
        bem.b(),
        bem.m("bordered", props.bordered && gutter.value[0] <= 0),
        bem.m("surround", props.bordered && gutter.value[0] > 0),
        bem.m("square", props.square),
        bem.m("clickable", props.clickable),
        bem.m(props.direction),
        bem.m("reverse", props.reverse),
        props.rootClass
      );
    });
    const gridStyle = computed(() => {
      return stringifyStyle(
        props.gap ? {
          marginLeft: -gutter.value[0] + gutter.value[1],
          marginRight: -gutter.value[0] + gutter.value[1]
        } : null,
        {
          rowGap: props.gap
        },
        props.rootStyle
      );
    });
    const __returned__ = { props, bem, gutter, gridClass, gridStyle };
    return __returned__;
  }
});
</script>

<style lang="scss">
@use './index.scss';
</style>