import {
ChangeDetectionStrategy,
Component,
contentChild,
input,
model,
output,
type TemplateRef,
viewChild,
ViewEncapsulation,
} from "@angular/core";
import { SdButton } from "../../controls/button/sd-button";
import { SdCommandDirective } from "../../core/commands/sd-command";
import { SdForm } from "../../controls/form/sd-form";
import type { SdViewType } from "../../core/routing/injectViewTypeSignal";
import { SdBaseContainer } from "./sd-base-container";
import { NgIcon } from "@ng-icons/core";
import { NgTemplateOutlet } from "@angular/common";
import { tablerDeviceFloppy } from "@ng-icons/tabler-icons";
@Component({
selector: "sd-crud-detail",
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
standalone: true,
imports: [SdBaseContainer, SdButton, NgIcon, NgTemplateOutlet, SdForm],
hostDirectives: [{ directive: SdCommandDirective, outputs: ["sdSaveCommand"] }],
host: {
"(sdSaveCommand)": "onSaveButtonClick()",
},
template: `
@if (viewType() === "page" && (!readonly() || commandTplRef())) {
@if (!readonly()) {
저장
(CTRL+S)
}
} @else if (viewType() === "control" && (!readonly() || commandTplRef())) {
@if (!readonly()) {
저장
(CTRL+S)
}
} @else if (commandTplRef()) {
}
@if (viewType() === "modal" || bottomCommandTplRef()) {
@if (bottomCommandTplRef()) {
}
확인
}
@if (contentTplRef()) {
@if (readonly()) {
} @else {
}
}
`,
})
export class SdCrudDetail {
ready = model(false);
initialized = input(false);
busyCount = model(0);
restricted = input(false);
readonly = input(false);
viewType = input.required();
formCtrl = viewChild("formCtrl");
submit = output();
commandTplRef = contentChild>("commandTpl");
contentTplRef = contentChild>("contentTpl");
bottomCommandTplRef = contentChild>("bottomCommandTpl");
onSaveButtonClick() {
this.formCtrl()?.requestSubmit();
}
protected readonly tablerDeviceFloppy = tablerDeviceFloppy;
}