import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { useRouter } from "@/i18n/routing";
import { setBanner } from "@/service/settings/settings";

export default function StatusToogle(props: {
  id: number;
  initChecked: boolean;
}) {
  const { id, initChecked } = props;
  const { toast } = useToast();
  const router = useRouter();

  const disableBanner = async () => {
    const response = await setBanner(id, false);

    if (response?.error) {
      toast({
        variant: "destructive",
        title: response?.message,
      });
      return false;
    }

    toast({
      title: "Success ",
    });
    router.push("/admin/settings/banner?dataChange=true");
  };
  return (
    <Switch
      id="status-toogle"
      checked={initChecked}
      onCheckedChange={() => disableBanner()}
    />
  );
}
