import React, { useState, useEffect } from "react";
import {
View,
Linking,
Text,
TouchableOpacity,
BackHandler,
Platform,
} from "react-native";
import AutoHeightImage from "react-native-auto-height-image";
import { FontAwesome, Foundation, Ionicons } from "@expo/vector-icons";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import ActionSheet, { SheetManager } from "react-native-actions-sheet";
import Sign from "../../components/駅名表/Sign";
import { TicketBox } from "../atom/TicketBox";
import { widthPercentageToDP as wp } from "react-native-responsive-screen";
import { getPDFViewURL } from "../../lib/getPdfViewURL";
import { useBusAndTrainData } from "../../stateBox/useBusAndTrainData";
import { AS } from "../../storageControl";
export const StationDeteilView = (props) => {
if (!props.payload) return <>>;
const {
currentStation,
originalStationList,
navigate,
onExit,
goTo,
useShow,
} = props.payload;
const { busAndTrainData } = useBusAndTrainData();
const [trainBus, setTrainBus] = useState();
useEffect(() => {
if (!currentStation) return () => {};
const data = busAndTrainData.filter((d) => {
return d.name === currentStation[0].Station_JP;
});
if (data.length == 0) {
setTrainBus();
}
setTrainBus(data[0]);
}, [currentStation]);
const [usePDFView, setUsePDFView] = useState(undefined);
useEffect(() => {
AS.getItem("usePDFView").then(setUsePDFView);
}, []);
const info =
currentStation &&
(currentStation[0].StationTimeTable.match(".pdf")
? getPDFViewURL(currentStation[0].StationTimeTable)
: currentStation[0].StationTimeTable);
const insets = useSafeAreaInsets();
return (
>}
isModal={Platform.OS == "ios"}
containerStyle={
Platform.OS == "android"
? {
paddingBottom: insets.bottom,
}
: {}
}
useBottomSafeAreaPadding={Platform.OS == "android"}
>
{currentStation && (
{
usePDFView == "true"
? Linking.openURL(currentStation[0].StationTimeTable)
: navigate("howto", {
info,
goTo,
useShow,
});
onExit();
}}
oLP={() => Linking.openURL(currentStation[0].StationTimeTable)}
/>
)}
{/* {currentStation &&
currentStation.map((d) => (
))} */}
{currentStation &&
currentStation[0].JrHpUrl &&
currentStation[0].StationNumber != "M12" && (
<駅構内図 //高松/阿波池田&後免&須崎kounai.png児島例外/
oP={() => {
navigate("howto", {
info:
currentStation[0].JrHpUrl.replace("/index.html", "/") +
"/kounai_map.html",
goTo,
useShow,
});
onExit();
}}
oLP={() => {
Linking.openURL(
currentStation[0].JrHpUrl.replace("/index.html", "/") +
"/kounai_map.html"
);
}}
uri={currentStation[0].JrHpUrl.replace("/index.html", "/")}
/>
)}
{currentStation && (
{!currentStation[0].JrHpUrl || (
}
flex={1}
onPressButton={() => {
navigate("howto", {
info: currentStation[0].JrHpUrl,
goTo,
useShow,
});
onExit();
}}
onLongPressButton={() =>
Linking.openURL(currentStation[0].JrHpUrl)
}
>
web
)}
{!currentStation[0].StationTimeTable || (
}
flex={1}
onPressButton={() => {
usePDFView == "true"
? Linking.openURL(currentStation[0].StationTimeTable)
: navigate("howto", {
info,
goTo,
useShow,
});
onExit();
}}
onLongPressButton={() =>
Linking.openURL(currentStation[0].StationTimeTable)
}
>
時刻表
)}
{!currentStation[0].StationMap || (
}
flex={1}
onPressButton={() =>
Linking.openURL(currentStation[0].StationMap)
}
>
Map
)}
{!trainBus || (
}
flex={1}
onPressButton={() => {
navigate("howto", {
info: trainBus.address,
goTo,
useShow,
});
onExit();
}}
onLongPressButton={() => Linking.openURL(trainBus.address)}
>
並行バス
)}
)}
);
};
const 駅構内図 = (props) => {
const [open, setOpen] = useState(false);
return (
<>
setOpen(!open)}
>
{open ? "駅構内図を非表示" : "駅構内図を表示"}
{open && (
<>
>
)}
>
);
};
const Handler = () => {
useEffect(() => {
const backAction = () => {
SheetManager.hide("StationDetailView");
return true;
};
const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction
);
return () => backHandler.remove();
}, []);
return <>>;
};