import { useLocal } from "@/utils/use-local"; import { FC, useEffect } from "react"; import { Button } from "../../ui/button"; import { FormHook, modify } from "../utils/utils"; export const Radio: FC<{ on_select: (val: any) => void; options: () => Promise<(string | { value: string; label: string })[]>; value: string; PassProp: any; custom: "y" | "n"; child: any; form?: FormHook; init_modify: (modify: any) => void; }> = ({ options, on_select, form, value, custom, child, PassProp, init_modify, }) => { const local = useLocal({ list: [] as { value: string; label: string }[], status: "init" as "init" | "loading" | "ready", mod: false, }); useEffect(() => { local.status = "loading"; local.render(); options().then((result) => { local.list = result.map((e) => { if (typeof e === "string") { return { value: e, label: e, }; } return e; }); local.status = "ready"; local.render(); }); }, [options]); let mod = null as any; if (form && !local.mod) { local.mod = true; mod = modify.bind({ form, change_hook(opt) { const result = opt.options; if (result) { local.list = result.map((e) => { if (typeof e === "string") { return { value: e, label: e, }; } return e; }); local.render(); } }, }); init_modify(mod); } return (