import { html } from "lit";
import { property, state } from "lit/decorators.js";
import { msg, localized } from "@lit/localize";
import orderBy from "lodash/fp/orderBy";
import type { AuthState } from "../utils/AuthService";
import LiteElement from "../utils/LiteElement";
import type { Profile } from "../pages/org/types";
import type { APIPaginatedList } from "../types/api";
/**
* Browser profile select dropdown
*
* Usage example:
* ```ts
* selectedProfile = value}
* >
* ```
*
* @event on-change
*/
@localized()
export class SelectBrowserProfile extends LiteElement {
@property({ type: Object })
authState!: AuthState;
@property({ type: String })
orgId!: string;
@property({ type: String })
profileId?: string;
@state()
private selectedProfile?: Profile;
@state()
private browserProfiles?: Profile[];
protected firstUpdated() {
this.fetchBrowserProfiles();
}
render() {
return html`
{
// Refetch to keep list up to date
this.fetchBrowserProfiles();
}}
@sl-hide=${this.stopProp}
@sl-after-hide=${this.stopProp}
>
${this.browserProfiles
? html`
${msg("Default Profile")}
`
: html` `}
${this.browserProfiles?.map(
(profile) => html`
${profile.name}
`
)}
${this.browserProfiles && !this.browserProfiles.length
? this.renderNoProfiles()
: ""}
${this.browserProfiles && this.browserProfiles.length
? this.renderSelectedProfileInfo()
: ""}
`;
}
private renderSelectedProfileInfo() {
if (!this.selectedProfile) return;
return html`
${this.selectedProfile.description
? html`
${this.selectedProfile.description}`
: ""}
${msg("View profile")}
`;
}
private renderNoProfiles() {
return html`