import { NgTemplateOutlet } from '@angular/common';
import * as i0 from '@angular/core';
import { input, contentChild, computed, ChangeDetectionStrategy, Component } from '@angular/core';
import { SdHrefDirective } from '@sdcorejs/angular/directives';
import { SdEmptyPipe } from '@sdcorejs/angular/pipes';

/**
 * `<sd-view>` — pure read-only display of a value (text, hyperlink, or a custom template).
 *
 * Presentational proxy with no state of its own: the parent form control (`<sd-select>`,
 * `<sd-input>`, …) computes the display string + resolved selection and passes them in;
 * `<sd-view>` only decides WHICH template renders. It is the single rendering path for every
 * "viewed" state across the form controls (DETAIL `viewed=true` and the `viewed='inline'`
 * text face), so a custom `valueTemplate` (e.g. `sdViewDef` / `#sdValue`) looks identical in
 * both. OnPush — re-renders only when an input signal changes.
 */
class SdView {
    // ==========================================
    // 1. SIGNAL INPUTS
    // ==========================================
    /** Optional label rendered above the value (omitted when a parent supplies its own label). */
    label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : /* istanbul ignore next */ []));
    /** Raw selected value — NOT rendered directly; only exposed in the `valueTemplate` context as `value`. */
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    value = input(...(ngDevMode ? [undefined, { debugName: "value" }] : /* istanbul ignore next */ []));
    /**
     * Display string — what shows when no custom value template is bound.
     * why: `input.required()` forces the parent to bind `[display]` (compile error otherwise),
     * so the component never has to guess a fallback string from `value`.
     */
    display = input.required(...(ngDevMode ? [{ debugName: "display" }] : /* istanbul ignore next */ []));
    /** When set, the value renders as a link (`<a [sdHref]>`) instead of plain text. */
    hyperlink = input(...(ngDevMode ? [undefined, { debugName: "hyperlink" }] : /* istanbul ignore next */ []));
    /** Label template handed down by a parent control (wins over `label` + `#sdLabel`). */
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    labelTemplate = input(...(ngDevMode ? [undefined, { debugName: "labelTemplate" }] : /* istanbul ignore next */ []));
    /** Value template handed down by a parent control (wins over `display` + `#sdValue`). */
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    valueTemplate = input(...(ngDevMode ? [undefined, { debugName: "valueTemplate" }] : /* istanbul ignore next */ []));
    /**
     * Resolved selected-item objects passed by the parent (e.g. `<sd-select>`).
     * why: the parent owns option/lazy resolution — `<sd-view>` is a proxy and must NOT rebuild
     * the list. Exposed in the value-template context so a "head +N" template can read `displayField`.
     */
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    selectedItems = input(...(ngDevMode ? [undefined, { debugName: "selectedItems" }] : /* istanbul ignore next */ []));
    // ==========================================
    // 2. SIGNAL QUERIES (replace @ContentChild)
    // ==========================================
    /** `#sdLabel` template projected directly into `<sd-view>` (fallback when no `[labelTemplate]`). */
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    contentLabelTemplate = contentChild('sdLabel', ...(ngDevMode ? [{ debugName: "contentLabelTemplate" }] : /* istanbul ignore next */ []));
    /** `#sdValue` template projected directly into `<sd-view>` (fallback when no `[valueTemplate]`). */
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    contentValueTemplate = contentChild('sdValue', ...(ngDevMode ? [{ debugName: "contentValueTemplate" }] : /* istanbul ignore next */ []));
    // ==========================================
    // 3. COMPUTED SIGNALS (replace getters)
    // ==========================================
    /**
     * Effective label template: input from parent wins, else the projected `#sdLabel`.
     * why: `computed` caches the choice so the template's `@if (activeLabelTemplate())` doesn't
     * re-evaluate two content-child reads on every change-detection pass.
     */
    activeLabelTemplate = computed(() => this.labelTemplate() ?? this.contentLabelTemplate(), ...(ngDevMode ? [{ debugName: "activeLabelTemplate" }] : /* istanbul ignore next */ []));
    /** Effective value template: input from parent wins, else the projected `#sdValue`. Cached for the same reason. */
    activeValueTemplate = computed(() => this.valueTemplate() ?? this.contentValueTemplate(), ...(ngDevMode ? [{ debugName: "activeValueTemplate" }] : /* istanbul ignore next */ []));
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdView, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.17", type: SdView, isStandalone: true, selector: "sd-view", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, display: { classPropertyName: "display", publicName: "display", isSignal: true, isRequired: true, transformFunction: null }, hyperlink: { classPropertyName: "hyperlink", publicName: "hyperlink", isSignal: true, isRequired: false, transformFunction: null }, labelTemplate: { classPropertyName: "labelTemplate", publicName: "labelTemplate", isSignal: true, isRequired: false, transformFunction: null }, valueTemplate: { classPropertyName: "valueTemplate", publicName: "valueTemplate", isSignal: true, isRequired: false, transformFunction: null }, selectedItems: { classPropertyName: "selectedItems", publicName: "selectedItems", isSignal: true, isRequired: false, transformFunction: null } }, queries: [{ propertyName: "contentLabelTemplate", first: true, predicate: ["sdLabel"], descendants: true, isSignal: true }, { propertyName: "contentValueTemplate", first: true, predicate: ["sdValue"], descendants: true, isSignal: true }], ngImport: i0, template: "@if (activeLabelTemplate()) {\n  <ng-container *ngTemplateOutlet=\"activeLabelTemplate()!\"></ng-container>\n} @else {\n  @if (label()) {\n    <div class=\"T14R text-black400\">{{ label() }}</div>\n  }\n}\n\n<!--\n  why: context ph\u1EA3i \u0111\u1EE7 cho M\u1ECCI consumer template (sdViewDef / #sdValue d\u00F9ng chung \u0111\u01B0\u1EDDng n\u00E0y):\n  $implicit = display (cho `let-x`), value = gi\u00E1 tr\u1ECB th\u00F4, selectedItems = list item \u0111\u00E3 ch\u1ECDn\n  (template \"head +N\"), selectedItem = item \u0111\u1EA7u (ti\u1EC7n cho single-select). Thi\u1EBFu key n\u00E0o l\u00E0\n  template c\u1EE7a consumer m\u1EA5t bi\u1EBFn \u0111\u00F3 \u2192 \u0111\u1EEBng r\u00FAt g\u1ECDn.\n-->\n@if (activeValueTemplate()) {\n  <ng-container\n    *ngTemplateOutlet=\"\n      activeValueTemplate()!;\n      context: {\n        $implicit: display(),\n        value: value(),\n        selectedItems: selectedItems(),\n        selectedItem: (selectedItems() ?? [])[0] ?? null,\n      }\n    \">\n  </ng-container>\n} @else {\n  @if (hyperlink(); as link) {\n    <a [sdHref]=\"link\">{{ display() }}</a>\n  } @else {\n    <div class=\"T14M\">{{ display() | sdEmpty }}</div>\n  }\n}", dependencies: [{ kind: "directive", type: SdHrefDirective, selector: "a[sdHref]", inputs: ["sdHref"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: SdEmptyPipe, name: "sdEmpty" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdView, decorators: [{
            type: Component,
            args: [{ selector: 'sd-view', standalone: true, imports: [SdEmptyPipe, SdHrefDirective, NgTemplateOutlet], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (activeLabelTemplate()) {\n  <ng-container *ngTemplateOutlet=\"activeLabelTemplate()!\"></ng-container>\n} @else {\n  @if (label()) {\n    <div class=\"T14R text-black400\">{{ label() }}</div>\n  }\n}\n\n<!--\n  why: context ph\u1EA3i \u0111\u1EE7 cho M\u1ECCI consumer template (sdViewDef / #sdValue d\u00F9ng chung \u0111\u01B0\u1EDDng n\u00E0y):\n  $implicit = display (cho `let-x`), value = gi\u00E1 tr\u1ECB th\u00F4, selectedItems = list item \u0111\u00E3 ch\u1ECDn\n  (template \"head +N\"), selectedItem = item \u0111\u1EA7u (ti\u1EC7n cho single-select). Thi\u1EBFu key n\u00E0o l\u00E0\n  template c\u1EE7a consumer m\u1EA5t bi\u1EBFn \u0111\u00F3 \u2192 \u0111\u1EEBng r\u00FAt g\u1ECDn.\n-->\n@if (activeValueTemplate()) {\n  <ng-container\n    *ngTemplateOutlet=\"\n      activeValueTemplate()!;\n      context: {\n        $implicit: display(),\n        value: value(),\n        selectedItems: selectedItems(),\n        selectedItem: (selectedItems() ?? [])[0] ?? null,\n      }\n    \">\n  </ng-container>\n} @else {\n  @if (hyperlink(); as link) {\n    <a [sdHref]=\"link\">{{ display() }}</a>\n  } @else {\n    <div class=\"T14M\">{{ display() | sdEmpty }}</div>\n  }\n}" }]
        }], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], display: [{ type: i0.Input, args: [{ isSignal: true, alias: "display", required: true }] }], hyperlink: [{ type: i0.Input, args: [{ isSignal: true, alias: "hyperlink", required: false }] }], labelTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelTemplate", required: false }] }], valueTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueTemplate", required: false }] }], selectedItems: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedItems", required: false }] }], contentLabelTemplate: [{ type: i0.ContentChild, args: ['sdLabel', { isSignal: true }] }], contentValueTemplate: [{ type: i0.ContentChild, args: ['sdValue', { isSignal: true }] }] } });

/**
 * Generated bundle index. Do not edit.
 */

export { SdView };
//# sourceMappingURL=sdcorejs-angular-components-view.mjs.map
