<template>
  <div :class="cellClasses" @click="_clicked">
    <div class="bml-cell__hd">
      <image class="bml-cell-image" :src="icon" v-if="icon"/>
      <bml-icon class="bml-cell-icon" :color="iconColor" :name="iconClass" v-if="iconClass"></bml-icon>
      <div class="bml-label" v-if="title"><text class="bml-label-text">{{title}}</text></div>
    </div>
    <slot name="title"/>
    <div class="bml-cell__bd bml-cell_input">
      <text class="bml-label-text" v-if="value">{{value}}</text>
      <slot/>
    </div>
    <div class="bml-cell__ft">
      <text class="bml-cell-ft-text" :class="footerClass" v-if="footer">{{footer}}</text>
      <slot name="footer"/>
      <bml-icon class="bml-cell-ft-icon" :color="footerColor" :name="footerIcon" v-if="footerIcon"></bml-icon>
      <slot name="action"/>
    </div>
  </div>
</template>

<script>
import bmlIcon from './bml-icon.vue';

const prefixCls = 'bml-cell';
export default {
  name: 'bml-cell',
  components: {bmlIcon},
  props: {
    link: {
      type: Boolean,
      default: false,
    },
    first: {
      type: Boolean,
      default: false,
    },
    last: {
      type: Boolean,
      default: false,
    },
    extClass: {
      type: String,
      default: 'bml-cell-single' // 默认为单行高度
    },
    icon: {
      type: String,
      default: ''
    },
    iconColor: {
      type: String,
      default: ''
    },
    iconClass: {
      type: String,
      default: null
    },
    title: { // 和icon二选一，都是放在cell_hd里面
      type: String,
      default: '',
    },
    value: {
      type: String,
      default: '',
    },
    showError: {
      type: Boolean,
      default: false
    },
    footerClass: {
      type: String,
      default: ''
    },
    footerIconColor: {
      type: String,
      default: ''
    },
    footer: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      outerClass:'',
      error:''
    }
  },
  methods: {
    setError(error) {
      this.error = error || false
    },
    _clicked(event) {
      this.$emit('click', event)
    }
  },
  computed: {
    footerIcon(){

      if(this.footerClass){
        return this.footerClass;
      }

      if(this.link){
        return 'ion-ios-arrow-right';
      }
      
      return undefined;
    },
    footerColor(){

      if(this.footerIconColor){
        return this.footerIconColor;
      }

      if(this.link){
        return '#cecece';
      }
      
      return undefined;
    },
    cellClasses(){
      return [
        `${prefixCls}`, this.extClass ,this.link ? `${prefixCls}-link`: '', this.extClass,this.first ? `${prefixCls}-first`: '', this.last ? `${prefixCls}-last`: ''
      ]
    }
  }
}
</script>
<style lang="scss" src="../css/cell.scss"/>

