import { defineComponent, ref, computed, createVNode, Fragment } from 'vue';
import { ReloadOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../theme/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import '../../locale-provider/index.mjs';
import { Spin } from '../../spin/index.mjs';
import { Button } from '../../button/index.mjs';
import useStyle from '../style/index.mjs';
import QRCodeCanvas from './Canvas.mjs';
import QRCodeSVG from './SVG.mjs';
import { qrcodeProps } from './props.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { useLocaleReceiver } from '../../locale-provider/src/useLocaleReceiver.mjs';
import { useToken } from '../../../theme/token/internal.mjs';

var qrCode = /* @__PURE__ */ defineComponent({
  name: "AQrcode",
  inheritAttrs: false,
  props: qrcodeProps(),
  emits: ["refresh"],
  setup(props, {
    emit,
    attrs,
    expose
  }) {
    if (process.env.NODE_ENV !== "production") {
      devWarning(!(props.icon && props.errorLevel === "L"), "QRCode", "ErrorLevel `L` is not recommended to be used with `icon`, for scanning result would be affected by low level.");
    }
    const [locale] = useLocaleReceiver("QRCode");
    const {
      prefixCls
    } = useConfigInject("qrcode", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const [, token] = useToken();
    const qrCodeCanvas = ref();
    expose({
      toDataURL: (type, quality) => {
        var _a;
        return (_a = qrCodeCanvas.value) == null ? void 0 : _a.toDataURL(type, quality);
      }
    });
    const qrCodeProps = computed(() => {
      const {
        value,
        icon = "",
        size = 160,
        iconSize = 40,
        color = token.value.colorText,
        bgColor = "transparent",
        errorLevel = "M"
      } = props;
      const imageSettings = {
        src: icon,
        x: void 0,
        y: void 0,
        height: iconSize,
        width: iconSize,
        excavate: true
      };
      return {
        value,
        size: size - (token.value.paddingSM + token.value.lineWidth) * 2,
        level: errorLevel,
        bgColor,
        fgColor: color,
        imageSettings: icon ? imageSettings : void 0
      };
    });
    return () => {
      const pre = prefixCls.value;
      return wrapSSR(createVNode("div", {
        ...attrs,
        "style": [attrs.style, {
          width: `${props.size}px`,
          height: `${props.size}px`,
          backgroundColor: qrCodeProps.value.bgColor
        }],
        "class": [hashId.value, pre, {
          [`${pre}-borderless`]: !props.bordered
        }]
      }, [props.status !== "active" && createVNode("div", {
        "class": `${pre}-mask`
      }, [props.status === "loading" && createVNode(Spin, null, null), props.status === "expired" && createVNode(Fragment, null, [createVNode("p", {
        "class": `${pre}-expired`
      }, [locale.value.expired]), createVNode(Button, {
        "type": "link",
        "onClick": (e) => emit("refresh", e)
      }, {
        default: () => [locale.value.refresh],
        icon: () => createVNode(ReloadOutlined, null, null)
      })])]), props.type === "canvas" ? createVNode(QRCodeCanvas, {
        "ref": qrCodeCanvas,
        ...qrCodeProps.value
      }, null) : createVNode(QRCodeSVG, qrCodeProps.value, null)]));
    };
  }
});

export { qrCode as default };
//# sourceMappingURL=QRCode.mjs.map
