import { useCallback, useEffect, useState } from "react" import { TextAreaInput } from "../../Input" import { PopupStartEndInput, TextView } from "../../Map" import { ActionButton } from "../Subcomponents/ActionsButton" import { LinkedItemsHeaderView } from "../Subcomponents/LinkedItemsHeaderView" import { TagsWidget } from "../Subcomponents/TagsWidget" import { useNavigate } from "react-router-dom" import { useUpdateItem } from "../../Map/hooks/useItems" export const TabsForm = ({ item, state, setState, updatePermission, linkItem, unlinkItem, loading, setUrlParams }) => { const [activeTab, setActiveTab] = useState(1); const navigate = useNavigate(); const updateItem = useUpdateItem(); const updateActiveTab = useCallback((id: number) => { setActiveTab(id); const params = new URLSearchParams(window.location.search); params.set("tab", `${id}`); const newUrl = location.pathname + "?" + params.toString(); window.history.pushState({}, '', newUrl); setUrlParams(params); }, [location.pathname]); useEffect(() => { const params = new URLSearchParams(location.search); const urlTab = params.get("tab"); setActiveTab(urlTab ? Number(urlTab) : 1); }, [location.search]); return (
updateActiveTab(1)} />
{item.layer.itemType.show_start_end_input && setState(prevState => ({ ...prevState, end: e }))} updateStartValue={(s) => setState(prevState => ({ ...prevState, start: s }))}> } setState(prevState => ({ ...prevState, text: v }))} containerStyle='tw-grow' inputStyle={`tw-h-full ${!item.layer.itemType.show_start_end_input && "tw-border-t-0 tw-rounded-tl-none"}`} />
setState(prevState => ({ ...prevState, contact: c }))} inputStyle="tw-h-24" containerStyle="tw-pt-4" />
{item.layer?.itemType.offers_and_needs && <> updateActiveTab(3)} />
setState(prevState => ({ ...prevState, offers: v }))} placeholder="enter your offers" containerStyle='tw-bg-transparent tw-w-full tw-h-full tw-mt-3 tw-text-xs tw-h-[calc(100%-1rem)] tw-min-h-[5em] tw-pb-2 tw-overflow-auto' />
setState(prevState => ({ ...prevState, needs: v }))} placeholder="enter your needs" containerStyle='tw-bg-transparent tw-w-full tw-h-full tw-mt-3 tw-text-xs tw-h-[calc(100%-1rem)] tw-min-h-[5em] tw-pb-2 tw-overflow-auto' />
} {item.layer?.itemType.relations && <> updateActiveTab(7)} />
{state.relations && state.relations.map(i =>
navigate('/item/' + i.id)}> unlinkItem(id, item, updateItem)} loading={loading} />
)} {updatePermission && linkItem(id, item, updateItem)} colorField={item.layer.itemColorField}>}
}
) }