// Site styles (imported here for Vite HMR).
import '@site/css/app.less';

import Vue from 'vue';
import { config } from './config.js';
import LazyLoad from "vanilla-lazyload";
import { ready } from '@site/js/utils/dom.js';
window.LazyLoad = LazyLoad;
window.globalConfig = config;

// Import vue-wrapper for side effects (VueResource setup, directives, filters)
import './vue-wrapper.js';

// Set production mode when not in development
if (process.env.NODE_ENV === 'production') {
  Vue.config.productionTip = false;
}

import {EventBus, vueEventHub} from "./event-bus";
window.EventBus = EventBus;
window.vueEventHub = vueEventHub;

// Vue component that renders menu structure with dropdowns and mega menus (desktop hover/click behavior)
import mtcMenu from '@components/navigation/menu.vue';
Vue.component("mtc-menu", mtcMenu);

import trustpilotWidget from '@components/shop/item/partials/trustpilot.vue';
Vue.component("trustpilot-widget",trustpilotWidget);

/*
* Font awesome
*/
import { library } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';

/* import specific icons */
import { faUpload } from '@fortawesome/pro-regular-svg-icons/faUpload';
import { faCircleXmark } from '@fortawesome/pro-regular-svg-icons/faCircleXmark';
import { faXmark } from '@fortawesome/pro-regular-svg-icons/faXmark';
import { faMagnifyingGlass } from '@fortawesome/pro-regular-svg-icons/faMagnifyingGlass';
import { faTrash } from '@fortawesome/pro-regular-svg-icons/faTrash';
library.add(faUpload, faCircleXmark, faXmark, faMagnifyingGlass, faTrash);
Vue.component('font-awesome-icon', FontAwesomeIcon);

// Slider (Vue 2 compatible wrapper around Swiper 8 core)
import 'swiper/css';
// Optional module CSS (Swiper 8)
import 'swiper/css/navigation';
import 'swiper/css/pagination';
import 'swiper/css/thumbs';
import 'swiper/css/effect-fade';

import MtcSliderWrapper from '@components/mtc_slider_wrapper.vue';
import SwiperCompat from '@components/swiper/Swiper.vue';
import SwiperSlideCompat from '@components/swiper/SwiperSlide.vue';

Vue.component('mtc-slider', MtcSliderWrapper);
Vue.component('mtc-swiper', SwiperCompat);
Vue.component('mtc-slide', SwiperSlideCompat);

/*
* Core
 */
import "@core/js/functions.js";
import "@core/js/plugins/mtc_mobile_menu.js";
import "@core/js/plugins/mtc_multi_currency.js";
import "@core/js/plugins/mtc_responsive_tables.js";
import "@core/js/plugins/mtc_number_arrows.js";
import "@core/js/plugins/mtc_tabs.js";
import "@core/js/site_scripts/mtc_show_hide_menus.js";
import "@core/js/plugins/mtc_zoom.js";
import "../../../cms/js/mtc_contact.js";
import "../../../cms/js/mtc_faq_section.js";
import "../../../modules/Members/js/mtc_members.js";
import "@plugins/Judopay/js/judopay.js";
import "@shop/js/mtc_checkout.js";
import "@shop/js/mtc_checkout_mobile.js";
import "@shop/js/mtc_checkout_stripe.js";
import "@shop/js/mtc_checkout_worldpay.js";
import "@shop/js/mtc_payment_button.js";


import mtcMinibasket from '@components/shop/basket/mtc_minibasket.vue';
Vue.component('mtc-minibasket', mtcMinibasket);

import loadingSpinner from '@components/loading_spinner.vue';
Vue.component("loading-spinner", loadingSpinner);

import componentRegistry from '@components/component_registry.vue';
Vue.component("component-registry", componentRegistry);

import BrowsePage from "@components/shop/browse/browse_page.vue";
Vue.component('browse-page', BrowsePage);

import QuickOrderPage from "@modules/QuickOrder/js/components/quick_order_page.vue";
Vue.component('quick-order-page', QuickOrderPage);

import multiCurrencyPrice from "@components/multi_currency_price.vue";
Vue.component('multi-currency-price', multiCurrencyPrice);

