"use client";
import { useState } from "react";
import { saveUser } from "./action";
import IdComponent from "./IdComponent";

export default function Page() {
  const [idList, setIdList] = useState<string[]>([]);
  async function submit() {
    let rs = await saveUser(idList);
    alert(`อัพเดทสำเร็จ ${rs.changes} คน`);
  }
  return (
    <div>
      <IdComponent updateIdList={(cids) => setIdList(cids)} />
      <p className="mt-2 flex items-center justify-center gap-4">
        Total: {idList.length}{" "}
        <button className="rounded-md bg-green-200 p-2" onClick={submit}>
          Submit
        </button>
      </p>
    </div>
  );
}
