<template>
  <component :is="url ? 'router-link' : 'div'" :to="url" class="ui-card" :class="{'is-border': border}">
    <div class="ui-card__main">
      <div class="ui-card__content">
        <div
          v-if="icon || $slots.icon"
          class="ui-card__icon"
        >
          <slot name="icon">
            <ui-image
              width="42px"
              height="42px"
              :src="icon"
            ></ui-image>
          </slot>
        </div>
        <div class="ui-card__field">
          <div class="ui-card__field-item">
            <strong class="ui-card__title" :title="title">{{ title }}</strong>
          </div>
          <div class="ui-card__field-item">
            <p class="ui-card__description" :title="description">
              <slot name="description">
                {{ description }}
              </slot>
            </p>
          </div>
        </div>
      </div>
      <div
        v-if="$slots.tools"
        class="ui-card__tools"
      >
        <slot name="tools"></slot>
      </div>
    </div>
    <div class="ui-card__addon" v-if="$slots['addon-left'] || $slots['addon-right']">
      <div class="ui-card__addon-left">
        <slot name="addon-left"></slot>
      </div>
      <div class="ui-card__addon-right">
        <slot name="addon-right"></slot>
      </div>
    </div>
  </component>
</template>
<script>
import UiImage from '@huntianning/components/packages/image'

export default {
  name: 'UiCard',
  components: {
    UiImage
  },
  props: {
    icon: {
      type: String
    },
    title: {
      type: String
    },
    description: {
      type: String
    },
    url: {
      type: String
    },
    border: {
      type: Boolean,
      default: true
    }
  }
}
</script>
<style lang="less">
.ui-card {
  background: #fff;
  transition: all .25s;
  line-height: 1.5em;
  display: block;
  color: #131313;
  text-decoration: none;
  &.is-border {
    padding-left: 18px;
    padding-right: 18px;
    border-radius: 4px;
    border: 1px solid #E6E7EA;
    .ui-card__main{
      padding-top: 18px;
      padding-bottom: 18px;
    }
  }
}
a.ui-card {
  &.is-border {
    &:hover {
      box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.06);
    }
  }
}
.ui-card__main{
  display: flex;
  flex-direction: row;
}
.ui-card__content{
  display: flex;
  flex-direction: row;
  flex: 1;
  min-width: 0;
}
.ui-card__icon{
  margin-right: 12px;
}
.ui-card__field{
  flex: 1;
  min-width: 0;
  padding-right: 12px;
}
.ui-card__title{
  font-size: 16px;
  font-weight: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
}
.ui-card__description{
  margin: 0;
  color: #606C80;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
  vertical-align: top;
}
.ui-card__addon{
  border-top: 1px solid #E6E7EA;
  padding-top: 2px;
  padding-bottom: 2px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.ui-card__addon-left,
.ui-card__addon-right{
  min-width: 0;
}
</style>
