<!-- 装修组件容器 -->
<template>
  <view :style="[elStyles, elBackground]"><slot /></view>
</template>

<script setup>
  /**
   * 容器组件 - 装修组件的样式容器
   */
  import { computed, provide, unref } from 'vue';
  import sheep from '@/common';

  const props = defineProps({
    styles: {
      type: Object,
      default() {},
    },
  });

  // 组件样式

  const elBackground = computed(() => {
    if (props.styles) {
      if (props.styles.bgType === 'color')
        return { background: props.styles.bgColor };
      if (props.styles.bgType === 'img')
        return {
          background: `url(${props.styles.bgImage}) no-repeat top center / 100% auto`,
        };
    }
  });

  const elStyles = computed(() => {
    if (props.styles) {
      return {
        marginTop: `${props.styles.marginTop || 0}rpx`,
        marginBottom: `${props.styles.marginBottom || 0}rpx`,
        marginLeft: `${props.styles.marginLeft || 0}rpx`,
        marginRight: `${props.styles.marginRight || 0}rpx`,
        paddingTop: `${props.styles.paddingTop || 0}rpx`,
        paddingRight: `${props.styles.paddingRight || 0}rpx`,
        paddingBottom: `${props.styles.paddingBottom || 0}rpx`,
        paddingLeft: `${props.styles.paddingLeft || 0}rpx`,
        borderTopLeftRadius: `${props.styles.borderTopLeftRadius || 0}rpx`,
        borderTopRightRadius: `${props.styles.borderTopRightRadius || 0}rpx`,
        borderBottomRightRadius: `${props.styles.borderBottomRightRadius || 0}rpx`,
        borderBottomLeftRadius: `${props.styles.borderBottomLeftRadius || 0}rpx`,
        overflow: 'hidden',
      };
    }
  });
</script>
