"use client";
import { CardPropertyData } from "@/schema/property";
import { useState } from "react";
import { fetchLatestPropertyREST } from "../rest/property";

export function useLatestPropertyQuery() {
  const [data, setData] = useState<CardPropertyData[]>([]);
  const [isFetching, setFetching] = useState(false);

  async function _fetch() {
    setFetching(true);
    const res = await fetchLatestPropertyREST();
    setFetching(false);

    if (Array.isArray(res?.formattedData)) {
      setData(res.formattedData);
    }
  }

  return {
    _fetch,
    data,
    isFetching,
  };
}
