<template>
  <div class="en-logo" data-weiling-mobile-ui-bc-en-logo>
    <template v-if="avatar_url">
      <WlPic :src="avatar_url" class="logo-pic logo-name" />
    </template>
    <div
      v-else-if="shortenName.length > 0 && shortenName.length <= 8"
      :style="{
        '--backgroundColor': color ? color : colorList[shortenName.length - 1],
      }"
      :class="logoClass"
    >
      <span>{{ shortenName }}</span>
    </div>
    <template v-else>
      <WlPic :src="en_group_default_logo" class="logo-pic logo-name" />
    </template>
    <div v-if="nameShow" class="name-sub" :style="nameExtraStyle">
      <p>{{ name }}</p>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "BCEnLogo",
};
</script>

<script lang="ts" setup>
import { computed } from "vue";
import { en_group_default_logo } from "@mobileUI/utils/cdn";
import WlPic from "@mobileUI/components/WlPic/src/index.vue";

type Props = {
  shortenName?: string;
  name?: string;
  avatar_url?: string;
  color?: string;
  colorList?: Array<any>;
  nameExtraStyle?: Object;
  nameShow?: boolean;
};
const props = withDefaults(defineProps<Props>(), {
  shortenName: "",
  name: "",
  avatar_url: "",
  color: "",
  colorList: () => [
    "rgba(188, 160, 219, 1)",
    "rgba(139, 202, 173, 1)",
    "rgba(206, 173, 158, 1)",
    "rgba(139, 202, 173, 1)",
    "rgba(206, 173, 158, 1)",
    "rgba(144, 163, 206, 1)",
    "rgba(188, 160, 219, 1)",
    "rgba(144, 163, 206, 1)",
  ],
  nameExtraStyle: () => {
    return {};
  },
  nameShow: true,
});

const logoClass = computed(() => {
  const len = props.shortenName.length;
  return len === 0 || len > 8
    ? "logo-name logo-pic"
    : `logo-name logo-number-${len}`;
});
</script>

<style lang="scss">
.en-logo[data-weiling-mobile-ui-bc-en-logo] {
  @extend %flex-middle;

  .logo-name {
    width: j(62);
    height: j(62);
    border-radius: j(10);
    background-color: var(--backgroundColor);
    text-align: center;
    color: white;
    box-sizing: border-box;
    flex-shrink: 0;
    @extend %flex-middle-center;
  }

  .logo-number-1 {
    font-size: j(30);
  }

  .logo-number-2 {
    font-size: j(24);
  }

  .logo-number-3,
  .logo-number-4 {
    font-size: j(18);
    padding: 0 j(4);
  }

  .logo-number-4 {
    padding: 0 j(13);
  }

  .logo-number-5,
  .logo-number-6 {
    font-size: j(16);
    padding: 0 j(6);
  }

  .logo-number-7,
  .logo-number-8 {
    font-size: j(14);
    padding: 0 j(3);
  }

  .name-sub {
    margin-left: j(12);
    font-size: j(17);
    color: rgba(48, 50, 51, 1);
    @include textEllipsis(1);
  }
}
</style>
