var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/authentication/admin/AuthMethods/components/LoginMethodsList.tsx
var LoginMethodsList_exports = {};
__export(LoginMethodsList_exports, {
  default: () => LoginMethodsList_default
});
module.exports = __toCommonJS(LoginMethodsList_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_core = require("@dnd-kit/core");
var import_sortable = require("@dnd-kit/sortable");
var import_utilities = require("@dnd-kit/utilities");
var SortableLoginMethod = ({ method, onToggle }) => {
  const { attributes, listeners, setNodeRef, transform, transition, isDragging } = (0, import_sortable.useSortable)({
    id: method.id
  });
  const style = {
    transform: import_utilities.CSS.Transform.toString(transform),
    transition
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref: setNodeRef,
      style,
      className: `login-method-item ${isDragging ? "dragging" : ""}`
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "login-method-drag", ...attributes, ...listeners }, /* @__PURE__ */ import_react.default.createElement(import_icons.HolderOutlined, null)),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "login-method-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "login-method-title" }, method.title), /* @__PURE__ */ import_react.default.createElement("div", { className: "login-method-description" }, method.description)),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Switch, { checked: method.enabled, onChange: onToggle })
  );
};
var LoginMethodsList = ({ methods, onMethodsChange }) => {
  const [loginMethods, setLoginMethods] = (0, import_react.useState)(methods);
  const sensors = (0, import_core.useSensors)(
    (0, import_core.useSensor)(import_core.PointerSensor, {
      activationConstraint: {
        distance: 8
      }
    }),
    (0, import_core.useSensor)(import_core.KeyboardSensor, {
      coordinateGetter: import_sortable.sortableKeyboardCoordinates
    })
  );
  const handleDragEnd = (event) => {
    const { active, over } = event;
    if (over && active.id !== over.id) {
      setLoginMethods((items) => {
        const oldIndex = items.findIndex((item) => item.id === active.id);
        const newIndex = items.findIndex((item) => item.id === over.id);
        const newItems = (0, import_sortable.arrayMove)(items, oldIndex, newIndex);
        onMethodsChange == null ? void 0 : onMethodsChange(newItems);
        return newItems;
      });
    }
  };
  const handleToggleLoginMethod = (methodId, enabled) => {
    const newMethods = loginMethods.map(
      (item) => item.id === methodId ? { ...item, enabled } : item
    );
    setLoginMethods(newMethods);
    onMethodsChange == null ? void 0 : onMethodsChange(newMethods);
  };
  return /* @__PURE__ */ import_react.default.createElement(import_core.DndContext, { sensors, collisionDetection: import_core.closestCenter, onDragEnd: handleDragEnd }, /* @__PURE__ */ import_react.default.createElement(
    import_sortable.SortableContext,
    {
      items: loginMethods.map((m) => m.id),
      strategy: import_sortable.verticalListSortingStrategy
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "login-methods-list" }, loginMethods.map((loginMethod) => /* @__PURE__ */ import_react.default.createElement(
      SortableLoginMethod,
      {
        key: loginMethod.id,
        method: loginMethod,
        onToggle: (enabled) => handleToggleLoginMethod(loginMethod.id, enabled)
      }
    )))
  ));
};
var LoginMethodsList_default = LoginMethodsList;
