import { Toggle } from "@/components/input/toggle";
import { TextInput } from "@/components/input/input";
import { ApiRoute } from "@/utils/type";

export const Request = ({
  parameters,
  children,
  onChange,
}: {
  parameters: any;
  children: React.ReactElement;
  onChange: (key: string, value: string | boolean) => void;
}) => {
  return (
    <div className="h-full bg-slate-900 p-5">
      {children}
      {parameters && (
        <div className="mt-6 grid grid-cols-2 gap-6">
          <p className="text-slate-200 uppercase text-xs font-semibold col-span-2">
            Optional parameters
          </p>
          {parameters &&
            Object.entries(parameters).map(([key, value]) => (
              <div
                key={key}
                className="flex items-center justify-between gap-2"
              >
                {typeof value === "boolean" ? (
                  <div>
                    <Toggle
                      checked={value}
                      label={key}
                      onChange={(e) => onChange(key, e)}
                    />
                  </div>
                ) : (
                  <TextInput
                    value={value as string}
                    label={key}
                    placeholder="value"
                    onChange={(e) => onChange(key, e)}
                  />
                )}
              </div>
            ))}
        </div>
      )}
    </div>
  );
};
