<template>
	<a-layout>
		<a-layout-header :class="style['layout-header']">
			<!-- 一体化平台的导航栏 -->
			<IntegrationPlatformNavbar v-if="IS_IN_INTEGRATED_PLATFORM" />
			<!--  -->
			<basic-header
				v-else
				@refresh-sider-collapsed="onRefreshSiderCollapsed"
			/>
		</a-layout-header>
		<a-layout
			:class="
				IS_IN_INTEGRATED_PLATFORM ? 'is_in_integrated_platform' : ''
			"
		>
			<a-layout-sider
				v-model:collapsed="collapsed"
				:trigger="null"
				collapsible
				:width="195"
				:class="style['layout-sider']"
			>
				<basic-sider-menu :menus="menus" />
			</a-layout-sider>
			<a-layout-content :class="style['layout-content']">
				<base-breadcrumb />
				<router-view />
				<a-back-top>
					<div :class="style['back-top']"></div>
				</a-back-top>
			</a-layout-content>
		</a-layout>
	</a-layout>
</template>
<script lang="ts">
import { defineComponent, computed, ref } from 'vue'
import BaseBreadcrumb from './BaseBreadcrumb.vue'
import BasicSiderMenu from './BasicSiderMenu.vue'
import BasicHeader from './BasicHeader.vue'
import style from './basic-layout.module.less'
import { permissionStore } from '@/store/modules/permission'
import { AppRouteRecordRaw } from '@/router/model'

import IntegrationPlatformNavbar from 'integration-platform-navbar'

export default defineComponent({
	components: {
		BasicSiderMenu,
		BasicHeader,
		BaseBreadcrumb,
		IntegrationPlatformNavbar,
	},
	setup() {
		//   localStorage.set('isInJiachengIntegratedPlatform', true)
		const IS_IN_INTEGRATED_PLATFORM =
			window.localStorage.getItem('isInJiachengIntegratedPlatform') ||
			false

		const usePermissionStore = permissionStore()
		const menus = computed(() => {
			let _arr = usePermissionStore.authoritiesRoutes.find(
				f => f.path === '/'
			)?.children

			if (IS_IN_INTEGRATED_PLATFORM && _arr && _arr.length > 0) {
				_arr.map(v => {
					v.meta.icon && (v.meta.icon += '-deep')
				})
			}
			return _arr
		})

		const collapsed = ref<boolean>(false)
		const onRefreshSiderCollapsed = (val: boolean) => {
			collapsed.value = val
		}

		return {
			style,
			menus: menus as unknown as AppRouteRecordRaw[],
			collapsed,
			onRefreshSiderCollapsed,
			IS_IN_INTEGRATED_PLATFORM,
		}
	},
})
</script>
