import { useSSRContext, ref, watch, mergeProps, unref } from 'vue';
import { ssrRenderAttrs, ssrInterpolate, ssrRenderClass } from 'vue/server-renderer';
import { w as useGlobalStore } from './server.mjs';

const _sfc_main = {
  __name: "GeneralCallToAction",
  __ssrInlineRender: true,
  props: {
    text: {
      type: String,
      required: true,
      default: ""
    },
    icon: {
      required: false,
      default: null
    },
    classes: {
      type: String,
      required: true,
      default: ""
    }
  },
  setup(__props) {
    const globalStore = useGlobalStore();
    const firstPhone = ref();
    function getAddress(phones) {
      var _a, _b, _c;
      const country = Intl.DateTimeFormat().resolvedOptions().timeZone;
      let phone = [];
      if (phones) {
        if (country.includes("Cairo")) {
          phone = phones.filter((el) => el.phone_code == "+20");
          if (!phone.length) {
            phone = phones;
          }
        } else if (country.includes("Riyadh")) {
          phone = phones.filter((el) => el.phone_code == "+966");
          if (!phone.length) {
            phone = phones;
          }
        } else {
          phone = phones.filter((el) => el.phone_code == "+971");
          if (!phone.length) {
            phone = phones;
          }
        }
      }
      firstPhone.value = (_c = (_a = phone[0]) == null ? void 0 : _a.phone_code) == null ? void 0 : _c.concat((_b = phone[0]) == null ? void 0 : _b.phone);
    }
    watch(
      () => globalStore,
      (store) => {
        var _a, _b;
        if ((_a = store.mainSettings) == null ? void 0 : _a.phones) {
          getAddress((_b = store.mainSettings) == null ? void 0 : _b.phones);
        }
      },
      {
        deep: true,
        immediate: true
      }
    );
    return (_ctx, _push, _parent, _attrs) => {
      _push(`<a${ssrRenderAttrs(mergeProps({
        href: `https://wa.me/${unref(firstPhone)}${_ctx.$route.query.message ? "/?text=" + _ctx.$route.query.message : ""}`,
        class: `flex items-center justify-center gap-3 w-fit ${__props.classes}`,
        target: "_blank"
      }, _attrs))}><span>${ssrInterpolate(__props.text)}</span>`);
      if (__props.icon) {
        _push(`<i class="${ssrRenderClass(__props.icon)}"></i>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</a>`);
    };
  }
};
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("components/general/GeneralCallToAction.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};

export { _sfc_main as _ };
//# sourceMappingURL=GeneralCallToAction-BNzByXfE.mjs.map
