import { useSelector } from "react-redux";

import type { AutoOrderData } from "@hooks/apis/auto/useAutoHistory";
import type { ReduxStateType } from "@store/types";
import { AutoData, type InflightInfo } from "../common/data";
import { useUpdateAutoStatus } from "../common/useUpdateAutoStatus";
import { InFlightLayout } from "../layout";

export const AutoInflight = () => {
	const { data: initialData } = useSelector(
		(state: ReduxStateType) => state.inflight,
	);
	const routeData = useUpdateAutoStatus({
		initialData: initialData as AutoOrderData,
	});

	const data: InflightInfo = {
		title: AutoData.title,
		subTitle: AutoData.subTitle,
		// biome-ignore lint/style/noNonNullAssertion: <explanation>
		info: routeData ?? initialData!,
	};

	return <InFlightLayout data={data} />;
};
