<template>
  <div class="page page-home" id="pageContainer">
    <div class="home-top">
      <div class="header">
        <home-header @login="emits('login')" sub-title="自然资源大模型" />
      </div>
      <div class="container">
        <div class="tool">
          <ul>
            <li class="active">
              <span class="iconfont icon-a-zu11199"></span>
              <span class="title">AI问答</span>
            </li>
            <li>
              <span class="iconfont icon-a-lujing11029"></span>
              <span class="title">智能选址</span>
            </li>
            <li>
              <span class="iconfont icon-66zhishikuguanli"></span>
              <span class="title">知识库</span>
            </li>
          </ul>
        </div>
        <div class="top-content">
          <div class="title">
            <div class="logo"></div>
            <div class="title-main"></div>
          </div>

          <div class="search-panel">
            <div class="type-box">
              <div class="scope-type-box">
                <div
                  class="item"
                  v-for="(item, index) in scopeTypes"
                  :key="index"
                  @click="toggleType(item, index)"
                  :class="{ checked: activeTypeIndex == index }"
                >
                  {{ item.name }}
                </div>
              </div>
            </div>
            <div class="search-input">
              <input
                type="text"
                v-model="question"
                @keydown.enter.native="search"
                :placeholder="placeholder"
              />
              <div class="input-tool">
                <div class="tool-box">
                  <a-select v-model:value="scope.name" class="select">
                    <a-select-option value="knowledge">知识库</a-select-option>
                    <a-select-option value="paper">学术</a-select-option>
                    <a-select-option value="net">全网</a-select-option>
                  </a-select>
                  <div class="ds-box">
                    <div @click="dsChange('1')" :class="{active: isDeepSeek === '1'}">
                      <i class="iconfont icon-deepsee"></i>
                    </div>
                    <div @click="dsChange('0')" :class="{active: isDeepSeek === '0'}">
                      <i class="iconfont icon-tongyi"></i>
                    </div>
                  </div>
                </div>
                <button class="search-btn" @click="search" v-login-required>
                  <span class="iconfont icon-a-zu11168"></span>
                </button>
              </div>
            </div>
            <div class="scopes">
              <div class="questions" v-if="typeIndex == 0">
                <slider-card-up-down @ask="jumpToSearch" />
              </div>
            </div>
          </div>
          <div class="ai_tool_box">
            <h4>AI工具</h4>
            <ul>
              <li @click="toToolPage('./#/policy/interpret')">
                <div>
                  <div class="icon_box icon_box1">
                    <span class="iconfont icon-a-lujing8796"></span>
                  </div>
                  <div>
                    <p class="name">政策解读</p>
                    <p>导入一个政策文件，AI快速总结政策要点</p>
                  </div>
                </div>
              </li>
              <li @click="toToolPage('./#/policy/smart')">
                <div>
                  <div class="icon_box icon_box2">
                    <span class="iconfont icon-a-lujing8794"></span>
                  </div>
                  <div>
                    <p class="name">政策比对</p>
                    <p>导入两个政策文件，AI快速比对两个文件的区别</p>
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
        <compare-policy />
      </div>
    </div>
    
  </div>
</template>
<script setup>
import HomeHeader from '@/views/home/components/HomeHeader.vue';

import { isEmptyStr } from '@/utils/common';
import SliderCardUpDown from '@/components/NewSliderCardUpDown.vue';
import ComparePolicy from './components/ComparePolicy.vue';

const emits = defineEmits(['login']);
const question = ref('');
const activeTypeIndex = ref(0);
const placeholder = ref('请输入您的问题，如“临时用地的审批流程”');
const scopeTypes = ref([
  {
    name: '简洁',
    value: '0'
  },
  {
    name: '深入',
    value: '1'
  },
  {
    name: '研究',
    value: '2'
  }
]);
const types = ref([
  {
    name: '简洁',
    key: '0'
  }, {
    name: '深入',
    key: '1'
  }, {
    name: '研究',
    key: '2'
  }
])
const typeIndex = ref(0);
const scope = ref({
  name: 'knowledge',
  type: '0'
});
const scopeQt = ref({
  name: 'title',
  type: '0'
});

