text: import{Button,LoadingSign}from"./_components.min.js";import{mergeObject}from"../libs/utils.min.js";import{i18n}from"../i18n/i18n.min.js";export function UserList(){let e=0;function t(t,n){let s=t.indexOf(n);-1!==s?t.splice(s,1):t.push(n),e=n}function n(t,n){let s=e,i=n;s>i&&(s=n,i=e);for(var r=s;r<=i;r++)-1===t.indexOf(r)&&t.push(r);e=n}return{view:function(e){let s=e.attrs.users,i=e.attrs.loading,r=e.attrs.class,o=e.attrs.selection,c=e.attrs.onNewClicked,l=e.attrs.onEditClicked,u=e.attrs.onResetClicked,a=e.attrs.onDeleteClicked;Array.isArray(s)||(s=[]),"boolean"!=typeof i&&(i=!1),"string"!=typeof r&&(r=""),Array.isArray(o)||(o=[]),"function"!=typeof c&&(c=()=>{}),"function"!=typeof l&&(l=()=>{}),"function"!=typeof u&&(u=()=>{}),"function"!=typeof a&&(a=()=>{});let p=i18n("User List"),f=[m("p.user-list__header__title",p)],h={iconOnly:!0,class:"user-list__header__button"};s.length>0&&!i&&f.unshift(m("input[type=checkbox].user__check",{checked:o.length===s.length,onclick(){!function(e,t){if(e.length===t)e.splice(0,e.length);else for(var n=0;n<t;n++)-1===e.indexOf(n)&&e.push(n)}(o,s.length)}})),1===o.length&&f.push(m(Button,mergeObject(h,{icon:"fa-pen",caption:i18n("Edit user"),onclick(){l()}}))),1===o.length&&f.push(m(Button,mergeObject(h,{icon:"fa-key",caption:i18n("Reset user's password"),onclick(){u()}}))),o.length>=1&&f.push(m(Button,mergeObject(h,{icon:"fa-trash-alt",caption:i18n("Delete user"),onclick(){a()}}))),f.push(m(Button,mergeObject(h,{icon:"fa-plus-circle",caption:i18n("New user"),onclick(){c()}})));let d=m(".user-list__header",f),_=[];i?_.push(m(LoadingSign,{class:"user-list__loading-sign"})):0===s.length?_.push(m("p.user-list__empty-message",i18n("No users registered"))):_=s.map((e,s)=>{let i={checked:-1!==o.indexOf(s),onclick(e){e.shiftKey?n(o,s):t(o,s)},onkeydown(e){"Enter"!==e.code&&"NumpadEnter"!==e.code||(e.shiftKey?n(o,s):t(o,s))}},r=[e.name];return e.admin&&r.push(m("span.user--admin",m("i.fas.fa-fw.fa-cog"))),m(".user",m("input[type=checkbox].user__check",i),m(".user__data",{onclick(){t(o,s)}},m("p.user__name",...r),m("p.user__username",e.username)))});let g=m(".user-list__body",_);return m(".user-list",{class:r},d,g)}}}