<template>
  <div class="resource-search">
    <div class="search-box">
      <input 
        v-model="searchText" 
        type="text" 
        placeholder="搜索思政资源"
        @keyup.enter="handleSearch"
      />
      <div class="search-button" @click="handleSearch">
        <img src="@/assets/imgs/search-icon.svg" alt="search" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const emit = defineEmits<{
  search: [keyword: string];
}>();

const searchText = ref('');

function handleSearch() {
  emit('search', searchText.value);
}
</script>

<style lang="scss" scoped>
.resource-search {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.search-box {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 36px;
  background: #FFFFFF;
  border: 1px solid rgba(186, 192, 204, 0.5);
  border-radius: 30px;
  display: flex;
  align-items: center;
  overflow: hidden;
}

input {
  flex: 1;
  height: 100%;
  padding: 0 90px 0 20px;
  border: none;
  outline: none;
  font-family: 'PingFang SC';
  font-size: 14px;
  color: #141F38;
  
  &::placeholder {
    color: rgba(0, 0, 0, 0.3);
  }
}

.search-button {
  position: absolute;
  right: 0;
  width: 60px;
  height: 100%;
  background: #C62828;
  border-radius: 0 30px 30px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.3s;
  
  &:hover {
    background: #B71C1C;
  }
  
  img {
    width: 18px;
    height: 18px;
    filter: brightness(0) invert(1);
  }
}
</style>