<template>
  <section class="AiItem" :class="{border,readonly}">
    <div v-if="topLabel" class="topLabel">
      <div class="labelPane flex">
        <div class="label" :class="{required,labelBold}" :style="{color}" v-text="label"/>
        <slot name="sub" v-if="$slots.sub"/>
      </div>
      <div class="itemContent">
        <slot v-if="$slots.default"/>
        <div v-else v-text="value"/>
      </div>
    </div>
    <div v-else class="normal flex">
      <div class="fill flex">
        <div class="label" :class="{required,labelBold}" :style="{color}" v-text="label"/>
        <slot name="sub" v-if="$slots.sub"/>
      </div>
      <div class="flexContent">
        <slot v-if="$slots.default"/>
        <div v-else v-text="value"/>
      </div>
    </div>
  </section>
</template>

<script>
export default {
  name: "AiItem",
  inject: {
    labelColor: {default: "#333"},
    description: {default: false}
  },
  props: {
    value: {default: ""},
    label: {default: ""},
    required: Boolean,
    topLabel: Boolean,
    border: {default: true},
    labelBold: Boolean,
  },
  computed: {
    color: v => v.labelColor,
    readonly: v => !!v.description
  }
}
</script>

<style lang="scss" scoped>
.AiItem {
  font-family: PingFangSC-Regular, PingFang SC;

  &.border {
    .normal {
      border-bottom: 2px solid #ddd;
    }

    .topLabel {
      border-bottom: 2px solid #ddd;
    }
  }

  .normal {
    width: 100%;
    padding: 32px 32px 32px 0;
    line-height: 44px;
    box-sizing: border-box;
    // height: 112px;

    .flexContent {
      max-width: 62vw;
    }
  }

  .label {
    padding-left: 20px;
    font-weight: 400;
    margin-right: 20px;
    position: relative;

    &.required:before {
      position: absolute;
      display: block;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      content: "*";
      color: #f46;
    }

    &.labelBold {
      font-weight: bold;
      font-size: 34px;
    }
  }

  ::v-deep.topLabel {
    padding: 32px 32px 32px 0;

    .labelPane {
      margin-bottom: 32px;
    }

    .itemContent {
      padding-left: 20px;

      .AiMore > .u-icon {
        width: 100%;
      }
    }
  }

  //展示模式下的特有样式
  &.readonly {
    .label, .itemContent {
      padding-left: 0;
    }
  }

  .AiStep:last-of-type {
    .stepLine {
      display: none
    }
  }
}
</style>
