<template>
  <div class="card-wrapper" :class="{ 'no-bg': noBg }">
    <div class="card-title">
      <p>
        {{ title }}
      </p>
      <div v-if="btns && btns.length > 0">
        <span
          v-for="btn in btns"
          :key="btn.key"
          :class="{ on: btn.key === curBtn }"
          @click="handleSelect(btn)"
        >
          {{ btn.name }}
        </span>
      </div>
    </div>
    <div class="card-content">
      <span class="border" />
      <span class="border" />
      <slot />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'

export default defineComponent({
  name: 'Mode4',
  props: {
    title: {
      type: String as PropType<string>,
      required: true,
    },
    noBg: {
      type: Boolean as PropType<boolean>,
      default: true,
    },
    btns: {
      type: Array as PropType<{ key?: string; name?: string }[]>,
      default: null,
    },
    curBtn: {
      type: String as PropType<string>,
      default: null,
    },
  },
  emits: ['select'],
  setup(_, ctx) {
    const handleSelect = (btn: { key?: string; name?: string }) => {
      ctx.emit('select', btn.key)
    }
    return { handleSelect }
  },
})
</script>

<style scoped lang="stylus">
@import '../main.styl'
.card-wrapper
  &.no-bg
    .card-title
      margin-bottom 0
    .card-content
      background transparent
  .card-title
    display flex
    align-items center
    justify-content space-between
    background linear-gradient(to right, rgba(59,85,102,.8), transparent)
    position relative
    border-bottom .01rem solid rgba(105,110,114,.15)
    margin-bottom .05rem
    padding 0 .1rem
    &:before
      content ''
      display block
      position absolute
      left 0
      width .02rem
      height 60%
      background #FADB71
    >p
      color $card-title-color
      font-size $card-title-size
      font-weight bold
      margin 0
    >div
      span
        cursor pointer
        margin-left .05rem
        color $primary-border
        &:hover
        &.on
          color #fff
          font-weight bold

  .card-content
    position relative
    box-sizing border-box
    background rgba(105,110,114,.15)
    padding .05rem .08rem
    &.no-bg
      background transparent
    >.border
      display block
      position absolute
      top 0
      left 0
      bottom 0
      width .01rem
      &:nth-of-type(2)
        left auto
        right 0
    >div
      $full()
</style>