const search = () => {
  if (typeIndex.value == 0) {
    if (!isEmptyStr(question.value)) {
      jumpToSearch(question.value);
    }
  } else if (typeIndex.value == 1) {
    var url =
      window.AppGlobalConfig.links[types.value[typeIndex.value].key] + '?keyword=' + question.value;
    window.open(url, '_blank');
  } else {
    var key = question.value;
    if (!key) {
      key = '=';
    }
    var url = window.AppGlobalConfig.links[types.value[typeIndex.value].key] + '?keyword=' + key;
    window.open(url, '_blank');
  }
};
const toggleType = (item, index) => {
  if (typeIndex.value == 0) {
    scope.value.type = item.value;
  } else {
    scopeQt.value.type = item.value;
  }
  activeTypeIndex.value = index;
};
const jumpToSearch = (q) => {
  const { name, type } = scope.value;
  window.open(`./#/ai-search?q=${encodeURIComponent(q)}&scope=${name}&type=${type}&ds=${isDeepSeek.value}`, '_blank');
};
const isDeepSeek = ref((localStorage.getItem("_isDeepSeek") || '1'))
const dsChange = (type) => {
  isDeepSeek.value = type;
  localStorage.setItem("_isDeepSeek", type);
}
const toToolPage = (path) => {
  window.open(path, '_blank')
}
</script>
<style scoped lang="scss">
$selectHeight: 36px;
.page-home {
  position: relative;
  .home-top {
    width: 100%;
    height: 100%;
    position: relative;
    background: url("/images/home/home_bg.jpg") no-repeat;
    background-size: 100% 100%;
    >.header {
      width: 100%;
      height: 60px;
    }
    >.container {
      display: flex;
      height: calc(100% - 60px);
      position: relative;
      >.tool {
        width: 96px;
        height: 100%;
        display: flex;
        align-items: center;
        background: #F4F7FD;
        box-shadow: 0px 4px 15px 1px rgba(0,54,116,0.15);
        >ul {
          width: 100%;
          text-align: center;
          padding: 8px;
          box-sizing: border-box;
          transform: translateY(-30%);
          >li {
            padding: 10px 0px;
            text-align: center;
            margin: 10px auto;
            cursor: pointer;
            >.iconfont {
              display: block;
              font-size: 28px;
              margin: auto;
              margin-bottom: 3px;
              color: #222222;
            }
            >.title {
              font-size: 14px;
              color: #373C45;
              white-space: nowrap;
            }
            &:hover, &.active {
              background: #E0EAFA;
              border-radius: 12px;
              >.iconfont {
                color: #507FFF;
              }
            }
          }
        }
      }
      >.top-content {
        width: calc(100% - 96px);
        padding-top: 100px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
        .title {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          margin-bottom: 45px;
          >.logo {
            width: 66px;
            height: 66px;
            background: url('@/assets/images/home/logo.png') no-repeat;
            background-size: 100% 100%;
          }
          &-main {
            width: 480px;
            height: 66px;
            background: url('@/assets/images/home/icon-title-main.png') no-repeat;
            background-size: 100% 100%;
            margin-bottom: 11px;
          }

          &-sub {
            font-family: PingFang SC, PingFang SC;
            font-weight: 500;
            font-size: 20px;
            color: #4B525F;
            letter-spacing: 10px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          }
        }

        .search-panel {
          width: 960px;
          .type-box {
            display: flex;
            margin-bottom: 10px;
            justify-content: space-between;
            >.scope-type-box {
              display: flex;
              background: #FFFFFF;
              border-radius: 7px;
              border: 1px solid #E3E4E4;;
              padding: 2px;
              >.item {
                color: #4A4F55;
                border-radius: 7px;
                padding: 6px 18px;
                flex: 1;
                display: flex;
                align-items: center;
                cursor: pointer;
                font-size: 14px;
                &.checked {
                  background: #0E83F8;
                  color: #FFF;
                }
              }
            }
          }
          .search-input {
            width: 960px;
            position: relative;
            margin-bottom: 19px;
            background: #FFFFFF;
            box-shadow: 0px 8px 16px 1px rgba(11,53,103,0.1);
            border-radius: 12px;
            border: 1px solid #E5E6EA;
            padding: 10px 20px;
            >input {
              width: 100%;
              padding: 15px 0px;
              background: #ffffff;
              font-family: PingFang SC, PingFang SC;
              border: 0px;
              border-bottom: 1px solid rgba(228, 231, 234, 0.6);
              &:hover,
              &:focus,
              &:focus-visible {
                border-bottom: 1px solid #0e83f8;
                outline: none;
              }
              &::placeholder {
                color: #858C93;
                font-size: 18px;
              }
            }
            >.input-tool {
              margin-top: 10px;
              display: flex;
              justify-content: space-between;
              >.tool-box {
                display: flex;
                align-items: center;
                .select {
                  height: $selectHeight;
                  left: 2px;
                  border-radius: 5px;
                  margin-right: 10px;
                  border: 1px solid #E3E4E4;
                  overflow: hidden;
                  :deep(.ant-select-selector) {
                    border: none;
                    height: $selectHeight;
                    line-height: $selectHeight;
                    box-shadow: none;
                  }
                  :deep(.ant-select-selection-item) {
                    line-height: $selectHeight;
                    font-family: PingFang SC, PingFang SC;
                    font-size: 15px;
                    color: #34383C;
                    text-align: center;
                    margin-right: 4px;
                  }
                  :deep(.ant-select-arrow) {
                    margin-top: -4px;
                  }
                }
                .ds-box {
                  display: flex;
                  height: 36px;
                  align-items: center;
                  border: 1px solid #E3E4E4;
                  background: #fff;
                  border-radius: 5px;
                  overflow: hidden;
                  >div {
                    height: 100%;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    width: 108px;
                    cursor: pointer;
                    padding: 10px 0px;
                    &.active {
                      background: #f2f5fe;
                      border: 1px solid #0E83F8;
                      &:nth-child(1) {
                        border-top-left-radius: 5px;
                        border-bottom-left-radius: 5px;
                        .iconfont {
                          color: #4f6bfe;
                        }
                      }
                      &:nth-child(2) {
                        border-top-right-radius: 5px;
                        border-bottom-right-radius: 5px;
                        .iconfont {
                          color: #605BEC;
                        }
                      }
                    }
                    .iconfont {
                      color: #34383C;
                      margin-top: 2px;
                    }
                    &:nth-child(1) {
                      .iconfont {
                        font-size: 16px;
                      }
                    }
                    &:nth-child(2) {
                      .iconfont {
                        font-size: 22px;
                      }
                    }
                  }
                  .sw {
                    :deep(.ant-switch) {
                      background-color: #eaeaea;
                    }
                    :deep(.ant-switch-handle::before) {
                      background-color: #fff;
                    }
                  }
                }
              }
              .search-btn {
                border-radius: 6px;
                cursor: pointer;
                border: none;
                padding: 10px;
                background: linear-gradient( 124deg, #505DFF 0%, #418CFF 100%);
                >.iconfont {
                  display: block;
                  width: 30px;
                  height: 30px;
                  font-size: 26px;
                  color: #fff;
                }
              }
            }
          }

          .scopes {
            display: flex;
            margin-bottom: 20px;
            font-weight: 400;
            font-size: 14px;
            text-align: left;
            height: 32px;
            font-style: normal;
            text-transform: none;
            color: #fff;

            .scope {
              flex: 1;

              display: flex;
              align-items: center;
              &-type {
                justify-content: flex-start;
              }
              :deep(.ant-radio-wrapper) {
                color: #fff;
              }
            }
            .questions {
              flex: 1;
            }
          }
        }

        .ai_tool_box {
          width: 960px;
          >h4 {
            color: #353745;
            font-size: 20px;
          }
          >ul {
            >li {
              cursor: pointer;
              border: 1px solid #E5E6EA;
              background: #fff;
              padding: 20px 15px;
              border-radius: 5px;
              display: inline-block;
              box-sizing: border-box;
              box-shadow: 0px 4px 8px 1px rgba(33,50,70,0.06);
              width: calc(50% - 15px);
              &:nth-child(2n+1) {
                margin-right: 15px;
              }
              &:nth-child(2n+2) {
                margin-left: 15px;
              }
              >div {
                height: 100%;
                display: flex;
                align-items: center;
                >.icon_box {
                  width: 40px;
                  height: 40px;
                  line-height: 40px;
                  border-radius: 4px;
                  text-align: center;
                  margin-right: 10px;
                  >.iconfont {
                    font-size: 22px;
                    display: inline-block;
                  }
                  &.icon_box1 {
                    background: #D4F3F7;
                    >.iconfont {
                      color: #29BECD;
                    }
                  }
                  &.icon_box2 {
                    background: #E5EFFC;
                    >.iconfont {
                      color: #4F7FFF;
                    }
                  }
                }
                >div {
                  >p {
                    margin: 5px 0px;
                    color: #76808E;
                    font-size: 15px;
                    &.name {
                      font-size: 18px;
                      font-weight: bold;
                      color: #414355;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
