import { defineComponent, ref, computed, createVNode, mergeProps, Fragment } from 'vue';
import { ReloadOutlined } from '@ant-design/icons-vue';
import '../hooks/index.mjs';
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver.mjs';
import { withInstall } from '../_util/type.mjs';
import '../spin/index.mjs';
import '../button/index.mjs';
import { useToken } from '../theme/internal.mjs';
import warning from '../_util/warning.mjs';
import { qrcodeProps } from './interface.mjs';
import useStyle from './style/index.mjs';
import { QRCodeCanvas } from './QRCodeCanvas.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';
import Spin from '../spin/Spin.mjs';
import Button from '../button/button.mjs';

const QRCode = /* @__PURE__ */ defineComponent({
  name: "AQrcode",
  inheritAttrs: false,
  props: qrcodeProps(),
  emits: ["refresh"],
  setup(props, {
    emit,
    attrs,
    expose
  }) {
    if (process.env.NODE_ENV !== "production") {
      warning(!(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 = "#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(createVNode("div", mergeProps(attrs, {
        "style": [attrs.style, {
          width: `${props.size}px`,
          height: `${props.size}px`
        }],
        "class": [hashId.value, pre, {
          [`${prefixCls}-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)
      })])]), createVNode(QRCodeCanvas, mergeProps({
        "ref": qrCodeCanvas
      }, qrCodeProps.value), null)]));
    };
  }
});
var index = withInstall(QRCode);

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