import { Ref, unref, computed } from 'vue';
<%_ if (enableTranslation) { _%>
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();
<%_ } _%>

// begcode-please-regenerate-this-file 如果您不希望重新生成代码时被覆盖，将please修改为don't ！！！

export function useUploadType({
  acceptRef,
  helpTextRef,
  maxNumberRef,
  maxSizeRef,
}: {
  acceptRef: Ref<string[]>;
  helpTextRef: Ref<string>;
  maxNumberRef: Ref<number>;
  maxSizeRef: Ref<number>;
}) {
  // 文件类型限制
  const getAccept = computed(() => {
    const accept = unref(acceptRef);
    if (accept && accept.length > 0) {
      return accept;
    }
    return [];
  });
  const getStringAccept = computed(() => {
    return unref(getAccept)
      .map((item) => {
        if (item.indexOf('/') > 0 || item.startsWith('.')) {
          return item;
        } else {
          return `.${item}`;
        }
      })
      .join(',');
  });

  // 支持jpg、jpeg、png格式，不超过2M，最多可选择10张图片，。
  const getHelpText = computed(() => {
    const helpText = unref(helpTextRef);
    if (helpText) {
      return helpText;
    }
    const helpTexts: string[] = [];

    const accept = unref(acceptRef);
    if (accept.length > 0) {
      helpTexts.push(<% if (enableTranslation) { %>t('component.upload.accept', [accept.join(',')])<% } else { %>`支持${accept.join(',')}格式`<% } %>);
    }

    const maxSize = unref(maxSizeRef);
    if (maxSize) {
      helpTexts.push(<% if (enableTranslation) { %>t('component.upload.maxSize', {maxSize: maxSize})<% } else { %>`单个文件不超过${maxSize}MB`<% } %>);
    }

    const maxNumber = unref(maxNumberRef);
    if (maxNumber && maxNumber !== Infinity) {
      helpTexts.push(<% if (enableTranslation) { %>t('component.upload.maxNumber', {maxNumber: maxNumber})<% } else { %>`最多只能上传${maxNumber}个文件`<% } %>);
    }
    return helpTexts.join('，');
  });
  return { getAccept, getStringAccept, getHelpText };
}
