<template>
  <view 
    v-if="formDefine.type === 'group'" 
    :class="`form-group ${formDefine.props.type}`"
  >
    <text class="form-group-title" v-if="formDefineParentLabel">
      {{ formDefineParentLabel }}
    </text>
    <SimpleDynamicFormCateInner
      :formDefine="formDefine"
      :formModel="formModel" 
      :groupType="formDefine.props.type"
    />
  </view>
  <SimpleDynamicFormCateInner
    v-else
    :formDefine="formDefine"
    :formModel="formModel" 
  />
</template>

<script setup lang="ts">
import type { PropType } from 'vue';
import type { FormDefine } from '.';
import SimpleDynamicFormCateInner from './SimpleDynamicFormCateInner.vue';

export interface FormGroupProps {
  type: 'row' | 'column' | 'block';

}

const props = defineProps({
  formDefineParentLabel: {
    type: null,
    default: '' 
  },
  formDefineParentKey: {
    type: String,
    default: '' 
  },
  formModel: {
    type: Object,
    default: () => ({})
  },
  formDefine: {
    type: Object as PropType<FormDefine>,
    default: () => ({})
  },
})
</script>

<style lang="scss">
.form-group {
  display: flex;
  flex-direction: column;

  &.block {
    margin-bottom: 32rpx;
    padding: 24rpx 26rpx;
    background: #fff;
    border-radius: 10rpx;

    .form-group-title {
      display: block;
      font-size: 28rpx;
      color: #333;
      margin-bottom: 16rpx;
    }
  }

  .form-group-title {
    display: block;
    flex-shrink: 0;
    font-size: 28rpx;
    color: #333;
    margin-bottom: 16rpx;
  }

  &.row {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;

    .form-group-title {
      display: inline-block;
      margin-left: 10rpx;
    }
  }
}
</style>