<%@ page title="" language="VB" masterpagefile="~/Template/Master.master" autoeventwireup="false" inherits="RCC_VPS_VPSAccounts, MachSol.MachPanel.Web" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CPH_Content" runat="Server">
    
    <!-- Include the external template so the DOM template is available before the module runs -->
    <!-- #include virtual="../../Components/VPS/VPSSchedules.html" -->    

    <script type="module">

        import { createApp } from 'vue'
        import VPSAccounts from '/Components/VPS/VPSAccounts.js?v=3.6'
        import VPSSchedules from '/Components/VPS/VPSSchedules.js?v=3.6'
        import TabContainer from '/Components/Common/TabContainer.js?v=3.6'
        import { getLabelText } from '/Components/Common/utils.js?v=3.6'

        createApp({
            data() {
                return {
                    readOnly: <%= Helper.ReadOnlyRole %>,
                    isLoggedInAsCustomer: <%= Helper.IsLoggedInAsCustomer.ToString().ToLower() %>,
                    customerId: '<%= IIF(Helper.IsLoggedInAsCustomer, Session("CustomerId"), 0) %>',
                    allowtoAddVM: <%= AllowtoAddVM.ToString().ToLower() %>,
                    sortPreference: <%= Newtonsoft.Json.JsonConvert.SerializeObject(InitialSortPreference) %>,
                    currentTab: 0,
                    tabPanels: []
                }
            },
            methods: {
                getLabelText,
                activeTabChanged: function (newTabIndex) {
                    this.currentTab = vueActiveTabChanged(newTabIndex, this.currentTab, this.tabPanels);
                },
            },
            created: function () {

                this.tabPanels = [
                    { text: this.getLabelText('strVirtualMachines'), enabled: true, hideTabs: [] },
                    { text: this.getLabelText('StrSchedules'), enabled: true, hideTabs: [] }
                ];

                let urlParams = new URLSearchParams(window.location.search);
                
                if (urlParams.has('IA')) {
                    if (urlParams.get('IA') == 1)
                        displayErrorMsg(Error(this.getLabelText('SPT002054')));
                    else if (urlParams.get('IA') == 2)
                        displayErrorMsg(Error(this.getLabelText('strVPSMoveIsInProcess')));
                }
                if (urlParams.has('TI')) {
                    this.activeTabChanged(urlParams.get('TI'));
                }
            },
            components: {
                TabContainer,
                VPSAccounts,
                VPSSchedules
            },
            template: `
            <TabContainer :id="'clientlist'" :tabPanels="tabPanels" :activeTabIndex="currentTab" @onActiveTabChanged="activeTabChanged"></TabContainer>
            <VPSAccounts v-if="currentTab == 0" :readOnly="readOnly" :isLoggedInAsCustomer="isLoggedInAsCustomer" :customerId="customerId" :sortPreference="sortPreference" :allowtoAddVM="allowtoAddVM" />
            <VPSSchedules v-if="currentTab == 1" :readOnly="readOnly" :isLoggedInAsCustomer="isLoggedInAsCustomer" :customerId="customerId" :sortPreference="sortPreference" :allowtoAddVM="allowtoAddVM" />
`
        }).mount('#app')

    </script>

    <div id="app">
    </div>

</asp:Content>
