'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { useAsyncEffect } from '../../../fd-toolbox/hooks/use-async-effect.js';
import { loadData, getUserListHeaderText, onDeleteConfirmation } from './UserList.funcs.js';
import { Switch } from '../../fd-component-toolbox/switch/Switch.js';
import { List } from '../../fd-component-toolbox/list/List.js';
import { Button } from '../../fd-component-toolbox/button/Button.js';
import { Icon, iconNames } from '../../fd-component-toolbox/icon/Icon.js';
import { YesOrNoDialog } from '../../fd-component-toolbox/dialog/YesOrNoDialog.js';
import { EditUserSheet } from '../edit-user-sheet/EditUserSheet.js';
import { silentChangeUrl } from '../../../fd-toolbox/routing/routers.js';
import { routes } from '../../../fd-toolbox/routing/routes.js';
import { useSetTitle } from '../../meta/page/use-set-title.js';
import { SubHeading } from '../../fd-component-toolbox/subheading/SubHeading.js';
import { messages } from '../../../fd-toolbox-core/constants/messages-constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
const pageTitleUserList = "User List";
function UserList() {
  const $ = c(7);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = [];
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const [users, setUsers] = useState(t0);
  const [showDisabledUsers, setShowDisabledUsers] = useState(false);
  useSetTitle(pageTitleUserList);
  let t1;
  let t2;
  if ($[1] !== showDisabledUsers) {
    t1 = async () => {
      await loadData(setUsers, showDisabledUsers);
    };
    t2 = [showDisabledUsers];
    $[1] = showDisabledUsers;
    $[2] = t1;
    $[3] = t2;
  } else {
    t1 = $[2];
    t2 = $[3];
  }
  useAsyncEffect(t1, t2);
  let t3;
  if ($[4] !== showDisabledUsers || $[5] !== users) {
    t3 = jsxs("div", {
      className: "p-6",
      children: [jsx(SubHeading, {
        className: "mb-4",
        children: getUserListHeaderText()
      }), jsxs("div", {
        className: "mb-4 flex flex-row items-center gap-5",
        children: [jsx(EditUserSheet, {
          onEditClick: _temp,
          children: jsx(Button, {
            className: "min-w-20",
            children: "Add"
          })
        }), jsx(Switch, {
          label: "Show disabled users",
          onCheckedChange: setShowDisabledUsers,
          checked: showDisabledUsers,
          name: "showDisabledUsers"
        })]
      }), jsx(List, {
        className: "overflow-auto border-y px-0 py-2",
        children: users?.map(userData => jsx("li", {
          className: "hover:bg-accent flex w-full items-center justify-between gap-2",
          children: jsxs("div", {
            className: "flex items-center gap-0.5",
            children: [jsx(EditUserSheet, {
              userData,
              onEditClick: () => silentChangeUrl(`${routes.editUser}?${userData.id}`),
              children: jsx(Button, {
                size: "sm",
                variant: "icon",
                className: "px-1",
                tooltipText: "Edit User",
                tooltipSide: "right",
                tooltipClassName: "ml-2",
                children: jsx(Icon, {
                  className: "text-fd-accent",
                  name: iconNames.edit
                })
              })
            }), jsx(YesOrNoDialog, {
              asTriggerChild: true,
              title: messages.deleteConfirmation || "",
              onResponse: isYes => onDeleteConfirmation(isYes, userData.id, users, setUsers),
              trigger: jsx(Button, {
                size: "sm",
                variant: "icon",
                className: "px-1",
                children: jsx(Icon, {
                  name: iconNames.trash
                })
              })
            }), jsx("div", {
              className: "grow px-6",
              children: `${userData.firstName} ${userData.lastName}`
            })]
          })
        }, userData.id))
      })]
    });
    $[4] = showDisabledUsers;
    $[5] = users;
    $[6] = t3;
  } else {
    t3 = $[6];
  }
  return t3;
}
function _temp() {
  return silentChangeUrl(routes.editUser);
}
__name(UserList, "UserList");

export { UserList as default, pageTitleUserList };