import stockBadge from '@components/shop/item/partials/stock_badge.vue';
Vue.component("stock-badge", stockBadge);

import addToBasket from '@components/shop/item/partials/add_to_basket.vue';
Vue.component('add-to-basket', addToBasket);

import deliveryCountdown from '@components/shop/item/partials/delivery_countdown.vue';
Vue.component('delivery-countdown', deliveryCountdown);

import productCard from "@components/shop/item/product_card.vue";
Vue.component("product-card", productCard);

import productImages from "@components/shop/item/partials/product_images.vue";
Vue.component("product-images", productImages);

import productSlider from "@components/shop/featured/product_slider.vue";
Vue.component("product-slider", productSlider);

import categoryProducts from "@components/shop/browse/category_products.vue";
Vue.component("category-products", categoryProducts);

import assessmentSteps from "@components/assessment/external/assessment_steps.vue";
Vue.component("assessment-steps", assessmentSteps);

import assessmentForm from "@components/assessment/assessment_form.vue";
Vue.component("assessment-form", assessmentForm);

import gpSurgerySearch from '@components/gp_surgery_search.vue';
Vue.component("gp-surgery-search", gpSurgerySearch);

// Legacy script that adds mobile accordion behavior and menu ready state (complements the mtc-menu Vue component)
import "@site_scripts/mtc_menu.js";
import "@site_scripts/mtc_accordions.js";
import "@site_scripts/mtc_content_sidebar.js";
import "@site_scripts/mtc_item.js";
import "@site_scripts/mtc_faqs.js";

// Delivery timer for the basket cutoff banner (vanilla countdown).
import "@site_scripts/mtc_timers.js";

// Vue search component for autocomplete functionality and legacy handlers for search toggle
import "@site_scripts/mtc_search.js";
import "@site_scripts/mtc_overlay.js";

// Members verification
import "@site_scripts/mtc_account_verify.js";

//Sidebar Functionality
import "@site_scripts/mtc_sidebar.js";

// "Alternative Products" side-panel overlay (used on product pages).
import "@site_scripts/mtc_alternative_overlay.js";

// Main script file
import "./script.js";

import DatePicker from '@components/date_picker.vue';
Vue.component('datepicker', DatePicker);

import DateTextField from './components/date_text_field.vue';
Vue.component('date-text-field', DateTextField);

import Chosen from '@components/chosen.vue';
Vue.component('chosen', Chosen);

/*
* Replacement for tagit
 */
import VueTagsInput from '@johmun/vue-tags-input';
Vue.component('vue-tags-input', VueTagsInput);

import MtcTagInput from '@components/mtc_tag_input.vue';
Vue.component('mtc-tag-input', MtcTagInput);

//Assessment Store
import store from '@components/store/store.js';


//Subscriptions
import mtcSubscriptionOptions from '../../../plugins/mtc_pharmacy_subscriptions/src/assets/js/components/shop/basket/subscription_options';
Vue.component('subscription-options', mtcSubscriptionOptions);

import mtcSubscriptionItem from '../../../plugins/mtc_pharmacy_subscriptions/src/assets/js/components/members/subscription/subscription_item';
Vue.component('subscription-item', mtcSubscriptionItem);

import mtcSubscriptionActions from '../../../plugins/mtc_pharmacy_subscriptions/src/assets/js/components/members/subscription/subscription_actions';
Vue.component('subscription-actions', mtcSubscriptionActions);

import mtcSubscriptionStatus from '../../../plugins/mtc_pharmacy_subscriptions/src/assets/js/components/members/subscription/subscription_status';
Vue.component('subscription-status', mtcSubscriptionStatus);


// Lazy-loading for `data-src` images across the whole site.
ready(() => {
    requestAnimationFrame(() => {
        window.lazyLoadInstance = new LazyLoad();
    });
});

// Mount Vue. The `vue:mounted` event is what every vanilla module's `ready()`
// helper waits on — Vue 2's `el:` mount replaces the DOM nodes during compile,
// so any listener attached before this event lands on a discarded node.
window.vue_environment = new Vue({
    el: '#vue_environment',
    store,
    delimiters: ['[%', '%]'],
    mounted() {
        document.dispatchEvent(new Event('vue:mounted'));
    },
});
