<template>
  <div class="config-rule-row">
    <div class="config-rule-row__info">
      <div class="config-rule-row__title">{{ title }}</div>
      <div v-if="description" class="config-rule-row__desc">{{ description }}</div>
    </div>
    <div class="config-rule-row__controls">
      <el-form-item label="天数" label-width="48px" class="config-rule-row__item">
        <el-input-number
          v-model="daysValue"
          :min="0"
          :max="3650"
          :precision="0"
          :step="1"
          controls-position="right"
          placeholder="0=不限制"
        />
        <span class="config-rule-row__suffix">天（0=不限制）</span>
      </el-form-item>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ConfigRuleRow',
  props: {
    title: {
      type: String,
      required: true
    },
    description: {
      type: String,
      default: ''
    },
    days: {
      type: Number,
      default: 0
    }
  },
  computed: {
    daysValue: {
      get() {
        return this.days
      },
      set(val) {
        this.$emit('update:days', val)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.config-rule-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 0;
  border-bottom: 1px solid #ebeef5;

  &:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  &__info {
    flex: 1;
    min-width: 0;
  }

  &__title {
    font-size: 14px;
    font-weight: 500;
    color: #303133;
    line-height: 22px;
  }

  &__desc {
    margin-top: 4px;
    font-size: 13px;
    color: #909399;
    line-height: 1.6;
  }

  &__controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
  }

  &__item {
    margin-bottom: 0;
  }

  &__suffix {
    margin-left: 6px;
    color: #909399;
    font-size: 13px;
    white-space: nowrap;
  }
}
</style>
