<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"
      />
      <soft-sales-scenario
        v-else-if="isSoftSalesScenario"
        :content-top="contentTop"
        :content-bottom="contentBottom"
      />
      <small-beautiful-sales
        v-else-if="isSmallBeautifulSalesScenario"
        :content-top="contentTop"
        :content-bottom="contentBottom"
      />
      <view v-else class="redirecting-text">
        <text>当前未配置为销售或轻销场景（backend-scenario 不是 sales / soft_sales / smallBeautiful_sales），工作台入口已隐藏。</text>
      </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';
import SmallBeautifulSales from './components/small_beautiful_sales.vue';
import SoftSalesScenario from '@/components/soft_sales_scenario.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,
    SmallBeautifulSales,
    SoftSalesScenario,
  },
  data() {
    const systemInfo = getSystemInfo();
    const totalNavbarHeight = systemInfo.statusBarHeight * 2 + 44 * 2;
    return {
      contentTop: totalNavbarHeight + 'rpx',
      contentBottom: '96rpx',
      isSalesScenario: false,
      isSoftSalesScenario: false,
      isSmallBeautifulSalesScenario: false,
    };
  },
  onShow() {
    this.refreshScenario();
  },
  methods: {
    refreshScenario() {
      const scenario = (uni.getStorageSync('backend-scenario') || '').toString().trim().toLowerCase();
      this.isSalesScenario = scenario === 'sales';
      this.isSoftSalesScenario = scenario === 'soft_sales';
      this.isSmallBeautifulSalesScenario = scenario === 'smallbeautiful_sales';
    },
  },
};
</script>

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

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

/* 子组件（销售工作台 / AI 分析主体）使用 position:absolute + top/bottom，不占文档流；
   若此处无明确高度，父级会被压成 0，导致整块空白。 */
.content {
  position: relative;
  width: 100%;
  min-height: 100vh;
  box-sizing: border-box;
}

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