{"version":3,"file":"sdcorejs-angular-components-view.mjs","sources":["../../../projects/sdcorejs-angular/components/view/src/view.component.ts","../../../projects/sdcorejs-angular/components/view/src/view.component.html","../../../projects/sdcorejs-angular/components/view/sdcorejs-angular-components-view.ts"],"sourcesContent":["import { NgTemplateOutlet } from '@angular/common';\nimport { ChangeDetectionStrategy, Component, TemplateRef, input, contentChild, computed } from '@angular/core';\nimport { SdHrefDirective } from '@sdcorejs/angular/directives';\nimport { SdViewPipe } from '@sdcorejs/angular/pipes';\n\n/**\n * `<sd-view>` — pure read-only display of a value (text, hyperlink, or a custom template).\n *\n * Presentational proxy with no state of its own: the parent form control (`<sd-select>`,\n * `<sd-input>`, …) computes the display string + resolved selection and passes them in;\n * `<sd-view>` only decides WHICH template renders. It is the single rendering path for every\n * \"viewed\" state across the form controls (DETAIL `viewed=true` and the `viewed='inline'`\n * text face), so a custom `valueTemplate` (e.g. `sdViewDef` / `#sdValue`) looks identical in\n * both. OnPush — re-renders only when an input signal changes.\n */\n@Component({\n  selector: 'sd-view',\n  standalone: true,\n  imports: [SdViewPipe, SdHrefDirective, NgTemplateOutlet],\n  templateUrl: './view.component.html',\n  changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class SdView {\n  // ==========================================\n  // 1. SIGNAL INPUTS\n  // ==========================================\n\n  /** Optional label rendered above the value (omitted when a parent supplies its own label). */\n  label = input<string | null | undefined>();\n\n  /** Raw selected value — NOT rendered directly; only exposed in the `valueTemplate` context as `value`. */\n\n  value = input<any>();\n\n  /**\n   * Display string — what shows when no custom value template is bound.\n   * why: `input.required()` forces the parent to bind `[display]` (compile error otherwise),\n   * so the component never has to guess a fallback string from `value`.\n   */\n  display = input.required<unknown>();\n\n  /** When set, the value renders as a link (`<a [sdHref]>`) instead of plain text. */\n  hyperlink = input<string | null | undefined>();\n\n  /** Label template handed down by a parent control (wins over `label` + `#sdLabel`). */\n\n  labelTemplate = input<TemplateRef<any> | undefined>();\n\n  /** Value template handed down by a parent control (wins over `display` + `#sdValue`). */\n\n  valueTemplate = input<TemplateRef<any> | undefined>();\n\n  /**\n   * Resolved selected-item objects passed by the parent (e.g. `<sd-select>`).\n   * why: the parent owns option/lazy resolution — `<sd-view>` is a proxy and must NOT rebuild\n   * the list. Exposed in the value-template context so a \"head +N\" template can read `displayField`.\n   */\n\n  selectedItems = input<any[] | undefined>();\n\n  // ==========================================\n  // 2. SIGNAL QUERIES (replace @ContentChild)\n  // ==========================================\n\n  /** `#sdLabel` template projected directly into `<sd-view>` (fallback when no `[labelTemplate]`). */\n\n  contentLabelTemplate = contentChild<TemplateRef<any>>('sdLabel');\n\n  /** `#sdValue` template projected directly into `<sd-view>` (fallback when no `[valueTemplate]`). */\n\n  contentValueTemplate = contentChild<TemplateRef<any>>('sdValue');\n\n  // ==========================================\n  // 3. COMPUTED SIGNALS (replace getters)\n  // ==========================================\n\n  /**\n   * Effective label template: input from parent wins, else the projected `#sdLabel`.\n   * why: `computed` caches the choice so the template's `@if (activeLabelTemplate())` doesn't\n   * re-evaluate two content-child reads on every change-detection pass.\n   */\n  activeLabelTemplate = computed(() => this.labelTemplate() ?? this.contentLabelTemplate());\n\n  /** Effective value template: input from parent wins, else the projected `#sdValue`. Cached for the same reason. */\n  activeValueTemplate = computed(() => this.valueTemplate() ?? this.contentValueTemplate());\n}\n","@if (activeLabelTemplate()) {\n  <ng-container *ngTemplateOutlet=\"activeLabelTemplate()!\"></ng-container>\n} @else {\n  @if (label()) {\n    <div class=\"T14R text-secondary\">{{ label() }}</div>\n  }\n}\n\n<!--\n  why: context phải đủ cho MỌI consumer template (sdViewDef / #sdValue dùng chung đường này):\n  $implicit = display (cho `let-x`), value = giá trị thô, selectedItems = list item đã chọn\n  (template \"head +N\"), selectedItem = item đầu (tiện cho single-select). Thiếu key nào là\n  template của consumer mất biến đó → đừng rút gọn.\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() | sdView }}</a>\n  } @else {\n    <div class=\"T14M\">{{ display() | sdView }}</div>\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAKA;;;;;;;;;AASG;MAQU,MAAM,CAAA;;;;;IAMjB,KAAK,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,OAAA,EAAA,CAAA,GAAA,EAAA,CAAA,CAA6B;;IAI1C,KAAK,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,OAAA,EAAA,CAAA,GAAA,EAAA,CAAA,CAAO;AAEpB;;;;AAIG;AACH,IAAA,OAAO,GAAG,KAAK,CAAC,QAAQ,kDAAW;;IAGnC,SAAS,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,WAAA,EAAA,CAAA,GAAA,EAAA,CAAA,CAA6B;;IAI9C,aAAa,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,eAAA,EAAA,CAAA,GAAA,EAAA,CAAA,CAAgC;;IAIrD,aAAa,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,eAAA,EAAA,CAAA,GAAA,EAAA,CAAA,CAAgC;AAErD;;;;AAIG;IAEH,aAAa,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,eAAA,EAAA,CAAA,GAAA,EAAA,CAAA,CAAqB;;;;;AAQ1C,IAAA,oBAAoB,GAAG,YAAY,CAAmB,SAAS,gEAAC;;AAIhE,IAAA,o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