import { css, html } from "lit";
import { property } from "lit/decorators.js";
import { BaseView } from "./BaseView.ts";
import { RuntimeInternals } from "../lib/runtime.ts";
import { CharmController } from "@commontools/charm/ops";
import { type DID } from "@commontools/identity";
export class XCharmListView extends BaseView {
static override styles = css`
:host {
display: block;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
a, a:visited {
color: var(--primary-font, "#000");
}
.charm-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 0;
border-bottom: 1px solid #eee;
}
.charm-item:last-child {
border-bottom: none;
}
.charm-link {
flex: 1;
text-decoration: none;
padding: 0.5rem 0;
}
.charm-link:hover {
text-decoration: underline;
}
.remove-button {
margin-left: 1rem;
}
`;
@property({ attribute: false })
charms?: CharmController[];
@property({ attribute: false })
spaceName?: string;
@property({ attribute: false })
spaceDid?: DID;
@property({ attribute: false })
rt?: RuntimeInternals;
async handleRemove(charmId: string) {
if (!this.rt) {
console.error("Runtime not available");
return;
}
try {
const removed = await this.rt.cc().remove(charmId);
if (removed) {
this.dispatchEvent(
new CustomEvent("charm-removed", {
detail: { charmId },
bubbles: true,
composed: true,
}),
);
}
} catch (error) {
console.error("Failed to remove charm:", error);
}
}
override render() {
const { charms, spaceName, spaceDid } = this;
if (!charms) {
return html`