<template>
  <view class="page">
    <!-- #ifdef APP -->
    <statusBar></statusBar>
    <!-- #endif -->

    <uni-nav-bar
      :fixed="true"
      :statusBar="true"
      :border="false"
      title="工作台"
      color="#333"
      backgroundColor="#FFFFFF"
    />

    <view class="content">
      <sales-scenario-new
        v-if="isSalesScenario"
        :contentTop="contentTop"
        :contentBottom="contentBottom"
      />
      <view v-else class="redirecting-text">正在跳转到 AI 分析...</view>
    </view>
  </view>
</template>

<script>
// #ifdef APP
import statusBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-status-bar';
// #endif
import SalesScenarioNew from './components/sales_scenario_new.vue';

function getSystemInfo() {
  try {
    const systemInfo = uni.getSystemInfoSync();
    return {
      statusBarHeight: systemInfo.statusBarHeight || 20,
    };
  } catch (e) {
    return {
      statusBarHeight: 20,
    };
  }
}

export default {
  components: {
    // #ifdef APP
    statusBar,
    // #endif
    SalesScenarioNew,
  },
  data() {
    const systemInfo = getSystemInfo();
    const totalNavbarHeight = systemInfo.statusBarHeight * 2 + 44 * 2;
    return {
      contentTop: totalNavbarHeight + 'rpx',
      contentBottom: '96rpx',
      isSalesScenario: false,
    };
  },
  onShow() {
    this.refreshScenario();
  },
  methods: {
    refreshScenario() {
      const scenario = (uni.getStorageSync('backend-scenario') || '').toString().toLowerCase();
      this.isSalesScenario = scenario === 'sales';
      if (!this.isSalesScenario) {
        uni.switchTab({
          url: '/pages/ai_analysis/ai_analysis',
        });
      }
    },
  },
};
</script>

<style scoped>
page {
  background-color: #f5f5f5;
}

.page {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.content {
  position: relative;
  min-height: 100vh;
}

.redirecting-text {
  padding: 40rpx 30rpx;
  color: #999;
  font-size: 28rpx;
  text-align: center;
}
</style>
