import type { BooleanInput } from '@angular/cdk/coercion'; import type { ComponentType } from '@angular/cdk/portal'; import { NgComponentOutlet } from '@angular/common'; import { booleanAttribute, ChangeDetectionStrategy, Component, computed, inject, input, } from '@angular/core'; import { NgIcon, provideIcons } from '@ng-icons/core'; import { lucideX } from '@ng-icons/lucide'; import { BrnDialogRef, injectBrnDialogContext } from '@spartan-ng/brain/dialog'; import { HlmButton } from '@spartan-ng/styles/button'; import { classes } from '@spartan-ng/styles/utils'; import { HlmDialogClose } from './hlm-dialog-close'; type HlmDialogContentContext = { $component?: ComponentType; $dynamicComponentClass?: string; $showCloseButton?: boolean; }; @Component({ selector: 'hlm-dialog-content', imports: [NgComponentOutlet, HlmButton, HlmDialogClose, NgIcon], providers: [provideIcons({ lucideX })], changeDetection: ChangeDetectionStrategy.OnPush, host: { 'data-slot': 'dialog-content', '[attr.data-state]': 'state()', }, template: ` @if (component) { } @else { } @if (showCloseButton()) { } `, }) export class HlmDialogContent { private readonly _dialogRef = inject(BrnDialogRef); private readonly _dialogContext = injectBrnDialogContext({ optional: true, }); public readonly showCloseButton = input( this._dialogContext?.$showCloseButton ?? true, { transform: booleanAttribute, }, ); public readonly state = computed(() => this._dialogRef?.state() ?? 'closed'); public readonly component = this._dialogContext?.$component; private readonly _dynamicComponentClass = this._dialogContext?.$dynamicComponentClass; constructor() { classes(() => [ 'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-4 rounded-xl p-4 text-sm ring-1 duration-100 sm:max-w-sm relative mx-auto w-full outline-none sm:mx-0', this._dynamicComponentClass, ]); } }