import{d as W,o as s,c as o,f as x,j as b,r,A as K,k as w,a as l,s as H,y as O,F as k,e as V,z as q,l as G,t as d,g as N,n as L,B as J,i as R,_ as M}from"./index-Bg3n6gLm.js";import{s as B}from"./index-BuBKbyog.js";const Q={class:"station-selector"},X={class:"station-panel"},Y={class:"search-box"},Z={key:0,class:"hot-stations"},ee={class:"station-tags"},te={key:1,class:"search-results"},ae={key:0,class:"no-result"},se=["onClick"],oe={class:"name"},le={class:"pinyin"},ne={class:"letter-title"},ie=["onClick"],ce={class:"name"},re={class:"pinyin"},de=W({__name:"StationSelector",props:{modelValue:{},placeholder:{},showHot:{type:Boolean,default:!0},selectorWidth:{default:400}},emits:["update:modelValue","change"],setup(h,{emit:T}){const i=h,f=T,g=r(!1),n=r(""),u=r([]),I=r([]),_=r([]),A=r(),$=r(),P=R(()=>{if(i.modelValue){const e=_.value.find(t=>t.id===i.modelValue||t.stationName===i.modelValue);return(e==null?void 0:e.stationName)||String(i.modelValue)}return""}),U=R(()=>{if(typeof i.modelValue=="number")return i.modelValue;const e=_.value.find(t=>t.stationName===i.modelValue);return e==null?void 0:e.id}),j=R(()=>{var p;const e={};for(const c of _.value){const v=((p=c.stationPinyin)==null?void 0:p.charAt(0).toUpperCase())||"#";e[v]||(e[v]=[]),e[v].push(c)}const t={};return Object.keys(e).sort().forEach(c=>{t[c]=e[c]}),t}),C=async()=>{try{const[e,t]=await Promise.all([B.getHot(),B.getAll()]);I.value=e.data||[],_.value=t.data||[]}catch(e){console.error("加载车站数据失败:",e)}},z=async()=>{if(!n.value.trim()){u.value=[];return}try{const e=await B.search(n.value);u.value=e.data||[]}catch(e){console.error("搜索失败:",e)}},S=e=>{f("update:modelValue",e.id),f("change",e),g.value=!1,n.value="",u.value=[]},D=()=>{f("update:modelValue",""),f("change",null)},E=()=>{C()},F=e=>{g.value=e,e&&(C(),K(()=>{var t;(t=A.value)==null||t.focus()}))};return C(),(e,t)=>{const p=w("el-input"),c=w("el-tag"),v=w("el-popover");return s(),o("div",Q,[x(v,{visible:g.value,placement:"bottom",width:h.selectorWidth||400,trigger:"click","onUpdate:visible":F},{reference:b(()=>[l("div",{class:"station-input",onClick:E},[x(p,{modelValue:P.value,"onUpdate:modelValue":t[0]||(t[0]=a=>P.value=a),placeholder:h.placeholder||"请选择车站",readonly:"","suffix-icon":H(J),onClear:D},null,8,["modelValue","placeholder","suffix-icon"])])]),default:b(()=>[l("div",X,[l("div",Y,[x(p,{modelValue:n.value,"onUpdate:modelValue":t[1]||(t[1]=a=>n.value=a),placeholder:"搜索车站名称或拼音","prefix-icon":H(O),clearable:"",onInput:z,ref_key:"searchInputRef",ref:A},null,8,["modelValue","prefix-icon"])]),!n.value&&h.showHot?(s(),o("div",Z,[t[2]||(t[2]=l("div",{class:"section-title"},"热门车站",-1)),l("div",ee,[(s(!0),o(k,null,V(I.value,a=>(s(),q(c,{key:a.id,class:"station-tag",onClick:y=>S(a)},{default:b(()=>[G(d(a.stationName),1)]),_:2},1032,["onClick"]))),128))])])):N("",!0),n.value?(s(),o("div",te,[t[3]||(t[3]=l("div",{class:"section-title"},"搜索结果",-1)),u.value.length===0?(s(),o("div",ae," 未找到相关车站 ")):(s(!0),o(k,{key:1},V(u.value,a=>(s(),o("div",{key:a.id,class:L(["station-item",{selected:a.id===U.value}]),onClick:y=>S(a)},[l("span",oe,d(a.stationName),1),l("span",le,d(a.stationPinyin),1)],10,se))),128))])):N("",!0),n.value?N("",!0):(s(),o("div",{key:2,class:"all-stations",ref_key:"stationListRef",ref:$},[(s(!0),o(k,null,V(j.value,(a,y)=>(s(),o("div",{key:y,class:"letter-group"},[l("div",ne,d(y),1),(s(!0),o(k,null,V(a,m=>(s(),o("div",{key:m.id,class:L(["station-item",{selected:m.id===U.value}]),onClick:ue=>S(m)},[l("span",ce,d(m.stationName),1),l("span",re,d(m.stationPinyin),1)],10,ie))),128))]))),128))],512))])]),_:1},8,["visible","width"])])}}}),me=M(de,[["__scopeId","data-v-ba8354a4"]]);export{me as S};
