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-4">
      {children}
      {parameters && (
        <div className="mt-6 grid grid-cols-1 gap-4">
          <p className="text-slate-400 uppercase text-xs font-semibold">
            Optional parameters
          </p>
          {parameters &&
            Object.entries(parameters).map(([key, value]) => (
              <div
                key={key}
                className="flex items-center justify-between gap-2"
              >
                <p className="text-slate-300 text-sm">{key}</p>
                {typeof value === "boolean" ? (
                  <div>
                    <input
                      type="checkbox"
                      checked={value}
                      onChange={(e) =>
                        onChange(key, e.target.checked as boolean)
                      }
                    />
                  </div>
                ) : (
                  <input
                    value={value as string}
                    type="text"
                    className="bg-slate-950/50 w-full rounded-md px-2 py-1 text-slate-100 outline-none placeholder:text-slate-600"
                    placeholder="value"
                    onChange={(e) => onChange(key, e.target.value)}
                  />
                )}
              </div>
            ))}
        </div>
      )}
    </div>
  );
};
