<template>
  <BasicTitle
    :class="[prefixCls, lined ? prefixCls + '--lined' : '']"
    v-if="getTitle"
    :helpMessage="helpMessage"
  >
    {{ getTitle }}
  </BasicTitle>
</template>
<script lang="ts">
  import { computed, defineComponent, PropType } from 'vue';
  import { BasicTitle } from '/@/components/Basic/index';
  import { useDesign } from '/@/hooks/web/useDesign';
  import { isFunction } from '/@/utils/is';

  export default defineComponent({
    name: 'BasicTableTitle',
    components: { BasicTitle },
    props: {
      title: {
        type: [Function, String] as PropType<string | ((data: Recordable) => string)>,
      },
      lined: {
        type: Boolean,
        default: false,
      },
      getSelectRows: {
        type: Function as PropType<() => Recordable[]>,
      },
      helpMessage: {
        type: [String, Array] as PropType<string | string[]>,
      },
    },
    setup(props) {
      const { prefixCls } = useDesign('basic-table-title');

      const getTitle = computed(() => {
        const { title, getSelectRows = () => {} } = props;
        let tit = title;

        if (isFunction(title)) {
          tit = title({
            selectRows: getSelectRows(),
          });
        }
        return tit;
      });

      return { getTitle, prefixCls };
    },
  });
</script>
<style lang="less">
  @prefix-cls: ~'@{namespace}-basic-table-title';

  .@{prefix-cls} {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;

    &--lined::after {
      position: absolute;
      content: '';
      top: 4px;
      left: 0;
      height: 14px;
      width: 2px;
      background: #000a18;
      border-radius: 1px;
    }
  }
</style>
