<template>
  <div class="btn-content">
    <Button
      :loading="!clickAble"
      :iconSrc="config.iconSrc"
      :color="config.color"
      :iconSize="props.iconSize || config.iconSize"
      :width="props.width || config.width"
      :height="props.height || config.height"
      :shape="config.shape"
      :loadingWidth="config.loadingWidth"
      :loadingHeight="config.loadingHeight"
      @click="handleClick"
    >
    </Button>
    <TKText 
      v-if="config.showText"
      width="70px"
      :lineClamp="2"
      :textStyle="config.textStyle"
      :color="config.textColor"
      :size="config.textSize"
    >
      {{ t('virtual-background') }}
    </TKText>
  </div>
</template>

<script lang="ts">
export default {
  options: {
    virtualHost: true,
  },
};
</script>

<script lang="ts" setup>
import { ref, computed, toRefs } from '../../../../adapter-vue';
import { TUICallKitServer, t } from '../../../../TUICallService/index';
import Button from '../../base/Button/Button.vue';
import TKText from '../../base/TKText/TKText.vue';
import { ButtonProps } from './props/Button';
import { useBtnConfig } from './hooks/useConfig';
import { useCallInfoContext } from '../../../hooks';

const props = defineProps(ButtonProps);
const clickAble = ref(true);
const { enableVirtualBackground } = toRefs(useCallInfoContext());
const configState = computed(() => {
  if (!clickAble.value) {
    return 'loadingConfig';
  }

  return enableVirtualBackground.value ? 'closedConfig' : 'basicConfig';
});
const config = useBtnConfig('virtualBackground', configState);
const handleClick = async () => {
  clickAble.value = false;
  await TUICallKitServer.setBlurBackground(!enableVirtualBackground.value);
  clickAble.value = true;
};
</script>

<style lang="scss" scoped>
@import './style/common.scss';
</style>

