import { addEventAPI, useNotifications } from "@/api";
import { LoadingData } from "@/components/common";
import { EventForm } from "@/components/events";
import { BasePage, Header } from "@/components/layout";
import { HandleError } from "@/pages/others";
import { CAPABILITY } from "@/utils/consts";
import { __ } from "@wordpress/i18n";

export const AddEvent = () => {
  const { data: notifications, isLoading, error } = useNotifications({});
  const defaultValues = {
    name: "",
    use_approval_system: false,
    show_worker: false,
    is_online_payment: false,
    min_time_to_close_booking: 0,
    min_time_to_cancel_booking: 0,
    max_tickets_per_booking: 1,
    notification_ids: [],
  };

  if (error) return <HandleError error={error} />;
  if (isLoading) return <LoadingData />;

  return (
    <BasePage capability={CAPABILITY.WRITE}>
      <Header title={__("Add Event", "yoyaku-manager")} />
      <EventForm
        defaultValues={defaultValues}
        dataHandler={addEventAPI}
        notifications={notifications}
        navigateTo={"/"}
      />
    </BasePage>
  );
};
