import React, { useState, useEffect } from "react";
import ShopList from "../ShopList/ShopList.js";
import "./HeadBar.scss";
import { searchTypes } from "../Options/Options";
import backpng from './back.png'
const HeadBar = ({
mall,
exit,
start,
end,
floors,
onSwap,
shop,
onSetStart,
onSetEnd,
isPick,
setIsPick,
blurMap,
showSearchType,
onClickSearchType,
searchType,
onIsTypingChange
}) => {
const [isTypingStart, setIsTypingStart] = useState(false);
const [isTypingEnd, setIsTypingEnd] = useState(false);
const isTyping = isTypingStart || isTypingEnd;
const [q, setQ] = useState(null);
const onlyShowStart = isTypingStart || (!start && isPick);
const onlyShowEnd = isTypingEnd || (!end && isPick);
const showStart = !onlyShowEnd;
const showEnd = !onlyShowStart;
const showBoth = !(isPick || isTyping);
const hasBoth = start && end;
const startValue =
q !== null ? q : isPick ? (shop ? shop.name : "") : start ? start.name : "";
const endValue =
q !== null ? q : isPick ? (shop ? shop.name : "") : end ? end.name : "";
useEffect(() => { onIsTypingChange(isTyping) }, [isTyping])
return (
blurMap()}
>
{
if (isPick) setIsPick(false);
else if (isTypingStart) {
setQ(null);
setIsTypingStart(false);
} else if (isTypingEnd) {
setQ(null);
setIsTypingEnd(false);
} else exit();
}}
>
{showBoth &&
}
{showStart && (
setIsTypingStart(true)}
onChange={(e) => setQ(e.target.value)}
readOnly={isPick}
disabled={isPick}
placeholder={isPick ? "请点击地图选择起点" : "请输入起点"}
>
{(start || (isPick && shop)) && (
{floors[(start ? start : shop).floorOrder][1]}
)}
{start === null && isPick && (
{
setIsPick(false);
onSetStart(shop);
}}
>
开始导航
)}
{start === null && !isPick && !isTypingStart && (
{
setQ(null);
setIsPick(true);
setIsTypingStart(false);
setIsTypingEnd(false);
}}
>
地图选点
)}
)}
{showEnd && (
setIsTypingEnd(true)}
onChange={(e) => setQ(e.target.value)}
readOnly={isPick}
disabled={isPick}
placeholder={isPick ? "请点击地图选择终点" : "请输入终点"}
>
{((isPick && shop) || end) && (
{floors[(end ? end : shop).floorOrder][1]}
)}
{end === null && isPick && (
{
setIsPick(false);
onSetEnd(shop);
}}
>
开始导航
)}
{end === null && !isPick && !isTypingEnd && (
{
setQ(null);
setIsPick(true);
setIsTypingEnd(false);
}}
>
地图选点
)}
)}
{showBoth &&
onSwap()}>
}
{showBoth && !hasBoth && (
请在顶部选择{!start ? "起" : "终"}点
)}
{isTyping && q && (
{
if (isTypingStart) {
onSetStart(shop);
setQ(null);
setIsTypingStart(false);
}
if (isTypingEnd) {
onSetEnd(shop);
setQ(null);
setIsTypingEnd(false);
}
}}
top={"70px"}
isRow={true}
>
)}
);
};
export default HeadBar;