'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
require('../hooks/index.js');
var LocaleReceiver = require('../locale-provider/LocaleReceiver.js');
var type = require('../_util/type.js');
require('../spin/index.js');
require('../button/index.js');
var internal = require('../theme/internal.js');
var warning = require('../_util/warning.js');
var _interface = require('./interface.js');
var index$1 = require('./style/index.js');
var QRCodeCanvas = require('./QRCodeCanvas.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var Spin = require('../spin/Spin.js');
var button = require('../button/button.js');

const QRCode = /* @__PURE__ */ vue.defineComponent({
  name: "AQrcode",
  inheritAttrs: false,
  props: _interface.qrcodeProps(),
  emits: ["refresh"],
  setup(props, {
    emit,
    attrs,
    expose
  }) {
    if (process.env.NODE_ENV !== "production") {
      warning.default(!(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] = LocaleReceiver.useLocaleReceiver("QRCode");
    const {
      prefixCls
    } = useConfigInject.default("qrcode", props);
    const [wrapSSR, hashId] = index$1.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 = "#000",
        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: "transparent",
        fgColor: color,
        imageSettings: icon ? imageSettings : void 0
      };
    });
    return () => {
      const pre = prefixCls.value;
      return wrapSSR(vue.createVNode("div", vue.mergeProps(attrs, {
        "style": [attrs.style, {
          width: `${props.size}px`,
          height: `${props.size}px`
        }],
        "class": [hashId.value, pre, {
          [`${prefixCls}-borderless`]: !props.bordered
        }]
      }), [props.status !== "active" && vue.createVNode("div", {
        "class": `${pre}-mask`
      }, [props.status === "loading" && vue.createVNode(Spin.default, null, null), props.status === "expired" && vue.createVNode(vue.Fragment, null, [vue.createVNode("p", {
        "class": `${pre}-expired`
      }, [locale.value.expired]), vue.createVNode(button.default, {
        "type": "link",
        "onClick": (e) => emit("refresh", e)
      }, {
        default: () => [locale.value.refresh],
        icon: () => vue.createVNode(CloseOutlined.ReloadOutlined, null, null)
      })])]), vue.createVNode(QRCodeCanvas.QRCodeCanvas, vue.mergeProps({
        "ref": qrCodeCanvas
      }, qrCodeProps.value), null)]));
    };
  }
});
var index = type.withInstall(QRCode);

exports.default = index;
//# sourceMappingURL=index.js.map
