import { jsxs, jsx } from "react/jsx-runtime";
import { Switch } from "antd";
import { useState, useEffect, useCallback } from "react";
import Label from "./internal/Label.js";
import Column from "./Column.js";
import { Row } from "./Row.js";
const Toggle = ({ checked = false, label, onChange, disabled }) => {
  const [toggled, setToggled] = useState(checked);
  useEffect(() => {
    setToggled(checked);
  }, [checked]);
  const handleClick = useCallback(() => {
    if (onChange) {
      onChange(!toggled);
    } else {
      setToggled(!toggled);
    }
  }, [toggled, onChange, setToggled]);
  return /* @__PURE__ */ jsxs(Row, { children: [
    /* @__PURE__ */ jsx(Column, { width: "hug", children: label && /* @__PURE__ */ jsx(Label, { type: "textOnly", children: label }) }),
    /* @__PURE__ */ jsx(Column, { width: "hug", children: /* @__PURE__ */ jsx(Switch, { checked: toggled, disabled, size: "small", onClick: handleClick }) })
  ] });
};
export {
  Toggle as default
};
