<template>
  <div class="search">
    <div class="search-bar">
      <el-input v-model="code" placeholder="请输入溯源码" size="large" clearable />
      <el-button type="primary" icon="Search" size="large" class="search-bar-btn" @click="onSearch">搜索</el-button>
    </div>
    <h2 class="search-title">农产品全生命周期管理</h2>
    <div class="search-panel">
      <el-card class="search-card" shadow="hover">
        <div class="search-card-item">
          <span class="icon"><img :src="getAssetsFile('images/trace/search-1.png')" /></span>
          <span class="text">种养植档案管理</span>
        </div>
      </el-card>
      <div class="search-card-connector"></div>
      <el-card class="search-card" shadow="hover">
        <div class="search-card-item">
          <span class="icon"><img :src="getAssetsFile('images/trace/search-2.png')" /></span>
          <span class="text">农事管理</span>
        </div>
      </el-card>
      <div class="search-card-connector"></div>
      <el-card class="search-card" shadow="hover">
        <div class="search-card-item">
          <span class="icon"><img :src="getAssetsFile('images/trace/search-3.png')" /></span>
          <span class="text">质量监管</span>
        </div>
      </el-card>
    </div>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useApp } from '@/hooks';
import { isEmpty, getAssetsFile } from '@/utils';

const router = useRouter();
const app = useApp();
const code = ref('');

const onSearch = () => {
  if (isEmpty(code.value)) {
    app.$message.error('请输入溯源码进行查询！');
    return;
  }
  router.push({ path: '/trace-info', query: { code: code.value } });
};
</script>
<style lang="scss" scoped>
.search {
  @include flex-column();
  align-items: center;
  padding: 80px 20px 20px;
  box-sizing: border-box;

  &-bar {
    width: 600px;
    margin-bottom: 80px;
    @include flex-row();

    &-btn {
      margin-left: -5px;
    }
  }

  &-title {
    color: $color-primary;
    margin-bottom: 80px;
    font-size: 30px;
    text-align: center;
  }

  &-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
  }

  &-card {
    flex: 1;
    max-width: 200px;
    cursor: pointer;
    transition: transform 0.3s;

    &-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 15px;
      padding: 20px;
    }

    .icon {
      display: block;
      width: 80px;
      height: 80px;
      img {
        width: 100%;
      }
    }

    .text {
      color: $color-primary;
      font-size: 16px;
    }

    &-connector {
      width: 160px;
      height: 3px;
      background-color: $color-success;
      border-radius: 2px;
      flex-shrink: 0;
    }
  }
}
</style>
