<template>
  <view class="poi-search-page">
    <view class="search-header">
      <view class="search-header-copy">
        <text class="page-title">点位搜索</text>
        <text class="page-subtitle">Search Museum Locations</text>
      </view>
      <view class="map-link" @tap="handleBackToMap">
        <text class="map-link-text">返回地图</text>
      </view>
    </view>

    <PoiSearchPanel
      :initial-keyword="initialKeyword"
      variant="page"
      autofocus
    />
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import PoiSearchPanel from '@/components/search/PoiSearchPanel.vue'

const initialKeyword = ref('')

onLoad((options: any) => {
  const keyword = typeof options.keyword === 'string'
    ? decodeURIComponent(options.keyword)
    : ''

  initialKeyword.value = keyword
})

const handleBackToMap = () => {
  uni.navigateBack({
    delta: 1,
    fail: () => {
      uni.reLaunch({
        url: '/pages/index/index?tab=guide'
      })
    }
  })
}
</script>

<style scoped lang="scss">
.poi-search-page {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 32px) 14px 24px;
  box-sizing: border-box;
  background:
    linear-gradient(180deg, rgba(224, 225, 0, 0.22) 0, rgba(245, 245, 237, 0) 146px),
    #f5f5ed;
  color: #262421;
  font-family: '鸿蒙黑体', 'HarmonyOS Sans SC', 'HarmonyOS Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  overflow-y: auto;
}

.search-header {
  min-height: 46px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 16px;
}

.search-header-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.page-title {
  font-size: 26px;
  line-height: 31px;
  font-weight: 800;
  letter-spacing: 0;
  color: #000000;
}

.page-subtitle {
  font-size: 11px;
  line-height: 15px;
  font-weight: 500;
  color: #5d5b50;
  white-space: nowrap;
}

.map-link {
  min-width: 74px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  box-sizing: border-box;
  background: #000000;
  border: 1px solid rgba(0, 0, 0, 0.88);
  border-radius: 8px;
}

.map-link-text {
  font-size: 13px;
  line-height: 18px;
  font-weight: 700;
  color: var(--museum-accent);
  white-space: nowrap;
}

@media (min-width: 768px) {
  .poi-search-page {
    max-width: 430px;
    margin: 0 auto;
  }
}
</style>
