'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../theme/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
require('../../locale-provider/index.cjs');
var index$1 = require('../../spin/index.cjs');
var index$2 = require('../../button/index.cjs');
var index = require('../style/index.cjs');
var Canvas = require('./Canvas.cjs');
var SVG = require('./SVG.cjs');
var props = require('./props.cjs');
var log = require('../../../utils/log.cjs');
var useLocaleReceiver = require('../../locale-provider/src/useLocaleReceiver.cjs');
var internal = require('../../../theme/token/internal.cjs');

var qrCode = /* @__PURE__ */ vue.defineComponent({
  name: "AQrcode",
  inheritAttrs: false,
  props: props.qrcodeProps(),
  emits: ["refresh"],
  setup(props, {
    emit,
    attrs,
    expose
  }) {
    if (process.env.NODE_ENV !== "production") {
      log.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.useLocaleReceiver("QRCode");
    const {
      prefixCls
    } = useConfigInject.default("qrcode", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    const [, token] = internal.useToken();
    const qrCodeCanvas = vue.ref();
    expose({
      toDataURL: (type, quality) => {
        var _a;
        return (_a = qrCodeCanvas.value) == null ? void 0 : _a.toDataURL(type, quality);
      }
    });
    const qrCodeProps = vue.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(vue.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" && vue.createVNode("div", {
        "class": `${pre}-mask`
      }, [props.status === "loading" && vue.createVNode(index$1.Spin, null, null), props.status === "expired" && vue.createVNode(vue.Fragment, null, [vue.createVNode("p", {
        "class": `${pre}-expired`
      }, [locale.value.expired]), vue.createVNode(index$2.Button, {
        "type": "link",
        "onClick": (e) => emit("refresh", e)
      }, {
        default: () => [locale.value.refresh],
        icon: () => vue.createVNode(iconsVue.ReloadOutlined, null, null)
      })])]), props.type === "canvas" ? vue.createVNode(Canvas.default, {
        "ref": qrCodeCanvas,
        ...qrCodeProps.value
      }, null) : vue.createVNode(SVG.default, qrCodeProps.value, null)]));
    };
  }
});

exports.default = qrCode;
//# sourceMappingURL=QRCode.cjs.map
