import { UMB_EDIT_USER_WORKSPACE_PATH_PATTERN } from '../paths.js';
import { UMB_COLLECTION_VIEW_USER_GRID } from './views/index.js';
import { UmbUserOrderBy } from './utils/index.js';
import { UmbDefaultCollectionContext } from '../../../core/collection/index.js';
import { UmbArrayState, UmbStringState } from '../../../../libs/observable-api/index.js';
import { UmbDirection } from '../../../core/utils/index.js';
const orderByOptions = [
    {
        unique: 'nameAscending',
        label: '#user_sortNameAscending',
        config: {
            orderBy: UmbUserOrderBy.NAME,
            orderDirection: UmbDirection.ASCENDING,
        },
    },
    {
        unique: 'nameDescending',
        label: '#user_sortNameDescending',
        config: {
            orderBy: UmbUserOrderBy.NAME,
            orderDirection: UmbDirection.DESCENDING,
        },
    },
    {
        unique: 'createDateDescending',
        label: '#user_sortCreateDateDescending',
        config: {
            orderBy: UmbUserOrderBy.CREATE_DATE,
            orderDirection: UmbDirection.DESCENDING,
        },
    },
    {
        unique: 'createDateAscending',
        label: '#user_sortCreateDateAscending',
        config: {
            orderBy: UmbUserOrderBy.CREATE_DATE,
            orderDirection: UmbDirection.ASCENDING,
        },
    },
    {
        unique: 'lastLoginDateDescending',
        label: '#user_sortLastLoginDateDescending',
        config: {
            orderBy: UmbUserOrderBy.LAST_LOGIN_DATE,
            orderDirection: UmbDirection.DESCENDING,
        },
    },
];
export class UmbUserCollectionContext extends UmbDefaultCollectionContext {
    #orderByOptions;
    #activeOrderByOption;
    constructor(host) {
        const firstOption = orderByOptions[0];
        super(host, UMB_COLLECTION_VIEW_USER_GRID, {
            orderBy: firstOption.config.orderBy,
            orderDirection: firstOption.config.orderDirection,
        });
        this.#orderByOptions = new UmbArrayState([], (x) => x.label);
        this.orderByOptions = this.#orderByOptions.asObservable();
        this.#activeOrderByOption = new UmbStringState(undefined);
        this.activeOrderByOption = this.#activeOrderByOption.asObservable();
        this.#orderByOptions.setValue(orderByOptions);
        this.#activeOrderByOption.setValue(firstOption.unique);
    }
    /**
     * Sets the active order by option for the collection and refreshes the collection.
     * @param {string} unique
     * @memberof UmbUserCollectionContext
     */
    setActiveOrderByOption(unique) {
        const option = this.#orderByOptions.getValue().find((x) => x.unique === unique);
        this.#activeOrderByOption.setValue(unique);
        this.setFilter({ orderBy: option?.config.orderBy, orderDirection: option?.config.orderDirection });
    }
    /**
     * Sets the state filter for the collection and refreshes the collection.
     * @param {Array<UmbUserStateFilterModel>} selection
     * @memberof UmbUserCollectionContext
     */
    setStateFilter(selection) {
        this.setFilter({ userStates: selection });
    }
    /**
     * Sets the order by filter for the collection and refreshes the collection.
     * @param {UmbUserOrderByModel} orderBy
     * @memberof UmbUserCollectionContext
     */
    setOrderByFilter(orderBy) {
        this.setFilter({ orderBy });
    }
    /**
     * Sets the user group filter for the collection and refreshes the collection.
     * @param {Array<string>} selection
     * @memberof UmbUserCollectionContext
     */
    setUserGroupFilter(selection) {
        this.setFilter({ userGroupIds: selection });
    }
    /**
     * Sets the order direction filter for the collection and refreshes the collection.
     * @param {any} orderDirection
     * @memberof UmbUserCollectionContext
     */
    setOrderDirectionFilter(orderDirection) {
        this.setFilter({ orderDirection });
    }
    /**
     * Returns the href for a specific user collection item.
     * @param {UmbUserDetailModel} item - The user item to get the href for.
     * @returns {Promise<string | undefined>} - The edit workspace href for the user.
     */
    async requestItemHref(item) {
        return `${UMB_EDIT_USER_WORKSPACE_PATH_PATTERN.generateAbsolute({ unique: item.unique })}`;
    }
}
export { UmbUserCollectionContext as api };
