<template>
  <div class="line-field">
    <div class="label">
      <slot name="label">
        {{label}}
      </slot>
    </div>
    <div class="right-box" >
      <slot>
        {{value}}
      </slot>
    </div>
    <el-button type="text" v-if="editable" icon="el-icon-edit" class="editable" @click="$emit('edit')"/>
  </div>
</template>

<script>
export default {
  name: "LineField",
  props: {
    label: {
      type: String,
      default: null
    },
    value: {
      type: [String, Number],
      default: null,
    },
    editable: {
      type: Boolean,
      default: false
    }
  }
}
</script>

<style scoped lang="scss">
.line-field {
  position: relative;
  width: 100%;
  padding: 0.5em 1.5em 0.5em 1em;
  font-size: 14px;
  display: flex;
  height: fit-content;
  line-height: 1.5em;
  justify-content: space-between;
  .label {
    width: fit-content;
    margin-right: 2em;
  }
  .right-box {
    flex: 1;
    text-align: right;
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    vertical-align: center;
  }
  i {
    line-height: 1.5em;
    margin: 0 0.5em;
  }
  .editable {
    position: absolute;
    padding: 0;
    top: 10px;
    right: 4px;
  }
}
.line-field:nth-child(n + 2) {
  border-top: 1px solid #ededed;
}
.line-field:hover {
  background-color: rgba(136, 131, 240, 0.08);
}
</style>
