import { RouteFocusModal } from "../../../components/modals/route-focus-modal"
import { useStore } from "../../../hooks/api/store"
import { currencies } from "../../../lib/data/currencies"
import { CreateRegionForm } from "./components/create-region-form"

export const RegionCreate = () => {
  const { store, isPending: isLoading, isError, error } = useStore()

  const storeCurrencies = (store?.supported_currencies ?? [])
    .map((c) => currencies[c.currency_code.toUpperCase()])
    .filter(Boolean)

  if (isError) {
    throw error
  }

  return (
    <RouteFocusModal>
      {!isLoading && store && <CreateRegionForm currencies={storeCurrencies} />}
    </RouteFocusModal>
  )
}
