@sdcorejs/angular 22.3.4 → 22.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/STYLE-GUIDE.md +78 -1
- package/assets/THEME.md +45 -3
- package/assets/scss/core/_popover-panel.scss +90 -0
- package/assets/scss/core/form.scss +5 -2
- package/assets/scss/core/utilities/_grid.scss +15 -0
- package/assets/scss/core/utilities/_sizing.scss +4 -0
- package/assets/scss/themes/_component-tokens.scss +9 -4
- package/assets/scss/themes/_semantic.scss +6 -5
- package/fesm2022/sdcorejs-angular-components-anchor.mjs +64 -3
- package/fesm2022/sdcorejs-angular-components-anchor.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-button.mjs +14 -6
- package/fesm2022/sdcorejs-angular-components-button.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-calendar.mjs +2565 -0
- package/fesm2022/sdcorejs-angular-components-calendar.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components-card.mjs +521 -23
- package/fesm2022/sdcorejs-angular-components-card.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-editor-engine.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-editor-engine.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-file-explorer.mjs +4 -18
- package/fesm2022/sdcorejs-angular-components-file-explorer.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs +7 -7
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-import-excel.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-import-excel.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-kanban.mjs +849 -157
- package/fesm2022/sdcorejs-angular-components-kanban.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-modal.mjs +66 -14
- package/fesm2022/sdcorejs-angular-components-modal.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-query-bar.mjs +1528 -375
- package/fesm2022/sdcorejs-angular-components-query-bar.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-quick-action.mjs +78 -2
- package/fesm2022/sdcorejs-angular-components-quick-action.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-scheduler.mjs +2006 -0
- package/fesm2022/sdcorejs-angular-components-scheduler.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components-side-drawer.mjs +2 -2
- package/fesm2022/sdcorejs-angular-components-side-drawer.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-tab-router.mjs +126 -26
- package/fesm2022/sdcorejs-angular-components-tab-router.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-tab.mjs +31 -2
- package/fesm2022/sdcorejs-angular-components-tab.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-table.mjs +6215 -3830
- package/fesm2022/sdcorejs-angular-components-table.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-timeline.mjs +501 -0
- package/fesm2022/sdcorejs-angular-components-timeline.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components-tree.mjs +613 -36
- package/fesm2022/sdcorejs-angular-components-tree.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-upload-file.mjs +2 -4
- package/fesm2022/sdcorejs-angular-components-upload-file.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components.mjs +3 -1
- package/fesm2022/sdcorejs-angular-components.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-directives.mjs +110 -22
- package/fesm2022/sdcorejs-angular-directives.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-date.mjs +142 -43
- package/fesm2022/sdcorejs-angular-forms-date.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-datetime.mjs +71 -22
- package/fesm2022/sdcorejs-angular-forms-datetime.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-directives.mjs +4 -3
- package/fesm2022/sdcorejs-angular-forms-directives.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-entity-picker.mjs +1 -1
- package/fesm2022/sdcorejs-angular-forms-entity-picker.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-select.mjs +23 -4
- package/fesm2022/sdcorejs-angular-forms-select.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-tree-select.mjs +1 -1
- package/fesm2022/sdcorejs-angular-forms-tree-select.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-i18n.mjs +812 -52
- package/fesm2022/sdcorejs-angular-i18n.mjs.map +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-configuration.page-SJIWI1dX.mjs → sdcorejs-angular-modules-generic-generic-configuration.page-j_thIw4L.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-configuration.page-SJIWI1dX.mjs.map → sdcorejs-angular-modules-generic-generic-configuration.page-j_thIw4L.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-form-host.page-BPhMLVbv.mjs → sdcorejs-angular-modules-generic-generic-form-host.page-DLsJ_8NR.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-form-host.page-BPhMLVbv.mjs.map → sdcorejs-angular-modules-generic-generic-form-host.page-DLsJ_8NR.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-list.page-aGhowe9Y.mjs → sdcorejs-angular-modules-generic-generic-list.page-CkYR7Y-b.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-list.page-aGhowe9Y.mjs.map → sdcorejs-angular-modules-generic-generic-list.page-CkYR7Y-b.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-N8_oGpqD.mjs → sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-Ddytu3Gb.mjs} +4 -4
- package/fesm2022/{sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-N8_oGpqD.mjs.map → sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-Ddytu3Gb.mjs.map} +1 -1
- package/fesm2022/sdcorejs-angular-modules-generic.mjs +1 -1
- package/fesm2022/sdcorejs-angular-modules-layout.mjs +17 -8
- package/fesm2022/sdcorejs-angular-modules-layout.mjs.map +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-base-api.service-C2o5xPVB.mjs → sdcorejs-angular-modules-pattern-base-api.service-vMdkWmw-.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-base-api.service-C2o5xPVB.mjs.map → sdcorejs-angular-modules-pattern-base-api.service-vMdkWmw-.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-create.component-RBvVv88D.mjs → sdcorejs-angular-modules-pattern-create.component--cdb_2ub.mjs} +11 -7
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component--cdb_2ub.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-create.component-CxicczH7.mjs → sdcorejs-angular-modules-pattern-create.component-BmKRynOI.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-create.component-CxicczH7.mjs.map → sdcorejs-angular-modules-pattern-create.component-BmKRynOI.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-create.component-D3MzNJ3F.mjs → sdcorejs-angular-modules-pattern-create.component-DoilYt0j.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-create.component-D3MzNJ3F.mjs.map → sdcorejs-angular-modules-pattern-create.component-DoilYt0j.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-customer.service-3hWkJClX.mjs → sdcorejs-angular-modules-pattern-customer.service-DpPC-tV2.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-customer.service-3hWkJClX.mjs.map → sdcorejs-angular-modules-pattern-customer.service-DpPC-tV2.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-detail.component-CcpYULut.mjs → sdcorejs-angular-modules-pattern-detail.component-Bh_rvQnq.mjs} +61 -55
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-Bh_rvQnq.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-detail.component-CEhbU12j.mjs → sdcorejs-angular-modules-pattern-detail.component-Dk1bomUT.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-detail.component-CEhbU12j.mjs.map → sdcorejs-angular-modules-pattern-detail.component-Dk1bomUT.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-flow.component-G5lHfG81.mjs → sdcorejs-angular-modules-pattern-flow.component-BarNCjsh.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-pattern-flow.component-G5lHfG81.mjs.map → sdcorejs-angular-modules-pattern-flow.component-BarNCjsh.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-index.component-CosbQK0W.mjs → sdcorejs-angular-modules-pattern-index.component--rIi-QIQ.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-index.component-CosbQK0W.mjs.map → sdcorejs-angular-modules-pattern-index.component--rIi-QIQ.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-lines-table-form.component-DmmVKrgM.mjs → sdcorejs-angular-modules-pattern-lines-table-form.component-G9Li--QF.mjs} +5 -5
- package/fesm2022/{sdcorejs-angular-modules-pattern-lines-table-form.component-DmmVKrgM.mjs.map → sdcorejs-angular-modules-pattern-lines-table-form.component-G9Li--QF.mjs.map} +1 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-2AZxTu9a.mjs +522 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-2AZxTu9a.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-CDM4V05g.mjs +520 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-CDM4V05g.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-list.component-C_pVqRcC.mjs → sdcorejs-angular-modules-pattern-list.component-DS9DROp-.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-pattern-list.component-C_pVqRcC.mjs.map → sdcorejs-angular-modules-pattern-list.component-DS9DROp-.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-list.component-CNVqk3JC.mjs → sdcorejs-angular-modules-pattern-list.component-DbF9z3da.mjs} +30 -39
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-DbF9z3da.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-list.component-EaNDEtCn.mjs → sdcorejs-angular-modules-pattern-list.component-DlF3i6ai.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-pattern-list.component-EaNDEtCn.mjs.map → sdcorejs-angular-modules-pattern-list.component-DlF3i6ai.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-mock-backend.factory-CFljqhjv.mjs → sdcorejs-angular-modules-pattern-mock-backend.factory-BpECki9p.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-mock-backend.factory-CFljqhjv.mjs.map → sdcorejs-angular-modules-pattern-mock-backend.factory-BpECki9p.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-pattern-source-viewer-BqHwKfoc.mjs → sdcorejs-angular-modules-pattern-pattern-source-viewer-DuhyXsGn.mjs} +4 -22
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source-viewer-DuhyXsGn.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-pattern-source.generated-CIiLOizq.mjs → sdcorejs-angular-modules-pattern-pattern-source.generated-bfpj85ke.mjs} +26 -27
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source.generated-bfpj85ke.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-product.service-DitXmlr1.mjs → sdcorejs-angular-modules-pattern-product.service-DEAQ4oro.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-product.service-DitXmlr1.mjs.map → sdcorejs-angular-modules-pattern-product.service-DEAQ4oro.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-profile.component-Dxw7Ix9d.mjs → sdcorejs-angular-modules-pattern-profile.component-D-dJk5vb.mjs} +27 -14
- package/fesm2022/sdcorejs-angular-modules-pattern-profile.component-D-dJk5vb.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-BxXgJVsW.mjs → sdcorejs-angular-modules-pattern-routes-Brr61WQo.mjs} +4 -4
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-BxXgJVsW.mjs.map → sdcorejs-angular-modules-pattern-routes-Brr61WQo.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-CWixJ2If.mjs → sdcorejs-angular-modules-pattern-routes-CPVcXcfq.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-CWixJ2If.mjs.map → sdcorejs-angular-modules-pattern-routes-CPVcXcfq.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-w4VY9P_H.mjs → sdcorejs-angular-modules-pattern-routes-CWCtuZ4z.mjs} +8 -8
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-w4VY9P_H.mjs.map → sdcorejs-angular-modules-pattern-routes-CWCtuZ4z.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-BOiWZHqg.mjs → sdcorejs-angular-modules-pattern-routes-CfXmYmCp.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-BOiWZHqg.mjs.map → sdcorejs-angular-modules-pattern-routes-CfXmYmCp.mjs.map} +1 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-CuDWVZ4I.mjs +56 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-CuDWVZ4I.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-CJ-RAMa5.mjs → sdcorejs-angular-modules-pattern-routes-D8W_NHEH.mjs} +5 -5
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-CJ-RAMa5.mjs.map → sdcorejs-angular-modules-pattern-routes-D8W_NHEH.mjs.map} +1 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-Db0ceW1C.mjs +66 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-Db0ceW1C.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-C43Q4Wtq.mjs → sdcorejs-angular-modules-pattern-routes-DdmOGRpF.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-pattern-routes-C43Q4Wtq.mjs.map → sdcorejs-angular-modules-pattern-routes-DdmOGRpF.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-sdcorejs-angular-modules-pattern-BQCWgQsr.mjs → sdcorejs-angular-modules-pattern-sdcorejs-angular-modules-pattern-JWx3RaLo.mjs} +12 -12
- package/fesm2022/{sdcorejs-angular-modules-pattern-sdcorejs-angular-modules-pattern-BQCWgQsr.mjs.map → sdcorejs-angular-modules-pattern-sdcorejs-angular-modules-pattern-JWx3RaLo.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-shell.component-BOjJteMd.mjs → sdcorejs-angular-modules-pattern-shell.component-DMJpUhpn.mjs} +4 -4
- package/fesm2022/{sdcorejs-angular-modules-pattern-shell.component-BOjJteMd.mjs.map → sdcorejs-angular-modules-pattern-shell.component-DMJpUhpn.mjs.map} +1 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-BHDd7D8y.mjs +498 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-BHDd7D8y.mjs.map +1 -0
- package/fesm2022/{sdcorejs-angular-modules-pattern-update.component-lGwicZKW.mjs → sdcorejs-angular-modules-pattern-update.component-Bx2zgc86.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-update.component-lGwicZKW.mjs.map → sdcorejs-angular-modules-pattern-update.component-Bx2zgc86.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-update.component-CS3jlV-R.mjs → sdcorejs-angular-modules-pattern-update.component-Cb29tp1H.mjs} +2 -2
- package/fesm2022/{sdcorejs-angular-modules-pattern-update.component-CS3jlV-R.mjs.map → sdcorejs-angular-modules-pattern-update.component-Cb29tp1H.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-pattern-update.component-CUgQPcR4.mjs → sdcorejs-angular-modules-pattern-update.component-e5BaHrDk.mjs} +9 -6
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-e5BaHrDk.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern.mjs +1 -1
- package/fesm2022/sdcorejs-angular-services-confirm.mjs +171 -158
- package/fesm2022/sdcorejs-angular-services-confirm.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-services-excel.mjs +34 -0
- package/fesm2022/sdcorejs-angular-services-excel.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-services-query-params.mjs +227 -0
- package/fesm2022/sdcorejs-angular-services-query-params.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-utilities-extensions.mjs +24 -1
- package/fesm2022/sdcorejs-angular-utilities-extensions.mjs.map +1 -1
- package/modules/pattern/README.md +5 -4
- package/modules/pattern/docs/detail.md +18 -9
- package/modules/pattern/docs/drawer.md +185 -83
- package/modules/pattern/docs/header-actions.md +1 -1
- package/modules/pattern/docs/list.md +3 -3
- package/modules/pattern/docs/states.md +1 -1
- package/modules/pattern/features/category/components/create-side-drawer/create-side-drawer.component.ts +12 -16
- package/modules/pattern/features/category/components/update-side-drawer/update-side-drawer.component.ts +58 -29
- package/modules/pattern/features/category/pages/list/list.component.html +11 -3
- package/modules/pattern/features/category/pages/list/list.component.ts +36 -10
- package/modules/pattern/features/category/routes.ts +5 -22
- package/modules/pattern/features/customer/components/create-side-drawer/create-side-drawer.component.ts +7 -11
- package/modules/pattern/features/customer/components/detail-side-drawer/detail-side-drawer.component.ts +70 -27
- package/modules/pattern/features/customer/components/summary-cards/summary-cards.component.ts +9 -53
- package/modules/pattern/features/customer/components/update-side-drawer/update-side-drawer.component.ts +53 -19
- package/modules/pattern/features/customer/entity.resolver.ts +1 -1
- package/modules/pattern/features/customer/pages/list/list.component.html +18 -3
- package/modules/pattern/features/customer/pages/list/list.component.ts +43 -16
- package/modules/pattern/features/customer/pages/profile/profile.component.ts +17 -8
- package/modules/pattern/features/customer/routes.ts +6 -27
- package/modules/pattern/features/order/components/approval-steps/approval-steps.component.ts +37 -56
- package/modules/pattern/features/order/components/summary-cards/summary-cards.component.ts +14 -76
- package/modules/pattern/features/order/pages/create/create.component.ts +7 -3
- package/modules/pattern/features/order/pages/detail/detail.component.ts +1 -1
- package/modules/pattern/features/order/pages/update/update.component.ts +5 -2
- package/package.json +17 -5
- package/types/sdcorejs-angular-components-anchor.d.ts +6 -1
- package/types/sdcorejs-angular-components-button.d.ts +7 -1
- package/types/sdcorejs-angular-components-calendar.d.ts +1092 -0
- package/types/sdcorejs-angular-components-card.d.ts +247 -9
- package/types/sdcorejs-angular-components-kanban.d.ts +191 -74
- package/types/sdcorejs-angular-components-modal.d.ts +15 -1
- package/types/sdcorejs-angular-components-query-bar.d.ts +204 -38
- package/types/sdcorejs-angular-components-quick-action.d.ts +65 -1
- package/types/sdcorejs-angular-components-scheduler.d.ts +544 -0
- package/types/sdcorejs-angular-components-tab.d.ts +6 -1
- package/types/sdcorejs-angular-components-table.d.ts +338 -31
- package/types/sdcorejs-angular-components-timeline.d.ts +216 -0
- package/types/sdcorejs-angular-components-tree.d.ts +119 -6
- package/types/sdcorejs-angular-components.d.ts +3 -1
- package/types/sdcorejs-angular-directives.d.ts +4 -2
- package/types/sdcorejs-angular-forms-date.d.ts +2 -0
- package/types/sdcorejs-angular-forms-directives.d.ts +1 -1
- package/types/sdcorejs-angular-i18n.d.ts +159 -9
- package/types/sdcorejs-angular-modules-layout.d.ts +2 -1
- package/types/sdcorejs-angular-services-confirm.d.ts +22 -81
- package/types/sdcorejs-angular-services-excel.d.ts +59 -0
- package/types/sdcorejs-angular-services-query-params.d.ts +67 -0
- package/types/sdcorejs-angular-utilities-extensions.d.ts +10 -1
- package/fesm2022/sdcorejs-angular-components-history.mjs +0 -54
- package/fesm2022/sdcorejs-angular-components-history.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-CRc9T7rb.mjs +0 -146
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-CRc9T7rb.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-Cz-MjRG0.mjs +0 -148
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-Cz-MjRG0.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component-RBvVv88D.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-customer.model-C3fr4yNw.mjs +0 -18
- package/fesm2022/sdcorejs-angular-modules-pattern-customer.model-C3fr4yNw.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-detail-side-drawer.component-DzDAX3B7.mjs +0 -152
- package/fesm2022/sdcorejs-angular-modules-pattern-detail-side-drawer.component-DzDAX3B7.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-CcpYULut.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-D8-WXUAE.mjs +0 -92
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-D8-WXUAE.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-DHTxzjRN.mjs +0 -242
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-DHTxzjRN.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-view.component-CTgHdGeQ.mjs +0 -72
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-view.component-CTgHdGeQ.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-BjehcQEk.mjs +0 -172
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-BjehcQEk.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-CNVqk3JC.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-jB3E20UF.mjs +0 -120
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-jB3E20UF.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source-viewer-BqHwKfoc.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source.generated-CIiLOizq.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-profile.component-Dxw7Ix9d.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-BWZxOMhB.mjs +0 -74
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-BWZxOMhB.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-CophQH_L.mjs +0 -100
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-CophQH_L.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-BT2PzXTG.mjs +0 -135
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-BT2PzXTG.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-qmGn2tCI.mjs +0 -146
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-qmGn2tCI.mjs.map +0 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-CUgQPcR4.mjs.map +0 -1
- package/modules/pattern/features/category/entity.resolver.ts +0 -27
- package/types/sdcorejs-angular-components-history.d.ts +0 -23
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdcorejs-angular-modules-pattern-pattern-source.generated-CIiLOizq.mjs","sources":["../../../projects/sdcorejs-angular/modules/pattern/core/pattern-shell/source/pattern-source.generated.ts"],"sourcesContent":["// Generated by scripts/pattern-docs.mjs from README.md, docs/ and features/ of modules/pattern. Do not edit:\n// run `npm run pattern:docs` after changing those files.\nexport const PATTERN_SOURCE: Readonly<Record<string, string>> = {\n 'docs/detail.md': '# Detail\\n\\nXem một bản ghi: `sd-page-detail`. Route mẫu: `/pattern/product/:id/detail` (section và `sd-view`), `/pattern/order/:id/detail` (workflow duyệt, cột phụ quy trình), `/pattern/customer/:id/360` (hồ sơ nhiều tab).\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng khi bản ghi có nhiều nhóm thông tin, quan hệ hoặc tác vụ nghiệp vụ.\\n- Bản ghi ngắn, xem nhanh ngay trên danh sách: dùng drawer chi tiết ([drawer](drawer.md)).\\n- Nhiều tab, bảng quan hệ lớn (hồ sơ 360°): luôn là trang, không đặt vào drawer.\\n\\n## Code mẫu\\n\\nBản ghi do resolver tải trước khi mở trang; trang nhận bản ghi qua `ActivatedRoute.data`, không gọi lại API chính.\\n\\n<!-- @source features/product/entity.resolver.ts -->\\n```ts\\nimport { HttpErrorResponse } from \\'@angular/common/http\\';\\nimport { inject } from \\'@angular/core\\';\\nimport type { ResolveFn } from \\'@angular/router\\';\\nimport { map, timeout } from \\'rxjs\\';\\nimport { ProductService } from \\'./services/product.service\\';\\nimport type { ProductDto } from \\'./services/product.model\\';\\n\\n/** Tải sản phẩm trước khi mở detail/update; lỗi (404, 403, timeout) đi tới navigation error handler của host. */\\nexport const entityResolver: ResolveFn<ProductDto> = route => {\\n const id = route.paramMap.get(\\'id\\');\\n if (!id?.trim()) throw new HttpErrorResponse({ status: 404 });\\n return inject(ProductService)\\n .detail(id)\\n .pipe(\\n timeout(10_000),\\n map(entity => {\\n if (!entity || entity.id !== id) throw new HttpErrorResponse({ status: 404 });\\n return entity;\\n })\\n );\\n};\\n```\\n\\n<!-- @source features/product/pages/detail/detail.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, computed, inject } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, RouterLink } from \\'@angular/router\\';\\nimport { map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdView } from \\'@sdcorejs/angular/components/view\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { PRODUCT_STATUS_OPTIONS, productStatusBadge, type ProductDto } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'detail\\',\\n standalone: true,\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [RouterLink, SdPageComponent, SdButton, SdSection, SdView, SdPermissionDirective, SdFormatNumberPipe],\\n template: `\\n @let product = entity();\\n <sd-page-detail [title]=\"\\'Chi tiết sản phẩm #\\' + product.code\" [description]=\"product.name\" [badges]=\"badges()\" [backLink]=\"[\\'../..\\']\">\\n <sd-button\\n headerRight\\n *sdPermission=\"\\'PATTERN_PRODUCT_U_UPDATE\\'\"\\n title=\"Cập nhật sản phẩm\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"product-update\"\\n [routerLink]=\"[\\'../update\\']\" />\\n <div class=\"d-flex flex-column gap-16 py-16\">\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"row p-8\">\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Mã sản phẩm\" [display]=\"product.code\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Tên sản phẩm\" [display]=\"product.name\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Trạng thái\" [display]=\"statusName()\" /></div>\\n </div>\\n </sd-section>\\n <sd-section title=\"Giá bán\">\\n <div class=\"row p-8\">\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Giá bán (₫)\" [display]=\"product.price | sdFormatNumber: 0\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Đơn vị tính\" [display]=\"product.unit\" /></div>\\n </div>\\n </sd-section>\\n </div>\\n </sd-page-detail>\\n `,\\n})\\nexport class DetailComponent {\\n /** Sản phẩm do resolver tải trước khi mở trang; đổi ID thì nhận bản ghi mới. */\\n protected readonly entity = toSignal(inject(ActivatedRoute).data.pipe(map(data => data[\\'entity\\'] as ProductDto)), { requireSync: true });\\n protected readonly badges = computed(() => [productStatusBadge(this.entity().status)]);\\n protected readonly statusName = computed(() => PRODUCT_STATUS_OPTIONS.find(option => option.id === this.entity().status)?.name);\\n}\\n```\\n\\nHồ sơ 360°: tab trong `sdSubheader`, tab ghi trên URL, mở tab nào mới tải tab đó:\\n\\n<!-- @source features/customer/pages/profile/profile.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, computed, inject, linkedSignal, untracked } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdTab, SdTabGroup } from \\'@sdcorejs/angular/components/tab\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { DebtsViewComponent } from \\'../../components/debts-view/debts-view.component\\';\\nimport { DocumentsViewComponent } from \\'../../components/documents-view/documents-view.component\\';\\nimport { GeneralInformationViewComponent } from \\'../../components/general-information-view/general-information-view.component\\';\\nimport { OrdersViewComponent } from \\'../../components/orders-view/orders-view.component\\';\\nimport { customerStatusBadge, customerTypeName, type CustomerDto } from \\'../../services/customer.model\\';\\n\\nconst TABS = [\\n { key: \\'info\\', label: \\'Thông tin\\' },\\n { key: \\'orders\\', label: \\'Đơn hàng\\' },\\n { key: \\'debts\\', label: \\'Công nợ\\' },\\n { key: \\'documents\\', label: \\'Tài liệu\\' },\\n] as const;\\ntype TabKey = (typeof TABS)[number][\\'key\\'];\\n\\n/**\\n * Hồ sơ 360° (`:id/360`): thông tin chung và các quan hệ của khách hàng theo tab. Tab ghi trên URL (`?tab=`);\\n * mở tab nào mới tải tab đó, mỗi tab tự có trạng thái đang tải, rỗng và lỗi.\\n */\\n@Component({\\n selector: \\'profile\\',\\n standalone: true,\\n imports: [\\n RouterLink,\\n SdPageComponent,\\n SdButton,\\n SdTabGroup,\\n SdTab,\\n SdPermissionDirective,\\n GeneralInformationViewComponent,\\n OrdersViewComponent,\\n DebtsViewComponent,\\n DocumentsViewComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let customer = entity();\\n <sd-page-detail\\n [title]=\"\\'Hồ sơ khách hàng #\\' + customer.code\"\\n [description]=\"customer.name + \\' · \\' + typeName()\"\\n [badges]=\"badges()\"\\n [backLink]=\"[\\'../..\\']\">\\n <sd-button\\n headerRight\\n *sdPermission=\"\\'PATTERN_CUSTOMER_U_UPDATE\\'\"\\n title=\"Cập nhật khách hàng\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"customer-profile-update\"\\n [routerLink]=\"[\\'../update\\']\" />\\n <sd-tab-group sdSubheader [selectedIndex]=\"tabIndex()\" (selectedIndexChange)=\"selectTab($event)\">\\n @for (tab of tabs; track tab.key) {\\n <sd-tab [label]=\"tab.label\" />\\n }\\n </sd-tab-group>\\n <div class=\"py-16\">\\n @for (tab of tabs; track tab.key; let index = $index) {\\n @if (opened().has(tab.key)) {\\n <div [hidden]=\"tabIndex() !== index\" [attr.data-customer-tab]=\"tab.key\">\\n @switch (tab.key) {\\n @case (\\'info\\') {\\n <general-information-view [customer]=\"customer\" />\\n }\\n @case (\\'orders\\') {\\n <orders-view [customerId]=\"customer.id\" />\\n }\\n @case (\\'debts\\') {\\n <debts-view [customerId]=\"customer.id\" />\\n }\\n @case (\\'documents\\') {\\n <documents-view [customerId]=\"customer.id\" />\\n }\\n }\\n </div>\\n }\\n }\\n </div>\\n </sd-page-detail>\\n `,\\n})\\nexport class ProfileComponent {\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n protected readonly tabs = TABS;\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as CustomerDto)), { requireSync: true });\\n protected readonly badges = computed(() => [customerStatusBadge(this.entity().status)]);\\n protected readonly typeName = computed(() => customerTypeName(this.entity().type));\\n readonly #tabParam = toSignal(this.#route.queryParamMap.pipe(map(params => params.get(\\'tab\\'))), { requireSync: true });\\n protected readonly tabIndex = computed(() =>\\n Math.max(\\n 0,\\n TABS.findIndex(tab => tab.key === this.#tabParam())\\n )\\n );\\n /** Tab đã mở ít nhất một lần: giữ lại khi chuyển tab, không tải lại. Đổi khách hàng thì bắt đầu lại. */\\n protected readonly opened = linkedSignal<CustomerDto, ReadonlySet<TabKey>>({\\n source: this.entity,\\n // untracked: đổi tab không được đặt lại các tab đã mở; chỉ đổi khách hàng mới bắt đầu lại.\\n computation: () => new Set<TabKey>([TABS[untracked(this.tabIndex)].key]),\\n });\\n\\n protected selectTab(index: number): void {\\n const key = TABS[index]?.key ?? \\'info\\';\\n this.opened.update(opened => new Set([...opened, key]));\\n void this.#router.navigate([], {\\n relativeTo: this.#route,\\n queryParams: { tab: key === \\'info\\' ? null : key },\\n queryParamsHandling: \\'merge\\',\\n replaceUrl: true,\\n });\\n }\\n}\\n```\\n\\n## Quy tắc\\n\\n- MUST đặt title \"Chi tiết <entity> #<mã>\", badge trạng thái cạnh title qua `[badges]` (tối đa hai: trạng thái trước, thuộc tính sau), mô tả ngắn ở dòng thứ hai. Không thay cả vùng trái bằng `headerLeft` chỉ để thêm nút ←: dùng `backLink` (E2).\\n- MUST tải bản ghi bằng resolver gọi `detail(id)` của service sở hữu entity; lỗi (404, 403, timeout) để navigation error handler của host xử lý, không mở trang với bản ghi rỗng.\\n- MUST nhận bản ghi mới khi đổi ID (`runGuardsAndResolvers: \\'paramsChange\\'`, đọc `data` dạng signal).\\n- MUST đặt nút chính \"Cập nhật <entity>\" (`type=\"fill\"`) ở `headerRight`; tối đa ba tác vụ cấp ngoài, từ tác vụ thứ ba gom vào Action Popover ([header-actions](header-actions.md)).\\n- MUST hiện tác vụ theo quyền (`*sdPermission`) và theo trạng thái nghiệp vụ (computed trong TS); quyền xem không suy ra quyền cập nhật.\\n- SHOULD chia thông tin theo `sd-section`; trong section dùng `sd-view` cho field ngắn hoặc `sd-section-item` cho dạng thuộc tính.\\n- SHOULD dùng `sdAside` cho thông tin phụ (quy trình duyệt, người phụ trách); dưới 1200px cột phụ xuống dưới thân.\\n\\n## Lỗi hay gặp\\n\\n- Gọi API tải bản ghi trong `ngOnInit` của trang: trang mở trước khi có dữ liệu, lỗi 404 hiện thành trang trống.\\n- Hiện ID quan hệ thay vì tên: dùng pipe [relation](relation.md).\\n- Tải mọi tab của hồ sơ 360° ngay khi mở trang: chậm và tốn request cho tab người dùng không xem.\\n',\n 'docs/drawer.md': '# Drawer\\n\\nXem, tạo, cập nhật ngay trên danh sách: `sd-side-drawer` trong route con của danh sách. Route mẫu: `/pattern/customer/create`, `/pattern/customer/:id/detail`, `/pattern/customer/:id/update`, `/pattern/category/create?parent=`, `/pattern/category/:id/update`, chi tiết đơn hàng mặc định của `/pattern/order`.\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng khi người dùng cần giữ ngữ cảnh danh sách: xem nhanh, sửa vài field, tạo bản ghi con.\\n- Nhiều tab, bảng quan hệ lớn, form nhiều bước hoặc rộng hơn 800px: dùng trang ([detail](detail.md), [form](form.md)).\\n\\n## Code mẫu\\n\\nChi tiết trong drawer: bản ghi tải bằng `detail(id)` qua resolver, footer có Hồ sơ 360° và Cập nhật, Xoá là icon đỏ cạnh X, đóng bằng X điều hướng về danh sách:\\n\\n<!-- @source features/customer/components/detail-side-drawer/detail-side-drawer.component.ts -->\\n```ts\\nimport { afterNextRender, ChangeDetectionStrategy, Component, computed, inject, signal, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdBadge } from \\'@sdcorejs/angular/components/badge\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport { customerStatusBadge, customerTypeName, type CustomerDto } from \\'../../services/customer.model\\';\\nimport { GeneralInformationViewComponent } from \\'../general-information-view/general-information-view.component\\';\\n\\n/**\\n * Chi tiết khách hàng trong drawer (route con `:id/detail` của danh sách). Bản ghi do resolver tải bằng\\n * `detail(id)`, không lấy dữ liệu của dòng. Chỉ đóng bằng X (cùng Esc, backdrop): không có nút Đóng (E4).\\n * Xoá là tác vụ hiếm dùng và phá huỷ: nút chỉ có icon màu đỏ ở header, cạnh X; footer giữ tác vụ thường dùng.\\n */\\n@Component({\\n selector: \\'detail-side-drawer\\',\\n standalone: true,\\n imports: [RouterLink, SdSideDrawer, SdBadge, SdButton, SdPermissionDirective, GeneralInformationViewComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let customer = entity();\\n <sd-side-drawer width=\"600px\" autoId=\"customer-detail\" (sdClosed)=\"closed()\">\\n <div sdHeaderLeft class=\"d-flex flex-column\">\\n <div class=\"d-flex align-items-center gap-8\">\\n <span class=\"T16M\">Chi tiết khách hàng #{{ customer.code }}</span>\\n <sd-badge size=\"md\" [type]=\"badge().type ?? \\'round\\'\" [title]=\"badge().title\" [color]=\"badge().color\" />\\n </div>\\n <span class=\"T14R text-secondary\">{{ typeName() }} · {{ customer.phone }}</span>\\n </div>\\n <sd-button\\n sdHeaderRight\\n *sdPermission=\"\\'PATTERN_CUSTOMER_D_DELETE\\'\"\\n prefixIcon=\"delete\"\\n tooltip=\"Xoá khách hàng\"\\n type=\"text\"\\n color=\"error\"\\n autoId=\"customer-delete\"\\n [loading]=\"deleting()\"\\n (click)=\"delete()\" />\\n <general-information-view [customer]=\"customer\" />\\n <div sdFooterRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Hồ sơ 360°\" prefixIcon=\"contact_page\" type=\"outline\" autoId=\"customer-profile\" [routerLink]=\"[\\'../360\\']\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_CUSTOMER_U_UPDATE\\'\"\\n title=\"Cập nhật khách hàng\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"customer-update\"\\n [routerLink]=\"[\\'../update\\']\" />\\n </div>\\n </sd-side-drawer>\\n `,\\n})\\nexport class DetailSideDrawerComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly drawer = viewChild.required(SdSideDrawer);\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as CustomerDto)), { requireSync: true });\\n protected readonly badge = computed(() => customerStatusBadge(this.entity().status));\\n protected readonly typeName = computed(() => customerTypeName(this.entity().type));\\n protected readonly deleting = signal(false);\\n\\n constructor() {\\n afterNextRender(() => this.drawer().open());\\n }\\n\\n protected closed(): void {\\n // X, Esc, backdrop đều qua sdClosed; về danh sách bằng điều hướng để Back của trình duyệt cũng đóng được.\\n // Sang drawer cập nhật hay hồ sơ 360° thì drawer này bị huỷ cùng route, không phát sdClosed.\\n void this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async delete(): Promise<void> {\\n const customer = this.entity();\\n try {\\n await this.#confirm.confirm(`Xoá khách hàng ${customer.name}? Thao tác không hoàn tác được.`, {\\n title: \\'Xoá khách hàng\\',\\n yesTitle: \\'Xoá\\',\\n noTitle: \\'Không xoá\\',\\n yesButtonColor: \\'error\\',\\n });\\n } catch {\\n return;\\n }\\n this.deleting.set(true);\\n try {\\n await firstValueFrom(this.#customerService.delete(customer.id));\\n this.#notify.success(`Đã xoá khách hàng ${customer.name}.`);\\n this.drawer().close();\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không xoá được khách hàng.\\'));\\n } finally {\\n this.deleting.set(false);\\n }\\n }\\n}\\n```\\n\\nCập nhật trong drawer: `beforeClose` hỏi trước khi bỏ thay đổi, lưu xong đóng drawer, danh sách tải lại, focus trở về dòng:\\n\\n<!-- @source features/customer/components/update-side-drawer/update-side-drawer.component.ts -->\\n```ts\\nimport {\\n afterNextRender,\\n ChangeDetectionStrategy,\\n Component,\\n DestroyRef,\\n ElementRef,\\n inject,\\n Injector,\\n signal,\\n viewChild,\\n} from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerDto } from \\'../../services/customer.model\\';\\nimport {\\n customerSaveReq,\\n GeneralInformationFormComponent,\\n invalidCustomerGroups,\\n type CustomerForm,\\n type CustomerFormGroup,\\n} from \\'../general-information-form/general-information-form.component\\';\\n\\n/**\\n * Cập nhật khách hàng trong drawer (route con `:id/update`). X, Esc và backdrop đi qua `beforeClose`: còn thay đổi\\n * thì hỏi trước khi bỏ. Lưu thành công thì đóng drawer; danh sách tải lại và focus trở về dòng đã mở.\\n */\\n@Component({\\n selector: \\'update-side-drawer\\',\\n standalone: true,\\n imports: [SdSideDrawer, SdButton, GeneralInformationFormComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-side-drawer\\n [title]=\"\\'Cập nhật khách hàng #\\' + entity().code\"\\n width=\"600px\"\\n autoId=\"customer-update\"\\n [beforeClose]=\"beforeClose\"\\n (sdClosed)=\"closed()\">\\n <general-information-form [form]=\"form\" [seed]=\"entity()\" [errors]=\"apiErrors.errors()\" [invalidGroups]=\"invalidGroups()\" />\\n <div sdFooterRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Lưu\" prefixIcon=\"save\" type=\"fill\" color=\"primary\" autoId=\"customer-save\" [loading]=\"saving()\" (click)=\"save()\" />\\n </div>\\n </sd-side-drawer>\\n `,\\n})\\nexport class UpdateSideDrawerComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #injector = inject(Injector);\\n private readonly drawer = viewChild.required(SdSideDrawer);\\n // why: sd-side-drawer chuyển nội dung ra body, nên tìm field lỗi trong form chứ không trong host của component.\\n private readonly formElement = viewChild.required(GeneralInformationFormComponent, { read: ElementRef });\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as CustomerDto)), { requireSync: true });\\n protected readonly form: CustomerForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n protected readonly invalidGroups = signal<CustomerFormGroup[]>([]);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'customer-update\\', dirty: \\'value\\' });\\n\\n /** Đóng khi còn thay đổi chưa lưu: hỏi, đồng ý thì bỏ thay đổi (guard rời route không hỏi lại). */\\n protected readonly beforeClose = async (): Promise<boolean> => {\\n if (!this.#unsaved.dirty() || this.saving()) return !this.saving();\\n try {\\n await this.#confirm.confirm(\\'Thay đổi chưa lưu sẽ bị mất.\\', {\\n title: \\'Đóng khi chưa lưu?\\',\\n yesTitle: \\'Bỏ thay đổi\\',\\n noTitle: \\'Tiếp tục sửa\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } catch {\\n return false;\\n }\\n this.#unsaved.markPristine();\\n return true;\\n };\\n\\n constructor() {\\n afterNextRender(() => this.drawer().open());\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected closed(): void {\\n void this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#showErrors();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n await firstValueFrom(this.#customerService.update(this.entity().id, customerSaveReq(this.form)));\\n this.#unsaved.markPristine();\\n this.#notify.success(\\'Đã cập nhật khách hàng.\\');\\n this.saving.set(false);\\n this.drawer().close();\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#showErrors();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n /** `sd-inform` trong từng nhóm có lỗi, rồi focus field lỗi đầu tiên. */\\n #showErrors(): void {\\n this.invalidGroups.set(invalidCustomerGroups(this.form, this.apiErrors.errors()));\\n afterNextRender(() => focusFirstInvalid(this.formElement().nativeElement), { injector: this.#injector });\\n }\\n}\\n```\\n\\nForm ba nhóm, nhóm còn lỗi có `sd-inform` cảnh báo ngay trong nhóm:\\n\\n<!-- @source features/customer/components/general-information-form/general-information-form.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, input, linkedSignal } from \\'@angular/core\\';\\nimport type { FormControl, FormGroup } from \\'@angular/forms\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdSwitch } from \\'@sdcorejs/angular/forms/switch\\';\\nimport { SdTextarea } from \\'@sdcorejs/angular/forms/textarea\\';\\nimport type { CustomerSaveReq, CustomerStatus, CustomerTier, CustomerType } from \\'../../services/customer.model\\';\\nimport { CustomerTypeSelectComponent } from \\'../customer-type-select/customer-type-select.component\\';\\n\\n/** Các field Core tự đăng ký control qua `[form]` + `name`. */\\nexport type CustomerForm = FormGroup<{\\n name?: FormControl<string>;\\n type?: FormControl<CustomerType>;\\n taxCode?: FormControl<string | null>;\\n vip?: FormControl<boolean>;\\n email?: FormControl<string>;\\n phone?: FormControl<string>;\\n address?: FormControl<string>;\\n active?: FormControl<boolean>;\\n note?: FormControl<string | null>;\\n}>;\\n\\n/** Ba nhóm của form; nhóm còn lỗi sau khi bấm Lưu hiện `sd-inform` cảnh báo ngay trong nhóm. */\\nexport type CustomerFormGroup = \\'general\\' | \\'contact\\' | \\'other\\';\\n\\nconst GROUP_FIELDS: Readonly<Record<CustomerFormGroup, readonly string[]>> = {\\n general: [\\'name\\', \\'type\\', \\'taxCode\\', \\'vip\\'],\\n contact: [\\'email\\', \\'phone\\', \\'address\\'],\\n other: [\\'active\\', \\'note\\'],\\n};\\n\\n/** Nhóm có field không hợp lệ: field còn lỗi validate hoặc lỗi do API trả về. */\\nexport function invalidCustomerGroups(form: CustomerForm, apiErrors: Readonly<Record<string, string>>): CustomerFormGroup[] {\\n return (Object.keys(GROUP_FIELDS) as CustomerFormGroup[]).filter(group =>\\n GROUP_FIELDS[group].some(field => form.get(field)?.invalid || !!apiErrors[field])\\n );\\n}\\n\\n/** Giá trị form → request lưu. */\\nexport function customerSaveReq(form: CustomerForm): CustomerSaveReq {\\n const value = form.getRawValue();\\n const type: CustomerType = value.type ?? \\'individual\\';\\n const tier: CustomerTier = value.vip ? \\'vip\\' : \\'standard\\';\\n const status: CustomerStatus = value.active === false ? \\'inactive\\' : \\'active\\';\\n return {\\n name: value.name ?? \\'\\',\\n type,\\n tier,\\n email: value.email ?? \\'\\',\\n phone: value.phone ?? \\'\\',\\n address: value.address ?? \\'\\',\\n taxCode: type === \\'business\\' ? (value.taxCode ?? null) : null,\\n status,\\n note: value.note || null,\\n };\\n}\\n\\n/** Form khách hàng ba nhóm, dùng chung cho drawer tạo mới và cập nhật. */\\n@Component({\\n selector: \\'general-information-form\\',\\n standalone: true,\\n imports: [SdSection, SdInput, SdTextarea, SdSwitch, SdInform, CustomerTypeSelectComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let invalid = invalidGroups();\\n <div class=\"d-flex flex-column gap-16\">\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"d-flex flex-column gap-8 p-16\">\\n @if (invalid.includes(\\'general\\')) {\\n <sd-inform warning description=\"Kiểm tra tên và loại khách hàng.\" autoId=\"customer-general-warning\" />\\n }\\n <sd-input\\n label=\"Tên khách hàng\"\\n name=\"name\"\\n autoId=\"customer-name\"\\n [form]=\"form()\"\\n [model]=\"seed().name\"\\n [inlineError]=\"errors()[\\'name\\']\"\\n maxlength=\"120\"\\n required />\\n <customer-type-select [form]=\"form()\" [model]=\"seed().type\" (modelChange)=\"type.set($event ?? \\'individual\\')\" />\\n @if (type() === \\'business\\') {\\n <sd-input\\n label=\"Mã số thuế\"\\n name=\"taxCode\"\\n autoId=\"customer-tax-code\"\\n [form]=\"form()\"\\n [model]=\"seed().taxCode\"\\n [inlineError]=\"errors()[\\'taxCode\\']\"\\n maxlength=\"14\"\\n required />\\n }\\n <sd-switch label=\"Khách VIP\" name=\"vip\" [form]=\"form()\" [model]=\"seed().tier === \\'vip\\'\" />\\n </div>\\n </sd-section>\\n <sd-section title=\"Liên hệ\">\\n <div class=\"d-flex flex-column gap-8 p-16\">\\n @if (invalid.includes(\\'contact\\')) {\\n <sd-inform warning description=\"Kiểm tra email và số điện thoại.\" autoId=\"customer-contact-warning\" />\\n }\\n <sd-input\\n label=\"Email\"\\n name=\"email\"\\n autoId=\"customer-email\"\\n [form]=\"form()\"\\n [model]=\"seed().email\"\\n [inlineError]=\"errors()[\\'email\\']\"\\n pattern=\"EMAIL\"\\n required />\\n <sd-input\\n label=\"Điện thoại\"\\n name=\"phone\"\\n autoId=\"customer-phone\"\\n [form]=\"form()\"\\n [model]=\"seed().phone\"\\n [inlineError]=\"errors()[\\'phone\\']\"\\n maxlength=\"15\"\\n required />\\n <sd-input label=\"Địa chỉ\" name=\"address\" autoId=\"customer-address\" [form]=\"form()\" [model]=\"seed().address\" maxlength=\"200\" />\\n </div>\\n </sd-section>\\n <sd-section title=\"Khác\">\\n <div class=\"d-flex flex-column gap-8 p-16\">\\n <sd-switch label=\"Đang hoạt động\" name=\"active\" [form]=\"form()\" [model]=\"seed().status !== \\'inactive\\'\" />\\n <sd-textarea label=\"Ghi chú\" name=\"note\" [form]=\"form()\" [model]=\"seed().note\" maxlength=\"500\" />\\n </div>\\n </sd-section>\\n </div>\\n `,\\n})\\nexport class GeneralInformationFormComponent {\\n readonly form = input.required<CustomerForm>();\\n readonly seed = input.required<CustomerSaveReq>();\\n /** Lỗi theo field do API trả về. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n readonly invalidGroups = input<readonly CustomerFormGroup[]>([]);\\n /** Loại khách đang chọn: doanh nghiệp mới có mã số thuế. */\\n protected readonly type = linkedSignal(() => this.seed().type);\\n}\\n```\\n\\nRoute con của danh sách; `data.detail: \\'page\\'` cho route mở thành trang thay chỗ danh sách:\\n\\n<!-- @source features/customer/routes.ts -->\\n```ts\\nimport type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { entityResolver } from \\'./entity.resolver\\';\\nimport { CustomerService } from \\'./services/customer.service\\';\\n\\n/**\\n * Chi tiết, tạo và cập nhật mở trong drawer (route con của danh sách); hồ sơ 360° là trang thay chỗ danh sách\\n * (`data.detail: \\'page\\'`). Đóng drawer hay quay lại đều giữ bộ lọc, trang và vị trí cuộn của danh sách.\\n */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [CustomerService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Khách hàng\\',\\n data: { permission: \\'PATTERN_CUSTOMER_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\'create\\',\\n data: { permission: \\'PATTERN_CUSTOMER_C_CREATE\\' },\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () =>\\n import(\\'./components/create-side-drawer/create-side-drawer.component\\').then(module => module.CreateSideDrawerComponent),\\n },\\n {\\n path: \\':id/detail\\',\\n data: { permission: \\'PATTERN_CUSTOMER_R_DETAIL\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () =>\\n import(\\'./components/detail-side-drawer/detail-side-drawer.component\\').then(module => module.DetailSideDrawerComponent),\\n },\\n {\\n path: \\':id/update\\',\\n data: { permission: \\'PATTERN_CUSTOMER_U_UPDATE\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () =>\\n import(\\'./components/update-side-drawer/update-side-drawer.component\\').then(module => module.UpdateSideDrawerComponent),\\n },\\n {\\n path: \\':id/360\\',\\n title: \\'Hồ sơ khách hàng\\',\\n data: { permission: \\'PATTERN_CUSTOMER_R_DETAIL\\', detail: \\'page\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () => import(\\'./pages/profile/profile.component\\').then(module => module.ProfileComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n```\\n\\n## Quy tắc\\n\\n- MUST đặt drawer trong component của route con (`create`, `:id/detail`, `:id/update`) và mở khi component sẵn sàng; `sdClosed` điều hướng về danh sách (`\\'../..\\'` từ route hai segment), nên Back của trình duyệt cũng đóng drawer.\\n- MUST chỉ đóng bằng X, Esc, backdrop (E4); không có nút Đóng hay Huỷ thường trực.\\n- MUST đi qua `beforeClose` cho mọi đường đóng khi còn thay đổi; đồng ý bỏ thì `markPristine()` để guard của route không hỏi lần hai.\\n- MUST đặt tác vụ thường dùng ở `sdFooterRight`: nút chính (`fill`, có icon) ở ngoài cùng bên phải, nút phụ (`outline`) bên trái nó. Mở màn khác (Hồ sơ 360°) cũng là nút, không phải link.\\n- MUST đặt tác vụ phá huỷ ít dùng (Xoá) ở `sdHeaderRight`, cạnh X: nút chỉ có icon màu đỏ (`type=\"text\"`, `color=\"error\"`) với `tooltip` làm tên, và vẫn hỏi xác nhận (E13).\\n- MUST tải chi tiết bằng `detail(id)`; không dùng object của dòng làm dữ liệu chi tiết.\\n- MUST chỉ tải lại danh sách khi lưu thành công; trả focus về phần tử đã mở drawer (`sd-page-list` giữ phần tử này kể cả khi chi tiết chuyển sang cập nhật).\\n- SHOULD dùng bề rộng 600px cho chi tiết và form thường, 480px cho nội dung ngắn, tối đa 800px (E9).\\n- SHOULD tách `detail-side-drawer`, `create-side-drawer`, `update-side-drawer`; dùng chung `-form`/`-view`, không gộp ba chế độ vào một drawer.\\n\\n## Lỗi hay gặp\\n\\n- Drawer mở bằng method mà không có route: Back của trình duyệt rời cả màn danh sách, link không chia sẻ được.\\n- Mở chồng drawer cập nhật lên drawer chi tiết: hai lớp backdrop, Esc chỉ đóng một lớp.\\n- Tải lại danh sách mỗi lần đóng drawer: mất vị trí cuộn và lựa chọn dù không có gì thay đổi.\\n',\n 'docs/flow.md': '# Flow\\n\\nQuy trình nhiều bước: `sd-page width=\"narrow\"` + `sd-stepper` trong thân + nút bước ở `sdFooterLeft` / `sdFooterRight`. Route mẫu: `/pattern/import` (bốn bước ngang: nguồn, ánh xạ, xem trước & xung đột, xác nhận), `/pattern/partner/create` (bước dọc, rẽ nhánh theo loại, kiểm tra trùng mã, lưu nháp).\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng khi bước sau phụ thuộc kết quả bước trước (ánh xạ cột rồi mới xem trước), hoặc khi dữ liệu nhiều đến mức chia bước giúp người dùng.\\n- Các nhóm độc lập, nhập theo thứ tự nào cũng được: dùng [form](form.md) với mục lục.\\n\\n## Code mẫu\\n\\nBước ngang, mỗi bước có cổng (`stepControl`) chỉ mở khi bước đã qua kiểm tra; bước cuối mới ghi dữ liệu:\\n\\n<!-- @source features/import/pages/flow/flow.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, computed, inject, signal } from \\'@angular/core\\';\\nimport { FormControl, FormGroup, Validators } from \\'@angular/forms\\';\\nimport { RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdStep, SdStepper } from \\'@sdcorejs/angular/components/stepper\\';\\nimport { SdSegmentedComponent, type SdSegmentedItem, type SdSegmentedModel } from \\'@sdcorejs/angular/forms/segmented\\';\\nimport { SdTextarea } from \\'@sdcorejs/angular/forms/textarea\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { MappingFormComponent } from \\'../../components/mapping-form/mapping-form.component\\';\\nimport { PreviewViewComponent } from \\'../../components/preview-view/preview-view.component\\';\\nimport { ImportService } from \\'../../services/import.service\\';\\nimport {\\n guessMapping,\\n IMPORT_FIELDS,\\n IMPORT_SAMPLE,\\n parseCsv,\\n type ImportCommitRes,\\n type ImportDuplicatePolicy,\\n type ImportMapping,\\n type ImportPreviewRowDto,\\n} from \\'../../services/import.model\\';\\n\\nconst DUPLICATES: readonly SdSegmentedItem<ImportDuplicatePolicy>[] = [\\n { value: \\'skip\\', label: \\'Bỏ qua dòng trùng\\' },\\n { value: \\'overwrite\\', label: \\'Ghi đè sản phẩm đã có\\' },\\n];\\n\\n/**\\n * Pattern flow ngang: `sd-page` hẹp + `sd-stepper`, nút bước ở footer. Bốn bước giữ dữ liệu khi quay lại; mỗi bước\\n * kiểm tra điều kiện của chính nó trước khi sang bước sau, bước cuối mới ghi dữ liệu.\\n */\\n@Component({\\n selector: \\'flow\\',\\n standalone: true,\\n imports: [\\n RouterLink,\\n SdPageComponent,\\n SdStepper,\\n SdStep,\\n SdButton,\\n SdInform,\\n SdSection,\\n SdSectionItem,\\n SdSegmentedComponent,\\n SdTextarea,\\n MappingFormComponent,\\n PreviewViewComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-page title=\"Nhập dữ liệu sản phẩm\" description=\"Nhập danh mục sản phẩm từ tệp CSV.\" [backLink]=\"[\\'..\\']\" width=\"narrow\">\\n <sd-stepper linear [(selectedIndex)]=\"step\" animationDuration=\"0ms\" autoId=\"import-steps\">\\n <sd-step label=\"Nguồn dữ liệu\" [stepControl]=\"gates[0]\">\\n <div class=\"d-flex flex-column gap-8 py-16\">\\n <sd-inform type=\"tip\" description=\"Dán nội dung CSV có dòng tiêu đề, hoặc dùng dữ liệu mẫu.\" />\\n <sd-textarea\\n label=\"Nội dung CSV\"\\n name=\"source\"\\n autoId=\"import-source\"\\n [form]=\"sourceForm\"\\n [model]=\"source()\"\\n (modelChange)=\"editSource($event ?? \\'\\')\"\\n [inlineError]=\"showErrors() && !rows().length ? \\'Cần ít nhất một dòng dữ liệu dưới dòng tiêu đề.\\' : undefined\"\\n [maxlength]=\"20000\"\\n required />\\n <div>\\n <sd-button title=\"Dùng dữ liệu mẫu\" type=\"text\" prefixIcon=\"description\" autoId=\"import-sample\" (click)=\"useSample()\" />\\n </div>\\n </div>\\n </sd-step>\\n <sd-step label=\"Nhận diện & ánh xạ\" [stepControl]=\"gates[1]\">\\n <div class=\"py-16\">\\n <p class=\"T14R text-secondary mt-0\">Đọc được {{ rows().length }} dòng, {{ columns().length }} cột.</p>\\n <mapping-form\\n [sourceColumns]=\"columns()\"\\n [mapping]=\"mapping()\"\\n [showErrors]=\"showErrors()\"\\n (mappingChange)=\"mapping.set($event)\" />\\n </div>\\n </sd-step>\\n <sd-step label=\"Xem trước & xung đột\" [stepControl]=\"gates[2]\">\\n <div class=\"d-flex flex-column gap-12 py-16\">\\n @if (preview(); as rows) {\\n <p class=\"T14R m-0\">\\n {{ counts().new }} dòng mới · {{ counts().duplicate }} dòng trùng mã · {{ counts().invalid }} dòng lỗi (bỏ qua)\\n </p>\\n <preview-view [rows]=\"rows\" />\\n @if (counts().duplicate) {\\n <sd-segmented\\n ariaLabel=\"Xử lý dòng trùng\"\\n autoId=\"import-duplicates\"\\n [items]=\"duplicateItems\"\\n [model]=\"duplicates()\"\\n (sdChange)=\"setDuplicates($event)\" />\\n }\\n } @else {\\n <p class=\"T14R text-secondary\">Đang kiểm tra dữ liệu…</p>\\n }\\n </div>\\n </sd-step>\\n <sd-step label=\"Xác nhận\">\\n <div class=\"py-16\">\\n @if (result(); as done) {\\n <sd-inform\\n success\\n title=\"Đã nhập dữ liệu\"\\n [description]=\"done.created + \\' sản phẩm mới, \\' + done.updated + \\' cập nhật, \\' + done.skipped + \\' bỏ qua.\\'\" />\\n <a class=\"d-inline-block mt-12\" [routerLink]=\"[\\'../product\\']\">Xem danh sách sản phẩm</a>\\n } @else {\\n <sd-section title=\"Tóm tắt\">\\n <sd-section-item label=\"Thêm mới\">{{ counts().new }}</sd-section-item>\\n <sd-section-item label=\"Trùng mã\"\\n >{{ counts().duplicate }} ({{ duplicates() === \\'overwrite\\' ? \\'ghi đè\\' : \\'bỏ qua\\' }})</sd-section-item\\n >\\n <sd-section-item label=\"Lỗi, bỏ qua\">{{ counts().invalid }}</sd-section-item>\\n </sd-section>\\n }\\n </div>\\n </sd-step>\\n </sd-stepper>\\n <sd-button\\n sdFooterLeft\\n title=\"Quay lại\"\\n type=\"outline\"\\n autoId=\"import-previous\"\\n [disabled]=\"step() === 0 || !!result()\"\\n (click)=\"step.set(step() - 1)\" />\\n @if (step() < 3) {\\n <sd-button\\n sdFooterRight\\n title=\"Tiếp tục\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"import-next\"\\n [loading]=\"checking()\"\\n (click)=\"next()\" />\\n } @else if (!result()) {\\n <sd-button\\n sdFooterRight\\n title=\"Nhập dữ liệu\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"import-commit\"\\n [loading]=\"committing()\"\\n (click)=\"commit()\" />\\n }\\n </sd-page>\\n `,\\n})\\nexport class FlowComponent {\\n readonly #importService = inject(ImportService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n protected readonly duplicateItems = DUPLICATES;\\n protected readonly step = signal(0);\\n /**\\n * Một cổng cho mỗi bước: chỉ đúng sau khi bước đó qua kiểm tra, nên stepper `linear` không cho bấm tiêu đề để\\n * vượt qua bước chưa kiểm tra. Đổi nguồn dữ liệu thì đóng lại các bước sau.\\n */\\n protected readonly gates = [0, 1, 2].map(() => new FormControl(false, { nonNullable: true, validators: Validators.requiredTrue }));\\n protected readonly showErrors = signal(false);\\n /** Chỉ để đánh dấu đã chạm ô nguồn khi bấm Tiếp: lỗi của ô hiện ngay cả khi người dùng chưa gõ gì. */\\n protected readonly sourceForm = new FormGroup({});\\n protected readonly source = signal(\\'\\');\\n readonly #parsed = computed(() => parseCsv(this.source()));\\n protected readonly columns = computed(() => this.#parsed().columns);\\n protected readonly rows = computed(() => this.#parsed().rows);\\n protected readonly mapping = signal<ImportMapping>({ code: null, name: null, unit: null, price: null });\\n protected readonly preview = signal<readonly ImportPreviewRowDto[] | null>(null);\\n protected readonly duplicates = signal<ImportDuplicatePolicy>(\\'skip\\');\\n protected readonly checking = signal(false);\\n protected readonly committing = signal(false);\\n protected readonly result = signal<ImportCommitRes | null>(null);\\n protected readonly counts = computed(() => {\\n const rows = this.preview() ?? [];\\n return {\\n new: rows.filter(row => row.result === \\'new\\').length,\\n duplicate: rows.filter(row => row.result === \\'duplicate\\').length,\\n invalid: rows.filter(row => row.result === \\'invalid\\').length,\\n };\\n });\\n\\n protected useSample(): void {\\n this.editSource(IMPORT_SAMPLE);\\n }\\n\\n /** Đổi nguồn thì các bước sau phải kiểm tra lại. */\\n protected editSource(value: string): void {\\n this.source.set(value);\\n this.gates.forEach(gate => gate.setValue(false));\\n }\\n\\n protected setDuplicates(value: SdSegmentedModel<ImportDuplicatePolicy>): void {\\n if (value === \\'skip\\' || value === \\'overwrite\\') this.duplicates.set(value);\\n }\\n\\n protected async next(): Promise<void> {\\n const step = this.step();\\n if (step === 0) {\\n if (!this.rows().length) {\\n this.sourceForm.markAllAsTouched();\\n return this.showErrors.set(true);\\n }\\n // Nguồn mới: ánh xạ lại theo tên cột, bỏ kết quả kiểm tra cũ.\\n this.mapping.set(guessMapping(this.columns()));\\n this.preview.set(null);\\n this.gates.slice(1).forEach(gate => gate.setValue(false));\\n }\\n if (step === 1) {\\n const missing = IMPORT_FIELDS.some(field => field.required && !this.mapping()[field.field]);\\n if (missing) return this.showErrors.set(true);\\n if (!(await this.#check())) return;\\n }\\n this.showErrors.set(false);\\n this.gates[step].setValue(true);\\n this.step.set(step + 1);\\n }\\n\\n protected async commit(): Promise<void> {\\n const { new: created, duplicate } = this.counts();\\n const overwrite = this.duplicates() === \\'overwrite\\' ? duplicate : 0;\\n try {\\n await this.#confirm.confirm(`Thêm ${created} sản phẩm${overwrite ? `, ghi đè ${overwrite} sản phẩm` : \\'\\'}?`, {\\n title: \\'Nhập dữ liệu\\',\\n yesTitle: \\'Nhập dữ liệu\\',\\n noTitle: \\'Không\\',\\n });\\n } catch {\\n return;\\n }\\n this.committing.set(true);\\n try {\\n this.result.set(await firstValueFrom(this.#importService.commit(this.#mappedRows(), this.duplicates())));\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không nhập được dữ liệu. Thử lại.\\'));\\n } finally {\\n this.committing.set(false);\\n }\\n }\\n\\n async #check(): Promise<boolean> {\\n this.checking.set(true);\\n try {\\n this.preview.set((await firstValueFrom(this.#importService.preview(this.#mappedRows()))).rows);\\n return true;\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không kiểm tra được dữ liệu. Thử lại.\\'));\\n return false;\\n } finally {\\n this.checking.set(false);\\n }\\n }\\n\\n #mappedRows() {\\n const mapping = this.mapping();\\n return this.rows().map(row => ({\\n code: mapping.code ? (row[mapping.code] ?? \\'\\') : \\'\\',\\n name: mapping.name ? (row[mapping.name] ?? \\'\\') : \\'\\',\\n unit: mapping.unit ? (row[mapping.unit] ?? \\'\\') : \\'\\',\\n price: mapping.price ? (row[mapping.price] ?? \\'\\') : \\'0\\',\\n }));\\n }\\n}\\n```\\n\\nBước dọc, rẽ nhánh theo loại đối tác, kiểm tra trùng mã khi rời bước đầu, lưu nháp mỗi lần thay đổi:\\n\\n<!-- @source features/partner/pages/create/create.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, signal } from \\'@angular/core\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, merge } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdStep, SdStepper } from \\'@sdcorejs/angular/components/stepper\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdSegmentedComponent } from \\'@sdcorejs/angular/forms/segmented\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdFormatDatetimePipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage, apiFieldErrors } from \\'../../../../utils/api-error\\';\\nimport { PartnerService } from \\'../../services/partner.service\\';\\nimport { PARTNER_TYPE_OPTIONS, type PartnerSaveReq, type PartnerType } from \\'../../services/partner.model\\';\\n\\n/** Bản nháp giữ trong tab trình duyệt: tải lại trang vẫn tiếp tục được. */\\ninterface PartnerDraft extends PartnerSaveReq {\\n readonly step: number;\\n readonly savedAt: string;\\n}\\n\\nconst DRAFT_KEY = \\'pattern.partner.create.draft\\';\\nconst EMPTY: PartnerSaveReq = {\\n code: \\'\\',\\n type: \\'individual\\',\\n name: \\'\\',\\n identity: \\'\\',\\n representative: null,\\n email: \\'\\',\\n phone: \\'\\',\\n address: \\'\\',\\n};\\n\\nfunction readDraft(): PartnerDraft | null {\\n try {\\n const raw = sessionStorage.getItem(DRAFT_KEY);\\n return raw ? (JSON.parse(raw) as PartnerDraft) : null;\\n } catch {\\n return null;\\n }\\n}\\n\\nfunction writeDraft(draft: PartnerDraft | null): void {\\n try {\\n if (draft) sessionStorage.setItem(DRAFT_KEY, JSON.stringify(draft));\\n else sessionStorage.removeItem(DRAFT_KEY);\\n } catch {\\n // Không lưu được nháp (chế độ riêng tư, hết dung lượng): flow vẫn chạy, chỉ không khôi phục sau khi tải lại.\\n }\\n}\\n\\n/**\\n * Pattern flow dọc: `sd-page` hẹp + `sd-stepper` dọc, nút bước ở footer. Bước 2 rẽ nhánh theo loại đối tác; rời bước 1\\n * thì kiểm tra trùng mã với API; mọi thay đổi được lưu nháp và khôi phục khi tải lại trang.\\n */\\n@Component({\\n selector: \\'create\\',\\n standalone: true,\\n imports: [\\n SdPageComponent,\\n SdStepper,\\n SdStep,\\n SdButton,\\n SdInform,\\n SdSection,\\n SdSectionItem,\\n SdInput,\\n SdSegmentedComponent,\\n SdFormatDatetimePipe,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let value = seed();\\n <sd-page title=\"Tạo đối tác\" description=\"Đối tác cá nhân hoặc doanh nghiệp.\" [backLink]=\"[\\'../..\\']\" width=\"narrow\">\\n @if (restored(); as draft) {\\n <sd-inform\\n info\\n class=\"mt-16\"\\n autoId=\"partner-draft\"\\n [description]=\"\\'Đã khôi phục bản nháp lưu lúc \\' + (draft.savedAt | sdFormatDatetime) + \\'.\\'\"\\n actionLabel=\"Bỏ nháp\"\\n (sdAction)=\"discard()\" />\\n }\\n <sd-stepper linear orientation=\"vertical\" animationDuration=\"0ms\" autoId=\"partner-steps\" [(selectedIndex)]=\"step\">\\n <sd-step label=\"Loại và mã đối tác\" [stepControl]=\"kind\">\\n <div class=\"d-flex flex-column gap-8 py-8\">\\n <sd-segmented\\n name=\"type\"\\n ariaLabel=\"Loại đối tác\"\\n autoId=\"partner-type\"\\n [form]=\"kind\"\\n [items]=\"types\"\\n [model]=\"value.type\"\\n (sdChange)=\"type.set($any($event) ?? \\'individual\\')\" />\\n <sd-input\\n label=\"Mã đối tác\"\\n name=\"code\"\\n autoId=\"partner-code\"\\n [form]=\"kind\"\\n [model]=\"value.code\"\\n [inlineError]=\"codeError() ?? undefined\"\\n maxlength=\"20\"\\n required />\\n </div>\\n </sd-step>\\n <sd-step [label]=\"type() === \\'business\\' ? \\'Thông tin doanh nghiệp\\' : \\'Thông tin cá nhân\\'\" [stepControl]=\"identity\">\\n <div class=\"d-flex flex-column gap-8 py-8\">\\n @if (type() === \\'business\\') {\\n <sd-input label=\"Tên doanh nghiệp\" name=\"name\" autoId=\"partner-name\" [form]=\"identity\" [model]=\"value.name\" required />\\n <sd-input\\n label=\"Mã số thuế\"\\n name=\"identity\"\\n autoId=\"partner-identity\"\\n [form]=\"identity\"\\n [model]=\"value.identity\"\\n maxlength=\"14\"\\n required />\\n <sd-input\\n label=\"Người đại diện\"\\n name=\"representative\"\\n autoId=\"partner-representative\"\\n [form]=\"identity\"\\n [model]=\"value.representative\"\\n required />\\n } @else {\\n <sd-input label=\"Họ và tên\" name=\"name\" autoId=\"partner-name\" [form]=\"identity\" [model]=\"value.name\" required />\\n <sd-input\\n label=\"Số CCCD\"\\n name=\"identity\"\\n autoId=\"partner-identity\"\\n [form]=\"identity\"\\n [model]=\"value.identity\"\\n maxlength=\"12\"\\n required />\\n }\\n </div>\\n </sd-step>\\n <sd-step label=\"Liên hệ\" [stepControl]=\"contact\">\\n <div class=\"d-flex flex-column gap-8 py-8\">\\n <sd-input label=\"Email\" name=\"email\" autoId=\"partner-email\" [form]=\"contact\" [model]=\"value.email\" pattern=\"EMAIL\" required />\\n <sd-input\\n label=\"Điện thoại\"\\n name=\"phone\"\\n autoId=\"partner-phone\"\\n [form]=\"contact\"\\n [model]=\"value.phone\"\\n maxlength=\"15\"\\n required />\\n <sd-input label=\"Địa chỉ\" name=\"address\" autoId=\"partner-address\" [form]=\"contact\" [model]=\"value.address\" maxlength=\"200\" />\\n </div>\\n </sd-step>\\n <sd-step label=\"Xác nhận\">\\n @let summary = request();\\n <sd-section title=\"Kiểm tra lại\" class=\"d-block my-8\">\\n <sd-section-item label=\"Mã đối tác\">{{ summary.code }}</sd-section-item>\\n <sd-section-item label=\"Loại\">{{ summary.type === \\'business\\' ? \\'Doanh nghiệp\\' : \\'Cá nhân\\' }}</sd-section-item>\\n <sd-section-item label=\"Tên\">{{ summary.name }}</sd-section-item>\\n <sd-section-item [label]=\"summary.type === \\'business\\' ? \\'Mã số thuế\\' : \\'Số CCCD\\'\">{{ summary.identity }}</sd-section-item>\\n @if (summary.type === \\'business\\') {\\n <sd-section-item label=\"Người đại diện\">{{ summary.representative }}</sd-section-item>\\n }\\n <sd-section-item label=\"Email\">{{ summary.email }}</sd-section-item>\\n <sd-section-item label=\"Điện thoại\">{{ summary.phone }}</sd-section-item>\\n </sd-section>\\n </sd-step>\\n </sd-stepper>\\n <sd-button\\n sdFooterLeft\\n title=\"Quay lại\"\\n type=\"outline\"\\n autoId=\"partner-previous\"\\n [disabled]=\"step() === 0\"\\n (click)=\"step.set(step() - 1)\" />\\n @if (step() < 3) {\\n <sd-button\\n sdFooterRight\\n title=\"Tiếp tục\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"partner-next\"\\n [loading]=\"checking()\"\\n (click)=\"next()\" />\\n } @else {\\n <sd-button\\n sdFooterRight\\n title=\"Tạo đối tác\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"partner-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n }\\n </sd-page>\\n `,\\n})\\nexport class CreateComponent {\\n readonly #partnerService = inject(PartnerService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #draft = readDraft();\\n protected readonly types = PARTNER_TYPE_OPTIONS;\\n /** Giá trị ban đầu của các field: bản nháp nếu có. */\\n protected readonly seed = signal<PartnerSaveReq>(this.#draft ?? EMPTY);\\n protected readonly restored = signal<PartnerDraft | null>(this.#draft);\\n protected readonly step = signal(this.#draft?.step ?? 0);\\n protected readonly type = signal<PartnerType>(this.#draft?.type ?? \\'individual\\');\\n // Mỗi bước một FormGroup: stepper `linear` không cho sang bước sau khi bước hiện tại còn lỗi.\\n protected readonly kind = new FormGroup({});\\n protected readonly identity = new FormGroup({});\\n protected readonly contact = new FormGroup({});\\n protected readonly codeError = signal<string | null>(null);\\n protected readonly checking = signal(false);\\n protected readonly saving = signal(false);\\n readonly #values = signal(0);\\n /** Đã tạo xong: khi trang đóng, field gỡ control khỏi form và phát valueChanges; không được ghi lại nháp vừa xoá. */\\n #created = false;\\n protected readonly request = computed<PartnerSaveReq>(() => {\\n this.#values();\\n // why: nội dung bước chỉ tạo khi bước được mở; bước chưa mở lại sau khi khôi phục nháp lấy giá trị của nháp.\\n const value = {\\n ...this.seed(),\\n ...this.kind.getRawValue(),\\n ...this.identity.getRawValue(),\\n ...this.contact.getRawValue(),\\n } as Partial<PartnerSaveReq>;\\n const type = this.type();\\n return {\\n code: (value.code ?? \\'\\').trim().toUpperCase(),\\n type,\\n name: value.name ?? \\'\\',\\n identity: value.identity ?? \\'\\',\\n representative: type === \\'business\\' ? (value.representative ?? \\'\\') : null,\\n email: value.email ?? \\'\\',\\n phone: value.phone ?? \\'\\',\\n address: value.address ?? \\'\\',\\n };\\n });\\n\\n constructor() {\\n // Mỗi thay đổi lưu nháp; mã đổi thì bỏ lỗi trùng mã cũ.\\n const subscription = merge(this.kind.valueChanges, this.identity.valueChanges, this.contact.valueChanges).subscribe(() => {\\n if (this.#created) return;\\n this.#values.update(count => count + 1);\\n this.#saveDraft();\\n });\\n const code = this.kind.valueChanges.subscribe(() => this.codeError.set(null));\\n inject(DestroyRef).onDestroy(() => {\\n subscription.unsubscribe();\\n code.unsubscribe();\\n });\\n }\\n\\n protected async next(): Promise<void> {\\n const step = this.step();\\n const group = [this.kind, this.identity, this.contact][step];\\n group.markAllAsTouched();\\n if (group.invalid) return;\\n if (step === 0 && !(await this.#codeAvailable())) return;\\n this.step.set(step + 1);\\n this.#saveDraft();\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.saving.set(true);\\n try {\\n const partner = await firstValueFrom(this.#partnerService.create(this.request()));\\n this.#created = true;\\n writeDraft(null);\\n this.#notify.success(`Đã tạo đối tác ${partner.code}.`);\\n await this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n } catch (error) {\\n const fields = apiFieldErrors(error);\\n if (fields[\\'code\\']) {\\n // Mã vừa bị người khác dùng: quay lại bước nhập mã, dữ liệu các bước khác giữ nguyên.\\n this.codeError.set(fields[\\'code\\']);\\n this.step.set(0);\\n } else this.#notify.error(apiErrorMessage(error, \\'Không tạo được đối tác. Dữ liệu vẫn được giữ trong bản nháp.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n protected async discard(): Promise<void> {\\n try {\\n await this.#confirm.confirm(\\'Xoá bản nháp và nhập lại từ đầu?\\', {\\n title: \\'Bỏ nháp\\',\\n yesTitle: \\'Bỏ nháp\\',\\n noTitle: \\'Giữ lại\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } catch {\\n return;\\n }\\n writeDraft(null);\\n this.restored.set(null);\\n this.step.set(0);\\n this.type.set(\\'individual\\');\\n this.seed.set({ ...EMPTY });\\n }\\n\\n async #codeAvailable(): Promise<boolean> {\\n this.checking.set(true);\\n try {\\n const { available } = await firstValueFrom(this.#partnerService.checkCode(this.request().code));\\n if (!available) this.codeError.set(`Mã ${this.request().code} đã được dùng.`);\\n return available;\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không kiểm tra được mã. Thử lại.\\'));\\n return false;\\n } finally {\\n this.checking.set(false);\\n }\\n }\\n\\n #saveDraft(): void {\\n writeDraft({ ...this.request(), step: this.step(), savedAt: new Date().toISOString() });\\n }\\n}\\n```\\n\\n## Quy tắc\\n\\n- MUST dùng `sd-page` với `backLink` và `width=\"narrow\"`; nút bước (Quay lại, Tiếp tục, nút hoàn tất) ở footer, không ở header (E3).\\n- MUST giữ dữ liệu khi quay lại bước trước hoặc chuyển bước (E8); đổi dữ liệu nguồn thì các bước sau phải kiểm tra lại.\\n- MUST kiểm tra bước hiện tại trước khi sang bước sau (validation của form bước, kiểm tra với API như trùng mã); dùng `linear` + `stepControl` để người dùng không vượt bước bằng tiêu đề.\\n- MUST chỉ ghi dữ liệu ở bước cuối, sau khi hỏi xác nhận; trước đó chỉ đọc hoặc kiểm tra.\\n- SHOULD lưu nháp vào storage của tab khi quy trình dài; tải lại trang thì khôi phục và báo rõ, kèm cách bỏ nháp.\\n- SHOULD hiện tóm tắt ở bước Xác nhận để người dùng kiểm tra lại trước khi ghi.\\n\\n## Lỗi hay gặp\\n\\n- Mỗi bước là một route riêng: dữ liệu mất khi tải lại hoặc quay lại.\\n- Bấm tiêu đề bước sau để bỏ qua kiểm tra: dữ liệu lỗi tới bước ghi.\\n- Rẽ nhánh bằng cách ẩn field bằng CSS: field ẩn vẫn còn validator và chặn bước.\\n- Thanh bước của `mat-stepper` cuộn cùng nội dung; có màn thứ ba cần thanh bước ghim thì tách thành component riêng.\\n',\n 'docs/form.md': '# Form\\n\\nTạo hoặc cập nhật một bản ghi trong một bước: `sd-page-form`. Route mẫu: `/pattern/product/create` và `/pattern/product/:id/update` (một section), `/pattern/order/create` và `/pattern/order/:id/update` (dòng hàng nhập trực tiếp, mục lục; thêm `?lines=sd-table` để xem cùng bảng dựng bằng `sd-table`), `/pattern/settings` (một bản ghi, nhiều nhóm, trạng thái lưu ở footer).\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng khi form cần cả trang: nhiều nhóm, bảng dòng chi tiết, hoặc người dùng cần tập trung.\\n- Form ngắn sửa ngay trên danh sách: dùng drawer ([drawer](drawer.md)).\\n- Nhiều bước có điều kiện chuyển bước: dùng [flow](flow.md).\\n\\n## Code mẫu\\n\\nNhóm field nằm trong component `-form` dùng chung cho tạo và cập nhật; field Core tự đăng ký control qua `[form]` + `name`. Thân section là `row px-16 pt-16 pb-8`: field thẳng lề 16px với title của section; dưới hàng cuối còn chỗ dành cho lỗi của field, nên đáy chỉ cần 8px:\\n\\n<!-- @source features/product/components/general-information-form/general-information-form.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, input } from \\'@angular/core\\';\\nimport type { FormControl, FormGroup } from \\'@angular/forms\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdInputNumber } from \\'@sdcorejs/angular/forms/input-number\\';\\nimport type { ProductSaveReq, ProductStatus } from \\'../../services/product.model\\';\\nimport { ProductStatusSelectComponent } from \\'../product-status-select/product-status-select.component\\';\\n\\n/** Các field Core tự đăng ký control qua `[form]` + `name`; page không khai báo trước control trùng tên. */\\nexport type ProductForm = FormGroup<{\\n code?: FormControl<string>;\\n name?: FormControl<string>;\\n unit?: FormControl<string>;\\n price?: FormControl<number>;\\n status?: FormControl<ProductStatus>;\\n}>;\\n\\n/** Giá trị form → request lưu. `code` truyền vào khi cập nhật (mã bị khoá). */\\nexport function productSaveReq(form: ProductForm, code?: string): ProductSaveReq {\\n const value = form.getRawValue();\\n return {\\n code: code ?? value.code ?? \\'\\',\\n name: value.name ?? \\'\\',\\n unit: value.unit ?? \\'\\',\\n price: value.price ?? 0,\\n status: value.status ?? \\'active\\',\\n };\\n}\\n\\n/** Nhóm \"Thông tin chung\" của form sản phẩm, dùng chung cho tạo mới và cập nhật. */\\n@Component({\\n selector: \\'general-information-form\\',\\n standalone: true,\\n imports: [SdInput, SdInputNumber, SdSection, ProductStatusSelectComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-section title=\"Thông tin chung\">\\n <div class=\"row px-16 pt-16 pb-8\">\\n <div class=\"col-12 col-md-6\">\\n <sd-input\\n label=\"Mã sản phẩm\"\\n name=\"code\"\\n autoId=\"product-code\"\\n [form]=\"form()\"\\n [model]=\"seed().code\"\\n [disabled]=\"editing()\"\\n [inlineError]=\"errors()[\\'code\\']\"\\n maxlength=\"20\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input\\n label=\"Tên sản phẩm\"\\n name=\"name\"\\n autoId=\"product-name\"\\n [form]=\"form()\"\\n [model]=\"seed().name\"\\n [inlineError]=\"errors()[\\'name\\']\"\\n maxlength=\"100\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input label=\"Đơn vị tính\" name=\"unit\" autoId=\"product-unit\" [form]=\"form()\" [model]=\"seed().unit\" maxlength=\"20\" />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input-number\\n label=\"Giá bán (₫)\"\\n name=\"price\"\\n autoId=\"product-price\"\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"form()\"\\n [model]=\"seed().price\"\\n [inlineError]=\"errors()[\\'price\\']\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <product-status-select [form]=\"form()\" [model]=\"seed().status\" />\\n </div>\\n </div>\\n </sd-section>`,\\n})\\nexport class GeneralInformationFormComponent {\\n readonly form = input.required<FormGroup>();\\n readonly seed = input.required<ProductSaveReq>();\\n readonly editing = input(false);\\n /** Lỗi theo field do API trả về. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n}\\n```\\n\\nTrang tạo: Huỷ · Tạo sản phẩm ở `headerRight`, lưu lỗi thì focus field lỗi đầu tiên và gắn lỗi của API vào field, lưu xong sang chi tiết bằng `replaceUrl`:\\n\\n<!-- @source features/product/pages/create/create.component.ts -->\\n```ts\\nimport { afterNextRender, ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, Injector, signal } from \\'@angular/core\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport {\\n GeneralInformationFormComponent,\\n productSaveReq,\\n type ProductForm,\\n} from \\'../../components/general-information-form/general-information-form.component\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport type { ProductSaveReq } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'create\\',\\n standalone: true,\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [SdPageComponent, SdButton, GeneralInformationFormComponent],\\n template: `\\n <sd-page-form title=\"Tạo mới sản phẩm\" [backLink]=\"[\\'..\\']\">\\n <div headerRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Huỷ\" type=\"outline\" autoId=\"product-cancel\" (click)=\"cancel()\" />\\n <sd-button\\n title=\"Tạo sản phẩm\"\\n prefixIcon=\"save\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"product-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n </div>\\n <div class=\"py-16\">\\n <general-information-form [form]=\"form\" [seed]=\"seed\" [errors]=\"apiErrors.errors()\" />\\n </div>\\n </sd-page-form>\\n `,\\n})\\nexport class CreateComponent {\\n readonly #productService = inject(ProductService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #host: HTMLElement = inject(ElementRef).nativeElement;\\n readonly #injector = inject(Injector);\\n protected readonly seed: ProductSaveReq = { code: \\'\\', name: \\'\\', unit: \\'Cái\\', price: 0, status: \\'active\\' };\\n protected readonly form: ProductForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n // Dirty theo giá trị: gõ rồi xoá về như cũ thì rời trang không bị hỏi.\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'product-create\\', dirty: \\'value\\' });\\n\\n constructor() {\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected cancel(): void {\\n void this.#router.navigate([\\'..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n const product = await firstValueFrom(this.#productService.create(productSaveReq(this.form)));\\n this.#unsaved.markPristine();\\n this.#notify.success(`Đã tạo sản phẩm ${product.code}.`);\\n // replaceUrl: Back ở trang chi tiết về danh sách, không quay lại form tạo mới.\\n await this.#router.navigate([\\'..\\', product.id, \\'detail\\'], { relativeTo: this.#route, replaceUrl: true });\\n } catch (error) {\\n // Lưu lỗi: giữ nguyên dữ liệu đã nhập; lỗi theo field hiện ngay trên field.\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.#host), { injector: this.#injector });\\n }\\n}\\n```\\n\\nTrang cập nhật: mã bị khoá, dirty tính theo giá trị:\\n\\n<!-- @source features/product/pages/update/update.component.ts -->\\n```ts\\nimport { afterNextRender, ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, Injector, signal } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport {\\n GeneralInformationFormComponent,\\n productSaveReq,\\n type ProductForm,\\n} from \\'../../components/general-information-form/general-information-form.component\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport type { ProductDto } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'update\\',\\n standalone: true,\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [SdPageComponent, SdButton, GeneralInformationFormComponent],\\n template: `\\n <sd-page-form [title]=\"\\'Cập nhật sản phẩm #\\' + entity().code\" [backLink]=\"[\\'../detail\\']\">\\n <div headerRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Huỷ\" type=\"outline\" autoId=\"product-cancel\" (click)=\"cancel()\" />\\n <sd-button title=\"Lưu\" prefixIcon=\"save\" type=\"fill\" color=\"primary\" autoId=\"product-save\" [loading]=\"saving()\" (click)=\"save()\" />\\n </div>\\n <div class=\"py-16\">\\n <general-information-form [form]=\"form\" [seed]=\"entity()\" [editing]=\"true\" [errors]=\"apiErrors.errors()\" />\\n </div>\\n </sd-page-form>\\n `,\\n})\\nexport class UpdateComponent {\\n readonly #productService = inject(ProductService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #host: HTMLElement = inject(ElementRef).nativeElement;\\n readonly #injector = inject(Injector);\\n /** Sản phẩm do resolver tải; draft khởi tạo từ đây, sửa draft không đổi bản ghi trước khi lưu thành công. */\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as ProductDto)), { requireSync: true });\\n protected readonly form: ProductForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'product-update\\', dirty: \\'value\\' });\\n\\n constructor() {\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected cancel(): void {\\n void this.#router.navigate([\\'../detail\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n // Mã bị khoá sau khi tạo: gửi mã của bản ghi, không lấy từ form.\\n await firstValueFrom(this.#productService.update(this.entity().id, productSaveReq(this.form, this.entity().code)));\\n this.#unsaved.markPristine();\\n this.#notify.success(\\'Đã cập nhật sản phẩm.\\');\\n await this.#router.navigate([\\'../detail\\'], { relativeTo: this.#route, replaceUrl: true });\\n } catch (error) {\\n // Lưu lỗi: giữ nguyên draft để sửa và thử lại.\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.#host), { injector: this.#injector });\\n }\\n}\\n```\\n\\nDòng hàng nhập trực tiếp: trạng thái của dòng (FormArray `form.lines`, thành tiền, tổng, chọn sản phẩm thì điền đơn giá) nằm trong một hàm dùng chung cho hai cách dựng bảng bên dưới:\\n\\n<!-- @source features/order/components/lines-form/order-lines.ts -->\\n```ts\\nimport { computed, DestroyRef, effect, inject, signal, untracked, type Signal } from \\'@angular/core\\';\\nimport { FormArray, FormGroup } from \\'@angular/forms\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { ProductService } from \\'../../../product/services/product.service\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\nimport type { OrderForm } from \\'../general-information-form/general-information-form.component\\';\\n\\n/** Một dòng đang nhập: field Core của dòng tự đăng ký vào `group`; `seed` là giá trị ban đầu của dòng. */\\nexport interface OrderLineRow {\\n readonly key: number;\\n readonly group: FormGroup;\\n readonly seed: OrderLineDto;\\n}\\n\\nexport interface OrderLines {\\n readonly rows: Signal<readonly OrderLineRow[]>;\\n /** Thành tiền theo thứ tự của `rows`. */\\n readonly amounts: Signal<readonly number[]>;\\n readonly total: Signal<number>;\\n add(): void;\\n remove(row: OrderLineRow): void;\\n /** Chọn sản phẩm thì điền đơn giá hiện hành của sản phẩm. */\\n pick(row: OrderLineRow, productId: string | null | undefined): Promise<void>;\\n /** Gắn `form.lines` vào form khi field của các dòng vừa nạp đã đăng ký; gọi lại khi đã gắn thì không làm gì. */\\n attach(): void;\\n}\\n\\n/**\\n * Dòng hàng của form đơn: mỗi dòng là một FormGroup trong `form.lines` (FormArray). Thành tiền và tổng tính lại khi\\n * giá trị đổi. `lines-form` (bảng HTML) và `lines-table-form` (`sd-table`) dùng chung, chỉ khác phần hiển thị.\\n * Gọi trong injection context của component.\\n *\\n * `registerSdUnsavedChangesForm(..., { dirty: \\'value\\' })` lấy giá trị của một control lúc nó vào form làm giá trị đã\\n * lưu, nên `form.lines` chỉ vào form khi field của các dòng đã đăng ký; vào sớm hơn thì form vừa mở đã bị coi là có\\n * thay đổi. `<table>` vẽ dòng ngay trong lượt change detection đó (`attach: \\'now\\'`); `sd-table` vẽ dòng sau lần đọc\\n * đầu, nên `lines-table-form` dùng `attach: \\'manual\\'` rồi gọi `attach()` khi bảng đã vẽ.\\n */\\nexport function orderLines(\\n form: Signal<OrderForm>,\\n seed: Signal<readonly OrderLineDto[]>,\\n options: { readonly attach: \\'now\\' | \\'manual\\' } = { attach: \\'now\\' }\\n): OrderLines {\\n const productService = inject(ProductService);\\n const array = new FormArray<FormGroup>([]);\\n const version = signal(0);\\n const rows = signal<readonly OrderLineRow[]>([]);\\n let nextKey = 0;\\n\\n const attach = (): void => {\\n if (form().get(\\'lines\\') !== array) form().setControl(\\'lines\\', array);\\n };\\n const push = (line: OrderLineDto): void => {\\n const group = new FormGroup({});\\n array.push(group);\\n rows.update(items => [...items, { key: nextKey++, group, seed: line }]);\\n };\\n const load = (lines: readonly OrderLineDto[]): void => {\\n // why: gỡ ra rồi gắn lại, để giá trị đã lưu của `lines` là các dòng mới chứ không phải dòng của đơn trước.\\n if (form().get(\\'lines\\') === array) form().removeControl(\\'lines\\');\\n array.clear();\\n rows.set([]);\\n (lines.length ? lines : [{ productId: \\'\\', quantity: 1, unitPrice: 0 }]).forEach(push);\\n if (options.attach === \\'now\\') attach();\\n };\\n\\n const subscription = array.valueChanges.subscribe(() => version.update(value => value + 1));\\n inject(DestroyRef).onDestroy(() => subscription.unsubscribe());\\n // why: trang cập nhật được dùng lại khi chỉ đổi `:id`; dòng hàng phải theo đơn mới, không giữ dòng của đơn trước.\\n effect(() => {\\n const lines = seed();\\n untracked(() => load(lines));\\n });\\n\\n const amounts = computed(() => {\\n version();\\n return rows().map(\\n row => Number(row.group.get(\\'quantity\\')?.value ?? row.seed.quantity) * Number(row.group.get(\\'unitPrice\\')?.value ?? row.seed.unitPrice)\\n );\\n });\\n\\n return {\\n rows: rows.asReadonly(),\\n amounts,\\n total: computed(() => amounts().reduce((sum, amount) => sum + amount, 0)),\\n add: () => push({ productId: \\'\\', quantity: 1, unitPrice: 0 }),\\n remove: row => {\\n const index = rows().indexOf(row);\\n if (index < 0) return;\\n // why: đánh dấu đã sửa TRƯỚC khi gỡ, để dirty theo giá trị so với danh sách dòng lúc trước.\\n array.markAsDirty();\\n array.removeAt(index);\\n rows.update(items => items.filter(item => item !== row));\\n },\\n pick: async (row, productId) => {\\n if (!productId) return;\\n const product = await firstValueFrom(productService.cachedDetail(productId));\\n row.group.get(\\'unitPrice\\')?.setValue(product.price);\\n },\\n attach,\\n };\\n}\\n```\\n\\nBảng dựng bằng `<table>`: field trong ô dùng `size=\"sm\"` và `hideInlineError`, mọi ô căn giữa theo chiều dọc, lỗi của API là icon kèm tooltip trên đúng ô nên dòng không cao thêm:\\n\\n<!-- @source features/order/components/lines-form/lines-form.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, input } from \\'@angular/core\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdInputNumber } from \\'@sdcorejs/angular/forms/input-number\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { ProductSelectComponent } from \\'../../../product/components/product-select/product-select.component\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\nimport type { OrderForm } from \\'../general-information-form/general-information-form.component\\';\\nimport { orderLines } from \\'./order-lines\\';\\n\\n/**\\n * Bảng dòng hàng nhập trực tiếp, dựng bằng `<table>`: mỗi dòng là một FormGroup trong `form.lines` (FormArray, do\\n * `orderLines()` quản lý), các field Core tự đăng ký vào dòng. Chọn sản phẩm điền đơn giá; thành tiền và tổng tự\\n * tính. Field trong ô dùng `size=\"sm\"` và `hideInlineError`: lỗi, kể cả lỗi API theo dòng (`lines.<i>.<field>`), là\\n * icon kèm tooltip ngay trên ô đó, dòng không cao thêm. Cùng bảng dựng bằng `sd-table`: `lines-table-form`.\\n */\\n@Component({\\n selector: \\'lines-form\\',\\n standalone: true,\\n imports: [SdSection, SdButton, SdInputNumber, SdFormatNumberPipe, ProductSelectComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Dòng hàng\">\\n <div sdHeaderRight>\\n <sd-button title=\"Thêm dòng\" prefixIcon=\"add\" type=\"text\" autoId=\"order-line-add\" (click)=\"lines.add()\" />\\n </div>\\n <div class=\"lines-scroll\">\\n <table class=\"lines\">\\n <colgroup>\\n <col />\\n <col class=\"lines__quantity\" />\\n <col class=\"lines__money\" />\\n <col class=\"lines__money\" />\\n <col class=\"lines__action\" />\\n </colgroup>\\n <thead>\\n <tr>\\n <th scope=\"col\">Sản phẩm <span class=\"text-error\" aria-hidden=\"true\">*</span></th>\\n <th scope=\"col\" class=\"lines__number\">Số lượng <span class=\"text-error\" aria-hidden=\"true\">*</span></th>\\n <th scope=\"col\" class=\"lines__number\">Đơn giá (₫) <span class=\"text-error\" aria-hidden=\"true\">*</span></th>\\n <th scope=\"col\" class=\"lines__number\">Thành tiền (₫)</th>\\n <th scope=\"col\" class=\"lines__action\"><span class=\"sd-visually-hidden\">Xoá dòng</span></th>\\n </tr>\\n </thead>\\n <tbody>\\n @for (row of lines.rows(); track row.key; let index = $index) {\\n <tr [attr.data-line]=\"index\">\\n <td>\\n <product-select\\n size=\"sm\"\\n hideInlineError\\n [label]=\"undefined\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.productId || null\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.productId\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-product\\'\"\\n (modelChange)=\"lines.pick(row, $event)\"\\n required />\\n </td>\\n <td class=\"lines__number\">\\n <sd-input-number\\n name=\"quantity\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.quantity\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.quantity\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-quantity\\'\"\\n required />\\n </td>\\n <td class=\"lines__number\">\\n <sd-input-number\\n name=\"unitPrice\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.unitPrice\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.unitPrice\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-unit-price\\'\"\\n required />\\n </td>\\n <td class=\"lines__number\" [attr.data-autoid]=\"\\'order-line-\\' + index + \\'-amount\\'\">\\n {{ lines.amounts()[index] | sdFormatNumber: 0 }}\\n </td>\\n <td class=\"lines__action\">\\n <sd-button\\n prefixIcon=\"delete\"\\n type=\"text\"\\n color=\"error\"\\n tooltip=\"Xoá dòng\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-remove\\'\"\\n [disabled]=\"lines.rows().length === 1\"\\n (click)=\"lines.remove(row)\" />\\n </td>\\n </tr>\\n }\\n </tbody>\\n <tfoot>\\n <tr>\\n <th scope=\"row\" colspan=\"3\" class=\"lines__number\">Tổng tiền (₫)</th>\\n <td class=\"lines__number lines__total\" data-autoid=\"order-total\">{{ lines.total() | sdFormatNumber: 0 }}</td>\\n <td class=\"lines__action\"></td>\\n </tr>\\n </tfoot>\\n </table>\\n </div>\\n </sd-section>\\n `,\\n styles: `\\n /* Màn hẹp thì cuộn ngang trong section thay vì bóp cột sản phẩm. */\\n .lines-scroll {\\n overflow-x: auto;\\n }\\n /* Cột cố định, sản phẩm lấy phần còn lại: vừa thân 576px của sd-page-form. */\\n .lines {\\n width: 100%;\\n min-width: 544px;\\n border-collapse: collapse;\\n table-layout: fixed;\\n }\\n .lines__quantity {\\n width: 88px;\\n }\\n .lines__money {\\n width: 120px;\\n }\\n .lines__action {\\n width: 48px;\\n }\\n .lines th,\\n .lines td {\\n padding: 8px;\\n text-align: left;\\n vertical-align: middle;\\n }\\n /* Cột đầu và cuối thẳng lề 16px với title và nút \"Thêm dòng\" của section. */\\n .lines th:first-child,\\n .lines td:first-child {\\n padding-left: 16px;\\n }\\n .lines th:last-child,\\n .lines td:last-child {\\n padding-right: 16px;\\n }\\n .lines thead th {\\n color: var(--sd-text-secondary);\\n font-size: 12px;\\n font-weight: 500;\\n border-bottom: 1px solid var(--sd-border);\\n }\\n .lines tbody tr:first-child td {\\n padding-top: 12px;\\n }\\n .lines tbody tr:last-child td {\\n padding-bottom: 12px;\\n }\\n .lines__number {\\n text-align: right !important;\\n }\\n .lines tfoot th,\\n .lines tfoot td {\\n padding-top: 12px;\\n padding-bottom: 12px;\\n border-top: 1px solid var(--sd-border);\\n }\\n .lines__total {\\n font-weight: 500;\\n }\\n `,\\n})\\nexport class LinesFormComponent {\\n readonly form = input.required<OrderForm>();\\n /** Dòng ban đầu (cập nhật) hoặc một dòng trống (tạo mới). */\\n readonly seed = input.required<readonly OrderLineDto[]>();\\n /** Lỗi theo field do API trả về, khoá dạng `lines.<index>.<field>`. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n protected readonly lines = orderLines(this.form, this.seed);\\n}\\n```\\n\\nCùng dòng hàng dựng bằng `sd-table` (`/pattern/order/create?lines=sd-table`): nút thêm dòng ở header cột command (`sdTableCommandHeaderDef`), xoá dòng là command của bảng, số dòng và tổng tiền dưới bảng. Dòng đổi thì `reload()` bảng; `rowKey` giữ view của các dòng còn lại nên giá trị đang nhập không mất. `sd-table` vẽ dòng sau lần đọc đầu, nên `form.lines` chỉ vào form khi bảng đã vẽ (`attach: \\'manual\\'` rồi `attach()` từ `reload.onReload`):\\n\\n<!-- @source features/order/components/lines-table-form/lines-table-form.component.ts -->\\n```ts\\nimport { afterNextRender, ChangeDetectionStrategy, Component, effect, inject, Injector, input, untracked, viewChild } from \\'@angular/core\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport {\\n SdTable,\\n SdTableCellDefDirective,\\n SdTableCommandHeaderDefDirective,\\n SdTableTitleDefDirective,\\n type SdTableOption,\\n} from \\'@sdcorejs/angular/components/table\\';\\nimport { SdInputNumber } from \\'@sdcorejs/angular/forms/input-number\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { ProductSelectComponent } from \\'../../../product/components/product-select/product-select.component\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\nimport type { OrderForm } from \\'../general-information-form/general-information-form.component\\';\\nimport { orderLines, type OrderLineRow } from \\'../lines-form/order-lines\\';\\n\\n/** Dòng của `sd-table`: dòng form cộng tên các cột. Ô của mọi cột vẽ bằng `sdTableCellDef` từ `group`/`seed`. */\\ninterface LineItem extends OrderLineRow {\\n readonly productId?: string;\\n readonly quantity?: number;\\n readonly unitPrice?: number;\\n readonly amount?: number;\\n}\\n\\n/**\\n * Dòng hàng nhập trực tiếp, dựng bằng `sd-table` thay cho `<table>` của `lines-form`; trạng thái dòng vẫn là\\n * `orderLines()`. Bảng local, không phân trang, không lọc. Nút thêm dòng nằm ở header cột command\\n * (`sdTableCommandHeaderDef`), ngay trên nút xoá của từng dòng; field trong ô dùng `size=\"sm\"` và `hideInlineError`,\\n * cột bắt buộc có `*` ở title; số dòng và tổng tiền ở dưới bảng. Dòng đổi thì `reload()` bảng; `rowKey` giữ view\\n * của các dòng còn lại nên giá trị đang nhập không mất. `form.lines` chỉ vào form khi bảng đã vẽ dòng (`attach`).\\n */\\n@Component({\\n selector: \\'lines-table-form\\',\\n standalone: true,\\n imports: [\\n SdSection,\\n SdButton,\\n SdTable,\\n SdTableCellDefDirective,\\n SdTableCommandHeaderDefDirective,\\n SdTableTitleDefDirective,\\n SdInputNumber,\\n SdFormatNumberPipe,\\n ProductSelectComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Dòng hàng\">\\n <sd-table autoId=\"order-lines\" [option]=\"option\">\\n <ng-template sdTableCommandHeaderDef>\\n <sd-button\\n tooltip=\"Thêm dòng\"\\n prefixIcon=\"add\"\\n size=\"sm\"\\n type=\"light\"\\n color=\"primary\"\\n autoId=\"order-line-add\"\\n (click)=\"lines.add()\" />\\n </ng-template>\\n <ng-template sdTableTitleDef=\"productId\">Sản phẩm <span class=\"text-error\" aria-hidden=\"true\">*</span></ng-template>\\n <ng-template sdTableTitleDef=\"quantity\">Số lượng <span class=\"text-error\" aria-hidden=\"true\">*</span></ng-template>\\n <ng-template sdTableTitleDef=\"unitPrice\">Đơn giá (₫) <span class=\"text-error\" aria-hidden=\"true\">*</span></ng-template>\\n <ng-template sdTableCellDef=\"productId\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <product-select\\n class=\"lines-table__input\"\\n size=\"sm\"\\n hideInlineError\\n [label]=\"undefined\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.productId || null\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.productId\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-product\\'\"\\n (modelChange)=\"lines.pick(row, $event)\"\\n required />\\n </ng-template>\\n <ng-template sdTableCellDef=\"quantity\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <sd-input-number\\n class=\"lines-table__input\"\\n name=\"quantity\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.quantity\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.quantity\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-quantity\\'\"\\n required />\\n </ng-template>\\n <ng-template sdTableCellDef=\"unitPrice\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <sd-input-number\\n class=\"lines-table__input\"\\n name=\"unitPrice\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.unitPrice\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.unitPrice\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-unit-price\\'\"\\n required />\\n </ng-template>\\n <ng-template sdTableCellDef=\"amount\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <strong class=\"lines-table__amount\" [attr.data-autoid]=\"\\'order-line-\\' + index + \\'-amount\\'\">\\n {{ lines.amounts()[index] | sdFormatNumber: 0 }}\\n </strong>\\n </ng-template>\\n </sd-table>\\n <div class=\"lines-table__summary\">\\n <span>{{ lines.rows().length }} dòng hàng</span>\\n <strong\\n >Tổng tiền: <span data-autoid=\"order-total\">{{ lines.total() | sdFormatNumber: 0 }}</span> ₫</strong\\n >\\n </div>\\n </sd-section>\\n `,\\n styles: `\\n /* Field trong dòng: 6px trên dưới để dòng 44px vẫn thoáng. */\\n .lines-table__input {\\n display: block;\\n padding-block: 6px;\\n }\\n .lines-table__amount {\\n display: block;\\n text-align: right;\\n font-variant-numeric: tabular-nums;\\n }\\n .lines-table__summary {\\n display: flex;\\n justify-content: space-between;\\n gap: 8px;\\n padding: 12px 16px;\\n color: var(--sd-text-secondary);\\n }\\n .lines-table__summary strong {\\n color: var(--sd-text);\\n }\\n `,\\n})\\nexport class LinesTableFormComponent {\\n readonly form = input.required<OrderForm>();\\n /** Dòng ban đầu (cập nhật) hoặc một dòng trống (tạo mới). */\\n readonly seed = input.required<readonly OrderLineDto[]>();\\n /** Lỗi theo field do API trả về, khoá dạng `lines.<index>.<field>`. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n readonly #injector = inject(Injector);\\n private readonly table = viewChild(SdTable<LineItem>);\\n protected readonly lines = orderLines(this.form, this.seed, { attach: \\'manual\\' });\\n protected readonly option: SdTableOption<LineItem> = {\\n type: \\'local\\',\\n items: () => [...this.lines.rows()],\\n rowKey: \\'key\\',\\n filter: { disabled: true },\\n paginate: { hidden: true, pageSize: 200 },\\n reload: {\\n visible: false,\\n // why: sd-table vẽ dòng sau lần đọc; field trong ô đăng ký xong thì mới gắn `form.lines` (xem `orderLines`).\\n onReload: () => {\\n afterNextRender(() => this.lines.attach(), { injector: this.#injector });\\n },\\n },\\n config: { visible: false },\\n columns: [\\n { field: \\'productId\\', title: \\'Sản phẩm\\', type: \\'string\\', minWidth: \\'180px\\' },\\n { field: \\'quantity\\', title: \\'Số lượng\\', type: \\'number\\', width: \\'88px\\' },\\n { field: \\'unitPrice\\', title: \\'Đơn giá (₫)\\', type: \\'number\\', width: \\'120px\\' },\\n { field: \\'amount\\', title: \\'Thành tiền (₫)\\', type: \\'number\\', width: \\'120px\\', align: \\'right\\' },\\n ],\\n command: {\\n commands: [\\n {\\n title: \\'Xoá dòng\\',\\n icon: \\'delete\\',\\n color: \\'error\\',\\n disabled: () => this.lines.rows().length === 1,\\n click: row => this.lines.remove(row),\\n },\\n ],\\n },\\n };\\n\\n constructor() {\\n // why: bảng local chỉ đọc `items` khi tải; thêm, xoá dòng hay nạp đơn khác đều phải `reload()` để vẽ lại. Gọi sau\\n // lượt render, khi `option` của bảng đã được gán.\\n effect(() => {\\n this.lines.rows();\\n untracked(() => afterNextRender(() => void this.table()?.reload(), { injector: this.#injector }));\\n });\\n }\\n}\\n```\\n\\n## Quy tắc\\n\\n- MUST đặt Huỷ (outline) và nút lưu (fill, primary) ở `headerRight` của `sd-page-form` (E3); không lặp nút lưu ở cuối thân.\\n- SHOULD cho nút lưu icon `save`; trang tạo ghi rõ hành động (\"Tạo đơn hàng\"), trang cập nhật ghi \"Lưu\".\\n- MUST đặt title \"Tạo mới <entity>\" hoặc \"Cập nhật <entity> #<mã>\" (E5).\\n- MUST bảo vệ thay đổi chưa lưu: `canDeactivate: [sdPageFormLeaveGuard]` trên route và `registerSdUnsavedChangesForm(..., { dirty: \\'value\\' })` trong trang. Gõ rồi sửa về như cũ không bị hỏi; đóng tab trình duyệt khi còn thay đổi có hộp thoại của trình duyệt.\\n- MUST kiểm tra khi rời field và khi bấm Lưu (`markAllAsTouched`); lưu lỗi thì focus field lỗi đầu tiên (E13).\\n- MUST gắn lỗi theo field của API vào đúng field (`[inlineError]`), giữ nguyên dữ liệu đã nhập; field đổi giá trị thì bỏ lỗi cũ của nó.\\n- MUST lưu xong thì `markPristine()` trước khi điều hướng, sang chi tiết với `replaceUrl: true` để Back không quay lại form tạo mới.\\n- MUST không khai báo trước FormControl trùng tên với field Core tự đăng ký.\\n- MUST dùng `size=\"sm\"` và `hideInlineError` cho field trong ô của bảng dòng, dù bảng là `<table>` hay `sd-table`; field trong ô không có label, cột bắt buộc có `*` màu error sau title.\\n- SHOULD dùng `toc` khi form có từ ba nhóm trở lên; mục lục lấy các `sd-section` có title, cả section nằm trong component `-form` con.\\n- SHOULD giữ bản ghi một dòng (cài đặt) ở lại trang sau khi lưu: `form.markAsPristine()` làm giá trị vừa lưu thành mốc so sánh mới, footer báo trạng thái lưu.\\n\\n## Lỗi hay gặp\\n\\n- Chụp giá trị ban đầu lúc khởi tạo form khi field Core chưa đăng ký: form vừa mở đã bị coi là có thay đổi. Dùng `dirty: \\'value\\'` của `registerSdUnsavedChangesForm`.\\n- Bắt mọi lỗi lưu rồi báo chung \"Không thể lưu\": lỗi theo field của API mất chỗ hiện.\\n- Điều hướng sau khi lưu mà chưa `markPristine()`: guard hỏi \"Rời trang khi chưa lưu?\" ngay sau khi lưu xong.\\n- Bấm Lưu liên tiếp tạo hai request: chặn bằng cờ `saving` và trạng thái `loading` của nút.\\n- Gắn FormArray dòng hàng vào form trước khi field của các dòng đăng ký xong (`sd-table` vẽ dòng sau lần đọc đầu): `dirty: \\'value\\'` lấy dòng còn trống làm giá trị đã lưu, form vừa mở đã hỏi \"Rời trang khi chưa lưu?\".\\n- Để field trong ô bảng ở cỡ `md` và lỗi hiện dưới field: ô số và select cao khác nhau, dòng có lỗi cao hơn các dòng khác, cột thành tiền và nút xoá lệch dòng.\\n',\n 'docs/header-actions.md': '# Header actions\\n\\nNút ở header của trang và tác vụ trên dòng, trên thanh chọn nhiều. Mẫu: `/pattern/product` (menu Nhập/Xuất + Tạo mới), `/pattern/order/:id/detail` (tác vụ theo trạng thái duyệt), `/pattern/order` (tác vụ hàng loạt), `/pattern/category` (thao tác theo dòng).\\n\\n## Khi nào dùng / khi nào không\\n\\n- Header chứa tác vụ của cả trang: tạo mới, nhập, xuất, cập nhật bản ghi, tác vụ trạng thái.\\n- Tác vụ của một dòng: `command` của `sd-table`; của nhiều dòng đã chọn: `selector.actions`.\\n\\n## Code mẫu\\n\\nMột wrapper `headerRight`; nút chính `type=\"fill\"` ngoài cùng bên phải; menu dùng Action Popover của `sd-button`:\\n\\n<!-- @source features/product/pages/list/list.component.html -->\\n```html\\n<sd-page-list title=\"Sản phẩm\" description=\"Danh mục sản phẩm đang kinh doanh.\">\\n <div headerRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <sd-button\\n *sdPermission=\"\\'PATTERN_PRODUCT_R_MENU\\'\"\\n title=\"Nhập/Xuất\"\\n suffixIcon=\"expand_more\"\\n type=\"outline\"\\n autoId=\"product-data-menu\">\\n <sd-button-item *sdPermission=\"\\'PATTERN_PRODUCT_C_IMPORT\\'\" prefixIcon=\"upload\" (click)=\"openImport()\">Nhập dữ liệu</sd-button-item>\\n <sd-button-item *sdPermission=\"\\'PATTERN_PRODUCT_R_EXPORT\\'\" prefixIcon=\"download\" (click)=\"exportData()\">Xuất dữ liệu</sd-button-item>\\n </sd-button>\\n <sd-button\\n *sdPermission=\"\\'PATTERN_PRODUCT_C_CREATE\\'\"\\n title=\"Tạo mới\"\\n prefixIcon=\"add\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"product-create\"\\n [routerLink]=\"[\\'create\\']\" />\\n </div>\\n\\n <sd-table autoId=\"product-list\" [option]=\"tableOption\">\\n <ng-template sdTableCellDef=\"code\" let-product=\"item\">\\n <a *sdPermission=\"\\'PATTERN_PRODUCT_R_DETAIL\\'\" [routerLink]=\"[product.id, \\'detail\\']\">{{ product.code }}</a>\\n @if (!canOpenDetail) {\\n <span>{{ product.code }}</span>\\n }\\n </ng-template>\\n </sd-table>\\n</sd-page-list>\\n```\\n\\nTác vụ theo quyền và trạng thái, xác nhận trước khi đổi trạng thái, Từ chối bắt buộc lý do:\\n\\n<!-- @source features/order/pages/detail/detail.component.ts -->\\n```ts\\nimport { AsyncPipe, NgTemplateOutlet } from \\'@angular/common\\';\\nimport { afterNextRender, ChangeDetectionStrategy, Component, computed, inject, linkedSignal, signal, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdBadge } from \\'@sdcorejs/angular/components/badge\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdView } from \\'@sdcorejs/angular/components/view\\';\\nimport { SD_PAGE_LIST, SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdEmptyPipe, SdFormatDatePipe, SdFormatDatetimePipe, SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { CustomerDetailPipe } from \\'../../../customer/pipes/customer-detail.pipe\\';\\nimport { ApprovalStepsComponent } from \\'../../components/approval-steps/approval-steps.component\\';\\nimport { LinesViewComponent } from \\'../../components/lines-view/lines-view.component\\';\\nimport { OrderService } from \\'../../services/order.service\\';\\nimport { canUpdateOrder, orderApprovalBadge, orderStatusBadge, type OrderAction, type OrderDto } from \\'../../services/order.model\\';\\n\\n/**\\n * Chi tiết đơn (`:id/detail`, route con của danh sách). Mở trong drawer 600px hoặc trang `sd-page-detail` theo\\n * `detail` của `sd-page-list`. Gửi duyệt, Duyệt và Từ chối đều hỏi xác nhận; Từ chối bắt buộc lý do (E13).\\n */\\n@Component({\\n selector: \\'detail\\',\\n standalone: true,\\n imports: [\\n AsyncPipe,\\n NgTemplateOutlet,\\n RouterLink,\\n SdPageComponent,\\n SdSideDrawer,\\n SdBadge,\\n SdButton,\\n SdSection,\\n SdSectionItem,\\n SdView,\\n SdPermissionDirective,\\n SdEmptyPipe,\\n SdFormatDatePipe,\\n SdFormatDatetimePipe,\\n SdFormatNumberPipe,\\n CustomerDetailPipe,\\n ApprovalStepsComponent,\\n LinesViewComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let order = entity();\\n @let customer = order.customerId | customerDetail | async;\\n <ng-template #actions>\\n @if (order.approval === \\'submitted\\') {\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_REJECT\\'\"\\n title=\"Từ chối\"\\n prefixIcon=\"close\"\\n type=\"light\"\\n color=\"warning\"\\n autoId=\"order-reject\"\\n [disabled]=\"pending()\"\\n (click)=\"act(\\'reject\\')\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_APPROVE\\'\"\\n title=\"Duyệt\"\\n prefixIcon=\"check\"\\n type=\"fill\"\\n color=\"success\"\\n autoId=\"order-approve\"\\n [disabled]=\"pending()\"\\n (click)=\"act(\\'approve\\')\" />\\n }\\n @if (editable()) {\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_SUBMIT\\'\"\\n title=\"Gửi duyệt\"\\n prefixIcon=\"send\"\\n type=\"outline\"\\n autoId=\"order-submit\"\\n [disabled]=\"pending()\"\\n (click)=\"act(\\'submit\\')\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_UPDATE\\'\"\\n title=\"Cập nhật đơn hàng\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"order-update\"\\n [disabled]=\"pending()\"\\n [routerLink]=\"[\\'../update\\']\" />\\n }\\n </ng-template>\\n\\n @if (mode() === \\'drawer\\') {\\n <sd-side-drawer width=\"600px\" autoId=\"order-detail\" (sdClosed)=\"closed()\">\\n <div sdHeaderLeft class=\"d-flex align-items-center gap-8\">\\n <span class=\"T16M\">Đơn hàng {{ order.code }}</span>\\n <sd-badge size=\"md\" type=\"round\" [title]=\"statusBadge().title\" [color]=\"statusBadge().color\" />\\n </div>\\n <sd-section title=\"Thông tin chung\">\\n <sd-section-item label=\"Khách hàng\">{{ order.customer }}</sd-section-item>\\n <sd-section-item label=\"Kênh bán\">{{ order.channel }}</sd-section-item>\\n <sd-section-item label=\"Kho xuất\">{{ order.warehouse }}</sd-section-item>\\n <sd-section-item label=\"Thanh toán\">{{ order.payment }}</sd-section-item>\\n <sd-section-item label=\"Ngày tạo\">{{ order.createdAt | sdFormatDatetime }}</sd-section-item>\\n <sd-section-item label=\"Tổng tiền (₫)\">{{ order.total | sdFormatNumber: 0 }}</sd-section-item>\\n <sd-section-item label=\"Trạng thái\">\\n <div class=\"d-flex align-items-center gap-8 flex-wrap\">\\n @for (badge of badges(); track $index) {\\n <sd-badge [type]=\"badge.type\" [title]=\"badge.title\" [color]=\"badge.color\" />\\n }\\n </div>\\n </sd-section-item>\\n </sd-section>\\n <div sdFooterRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <ng-container [ngTemplateOutlet]=\"actions\" />\\n </div>\\n </sd-side-drawer>\\n } @else {\\n <sd-page-detail\\n [title]=\"\\'Chi tiết đơn hàng #\\' + order.code\"\\n [description]=\"order.customer + \\' · \\' + order.channel\"\\n [badges]=\"badges()\"\\n [backLink]=\"[\\'../..\\']\">\\n <div headerRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <ng-container [ngTemplateOutlet]=\"actions\" />\\n </div>\\n <div class=\"d-flex flex-column gap-16 py-16\">\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"row p-8\">\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Khách hàng\" [display]=\"order.customer\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Điện thoại\" [display]=\"customer?.phone\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Kênh bán\" [display]=\"order.channel\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Kho xuất\" [display]=\"order.warehouse\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Thanh toán\" [display]=\"order.payment\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Ngày tạo\" [display]=\"order.createdAt | sdFormatDatetime\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Ngày giao\" [display]=\"order.deliveredAt | sdFormatDate\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Mã vận đơn\" [display]=\"order.tracking\" /></div>\\n </div>\\n </sd-section>\\n <lines-view [lines]=\"order.lines\" />\\n <sd-section title=\"Thông tin phê duyệt\">\\n <sd-section-item label=\"Trạng thái duyệt\">\\n <sd-badge [type]=\"approvalBadge().type\" [title]=\"approvalBadge().title\" [color]=\"approvalBadge().color\" />\\n </sd-section-item>\\n <sd-section-item label=\"Người gửi duyệt\">{{ submitted()?.by | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Người duyệt\">{{ decided()?.by | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Lý do từ chối\">{{ decided()?.reason | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Ghi chú\">{{ order.note | sdEmpty }}</sd-section-item>\\n </sd-section>\\n </div>\\n <approval-steps sdAside [steps]=\"order.approvalHistory\" />\\n </sd-page-detail>\\n }\\n `,\\n})\\nexport class DetailComponent {\\n readonly #orderService = inject(OrderService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly drawer = viewChild(SdSideDrawer);\\n protected readonly mode = inject(SD_PAGE_LIST).detail;\\n readonly #resolved = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as OrderDto)), { requireSync: true });\\n /** Đơn do resolver tải; sau mỗi tác vụ thay bằng đơn API trả về. */\\n protected readonly entity = linkedSignal(() => this.#resolved());\\n protected readonly pending = signal(false);\\n protected readonly statusBadge = computed(() => orderStatusBadge(this.entity().status));\\n protected readonly approvalBadge = computed(() => orderApprovalBadge(this.entity().approval));\\n /** Trạng thái đơn và trạng thái duyệt: title của trang, dòng \"Trạng thái\" của drawer. */\\n protected readonly badges = computed(() => [this.statusBadge(), this.approvalBadge()]);\\n protected readonly editable = computed(() => canUpdateOrder(this.entity()));\\n protected readonly submitted = computed(() => [...this.entity().approvalHistory].reverse().find(step => step.action === \\'submit\\'));\\n protected readonly decided = computed(() =>\\n this.entity().approval === \\'approved\\' || this.entity().approval === \\'rejected\\' ? this.entity().approvalHistory.at(-1) : undefined\\n );\\n\\n constructor() {\\n afterNextRender(() => this.drawer()?.open());\\n }\\n\\n protected closed(): void {\\n void this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n }\\n\\n /** Hỏi xác nhận (Từ chối kèm lý do), gọi API, rồi hiển thị đơn mới; lỗi giữ nguyên màn để thử lại. */\\n protected async act(action: Extract<OrderAction, \\'submit\\' | \\'approve\\' | \\'reject\\'>): Promise<void> {\\n const order = this.entity();\\n let reason: string | undefined;\\n try {\\n if (action === \\'reject\\') {\\n reason = await this.#confirm.withInput(`Từ chối đơn ${order.code}. Lý do được gửi cho người lập đơn.`, {\\n title: \\'Từ chối đơn hàng\\',\\n label: \\'Lý do từ chối\\',\\n required: true,\\n maxlength: 200,\\n yesTitle: \\'Từ chối\\',\\n noTitle: \\'Không\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } else {\\n await this.#confirm.confirm(action === \\'approve\\' ? `Duyệt đơn ${order.code}?` : `Gửi đơn ${order.code} cho người duyệt?`, {\\n title: action === \\'approve\\' ? \\'Duyệt đơn hàng\\' : \\'Gửi duyệt\\',\\n yesTitle: action === \\'approve\\' ? \\'Duyệt\\' : \\'Gửi duyệt\\',\\n noTitle: \\'Không\\',\\n });\\n }\\n } catch {\\n return;\\n }\\n this.pending.set(true);\\n try {\\n this.entity.set(await firstValueFrom(this.#orderService.act(action, { id: order.id, reason })));\\n this.#notify.success(action === \\'approve\\' ? \\'Đã duyệt đơn.\\' : action === \\'reject\\' ? \\'Đã từ chối đơn.\\' : \\'Đã gửi duyệt.\\');\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error));\\n } finally {\\n this.pending.set(false);\\n }\\n }\\n}\\n```\\n\\nTác vụ hàng loạt báo kết quả từng phần, giữ các dòng lỗi đang chọn, cho thử lại phần lỗi:\\n\\n<!-- @source features/order/components/bulk-result/bulk-result.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, computed, input, output } from \\'@angular/core\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\n\\n/** Kết quả của một tác vụ hàng loạt: số thành công trên tổng và từng đơn lỗi. */\\nexport interface OrderBulkSummary {\\n /** Động từ của tác vụ, ví dụ \"Đã xác nhận\". */\\n readonly done: string;\\n readonly total: number;\\n readonly failed: readonly { readonly id: string; readonly code: string; readonly message: string }[];\\n}\\n\\n/** Báo kết quả từng phần (E13): \"Đã xác nhận 8/10. 2 đơn lỗi.\" kèm lỗi từng đơn và nút thử lại phần lỗi. */\\n@Component({\\n selector: \\'bulk-result\\',\\n standalone: true,\\n imports: [SdInform],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let _result = result();\\n <sd-inform\\n autoId=\"order-bulk-result\"\\n [color]=\"_result.failed.length ? \\'warning\\' : \\'success\\'\"\\n [title]=\"title()\"\\n [description]=\"failures()\"\\n [actionLabel]=\"_result.failed.length ? \\'Thử lại phần lỗi\\' : undefined\"\\n closable\\n (sdAction)=\"retry.emit()\"\\n (sdClosed)=\"dismiss.emit()\" />\\n `,\\n})\\nexport class BulkResultComponent {\\n readonly result = input.required<OrderBulkSummary>();\\n readonly retry = output<void>();\\n readonly dismiss = output<void>();\\n protected readonly title = computed(() => {\\n const { done, total, failed } = this.result();\\n return `${done} ${total - failed.length}/${total}.` + (failed.length ? ` ${failed.length} đơn lỗi.` : \\'\\');\\n });\\n // why: nội dung chiếu vào sd-inform thay cả tiêu đề lẫn nút hành động; lỗi từng đơn đi qua `description`.\\n protected readonly failures = computed(\\n () =>\\n this.result()\\n .failed.map(item => `${item.code}: ${item.message}`)\\n .join(\\' \\') || undefined\\n );\\n}\\n```\\n\\n## Quy tắc\\n\\n- MUST có một nút chính nổi bật; nút phụ dùng kiểu nhẹ hơn và thứ tự ổn định.\\n- MUST tối đa ba tác vụ cấp ngoài trong mỗi vùng; từ bốn tác vụ, giữ hai tác vụ ưu tiên và gom từ tác vụ thứ ba vào \"Thao tác khác\".\\n- MUST dùng \"Cập nhật <entity>\", không dùng \"Chỉnh sửa\" (E5); nút cập nhật có icon `edit`.\\n- MUST gắn `*sdPermission` cho từng tác vụ và cho menu; điều kiện trạng thái tính trong TS. Không có nhóm rỗng khi mọi tác vụ con bị ẩn.\\n- MUST hỏi xác nhận trước Xoá, Duyệt, Từ chối và mọi tác vụ đổi trạng thái, cả từng bản ghi lẫn hàng loạt; Từ chối và Huỷ bắt buộc lý do (E13).\\n- MUST báo kết quả hàng loạt theo từng bản ghi: \"Đã xác nhận 8/10. 2 đơn lỗi.\", giữ dòng lỗi đang chọn, có \"Thử lại phần lỗi\".\\n- MUST chặn bấm lặp khi tác vụ đang chạy (`disabled`, `loading`).\\n\\n## Lỗi hay gặp\\n\\n- Coi request hàng loạt trả 200 là thành công toàn bộ: API trả kết quả từng bản ghi, phải đọc.\\n- Bỏ chọn tất cả sau tác vụ hàng loạt: người dùng mất dấu các dòng lỗi.\\n- Tác vụ Cập nhật, Chi tiết trên dòng danh sách: mở chi tiết bằng link trên mã; cập nhật nằm ở chi tiết.\\n',\n 'docs/list.md': '# List\\n\\nDanh sách có bảng: `sd-page-list` + `sd-table`. Route mẫu: `/pattern/product` (đơn giản), `/pattern/order` (tab, score card, chọn nhiều, tác vụ hàng loạt), `/pattern/customer` (score card lọc), `/pattern/category` (bảng cây).\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng cho màn có một bảng chính: tìm, lọc, phân trang, mở chi tiết.\\n- Danh sách và chi tiết cần cạnh nhau để xử lý nhanh từng mục: dùng [split](split.md).\\n- Một bản ghi duy nhất (cài đặt): dùng [form](form.md), không dựng danh sách một dòng.\\n\\n## Code mẫu\\n\\nDanh sách đơn giản: quick search, filter dưới cột, mã là link theo quyền, header có menu Nhập/Xuất và Tạo mới.\\n\\n<!-- @source features/product/pages/list/list.component.html -->\\n```html\\n<sd-page-list title=\"Sản phẩm\" description=\"Danh mục sản phẩm đang kinh doanh.\">\\n <div headerRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <sd-button\\n *sdPermission=\"\\'PATTERN_PRODUCT_R_MENU\\'\"\\n title=\"Nhập/Xuất\"\\n suffixIcon=\"expand_more\"\\n type=\"outline\"\\n autoId=\"product-data-menu\">\\n <sd-button-item *sdPermission=\"\\'PATTERN_PRODUCT_C_IMPORT\\'\" prefixIcon=\"upload\" (click)=\"openImport()\">Nhập dữ liệu</sd-button-item>\\n <sd-button-item *sdPermission=\"\\'PATTERN_PRODUCT_R_EXPORT\\'\" prefixIcon=\"download\" (click)=\"exportData()\">Xuất dữ liệu</sd-button-item>\\n </sd-button>\\n <sd-button\\n *sdPermission=\"\\'PATTERN_PRODUCT_C_CREATE\\'\"\\n title=\"Tạo mới\"\\n prefixIcon=\"add\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"product-create\"\\n [routerLink]=\"[\\'create\\']\" />\\n </div>\\n\\n <sd-table autoId=\"product-list\" [option]=\"tableOption\">\\n <ng-template sdTableCellDef=\"code\" let-product=\"item\">\\n <a *sdPermission=\"\\'PATTERN_PRODUCT_R_DETAIL\\'\" [routerLink]=\"[product.id, \\'detail\\']\">{{ product.code }}</a>\\n @if (!canOpenDetail) {\\n <span>{{ product.code }}</span>\\n }\\n </ng-template>\\n </sd-table>\\n</sd-page-list>\\n```\\n\\n<!-- @source features/product/pages/list/list.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, effect, inject, untracked, viewChild } from \\'@angular/core\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton, SdButtonItem } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { SdPageList } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective, SdPermissionService } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport { PRODUCT_STATUS_OPTIONS, productStatusBadge, type ProductDto } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'list\\',\\n standalone: true,\\n templateUrl: \\'./list.component.html\\',\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [RouterLink, SdPageList, SdButton, SdButtonItem, SdTable, SdTableCellDefDirective, SdPermissionDirective],\\n})\\nexport class ListComponent {\\n readonly #productService = inject(ProductService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly pageList = viewChild.required(SdPageList);\\n private readonly table = viewChild.required(SdTable);\\n // Route guard đã nạp quyền trước khi tạo page; dùng cho text thay link khi thiếu quyền xem chi tiết.\\n protected readonly canOpenDetail = inject(SdPermissionService).hasPermission(\\'PATTERN_PRODUCT_R_DETAIL\\');\\n\\n protected readonly tableOption: SdTableOption<ProductDto> = {\\n type: \\'server\\',\\n items: (_, req) => firstValueFrom(this.#productService.list(req)),\\n sort: { enable: true },\\n filter: {\\n quickSearch: {\\n containFields: [\\'code\\', \\'name\\'],\\n placeholder: \\'Tìm theo mã hoặc tên sản phẩm\\',\\n },\\n },\\n columns: [\\n { field: \\'code\\', title: \\'Mã sản phẩm\\', type: \\'string\\', width: \\'160px\\', sortable: true },\\n { field: \\'name\\', title: \\'Tên sản phẩm\\', type: \\'string\\', minWidth: \\'240px\\', sortable: true },\\n { field: \\'unit\\', title: \\'Đơn vị tính\\', type: \\'string\\', width: \\'140px\\' },\\n { field: \\'price\\', title: \\'Giá bán (₫)\\', type: \\'number\\', width: \\'150px\\', align: \\'right\\', sortable: true },\\n {\\n field: \\'status\\',\\n title: \\'Trạng thái\\',\\n type: \\'values\\',\\n width: \\'180px\\',\\n option: { items: PRODUCT_STATUS_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: status => productStatusBadge(status),\\n },\\n ],\\n };\\n\\n constructor() {\\n // Lưu ở trang con xong rồi quay về: tải lại đúng trang, bộ lọc và vị trí cuộn đang có.\\n let seen = this.#productService.changes();\\n effect(() => {\\n const changes = this.#productService.changes();\\n if (this.pageList().childActive() || changes === seen) return;\\n seen = changes;\\n untracked(() => void this.table().reload(true, false));\\n });\\n }\\n\\n protected openImport(): void {\\n void this.#router.navigate([\\'../import\\'], { relativeTo: this.#route });\\n }\\n\\n protected exportData(): void {\\n this.table().exportExcel();\\n }\\n}\\n```\\n\\nChi tiết, tạo và cập nhật là route con của danh sách, nên quay lại vẫn giữ bộ lọc, trang và vị trí cuộn:\\n\\n<!-- @source features/product/routes.ts -->\\n```ts\\nimport type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { entityResolver } from \\'./entity.resolver\\';\\nimport { ProductService } from \\'./services/product.service\\';\\n\\n/** Detail, create và update là route con của danh sách: quay lại vẫn giữ bộ lọc, trang và vị trí cuộn. */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [ProductService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\'create\\',\\n title: \\'Tạo sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_C_CREATE\\' },\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/create/create.component\\').then(module => module.CreateComponent),\\n },\\n {\\n path: \\':id/detail\\',\\n title: \\'Chi tiết sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_R_DETAIL\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () => import(\\'./pages/detail/detail.component\\').then(module => module.DetailComponent),\\n },\\n {\\n path: \\':id/update\\',\\n title: \\'Cập nhật sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_U_UPDATE\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/update/update.component\\').then(module => module.UpdateComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n```\\n\\nTab, score card và request dùng chung một state; đổi trạng thái thì đọc lại từ trang 1:\\n\\n<!-- @source features/order/pages/list/list.component.html -->\\n```html\\n@let _settings = settings();\\n<sd-page-list title=\"Đơn hàng\" description=\"Đơn bán lẻ từ mọi kênh.\" [detail]=\"detailMode()\" [autoCompact]=\"_settings.autoCompact\">\\n <div headerRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <!-- Chỉ có ở /pattern. -->\\n <sd-pattern-settings-button />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_C_CREATE\\'\"\\n title=\"Tạo đơn hàng\"\\n prefixIcon=\"add\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"order-create\"\\n [routerLink]=\"[\\'create\\']\" />\\n </div>\\n\\n @if (_settings.tabs) {\\n <sd-tab-group sdSubheader [selectedIndex]=\"tabIndex()\" (selectedIndexChange)=\"selectTab($event)\">\\n @for (tab of tabs; track tab.label) {\\n <sd-tab [label]=\"tab.label\" [badge]=\"counts()?.[tab.status ?? \\'all\\']\" />\\n }\\n </sd-tab-group>\\n }\\n @if (_settings.score) {\\n <summary-cards [counts]=\"counts()\" [(status)]=\"status\" />\\n }\\n @if (bulkResult(); as result) {\\n <bulk-result [result]=\"result\" (retry)=\"retryFailed()\" (dismiss)=\"bulkResult.set(null)\" />\\n }\\n\\n <sd-table autoId=\"orders\" [option]=\"option()\">\\n <ng-template sdTableCellDef=\"code\" let-order=\"item\">\\n <a *sdPermission=\"\\'PATTERN_ORDER_R_DETAIL\\'\" [routerLink]=\"[order.id, \\'detail\\']\">{{ order.code }}</a>\\n @if (!canOpenDetail) {\\n <span>{{ order.code }}</span>\\n }\\n </ng-template>\\n </sd-table>\\n</sd-page-list>\\n```\\n\\n<!-- @source features/order/pages/list/list.component.ts#state -->\\n```ts\\n/** Một state cho tab, score card và request: đổi trạng thái thì đọc lại từ trang 1. */\\nprotected readonly status = signal<OrderStatus | null>(null);\\nprotected readonly tabIndex = computed(() => TABS.findIndex(tab => tab.status === this.status()));\\nprotected readonly counts = signal<OrderCounts | null>(null);\\n```\\n\\n## Quy tắc\\n\\n- MUST dùng `sd-page-list`; bảng chính là `sd-table` trực tiếp trong thân (hoặc phần tử gắn `sdPageListMain`). Không viết `h-full`, `overflow` hay chiều cao cho danh sách (E1).\\n- MUST mở chi tiết bằng link trên mã hoặc tên ở cột dữ liệu đầu tiên. Không có tác vụ Xem/Cập nhật trên dòng, trên thanh chọn nhiều hay ở header.\\n- MUST hiện mã dạng chữ khi thiếu quyền xem chi tiết; chuẩn bị cờ quyền trong TS (`hasPermission` sau khi guard đã nạp quyền), không gọi service quyền trong template.\\n- MUST đặt chi tiết, tạo, cập nhật là route con của danh sách; `detail=\"page\"` ẩn danh sách, `detail=\"drawer\"` giữ danh sách trên màn.\\n- MUST tải lại danh sách khi trang con đã lưu thành công (service đếm số lần thay đổi), không tải lại mỗi lần đóng.\\n- MUST giữ một chỗ lọc cho mỗi field (E6): field có cột lọc dưới cột; external filter chỉ chứa field không có cột; có tab trạng thái thì tắt filter dưới cột Trạng thái. Không bật quick search cùng external filter.\\n- MUST truyền nguyên `PagingReq` (tham số thứ hai của `items`) vào service; service chuyển sang định dạng của API.\\n- SHOULD giữ mặc định `hideInlineFilter: false`; màn ít dữ liệu dùng `\\'auto\\'`; không dùng `true` (E7).\\n- SHOULD gọi `reloadFirstPage()` của `sd-table` khi một điều kiện ngoài bảng (tab, score card) đổi; `reload()` giữ trang hiện tại.\\n\\n## Lỗi hay gặp\\n\\n- Bọc `sd-table` trong `div` có chiều cao cố định hoặc `overflow: auto`: sinh scrollbar thứ hai, paginator bị đẩy khỏi màn hình.\\n- Lọc trạng thái ở cả tab, score card và dưới cột: ba state lệch nhau, request không khớp thứ người dùng thấy.\\n- Đổi tab mà vẫn ở trang 3: danh sách rỗng dù có dữ liệu.\\n- Lấy dữ liệu của dòng làm chi tiết: dòng chỉ có vài field; chi tiết luôn tải bằng `detail(id)`.\\n',\n 'docs/relation.md': '# Relation\\n\\nHiện bản ghi liên quan theo ID bằng pipe `<entity>Detail` của feature sở hữu entity. Mẫu: `customerDetail` (điện thoại khách trên chi tiết đơn hàng), `productDetail` (tên sản phẩm trên dòng hàng).\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng khi bản ghi chỉ có ID của entity khác và màn cần tên, mã hay field khác của entity đó.\\n- Response đã có tên (chứng từ giữ snapshot tên khách lúc lập đơn): hiện snapshot, không tra lại tên hiện tại.\\n\\n## Code mẫu\\n\\n<!-- @source features/customer/pipes/customer-detail.pipe.ts -->\\n```ts\\nimport { inject, Pipe, type PipeTransform } from \\'@angular/core\\';\\nimport { of, type Observable } from \\'rxjs\\';\\nimport { CustomerService } from \\'../services/customer.service\\';\\nimport type { CustomerDto } from \\'../services/customer.model\\';\\n\\n/**\\n * Relation khách hàng theo ID: `@let customer = order.customerId | customerDetail | async;`.\\n * CustomerService cache và chia sẻ request theo ID; nơi dùng pipe phải có CustomerService trong injector.\\n */\\n@Pipe({ name: \\'customerDetail\\', standalone: true })\\nexport class CustomerDetailPipe implements PipeTransform {\\n readonly #customerService = inject(CustomerService);\\n\\n transform(id: CustomerDto[\\'id\\'] | null | undefined): Observable<CustomerDto | null> {\\n if (id === null || id === undefined || id === \\'\\') return of(null);\\n return this.#customerService.cachedDetail(id);\\n }\\n}\\n```\\n\\nService sở hữu cache và chia sẻ request theo ID; lỗi tra cứu không được cache:\\n\\n<!-- @source features/customer/services/customer.service.ts -->\\n```ts\\nimport { HttpParams } from \\'@angular/common/http\\';\\nimport { Injectable, signal } from \\'@angular/core\\';\\nimport { shareReplay, tap, type Observable } from \\'rxjs\\';\\nimport type { Filter, PagingRes } from \\'@sdcorejs/utils/models\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type {\\n CustomerCounts,\\n CustomerDebtDto,\\n CustomerDocumentDto,\\n CustomerDto,\\n CustomerListReq,\\n CustomerListRes,\\n CustomerOrderDto,\\n CustomerSaveReq,\\n} from \\'./customer.model\\';\\n\\n@Injectable()\\nexport class CustomerService extends BaseApiService {\\n readonly #details = new Map<string, Observable<CustomerDto>>();\\n readonly #changes = signal(0);\\n /** Tăng sau mỗi lần tạo, cập nhật hoặc xoá thành công: danh sách chỉ tải lại khi có thay đổi. */\\n readonly changes = this.#changes.asReadonly();\\n\\n list(req: CustomerListReq): Observable<CustomerListRes> {\\n return this.http.get<CustomerListRes>(this.apiUrl(\\'customers\\'), { params: this.buildPagingReq(req) });\\n }\\n\\n /** Số khách theo nhóm cho score card, theo cùng bộ lọc của danh sách. */\\n counts(filters: Filter<CustomerDto>[]): Observable<CustomerCounts> {\\n return this.http.get<CustomerCounts>(this.apiUrl(\\'customers\\', \\'counts\\'), {\\n params: new HttpParams().set(\\'filters\\', JSON.stringify(filters)),\\n });\\n }\\n\\n detail(id: string): Observable<CustomerDto> {\\n return this.http.get<CustomerDto>(this.apiUrl(\\'customers\\', id));\\n }\\n\\n /** `detail(id)` có cache, cho relation (`customerDetail`) và giá trị đã chọn của `customer-select`. */\\n cachedDetail(id: string): Observable<CustomerDto> {\\n let detail = this.#details.get(id);\\n if (!detail) {\\n detail = this.detail(id).pipe(shareReplay({ bufferSize: 1, refCount: false }));\\n this.#details.set(id, detail);\\n // Lỗi tra cứu không được cache: lần gọi sau hỏi lại.\\n detail.subscribe({ error: () => this.#details.delete(id) });\\n }\\n return detail;\\n }\\n\\n create(req: CustomerSaveReq): Observable<CustomerDto> {\\n return this.http.post<CustomerDto>(this.apiUrl(\\'customers\\'), req).pipe(tap(() => this.#changed()));\\n }\\n\\n update(id: string, req: CustomerSaveReq): Observable<CustomerDto> {\\n return this.http.put<CustomerDto>(this.apiUrl(\\'customers\\', id), req).pipe(tap(() => this.#changed(id)));\\n }\\n\\n delete(id: string): Observable<void> {\\n return this.http.delete<void>(this.apiUrl(\\'customers\\', id)).pipe(tap(() => this.#changed(id)));\\n }\\n\\n orders(id: string): Observable<PagingRes<CustomerOrderDto>> {\\n return this.http.get<PagingRes<CustomerOrderDto>>(this.apiUrl(\\'customers\\', id, \\'orders\\'));\\n }\\n\\n debts(id: string): Observable<PagingRes<CustomerDebtDto>> {\\n return this.http.get<PagingRes<CustomerDebtDto>>(this.apiUrl(\\'customers\\', id, \\'debts\\'));\\n }\\n\\n documents(id: string): Observable<PagingRes<CustomerDocumentDto>> {\\n return this.http.get<PagingRes<CustomerDocumentDto>>(this.apiUrl(\\'customers\\', id, \\'documents\\'));\\n }\\n\\n #changed(id?: string): void {\\n if (id) this.#details.delete(id);\\n this.#changes.update(count => count + 1);\\n }\\n}\\n```\\n\\nDùng trong template:\\n\\n<!-- @source features/order/components/lines-view/lines-view.component.ts -->\\n```ts\\nimport { AsyncPipe } from \\'@angular/common\\';\\nimport { ChangeDetectionStrategy, Component, computed, input } from \\'@angular/core\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { ProductDetailPipe } from \\'../../../product/pipes/product-detail.pipe\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\n\\n/** Dòng hàng chỉ đọc; tên sản phẩm lấy qua relation `productDetail`, không hiện ID thô. */\\n@Component({\\n selector: \\'lines-view\\',\\n standalone: true,\\n imports: [AsyncPipe, SdSection, SdTable, SdTableCellDefDirective, ProductDetailPipe],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Dòng hàng\">\\n <sd-table autoId=\"order-lines\" [option]=\"option()\">\\n <ng-template sdTableCellDef=\"productId\" let-line=\"item\">\\n @let product = line.productId | productDetail | async;\\n {{ product?.name ?? \\'…\\' }}\\n </ng-template>\\n </sd-table>\\n </sd-section>\\n `,\\n})\\nexport class LinesViewComponent {\\n readonly lines = input.required<readonly OrderLineDto[]>();\\n protected readonly option = computed<SdTableOption<OrderLineDto & { amount: number }>>(() => {\\n const items = this.lines().map(line => ({ ...line, amount: line.quantity * line.unitPrice }));\\n return {\\n type: \\'local\\',\\n items: () => items,\\n paginate: { pageSize: 50 },\\n filter: { hideInlineFilter: \\'auto\\' },\\n columns: [\\n { field: \\'productId\\', title: \\'Sản phẩm\\', type: \\'string\\', minWidth: \\'200px\\' },\\n { field: \\'quantity\\', title: \\'Số lượng\\', type: \\'number\\', width: \\'110px\\', align: \\'right\\' },\\n { field: \\'unitPrice\\', title: \\'Đơn giá (₫)\\', type: \\'number\\', width: \\'140px\\', align: \\'right\\' },\\n { field: \\'amount\\', title: \\'Thành tiền (₫)\\', type: \\'number\\', width: \\'150px\\', align: \\'right\\' },\\n ],\\n };\\n });\\n}\\n```\\n\\n## Quy tắc\\n\\n- MUST đặt pipe trong `pipes/<entity>-detail.pipe.ts` của feature sở hữu entity; tên template `<entity>Detail`, trả object có kiểu của entity, không trả chuỗi.\\n- MUST gọi service của đúng entity; pipe không tự gọi HTTP.\\n- MUST trả `null` không gọi API khi ID rỗng.\\n- MUST để service chia sẻ request theo ID; nhiều dòng cùng ID chỉ một request.\\n- MUST cấp service của entity ở route nơi pipe chạy.\\n- SHOULD hiện placeholder của Core (`sdEmpty`, `sd-view`) khi giá trị rỗng; không tự viết `--`.\\n\\n## Lỗi hay gặp\\n\\n- Gọi hàm tra tên trong template: chạy lại mỗi lần change detection, mỗi lần một request.\\n- Bắt lỗi tra cứu rồi trả `null` như thành công: người dùng thấy `--` thay vì biết là lỗi.\\n- Hiện ID thô thay cho tên.\\n',\n 'docs/select.md': '# Select\\n\\nChọn entity hoặc enum qua wrapper của feature sở hữu entity. Mẫu: `product-select` và `customer-select` (dòng đơn hàng, đầu đơn hàng), `product-status-select`, `customer-type-select`.\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng wrapper mỗi khi một màn chọn entity của feature khác, hoặc chọn một enum của entity.\\n- Danh sách lựa chọn cố định chỉ dùng một lần trong chính feature (kênh bán của đơn hàng): `sd-select` với hằng số trong `<entity>.model.ts` là đủ.\\n\\n## Code mẫu\\n\\nEntity: lựa chọn mới chỉ gồm bản ghi đang hoạt động (`SEARCH`); giá trị đã chọn tải theo ID (`VALUE`) nên bản ghi đã ngừng vẫn hiện khi cập nhật. Option hai dòng có avatar:\\n\\n<!-- @source features/customer/components/customer-select/customer-select.component.ts -->\\n```ts\\nimport { booleanAttribute, ChangeDetectionStrategy, Component, inject, input, model } from \\'@angular/core\\';\\nimport type { FormGroup } from \\'@angular/forms\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdAvatar } from \\'@sdcorejs/angular/components/avatar\\';\\nimport { SdItemDefDefDirective } from \\'@sdcorejs/angular/forms/directives\\';\\nimport type { SdSearchReq } from \\'@sdcorejs/angular/forms/models\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport type { Filter } from \\'@sdcorejs/utils/models\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerDto } from \\'../../services/customer.model\\';\\n\\n/**\\n * Chọn khách hàng cho màn khác (đơn hàng). Lựa chọn mới chỉ gồm khách đang hoạt động; giá trị đã chọn tải theo ID\\n * (`VALUE`) nên khách đã ngừng vẫn hiện khi cập nhật. Option hai dòng có avatar: tên · mã · điện thoại.\\n */\\n@Component({\\n selector: \\'customer-select\\',\\n standalone: true,\\n imports: [SdSelect, SdItemDefDefDirective, SdAvatar],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-select\\n [label]=\"label()\"\\n [name]=\"name()\"\\n [form]=\"form()\"\\n [(model)]=\"model\"\\n [items]=\"search\"\\n valueField=\"id\"\\n displayField=\"name\"\\n [required]=\"required()\"\\n [autoId]=\"autoId()\">\\n <ng-template sdItemDef let-item=\"item\">\\n <div class=\"d-flex align-items-center gap-8\">\\n <sd-avatar [src]=\"null\" [name]=\"item.name\" [size]=\"28\" />\\n <div class=\"d-flex flex-column\">\\n <span>{{ item.name }}</span>\\n <small class=\"text-secondary\"\\n >{{ item.code }} · {{ item.phone }}{{ item.status === \\'inactive\\' ? \\' · Ngừng hoạt động\\' : \\'\\' }}</small\\n >\\n </div>\\n </div>\\n </ng-template>\\n </sd-select>`,\\n})\\nexport class CustomerSelectComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly form = input<FormGroup>();\\n readonly name = input(\\'customerId\\');\\n readonly label = input<string | undefined>(\\'Khách hàng\\');\\n readonly required = input(false, { transform: booleanAttribute });\\n readonly autoId = input<string>();\\n readonly model = model<string | null | undefined>();\\n\\n protected readonly search = async (req: SdSearchReq): Promise<CustomerDto[]> => {\\n if (req.type === \\'VALUE\\') {\\n const ids = (Array.isArray(req.value) ? req.value : [req.value]).filter((id): id is string => !!id);\\n return Promise.all(ids.map(id => firstValueFrom(this.#customerService.cachedDetail(id))));\\n }\\n const filters: Filter<CustomerDto>[] = [{ field: \\'status\\', operator: \\'EQUAL\\', data: \\'active\\' }];\\n if (req.searchText) {\\n filters.push({\\n operator: \\'OR\\',\\n data: [\\n { field: \\'name\\', operator: \\'CONTAIN\\', data: req.searchText },\\n { field: \\'code\\', operator: \\'CONTAIN\\', data: req.searchText },\\n { field: \\'phone\\', operator: \\'CONTAIN\\', data: req.searchText },\\n ],\\n });\\n }\\n const res = await firstValueFrom(this.#customerService.list({ pageNumber: 0, pageSize: 20, filters }));\\n return res.items;\\n };\\n}\\n```\\n\\n<!-- @source features/product/components/product-select/product-select.component.ts -->\\n```ts\\nimport { booleanAttribute, ChangeDetectionStrategy, Component, inject, input, model } from \\'@angular/core\\';\\nimport type { FormGroup } from \\'@angular/forms\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdItemDefDefDirective } from \\'@sdcorejs/angular/forms/directives\\';\\nimport type { SdSearchReq } from \\'@sdcorejs/angular/forms/models\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport type { Filter, Size } from \\'@sdcorejs/utils/models\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport type { ProductDto } from \\'../../services/product.model\\';\\n\\n/**\\n * Chọn sản phẩm cho màn khác (dòng đơn hàng). Lựa chọn mới chỉ gồm sản phẩm đang hoạt động; giá trị đã chọn\\n * được tải theo ID (`VALUE`) nên sản phẩm đã ngừng vẫn hiển thị khi cập nhật. Option hai dòng: tên · mã · đơn vị.\\n * `size`, `hideInlineError` và `inlineError` chuyển thẳng xuống `sd-select`, để dùng được trong ô của bảng.\\n */\\n@Component({\\n selector: \\'product-select\\',\\n standalone: true,\\n imports: [SdSelect, SdItemDefDefDirective],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-select\\n [label]=\"label()\"\\n [name]=\"name()\"\\n [form]=\"form()\"\\n [(model)]=\"model\"\\n [items]=\"search\"\\n valueField=\"id\"\\n displayField=\"name\"\\n [required]=\"required()\"\\n [size]=\"size()\"\\n [hideInlineError]=\"hideInlineError()\"\\n [inlineError]=\"inlineError()\"\\n [autoId]=\"autoId()\">\\n <ng-template sdItemDef let-item=\"item\">\\n <div class=\"d-flex flex-column\">\\n <span>{{ item.name }}</span>\\n <small class=\"text-secondary\">{{ item.code }} · {{ item.unit }}{{ item.status === \\'inactive\\' ? \\' · Ngừng hoạt động\\' : \\'\\' }}</small>\\n </div>\\n </ng-template>\\n </sd-select>`,\\n})\\nexport class ProductSelectComponent {\\n readonly #productService = inject(ProductService);\\n readonly form = input<FormGroup>();\\n readonly name = input(\\'productId\\');\\n readonly label = input<string | undefined>(\\'Sản phẩm\\');\\n readonly required = input(false, { transform: booleanAttribute });\\n readonly size = input<Size>(\\'md\\');\\n readonly hideInlineError = input(false, { transform: booleanAttribute });\\n /** Lỗi của API cho field này (vd `lines.0.productId`). */\\n readonly inlineError = input<string>();\\n readonly autoId = input<string>();\\n readonly model = model<string | null | undefined>();\\n\\n protected readonly search = async (req: SdSearchReq): Promise<ProductDto[]> => {\\n if (req.type === \\'VALUE\\') {\\n const ids = (Array.isArray(req.value) ? req.value : [req.value]).filter((id): id is string => !!id);\\n return Promise.all(ids.map(id => firstValueFrom(this.#productService.cachedDetail(id))));\\n }\\n const filters: Filter<ProductDto>[] = [{ field: \\'status\\', operator: \\'EQUAL\\', data: \\'active\\' }];\\n if (req.searchText) {\\n filters.push({\\n operator: \\'OR\\',\\n data: [\\n { field: \\'name\\', operator: \\'CONTAIN\\', data: req.searchText },\\n { field: \\'code\\', operator: \\'CONTAIN\\', data: req.searchText },\\n ],\\n });\\n }\\n const res = await firstValueFrom(this.#productService.list({ pageNumber: 0, pageSize: 20, filters }));\\n return res.items;\\n };\\n}\\n```\\n\\nEnum: options và label thuộc model của feature:\\n\\n<!-- @source features/product/components/product-status-select/product-status-select.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, input, model } from \\'@angular/core\\';\\nimport type { FormGroup } from \\'@angular/forms\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport { PRODUCT_STATUS_OPTIONS, type ProductStatus } from \\'../../services/product.model\\';\\n\\n/** Dropdown trạng thái sản phẩm: options và label thuộc feature, nơi dùng chỉ bind model/form. */\\n@Component({\\n selector: \\'product-status-select\\',\\n standalone: true,\\n imports: [SdSelect],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-select\\n [label]=\"label()\"\\n [name]=\"name()\"\\n [form]=\"form()\"\\n [(model)]=\"model\"\\n [items]=\"options\"\\n valueField=\"id\"\\n displayField=\"name\"\\n [required]=\"required()\"\\n [clearable]=\"false\" />`,\\n})\\nexport class ProductStatusSelectComponent {\\n readonly form = input<FormGroup>();\\n readonly name = input(\\'status\\');\\n readonly label = input(\\'Trạng thái\\');\\n readonly required = input(true);\\n readonly model = model<ProductStatus | null | undefined>();\\n protected readonly options = PRODUCT_STATUS_OPTIONS;\\n}\\n```\\n\\n## Quy tắc\\n\\n- MUST đặt wrapper trong `components/` của feature sở hữu entity; màn dùng nó (đơn hàng) không tự gọi API của entity khác, không khai báo lại `items`, `valueField`, `displayField`.\\n- MUST tách lựa chọn mới (`SEARCH`, có điều kiện như đang hoạt động) với giá trị đã chọn (`VALUE`, tải theo ID kể cả bản ghi đã ngừng).\\n- MUST cấp service của entity ở route của màn dùng wrapper (`providers` của route đơn hàng có `CustomerService`, `ProductService`).\\n- MUST giữ option tối đa hai dòng: dòng đầu là tên, dòng hai là mã và thông tin phân biệt; trong bảng nhập liệu, giá trị đã chọn chỉ hiện gọn trong ô.\\n- SHOULD mở input của wrapper chỉ cho thứ nơi dùng cần (`form`, `name`, `model`, `required`, `label`).\\n\\n## Lỗi hay gặp\\n\\n- Lọc bản ghi đang hoạt động ở client cho cả giá trị đã chọn: đơn của khách đã ngừng mở ra ô trống.\\n- Gọi `detail(id)` cho từng option: dùng kết quả tìm kiếm cho danh sách, chỉ tải theo ID cho giá trị đã chọn.\\n',\n 'docs/split.md': '# Split\\n\\nDanh sách và chi tiết cạnh nhau để xử lý nhanh từng mục: `sd-page-list detail=\"none\"` + `sd-splitter` + route con `:id` trong panel phải. Route mẫu: `/pattern/approval`, `/pattern/approval/:id`.\\n\\n## Khi nào dùng / khi nào không\\n\\n- Dùng cho hộp xử lý: người dùng đi qua từng mục, duyệt hoặc từ chối, rồi sang mục kế.\\n- Xem chi tiết thỉnh thoảng: dùng [drawer](drawer.md) hoặc [detail](detail.md).\\n\\n## Code mẫu\\n\\n<!-- @source features/approval/pages/list/list.component.html -->\\n```html\\n<sd-page-list title=\"Phê duyệt\" description=\"Đề nghị thanh toán chờ xử lý. Dùng ↑ ↓ để chuyển mục.\" detail=\"none\">\\n <div sdPageListMain class=\"approval\" [class.approval--narrow]=\"narrow()\" [class.approval--active]=\"active()\">\\n <sd-splitter [option]=\"splitter\">\\n <!-- Kéo trong khoảng 360–760px; panel chi tiết nhận phần còn lại (unit flex: minSize là trọng số, không phải px). -->\\n <sd-splitter-panel class=\"approval__list\" panelId=\"list\" [size]=\"520\" unit=\"px\" [minSize]=\"360\" [maxSize]=\"760\">\\n <sd-table autoId=\"approval-list\" [option]=\"option\">\\n <ng-template sdTableCellDef=\"code\" let-item=\"item\">\\n <a [routerLink]=\"[item.id]\" [attr.aria-current]=\"item.id === selectedId() ? \\'true\\' : null\">{{ item.code }}</a>\\n </ng-template>\\n </sd-table>\\n </sd-splitter-panel>\\n <sd-splitter-panel class=\"approval__detail\" panelId=\"detail\" [size]=\"1\">\\n <router-outlet (activate)=\"active.set(true)\" (deactivate)=\"active.set(false)\" />\\n @if (!active()) {\\n <sd-data-state state=\"empty\" icon=\"inbox\" title=\"Chọn một mục\" message=\"Chọn một đề nghị bên trái để xem chi tiết và xử lý.\" />\\n }\\n </sd-splitter-panel>\\n </sd-splitter>\\n </div>\\n</sd-page-list>\\n```\\n\\n<!-- @source features/approval/pages/list/list.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, DestroyRef, effect, forwardRef, inject, signal, untracked, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet } from \\'@angular/router\\';\\nimport { filter, firstValueFrom, map, startWith } from \\'rxjs\\';\\nimport { SdDataState } from \\'@sdcorejs/angular/components/data-state\\';\\nimport { SdSplitterComponent, SdSplitterPanelComponent, type SdSplitterOption } from \\'@sdcorejs/angular/components/splitter\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { SdPageList } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { ApprovalService } from \\'../../services/approval.service\\';\\nimport { APPROVAL_STATUS_OPTIONS, approvalStatusBadge, type ApprovalDto } from \\'../../services/approval.model\\';\\nimport { ApprovalInbox } from \\'./approval-inbox\\';\\n\\n/** Dưới bề rộng này chi tiết thay hẳn danh sách, có nút quay lại. */\\nconst NARROW = \\'(max-width: 767.98px)\\';\\n\\n/**\\n * Hộp duyệt (pattern split): danh sách bên trái, chi tiết là route con `:id` trong panel phải. ↑ ↓ chuyển mục;\\n * duyệt hoặc từ chối xong panel chi tiết tự chọn mục kế, bộ lọc và vị trí cuộn của danh sách giữ nguyên.\\n */\\n@Component({\\n selector: \\'list\\',\\n standalone: true,\\n templateUrl: \\'./list.component.html\\',\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n // Phím ↑ ↓ nổi lên từ dòng hay nút đang focus trong danh sách hoặc panel chi tiết.\\n host: { \\'(keydown)\\': \\'move($event)\\' },\\n imports: [\\n RouterLink,\\n RouterOutlet,\\n SdPageList,\\n SdSplitterComponent,\\n SdSplitterPanelComponent,\\n SdTable,\\n SdTableCellDefDirective,\\n SdDataState,\\n ],\\n providers: [{ provide: ApprovalInbox, useExisting: forwardRef(() => ListComponent) }],\\n styles: `\\n .approval > sd-splitter {\\n flex: 1 1 0;\\n min-height: 0;\\n }\\n .approval sd-splitter-panel {\\n display: flex;\\n flex-direction: column;\\n }\\n .approval__list {\\n background: var(--sd-surface, #ffffff);\\n border: 1px solid var(--sd-border, #e3e5ea);\\n border-radius: 8px;\\n }\\n .approval__list > sd-table {\\n flex: 1 1 0;\\n min-height: 0;\\n }\\n .approval__detail {\\n overflow-y: auto;\\n }\\n .approval--narrow.approval--active sd-splitter-panel:first-child,\\n .approval--narrow:not(.approval--active) sd-splitter-panel:last-of-type {\\n display: none;\\n }\\n `,\\n})\\nexport class ListComponent extends ApprovalInbox {\\n readonly #approvalService = inject(ApprovalService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly table = viewChild.required(SdTable);\\n protected readonly active = signal(false);\\n protected readonly narrow = signal(false);\\n /** ID đang mở ở panel phải, đọc từ route con. */\\n protected readonly selectedId = toSignal(\\n this.#router.events.pipe(\\n filter(event => event instanceof NavigationEnd),\\n startWith(null),\\n map(() => this.#route.firstChild?.snapshot.paramMap.get(\\'id\\') ?? null)\\n ),\\n { requireSync: true }\\n );\\n protected readonly splitter: SdSplitterOption = { storageKey: \\'sd-pattern.approval.splitter\\' };\\n protected readonly option: SdTableOption<ApprovalDto> = {\\n type: \\'server\\',\\n rowKey: \\'id\\',\\n items: (_, req) => firstValueFrom(this.#approvalService.list(req)),\\n filter: {\\n quickSearch: { containFields: [\\'code\\', \\'title\\', \\'requester\\'], placeholder: \\'Tìm theo mã, nội dung, người đề nghị\\' },\\n },\\n paginate: { pageSize: 20, pages: [20, 50] },\\n columns: [\\n { field: \\'code\\', title: \\'Mã\\', type: \\'string\\', width: \\'96px\\' },\\n { field: \\'title\\', title: \\'Nội dung\\', type: \\'string\\', minWidth: \\'140px\\' },\\n { field: \\'amount\\', title: \\'Số tiền (₫)\\', type: \\'number\\', width: \\'120px\\', align: \\'right\\' },\\n {\\n field: \\'status\\',\\n title: \\'Trạng thái\\',\\n type: \\'values\\',\\n width: \\'128px\\',\\n option: { items: APPROVAL_STATUS_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: status => approvalStatusBadge(status),\\n // Hộp duyệt mở sẵn các đề nghị đang chờ; đổi bộ lọc để xem đề nghị đã xử lý.\\n filter: { default: \\'pending\\' },\\n },\\n ],\\n style: {\\n rowCss: (row): Record<string, string> => (row.id === this.selectedId() ? { background: \\'var(--sd-primary-light)\\' } : {}),\\n },\\n };\\n\\n constructor() {\\n super();\\n // Dòng đang mở được tô nền: vẽ lại bảng khi chọn mục khác.\\n effect(() => {\\n this.selectedId();\\n untracked(() => this.table().detectChanges());\\n });\\n const media = typeof matchMedia === \\'function\\' ? matchMedia(NARROW) : null;\\n if (media) {\\n this.narrow.set(media.matches);\\n const onChange = (event: MediaQueryListEvent): void => this.narrow.set(event.matches);\\n media.addEventListener(\\'change\\', onChange);\\n inject(DestroyRef).onDestroy(() => media.removeEventListener(\\'change\\', onChange));\\n }\\n }\\n\\n nextOf(id: string): string | null {\\n const rows = this.table().dataItems;\\n const index = rows.findIndex(row => row.id === id);\\n if (index < 0) return rows[0]?.id ?? null;\\n return rows[index + 1]?.id ?? rows[index - 1]?.id ?? null;\\n }\\n\\n async refresh(): Promise<void> {\\n await this.table().reload(true, false);\\n }\\n\\n /** ↑ ↓ chuyển sang dòng trước/sau; bỏ qua khi đang gõ trong ô nhập. */\\n protected move(event: KeyboardEvent): void {\\n if (event.key !== \\'ArrowDown\\' && event.key !== \\'ArrowUp\\') return;\\n const target = event.target as HTMLElement | null;\\n if (target?.closest(\\'input, textarea, select, [contenteditable=\"true\"], mat-select, [role=\"separator\"]\\')) return;\\n const rows = this.table().dataItems;\\n if (!rows.length) return;\\n const index = rows.findIndex(row => row.id === this.selectedId());\\n const next = rows[Math.min(rows.length - 1, Math.max(0, index < 0 ? 0 : index + (event.key === \\'ArrowDown\\' ? 1 : -1)))];\\n event.preventDefault();\\n if (next.id !== this.selectedId()) void this.#router.navigate([next.id], { relativeTo: this.#route });\\n }\\n}\\n```\\n\\nPanel chi tiết: xử lý xong thì tự mở mục kế trong danh sách đang lọc:\\n\\n<!-- @source features/approval/pages/detail/detail.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, computed, inject, linkedSignal, signal } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdBadge } from \\'@sdcorejs/angular/components/badge\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdEmptyPipe, SdFormatDatetimePipe, SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { ApprovalService } from \\'../../services/approval.service\\';\\nimport { approvalStatusBadge, type ApprovalDto } from \\'../../services/approval.model\\';\\nimport { ApprovalInbox } from \\'../list/approval-inbox\\';\\n\\n/** Chi tiết một đề nghị trong panel phải của hộp duyệt (route con `:id`). */\\n@Component({\\n selector: \\'detail\\',\\n standalone: true,\\n imports: [\\n RouterLink,\\n SdBadge,\\n SdButton,\\n SdSection,\\n SdSectionItem,\\n SdPermissionDirective,\\n SdEmptyPipe,\\n SdFormatDatetimePipe,\\n SdFormatNumberPipe,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let item = entity();\\n <article class=\"d-flex flex-column gap-16 p-16\" [attr.aria-label]=\"\\'Đề nghị \\' + item.code\">\\n <header class=\"d-flex align-items-start justify-content-between gap-16 flex-wrap\">\\n <div class=\"d-flex flex-column gap-4\">\\n <!-- Màn hẹp: chi tiết thay danh sách, quay lại bằng liên kết này. -->\\n <a class=\"approval-back\" [routerLink]=\"[\\'..\\']\">← Danh sách</a>\\n <div class=\"d-flex align-items-center gap-8\">\\n <h2 class=\"T18M m-0\">{{ item.code }} · {{ item.title }}</h2>\\n <sd-badge size=\"md\" type=\"round\" [title]=\"badge().title\" [color]=\"badge().color\" />\\n </div>\\n <span class=\"T14R text-secondary\">{{ item.requester }} · {{ item.department }}</span>\\n </div>\\n @if (item.status === \\'pending\\') {\\n <div class=\"d-flex align-items-center gap-8\">\\n <sd-button\\n *sdPermission=\"\\'PATTERN_APPROVAL_U_REJECT\\'\"\\n title=\"Từ chối\"\\n prefixIcon=\"close\"\\n type=\"light\"\\n color=\"warning\"\\n autoId=\"approval-reject\"\\n [disabled]=\"pending()\"\\n (click)=\"decide(\\'reject\\')\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_APPROVAL_U_APPROVE\\'\"\\n title=\"Duyệt\"\\n prefixIcon=\"check\"\\n type=\"fill\"\\n color=\"success\"\\n autoId=\"approval-approve\"\\n [disabled]=\"pending()\"\\n (click)=\"decide(\\'approve\\')\" />\\n </div>\\n }\\n </header>\\n <sd-section title=\"Thông tin đề nghị\">\\n <sd-section-item label=\"Số tiền (₫)\">{{ item.amount | sdFormatNumber: 0 }}</sd-section-item>\\n <sd-section-item label=\"Ngày gửi\">{{ item.submittedAt | sdFormatDatetime }}</sd-section-item>\\n <sd-section-item label=\"Ghi chú\">{{ item.note | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Lý do từ chối\">{{ item.reason | sdEmpty }}</sd-section-item>\\n </sd-section>\\n </article>\\n `,\\n styles: `\\n .approval-back {\\n display: none;\\n font-size: 13px;\\n }\\n @media (max-width: 767.98px) {\\n .approval-back {\\n display: inline;\\n }\\n }\\n `,\\n})\\nexport class DetailComponent {\\n readonly #approvalService = inject(ApprovalService);\\n readonly #inbox = inject(ApprovalInbox);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #resolved = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as ApprovalDto)), { requireSync: true });\\n protected readonly entity = linkedSignal(() => this.#resolved());\\n protected readonly badge = computed(() => approvalStatusBadge(this.entity().status));\\n protected readonly pending = signal(false);\\n\\n /** Hỏi xác nhận (Từ chối kèm lý do), xử lý, rồi tự mở mục kế trong danh sách đang lọc. */\\n protected async decide(action: \\'approve\\' | \\'reject\\'): Promise<void> {\\n const item = this.entity();\\n let reason: string | undefined;\\n try {\\n if (action === \\'reject\\') {\\n reason = await this.#confirm.withInput(`Từ chối ${item.code}. Lý do được gửi cho ${item.requester}.`, {\\n title: \\'Từ chối đề nghị\\',\\n label: \\'Lý do từ chối\\',\\n required: true,\\n maxlength: 200,\\n yesTitle: \\'Từ chối\\',\\n noTitle: \\'Không\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } else {\\n await this.#confirm.confirm(`Duyệt ${item.code}: ${item.title}?`, { title: \\'Duyệt đề nghị\\', yesTitle: \\'Duyệt\\', noTitle: \\'Không\\' });\\n }\\n } catch {\\n return;\\n }\\n this.pending.set(true);\\n try {\\n const next = this.#inbox.nextOf(item.id);\\n this.entity.set(\\n await firstValueFrom(\\n action === \\'approve\\' ? this.#approvalService.approve({ id: item.id }) : this.#approvalService.reject({ id: item.id, reason })\\n )\\n );\\n this.#notify.success(action === \\'approve\\' ? `Đã duyệt ${item.code}.` : `Đã từ chối ${item.code}.`);\\n await this.#inbox.refresh();\\n await this.#router.navigate(next ? [\\'..\\', next] : [\\'..\\'], { relativeTo: this.#route });\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error));\\n } finally {\\n this.pending.set(false);\\n }\\n }\\n}\\n```\\n\\n## Quy tắc\\n\\n- MUST dùng `detail=\"none\"`: `sd-page-list` không đặt router-outlet, màn đặt outlet trong panel phải. Bọc `sd-splitter` trong phần tử `sdPageListMain` để vùng chia đôi lấp phần còn lại của trang.\\n- MUST hiện trạng thái trống (\"Chọn một mục\") khi chưa mở mục nào.\\n- MUST cho ↑ ↓ chuyển mục khi focus không ở ô nhập; tô nền dòng đang mở.\\n- MUST giữ bộ lọc, trang và vị trí cuộn khi chuyển mục và sau khi xử lý; tải lại bằng `reload(true, false)`.\\n- MUST cho panel danh sách bề rộng px (`unit=\"px\"`) với `minSize`/`maxSize` px, panel chi tiết `unit=\"flex\"` nhận phần còn lại; đặt `display: flex; flex-direction: column` cho panel để bảng lấp chiều cao và paginator luôn hiện.\\n- SHOULD lưu bề rộng panel (`storageKey` của `sd-splitter`).\\n- SHOULD dưới 768px cho chi tiết thay hẳn danh sách, có liên kết quay lại.\\n\\n## Lỗi hay gặp\\n\\n- Để `sd-page-list` mặc định (`detail=\"page\"`): route con hiện thay chỗ cả danh sách, không còn cạnh nhau.\\n- Đặt `sdPageListMain` trực tiếp lên `sd-splitter`: kiểu cột của vùng chính đè hướng ngang của splitter.\\n- Đặt `[minSize]=\"360\"` lên panel `unit=\"flex\"` để giữ chỗ cho chi tiết: với panel flex, `minSize` là trọng số chứ không phải px, nên handle không kéo được. Giới hạn bằng `maxSize` px của panel danh sách.\\n- Để panel ở `display: block` mặc định: bảng ở chế độ fill không co theo panel, dòng cuối và paginator bị cắt.\\n- Chọn mục kế sau khi đã tải lại danh sách: mục vừa xử lý đã biến mất khỏi bộ lọc, vị trí kế bị lệch. Lấy mục kế trước khi tải lại.\\n',\n 'docs/states.md': '# States\\n\\nĐang tải, rỗng, lỗi và thiếu quyền. Thanh công cụ của `/pattern` đổi độ trễ, lỗi giả lập (500, timeout, 404, 403) và vai trò để xem từng trạng thái trên mọi route; drawer \"Tuỳ chỉnh hiển thị\" của `/pattern/order` ép trạng thái đọc của danh sách.\\n\\n## Khi nào dùng / khi nào không\\n\\n- Mọi vùng tải dữ liệu đều có trạng thái đang tải, rỗng và lỗi riêng.\\n- Bảng `sd-table` đã tự có ba trạng thái này: không bọc thêm.\\n\\n## Code mẫu\\n\\nTab tự tải, trạng thái riêng bằng `sd-data-state`:\\n\\n<!-- @source features/customer/components/documents-view/documents-view.component.ts -->\\n```ts\\nimport { ChangeDetectionStrategy, Component, inject, input, OnInit, signal } from \\'@angular/core\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdDataState } from \\'@sdcorejs/angular/components/data-state\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerDocumentDto } from \\'../../services/customer.model\\';\\n\\n/** Tab Tài liệu của hồ sơ 360°: danh sách ngắn, trạng thái riêng bằng `sd-data-state`. */\\n@Component({\\n selector: \\'documents-view\\',\\n standalone: true,\\n imports: [SdDataState, SdSection, SdSectionItem, SdFormatNumberPipe],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-data-state\\n [state]=\"state()\"\\n retryable\\n title=\"\"\\n [message]=\"state() === \\'empty\\' ? \\'Khách hàng chưa có tài liệu.\\' : undefined\"\\n (sdRetry)=\"load()\">\\n <sd-section title=\"Tài liệu\">\\n @for (document of documents(); track document.id) {\\n <sd-section-item [label]=\"document.name\">{{ document.size / 1024 | sdFormatNumber: 0 }} KB</sd-section-item>\\n }\\n </sd-section>\\n </sd-data-state>\\n `,\\n})\\nexport class DocumentsViewComponent implements OnInit {\\n readonly #customerService = inject(CustomerService);\\n readonly customerId = input.required<string>();\\n protected readonly state = signal<\\'loading\\' | \\'empty\\' | \\'error\\' | \\'success\\'>(\\'loading\\');\\n protected readonly documents = signal<readonly CustomerDocumentDto[]>([]);\\n\\n ngOnInit(): void {\\n void this.load();\\n }\\n\\n protected async load(): Promise<void> {\\n this.state.set(\\'loading\\');\\n try {\\n const res = await firstValueFrom(this.#customerService.documents(this.customerId()));\\n this.documents.set(res.items);\\n this.state.set(res.items.length ? \\'success\\' : \\'empty\\');\\n } catch {\\n this.state.set(\\'error\\');\\n }\\n }\\n}\\n```\\n\\nLỗi trước khi mở trang thuộc resolver; host chuyển 404, 403, lỗi mạng sang trang lỗi của mình:\\n\\n<!-- @source features/customer/entity.resolver.ts -->\\n```ts\\nimport { HttpErrorResponse } from \\'@angular/common/http\\';\\nimport { inject } from \\'@angular/core\\';\\nimport type { ResolveFn } from \\'@angular/router\\';\\nimport { map, timeout } from \\'rxjs\\';\\nimport { CustomerService } from \\'./services/customer.service\\';\\nimport type { CustomerDto } from \\'./services/customer.model\\';\\n\\n/** Tải khách hàng bằng `detail(id)` trước khi mở drawer/trang; lỗi đi tới navigation error handler của host. */\\nexport const entityResolver: ResolveFn<CustomerDto> = route => {\\n const id = route.paramMap.get(\\'id\\');\\n if (!id?.trim()) throw new HttpErrorResponse({ status: 404 });\\n return inject(CustomerService)\\n .detail(id)\\n .pipe(\\n timeout(10_000),\\n map(entity => {\\n if (!entity || entity.id !== id) throw new HttpErrorResponse({ status: 404 });\\n return entity;\\n })\\n );\\n};\\n```\\n\\nQuyền vào route bằng `canActivateChild: [SdPermissionGuard]` và `data.permission` trên từng route:\\n\\n<!-- @source features/order/routes.ts -->\\n```ts\\nimport type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { CustomerService } from \\'../customer/services/customer.service\\';\\nimport { ProductService } from \\'../product/services/product.service\\';\\nimport { entityResolver, updatableEntityResolver } from \\'./entity.resolver\\';\\nimport { OrderService } from \\'./services/order.service\\';\\n\\n/**\\n * Chi tiết là route con của danh sách (drawer hoặc trang theo `detail`); tạo và cập nhật là trang thay chỗ danh sách\\n * (`data.detail: \\'page\\'`). CustomerService và ProductService được cấp ở đây cho `customer-select`, `product-select`\\n * và các pipe relation: đơn hàng dùng wrapper của feature sở hữu entity, không tự gọi API của entity khác.\\n */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [OrderService, CustomerService, ProductService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\'create\\',\\n title: \\'Tạo mới đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_C_CREATE\\', detail: \\'page\\' },\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/create/create.component\\').then(module => module.CreateComponent),\\n },\\n {\\n path: \\':id/detail\\',\\n title: \\'Chi tiết đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_R_DETAIL\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () => import(\\'./pages/detail/detail.component\\').then(module => module.DetailComponent),\\n },\\n {\\n path: \\':id/update\\',\\n title: \\'Cập nhật đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_U_UPDATE\\', detail: \\'page\\' },\\n resolve: { entity: updatableEntityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/update/update.component\\').then(module => module.UpdateComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n```\\n\\n## Quy tắc\\n\\n- MUST để lỗi tải bản ghi bắt buộc đi qua resolver tới navigation error handler của host; không mở trang rồi mới báo lỗi.\\n- MUST khai báo `data.permission` cho mọi route con; guard từ chối route quên khai báo.\\n- MUST giữ các vùng phụ (tab của hồ sơ, relation) có trạng thái riêng; lỗi một vùng không làm hỏng cả trang.\\n- MUST không biến lỗi thành dữ liệu rỗng thành công; có nút thử lại khi lỗi có thể hết.\\n- MUST giữ dữ liệu người dùng đã nhập khi lưu lỗi (500, timeout).\\n- SHOULD dùng `sd-data-state` cho vùng không phải bảng; `retryable` khi thử lại có ý nghĩa.\\n\\n## Lỗi hay gặp\\n\\n- Bắt lỗi API rồi trả mảng rỗng: người dùng thấy \"Không có dữ liệu\" khi máy chủ đang lỗi.\\n- Chỉ ẩn nút theo quyền mà không chặn route: mở URL trực tiếp vẫn vào được.\\n- Đổi vai trò mà không chạy lại guard: nút theo quyền cũ còn trên màn. `*sdPermission` đọc quyền lúc tạo, nên màn phải mở lại.\\n',\n 'features/approval/entity.resolver.ts': 'import { HttpErrorResponse } from \\'@angular/common/http\\';\\nimport { inject } from \\'@angular/core\\';\\nimport type { ResolveFn } from \\'@angular/router\\';\\nimport { map, timeout } from \\'rxjs\\';\\nimport { ApprovalService } from \\'./services/approval.service\\';\\nimport type { ApprovalDto } from \\'./services/approval.model\\';\\n\\n/** Tải đề nghị bằng `detail(id)` trước khi mở panel chi tiết; lỗi đi tới navigation error handler của host. */\\nexport const entityResolver: ResolveFn<ApprovalDto> = route => {\\n const id = route.paramMap.get(\\'id\\');\\n if (!id?.trim()) throw new HttpErrorResponse({ status: 404 });\\n return inject(ApprovalService)\\n .detail(id)\\n .pipe(\\n timeout(10_000),\\n map(entity => {\\n if (!entity || entity.id !== id) throw new HttpErrorResponse({ status: 404 });\\n return entity;\\n })\\n );\\n};\\n',\n 'features/approval/pages/detail/detail.component.ts': 'import { ChangeDetectionStrategy, Component, computed, inject, linkedSignal, signal } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdBadge } from \\'@sdcorejs/angular/components/badge\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdEmptyPipe, SdFormatDatetimePipe, SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { ApprovalService } from \\'../../services/approval.service\\';\\nimport { approvalStatusBadge, type ApprovalDto } from \\'../../services/approval.model\\';\\nimport { ApprovalInbox } from \\'../list/approval-inbox\\';\\n\\n/** Chi tiết một đề nghị trong panel phải của hộp duyệt (route con `:id`). */\\n@Component({\\n selector: \\'detail\\',\\n standalone: true,\\n imports: [\\n RouterLink,\\n SdBadge,\\n SdButton,\\n SdSection,\\n SdSectionItem,\\n SdPermissionDirective,\\n SdEmptyPipe,\\n SdFormatDatetimePipe,\\n SdFormatNumberPipe,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let item = entity();\\n <article class=\"d-flex flex-column gap-16 p-16\" [attr.aria-label]=\"\\'Đề nghị \\' + item.code\">\\n <header class=\"d-flex align-items-start justify-content-between gap-16 flex-wrap\">\\n <div class=\"d-flex flex-column gap-4\">\\n <!-- Màn hẹp: chi tiết thay danh sách, quay lại bằng liên kết này. -->\\n <a class=\"approval-back\" [routerLink]=\"[\\'..\\']\">← Danh sách</a>\\n <div class=\"d-flex align-items-center gap-8\">\\n <h2 class=\"T18M m-0\">{{ item.code }} · {{ item.title }}</h2>\\n <sd-badge size=\"md\" type=\"round\" [title]=\"badge().title\" [color]=\"badge().color\" />\\n </div>\\n <span class=\"T14R text-secondary\">{{ item.requester }} · {{ item.department }}</span>\\n </div>\\n @if (item.status === \\'pending\\') {\\n <div class=\"d-flex align-items-center gap-8\">\\n <sd-button\\n *sdPermission=\"\\'PATTERN_APPROVAL_U_REJECT\\'\"\\n title=\"Từ chối\"\\n prefixIcon=\"close\"\\n type=\"light\"\\n color=\"warning\"\\n autoId=\"approval-reject\"\\n [disabled]=\"pending()\"\\n (click)=\"decide(\\'reject\\')\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_APPROVAL_U_APPROVE\\'\"\\n title=\"Duyệt\"\\n prefixIcon=\"check\"\\n type=\"fill\"\\n color=\"success\"\\n autoId=\"approval-approve\"\\n [disabled]=\"pending()\"\\n (click)=\"decide(\\'approve\\')\" />\\n </div>\\n }\\n </header>\\n <sd-section title=\"Thông tin đề nghị\">\\n <sd-section-item label=\"Số tiền (₫)\">{{ item.amount | sdFormatNumber: 0 }}</sd-section-item>\\n <sd-section-item label=\"Ngày gửi\">{{ item.submittedAt | sdFormatDatetime }}</sd-section-item>\\n <sd-section-item label=\"Ghi chú\">{{ item.note | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Lý do từ chối\">{{ item.reason | sdEmpty }}</sd-section-item>\\n </sd-section>\\n </article>\\n `,\\n styles: `\\n .approval-back {\\n display: none;\\n font-size: 13px;\\n }\\n @media (max-width: 767.98px) {\\n .approval-back {\\n display: inline;\\n }\\n }\\n `,\\n})\\nexport class DetailComponent {\\n readonly #approvalService = inject(ApprovalService);\\n readonly #inbox = inject(ApprovalInbox);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #resolved = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as ApprovalDto)), { requireSync: true });\\n protected readonly entity = linkedSignal(() => this.#resolved());\\n protected readonly badge = computed(() => approvalStatusBadge(this.entity().status));\\n protected readonly pending = signal(false);\\n\\n /** Hỏi xác nhận (Từ chối kèm lý do), xử lý, rồi tự mở mục kế trong danh sách đang lọc. */\\n protected async decide(action: \\'approve\\' | \\'reject\\'): Promise<void> {\\n const item = this.entity();\\n let reason: string | undefined;\\n try {\\n if (action === \\'reject\\') {\\n reason = await this.#confirm.withInput(`Từ chối ${item.code}. Lý do được gửi cho ${item.requester}.`, {\\n title: \\'Từ chối đề nghị\\',\\n label: \\'Lý do từ chối\\',\\n required: true,\\n maxlength: 200,\\n yesTitle: \\'Từ chối\\',\\n noTitle: \\'Không\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } else {\\n await this.#confirm.confirm(`Duyệt ${item.code}: ${item.title}?`, { title: \\'Duyệt đề nghị\\', yesTitle: \\'Duyệt\\', noTitle: \\'Không\\' });\\n }\\n } catch {\\n return;\\n }\\n this.pending.set(true);\\n try {\\n const next = this.#inbox.nextOf(item.id);\\n this.entity.set(\\n await firstValueFrom(\\n action === \\'approve\\' ? this.#approvalService.approve({ id: item.id }) : this.#approvalService.reject({ id: item.id, reason })\\n )\\n );\\n this.#notify.success(action === \\'approve\\' ? `Đã duyệt ${item.code}.` : `Đã từ chối ${item.code}.`);\\n await this.#inbox.refresh();\\n await this.#router.navigate(next ? [\\'..\\', next] : [\\'..\\'], { relativeTo: this.#route });\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error));\\n } finally {\\n this.pending.set(false);\\n }\\n }\\n}\\n',\n 'features/approval/pages/list/approval-inbox.ts': '/** Hộp duyệt mà panel chi tiết dùng để tự chọn mục kế sau khi duyệt hoặc từ chối. */\\nexport abstract class ApprovalInbox {\\n /** Mục sau `id` trong các dòng đang hiện (mục trước nếu `id` là dòng cuối); `null` khi không còn mục nào. */\\n abstract nextOf(id: string): string | null;\\n /** Đọc lại danh sách, giữ bộ lọc, trang và vị trí cuộn. */\\n abstract refresh(): Promise<void>;\\n}\\n',\n 'features/approval/pages/list/list.component.html': '<sd-page-list title=\"Phê duyệt\" description=\"Đề nghị thanh toán chờ xử lý. Dùng ↑ ↓ để chuyển mục.\" detail=\"none\">\\n <div sdPageListMain class=\"approval\" [class.approval--narrow]=\"narrow()\" [class.approval--active]=\"active()\">\\n <sd-splitter [option]=\"splitter\">\\n <!-- Kéo trong khoảng 360–760px; panel chi tiết nhận phần còn lại (unit flex: minSize là trọng số, không phải px). -->\\n <sd-splitter-panel class=\"approval__list\" panelId=\"list\" [size]=\"520\" unit=\"px\" [minSize]=\"360\" [maxSize]=\"760\">\\n <sd-table autoId=\"approval-list\" [option]=\"option\">\\n <ng-template sdTableCellDef=\"code\" let-item=\"item\">\\n <a [routerLink]=\"[item.id]\" [attr.aria-current]=\"item.id === selectedId() ? \\'true\\' : null\">{{ item.code }}</a>\\n </ng-template>\\n </sd-table>\\n </sd-splitter-panel>\\n <sd-splitter-panel class=\"approval__detail\" panelId=\"detail\" [size]=\"1\">\\n <router-outlet (activate)=\"active.set(true)\" (deactivate)=\"active.set(false)\" />\\n @if (!active()) {\\n <sd-data-state state=\"empty\" icon=\"inbox\" title=\"Chọn một mục\" message=\"Chọn một đề nghị bên trái để xem chi tiết và xử lý.\" />\\n }\\n </sd-splitter-panel>\\n </sd-splitter>\\n </div>\\n</sd-page-list>\\n',\n 'features/approval/pages/list/list.component.ts': 'import { ChangeDetectionStrategy, Component, DestroyRef, effect, forwardRef, inject, signal, untracked, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet } from \\'@angular/router\\';\\nimport { filter, firstValueFrom, map, startWith } from \\'rxjs\\';\\nimport { SdDataState } from \\'@sdcorejs/angular/components/data-state\\';\\nimport { SdSplitterComponent, SdSplitterPanelComponent, type SdSplitterOption } from \\'@sdcorejs/angular/components/splitter\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { SdPageList } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { ApprovalService } from \\'../../services/approval.service\\';\\nimport { APPROVAL_STATUS_OPTIONS, approvalStatusBadge, type ApprovalDto } from \\'../../services/approval.model\\';\\nimport { ApprovalInbox } from \\'./approval-inbox\\';\\n\\n/** Dưới bề rộng này chi tiết thay hẳn danh sách, có nút quay lại. */\\nconst NARROW = \\'(max-width: 767.98px)\\';\\n\\n/**\\n * Hộp duyệt (pattern split): danh sách bên trái, chi tiết là route con `:id` trong panel phải. ↑ ↓ chuyển mục;\\n * duyệt hoặc từ chối xong panel chi tiết tự chọn mục kế, bộ lọc và vị trí cuộn của danh sách giữ nguyên.\\n */\\n@Component({\\n selector: \\'list\\',\\n standalone: true,\\n templateUrl: \\'./list.component.html\\',\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n // Phím ↑ ↓ nổi lên từ dòng hay nút đang focus trong danh sách hoặc panel chi tiết.\\n host: { \\'(keydown)\\': \\'move($event)\\' },\\n imports: [\\n RouterLink,\\n RouterOutlet,\\n SdPageList,\\n SdSplitterComponent,\\n SdSplitterPanelComponent,\\n SdTable,\\n SdTableCellDefDirective,\\n SdDataState,\\n ],\\n providers: [{ provide: ApprovalInbox, useExisting: forwardRef(() => ListComponent) }],\\n styles: `\\n .approval > sd-splitter {\\n flex: 1 1 0;\\n min-height: 0;\\n }\\n .approval sd-splitter-panel {\\n display: flex;\\n flex-direction: column;\\n }\\n .approval__list {\\n background: var(--sd-surface, #ffffff);\\n border: 1px solid var(--sd-border, #e3e5ea);\\n border-radius: 8px;\\n }\\n .approval__list > sd-table {\\n flex: 1 1 0;\\n min-height: 0;\\n }\\n .approval__detail {\\n overflow-y: auto;\\n }\\n .approval--narrow.approval--active sd-splitter-panel:first-child,\\n .approval--narrow:not(.approval--active) sd-splitter-panel:last-of-type {\\n display: none;\\n }\\n `,\\n})\\nexport class ListComponent extends ApprovalInbox {\\n readonly #approvalService = inject(ApprovalService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly table = viewChild.required(SdTable);\\n protected readonly active = signal(false);\\n protected readonly narrow = signal(false);\\n /** ID đang mở ở panel phải, đọc từ route con. */\\n protected readonly selectedId = toSignal(\\n this.#router.events.pipe(\\n filter(event => event instanceof NavigationEnd),\\n startWith(null),\\n map(() => this.#route.firstChild?.snapshot.paramMap.get(\\'id\\') ?? null)\\n ),\\n { requireSync: true }\\n );\\n protected readonly splitter: SdSplitterOption = { storageKey: \\'sd-pattern.approval.splitter\\' };\\n protected readonly option: SdTableOption<ApprovalDto> = {\\n type: \\'server\\',\\n rowKey: \\'id\\',\\n items: (_, req) => firstValueFrom(this.#approvalService.list(req)),\\n filter: {\\n quickSearch: { containFields: [\\'code\\', \\'title\\', \\'requester\\'], placeholder: \\'Tìm theo mã, nội dung, người đề nghị\\' },\\n },\\n paginate: { pageSize: 20, pages: [20, 50] },\\n columns: [\\n { field: \\'code\\', title: \\'Mã\\', type: \\'string\\', width: \\'96px\\' },\\n { field: \\'title\\', title: \\'Nội dung\\', type: \\'string\\', minWidth: \\'140px\\' },\\n { field: \\'amount\\', title: \\'Số tiền (₫)\\', type: \\'number\\', width: \\'120px\\', align: \\'right\\' },\\n {\\n field: \\'status\\',\\n title: \\'Trạng thái\\',\\n type: \\'values\\',\\n width: \\'128px\\',\\n option: { items: APPROVAL_STATUS_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: status => approvalStatusBadge(status),\\n // Hộp duyệt mở sẵn các đề nghị đang chờ; đổi bộ lọc để xem đề nghị đã xử lý.\\n filter: { default: \\'pending\\' },\\n },\\n ],\\n style: {\\n rowCss: (row): Record<string, string> => (row.id === this.selectedId() ? { background: \\'var(--sd-primary-light)\\' } : {}),\\n },\\n };\\n\\n constructor() {\\n super();\\n // Dòng đang mở được tô nền: vẽ lại bảng khi chọn mục khác.\\n effect(() => {\\n this.selectedId();\\n untracked(() => this.table().detectChanges());\\n });\\n const media = typeof matchMedia === \\'function\\' ? matchMedia(NARROW) : null;\\n if (media) {\\n this.narrow.set(media.matches);\\n const onChange = (event: MediaQueryListEvent): void => this.narrow.set(event.matches);\\n media.addEventListener(\\'change\\', onChange);\\n inject(DestroyRef).onDestroy(() => media.removeEventListener(\\'change\\', onChange));\\n }\\n }\\n\\n nextOf(id: string): string | null {\\n const rows = this.table().dataItems;\\n const index = rows.findIndex(row => row.id === id);\\n if (index < 0) return rows[0]?.id ?? null;\\n return rows[index + 1]?.id ?? rows[index - 1]?.id ?? null;\\n }\\n\\n async refresh(): Promise<void> {\\n await this.table().reload(true, false);\\n }\\n\\n /** ↑ ↓ chuyển sang dòng trước/sau; bỏ qua khi đang gõ trong ô nhập. */\\n protected move(event: KeyboardEvent): void {\\n if (event.key !== \\'ArrowDown\\' && event.key !== \\'ArrowUp\\') return;\\n const target = event.target as HTMLElement | null;\\n if (target?.closest(\\'input, textarea, select, [contenteditable=\"true\"], mat-select, [role=\"separator\"]\\')) return;\\n const rows = this.table().dataItems;\\n if (!rows.length) return;\\n const index = rows.findIndex(row => row.id === this.selectedId());\\n const next = rows[Math.min(rows.length - 1, Math.max(0, index < 0 ? 0 : index + (event.key === \\'ArrowDown\\' ? 1 : -1)))];\\n event.preventDefault();\\n if (next.id !== this.selectedId()) void this.#router.navigate([next.id], { relativeTo: this.#route });\\n }\\n}\\n',\n 'features/approval/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { entityResolver } from \\'./entity.resolver\\';\\nimport { ApprovalService } from \\'./services/approval.service\\';\\n\\n/** Chi tiết là route con `:id`, hiện trong panel phải của danh sách (pattern split). */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [ApprovalService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Phê duyệt\\',\\n data: { permission: \\'PATTERN_APPROVAL_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\':id\\',\\n data: { permission: \\'PATTERN_APPROVAL_R_DETAIL\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () => import(\\'./pages/detail/detail.component\\').then(module => module.DetailComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n',\n 'features/approval/services/approval.model.ts': 'import type { SdBadgeData } from \\'@sdcorejs/angular/components/badge\\';\\nimport type { PagingReq, PagingRes } from \\'@sdcorejs/utils/models\\';\\n\\nexport type ApprovalStatus = \\'pending\\' | \\'approved\\' | \\'rejected\\';\\n\\nexport const APPROVAL_STATUS_OPTIONS = [\\n { id: \\'pending\\', name: \\'Chờ duyệt\\', color: \\'warning\\' },\\n { id: \\'approved\\', name: \\'Đã duyệt\\', color: \\'success\\' },\\n { id: \\'rejected\\', name: \\'Bị từ chối\\', color: \\'error\\' },\\n] satisfies { id: ApprovalStatus; name: string; color: SdBadgeData[\\'color\\'] }[];\\n\\n/** Đề nghị thanh toán chờ người duyệt xử lý. */\\nexport interface ApprovalDto {\\n readonly id: string;\\n readonly code: string;\\n readonly title: string;\\n readonly requester: string;\\n readonly department: string;\\n /** Số tiền đề nghị (₫). */\\n readonly amount: number;\\n readonly submittedAt: string;\\n readonly status: ApprovalStatus;\\n readonly reason: string | null;\\n readonly note: string | null;\\n}\\n\\nexport type ApprovalListReq = PagingReq<ApprovalDto>;\\nexport type ApprovalListRes = PagingRes<ApprovalDto>;\\n\\nexport interface ApprovalDecisionReq {\\n readonly id: string;\\n readonly reason?: string;\\n}\\n\\nexport function approvalStatusBadge(status: ApprovalStatus): SdBadgeData {\\n const option = APPROVAL_STATUS_OPTIONS.find(item => item.id === status);\\n return { type: \\'round\\', title: option?.name ?? status, color: option?.color };\\n}\\n',\n 'features/approval/services/approval.service.ts': 'import { Injectable } from \\'@angular/core\\';\\nimport type { Observable } from \\'rxjs\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type { ApprovalDecisionReq, ApprovalDto, ApprovalListReq, ApprovalListRes } from \\'./approval.model\\';\\n\\n@Injectable()\\nexport class ApprovalService extends BaseApiService {\\n list(req: ApprovalListReq): Observable<ApprovalListRes> {\\n return this.http.get<ApprovalListRes>(this.apiUrl(\\'approvals\\'), { params: this.buildPagingReq(req) });\\n }\\n\\n detail(id: string): Observable<ApprovalDto> {\\n return this.http.get<ApprovalDto>(this.apiUrl(\\'approvals\\', id));\\n }\\n\\n approve(req: ApprovalDecisionReq): Observable<ApprovalDto> {\\n return this.http.post<ApprovalDto>(this.apiUrl(\\'approvals\\', req.id, \\'approve\\'), {});\\n }\\n\\n reject(req: ApprovalDecisionReq): Observable<ApprovalDto> {\\n return this.http.post<ApprovalDto>(this.apiUrl(\\'approvals\\', req.id, \\'reject\\'), { reason: req.reason });\\n }\\n}\\n',\n 'features/category/components/create-side-drawer/create-side-drawer.component.ts': 'import {\\n afterNextRender,\\n ChangeDetectionStrategy,\\n Component,\\n DestroyRef,\\n ElementRef,\\n inject,\\n Injector,\\n signal,\\n viewChild,\\n} from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport { CategoryService } from \\'../../services/category.service\\';\\nimport type { CategoryDto, CategorySaveReq } from \\'../../services/category.model\\';\\nimport {\\n categorySaveReq,\\n GeneralInformationFormComponent,\\n type CategoryForm,\\n} from \\'../general-information-form/general-information-form.component\\';\\n\\n/**\\n * Tạo danh mục trong drawer (route con `create`, `?parent=<id>` cho danh mục con). Danh mục cha do resolver tải.\\n * X, Esc và backdrop hỏi trước khi bỏ thay đổi; lưu xong đóng drawer và danh sách tải lại.\\n */\\n@Component({\\n selector: \\'create-side-drawer\\',\\n standalone: true,\\n imports: [SdSideDrawer, SdButton, GeneralInformationFormComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-side-drawer\\n [title]=\"parent() ? \\'Thêm danh mục con của \\' + parent()!.name : \\'Tạo danh mục\\'\"\\n autoId=\"category-create\"\\n [beforeClose]=\"beforeClose\"\\n (sdClosed)=\"closed()\">\\n <general-information-form [form]=\"form\" [seed]=\"seed\" [parentName]=\"parent()?.name ?? null\" [errors]=\"apiErrors.errors()\" />\\n <div sdFooterRight class=\"d-flex align-items-center gap-8\">\\n <sd-button\\n title=\"Tạo danh mục\"\\n prefixIcon=\"save\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"category-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n </div>\\n </sd-side-drawer>\\n `,\\n})\\nexport class CreateSideDrawerComponent {\\n readonly #categoryService = inject(CategoryService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #injector = inject(Injector);\\n private readonly drawer = viewChild.required(SdSideDrawer);\\n private readonly formElement = viewChild.required(GeneralInformationFormComponent, { read: ElementRef });\\n protected readonly parent = toSignal(this.#route.data.pipe(map(data => (data[\\'parent\\'] as CategoryDto | null) ?? null)), {\\n requireSync: true,\\n });\\n protected readonly seed: CategorySaveReq = { code: \\'\\', name: \\'\\', parentId: null, status: \\'active\\' };\\n protected readonly form: CategoryForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'category-create\\', dirty: \\'value\\' });\\n\\n protected readonly beforeClose = async (): Promise<boolean> => {\\n if (this.saving()) return false;\\n if (!this.#unsaved.dirty()) return true;\\n try {\\n await this.#confirm.confirm(\\'Thay đổi chưa lưu sẽ bị mất.\\', {\\n title: \\'Đóng khi chưa lưu?\\',\\n yesTitle: \\'Bỏ thay đổi\\',\\n noTitle: \\'Tiếp tục sửa\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } catch {\\n return false;\\n }\\n this.#unsaved.markPristine();\\n return true;\\n };\\n\\n constructor() {\\n afterNextRender(() => this.drawer().open());\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected closed(): void {\\n void this.#router.navigate([\\'..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n const category = await firstValueFrom(this.#categoryService.create(categorySaveReq(this.form, this.parent()?.id ?? null)));\\n this.#unsaved.markPristine();\\n this.#notify.success(`Đã tạo danh mục ${category.name}.`);\\n this.saving.set(false);\\n this.drawer().close();\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.formElement().nativeElement), { injector: this.#injector });\\n }\\n}\\n',\n 'features/category/components/general-information-form/general-information-form.component.ts': 'import { ChangeDetectionStrategy, Component, input } from \\'@angular/core\\';\\nimport type { FormControl, FormGroup } from \\'@angular/forms\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdView } from \\'@sdcorejs/angular/components/view\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdSwitch } from \\'@sdcorejs/angular/forms/switch\\';\\nimport type { CategorySaveReq } from \\'../../services/category.model\\';\\n\\nexport type CategoryForm = FormGroup<{\\n code?: FormControl<string>;\\n name?: FormControl<string>;\\n active?: FormControl<boolean>;\\n}>;\\n\\n/** Giá trị form → request lưu; danh mục cha do drawer quyết định, không sửa trong form. */\\nexport function categorySaveReq(form: CategoryForm, parentId: string | null, code?: string): CategorySaveReq {\\n const value = form.getRawValue();\\n return { code: code ?? value.code ?? \\'\\', name: value.name ?? \\'\\', parentId, status: value.active === false ? \\'inactive\\' : \\'active\\' };\\n}\\n\\n/** Form danh mục một nhóm, dùng chung cho drawer tạo và cập nhật. */\\n@Component({\\n selector: \\'general-information-form\\',\\n standalone: true,\\n imports: [SdSection, SdView, SdInput, SdSwitch],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"d-flex flex-column gap-8 p-16\">\\n <sd-view label=\"Danh mục cha\" [display]=\"parentName()\" />\\n <sd-input\\n label=\"Mã danh mục\"\\n name=\"code\"\\n autoId=\"category-code\"\\n [form]=\"form()\"\\n [model]=\"seed().code\"\\n [disabled]=\"editing()\"\\n [inlineError]=\"errors()[\\'code\\']\"\\n maxlength=\"30\"\\n required />\\n <sd-input\\n label=\"Tên danh mục\"\\n name=\"name\"\\n autoId=\"category-name\"\\n [form]=\"form()\"\\n [model]=\"seed().name\"\\n [inlineError]=\"errors()[\\'name\\']\"\\n maxlength=\"100\"\\n required />\\n <sd-switch label=\"Đang dùng\" name=\"active\" [form]=\"form()\" [model]=\"seed().status !== \\'inactive\\'\" />\\n </div>\\n </sd-section>\\n `,\\n})\\nexport class GeneralInformationFormComponent {\\n readonly form = input.required<CategoryForm>();\\n readonly seed = input.required<CategorySaveReq>();\\n readonly parentName = input<string | null>(null);\\n readonly editing = input(false);\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n}\\n',\n 'features/category/components/update-side-drawer/update-side-drawer.component.ts': 'import {\\n afterNextRender,\\n ChangeDetectionStrategy,\\n Component,\\n DestroyRef,\\n ElementRef,\\n inject,\\n Injector,\\n signal,\\n viewChild,\\n} from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport { CategoryService } from \\'../../services/category.service\\';\\nimport type { CategoryDto } from \\'../../services/category.model\\';\\nimport {\\n categorySaveReq,\\n GeneralInformationFormComponent,\\n type CategoryForm,\\n} from \\'../general-information-form/general-information-form.component\\';\\n\\n/**\\n * Cập nhật danh mục trong drawer (route con `:id/update`, mở từ tên danh mục). Mã bị khoá; danh mục cha giữ nguyên.\\n * X, Esc và backdrop hỏi trước khi bỏ thay đổi; lưu xong đóng drawer và danh sách tải lại.\\n */\\n@Component({\\n selector: \\'update-side-drawer\\',\\n standalone: true,\\n imports: [SdSideDrawer, SdButton, GeneralInformationFormComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-side-drawer\\n [title]=\"\\'Cập nhật danh mục \\' + entity().code\"\\n autoId=\"category-update\"\\n [beforeClose]=\"beforeClose\"\\n (sdClosed)=\"closed()\">\\n <general-information-form\\n [form]=\"form\"\\n [seed]=\"entity()\"\\n [parentName]=\"parentName()\"\\n [editing]=\"true\"\\n [errors]=\"apiErrors.errors()\" />\\n <div sdFooterRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Lưu\" prefixIcon=\"save\" type=\"fill\" color=\"primary\" autoId=\"category-save\" [loading]=\"saving()\" (click)=\"save()\" />\\n </div>\\n </sd-side-drawer>\\n `,\\n})\\nexport class UpdateSideDrawerComponent {\\n readonly #categoryService = inject(CategoryService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #injector = inject(Injector);\\n private readonly drawer = viewChild.required(SdSideDrawer);\\n private readonly formElement = viewChild.required(GeneralInformationFormComponent, { read: ElementRef });\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as CategoryDto)), { requireSync: true });\\n protected readonly parentName = signal<string | null>(null);\\n protected readonly form: CategoryForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'category-update\\', dirty: \\'value\\' });\\n\\n protected readonly beforeClose = async (): Promise<boolean> => {\\n if (this.saving()) return false;\\n if (!this.#unsaved.dirty()) return true;\\n try {\\n await this.#confirm.confirm(\\'Thay đổi chưa lưu sẽ bị mất.\\', {\\n title: \\'Đóng khi chưa lưu?\\',\\n yesTitle: \\'Bỏ thay đổi\\',\\n noTitle: \\'Tiếp tục sửa\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } catch {\\n return false;\\n }\\n this.#unsaved.markPristine();\\n return true;\\n };\\n\\n constructor() {\\n afterNextRender(() => this.drawer().open());\\n const parentId = this.entity().parentId;\\n if (parentId) {\\n firstValueFrom(this.#categoryService.detail(parentId)).then(\\n parent => this.parentName.set(parent.name),\\n () => this.parentName.set(null)\\n );\\n }\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected closed(): void {\\n void this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n const entity = this.entity();\\n await firstValueFrom(this.#categoryService.update(entity.id, categorySaveReq(this.form, entity.parentId, entity.code)));\\n this.#unsaved.markPristine();\\n this.#notify.success(\\'Đã cập nhật danh mục.\\');\\n this.saving.set(false);\\n this.drawer().close();\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.formElement().nativeElement), { injector: this.#injector });\\n }\\n}\\n',\n 'features/category/entity.resolver.ts': 'import { HttpErrorResponse } from \\'@angular/common/http\\';\\nimport { inject } from \\'@angular/core\\';\\nimport type { ResolveFn } from \\'@angular/router\\';\\nimport { map, of, timeout } from \\'rxjs\\';\\nimport { CategoryService } from \\'./services/category.service\\';\\nimport type { CategoryDto } from \\'./services/category.model\\';\\n\\n/** Tải danh mục bằng `detail(id)` trước khi mở drawer cập nhật; lỗi đi tới navigation error handler của host. */\\nexport const entityResolver: ResolveFn<CategoryDto> = route => {\\n const id = route.paramMap.get(\\'id\\');\\n if (!id?.trim()) throw new HttpErrorResponse({ status: 404 });\\n return inject(CategoryService)\\n .detail(id)\\n .pipe(\\n timeout(10_000),\\n map(entity => {\\n if (!entity || entity.id !== id) throw new HttpErrorResponse({ status: 404 });\\n return entity;\\n })\\n );\\n};\\n\\n/** Danh mục cha của drawer tạo (`?parent=<id>`); không có tham số thì tạo danh mục gốc. */\\nexport const parentResolver: ResolveFn<CategoryDto | null> = route => {\\n const id = route.queryParamMap.get(\\'parent\\');\\n return id ? inject(CategoryService).detail(id).pipe(timeout(10_000)) : of(null);\\n};\\n',\n 'features/category/pages/list/list.component.html': '<sd-page-list title=\"Danh mục\" description=\"Danh mục sản phẩm ba cấp.\" detail=\"drawer\">\\n <sd-button\\n headerRight\\n *sdPermission=\"\\'PATTERN_CATEGORY_C_CREATE\\'\"\\n title=\"Tạo danh mục\"\\n prefixIcon=\"add\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"category-create\"\\n [routerLink]=\"[\\'create\\']\" />\\n\\n <sd-table autoId=\"categories\" [option]=\"option\">\\n <ng-template sdTableCellDef=\"name\" let-category=\"item\">\\n <a *sdPermission=\"\\'PATTERN_CATEGORY_U_UPDATE\\'\" [routerLink]=\"[category.id, \\'update\\']\">{{ category.name }}</a>\\n @if (!canUpdate) {\\n <span>{{ category.name }}</span>\\n }\\n </ng-template>\\n </sd-table>\\n</sd-page-list>\\n',\n 'features/category/pages/list/list.component.ts': 'import { ChangeDetectionStrategy, Component, effect, inject, untracked, viewChild } from \\'@angular/core\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { SdPageList } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective, SdPermissionService } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { CategoryService } from \\'../../services/category.service\\';\\nimport { CATEGORY_MAX_LEVEL, CATEGORY_STATUS_OPTIONS, categoryStatusBadge, type CategoryNodeDto } from \\'../../services/category.model\\';\\n\\n/**\\n * Bảng cây ba cấp. Tên mở drawer cập nhật; thao tác theo dòng: thêm danh mục con (drawer, tối đa cấp 3) và xoá\\n * (hỏi xác nhận, API từ chối khi còn danh mục con).\\n */\\n@Component({\\n selector: \\'list\\',\\n standalone: true,\\n templateUrl: \\'./list.component.html\\',\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [RouterLink, SdPageList, SdButton, SdTable, SdTableCellDefDirective, SdPermissionDirective],\\n})\\nexport class ListComponent {\\n readonly #categoryService = inject(CategoryService);\\n readonly #permission = inject(SdPermissionService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly pageList = viewChild.required(SdPageList);\\n private readonly table = viewChild.required(SdTable);\\n protected readonly canUpdate = this.#permission.hasPermission(\\'PATTERN_CATEGORY_U_UPDATE\\');\\n\\n protected readonly option: SdTableOption<CategoryNodeDto> = {\\n type: \\'local\\',\\n rowKey: \\'id\\',\\n items: () => firstValueFrom(this.#categoryService.tree()),\\n // Cây nhỏ (3 cấp): mở hết để danh mục con vừa tạo hiện ngay dưới danh mục cha.\\n tree: { loadType: \\'static\\', childrenKey: \\'children\\', maxDepth: CATEGORY_MAX_LEVEL, defaultExpanded: true },\\n filter: { quickSearch: { containFields: [\\'code\\', \\'name\\'], placeholder: \\'Tìm theo mã hoặc tên danh mục\\' } },\\n paginate: { pageSize: 50 },\\n columns: [\\n { field: \\'name\\', title: \\'Tên danh mục\\', type: \\'string\\', minWidth: \\'260px\\' },\\n { field: \\'code\\', title: \\'Mã\\', type: \\'string\\', width: \\'160px\\' },\\n { field: \\'productCount\\', title: \\'Số sản phẩm\\', type: \\'number\\', width: \\'140px\\', align: \\'right\\' },\\n {\\n field: \\'status\\',\\n title: \\'Trạng thái\\',\\n type: \\'values\\',\\n width: \\'150px\\',\\n option: { items: CATEGORY_STATUS_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: status => categoryStatusBadge(status),\\n },\\n ],\\n command: {\\n commands: [\\n {\\n title: \\'Thêm danh mục con\\',\\n icon: \\'add\\',\\n hidden: row => !this.#permission.hasPermission(\\'PATTERN_CATEGORY_C_CREATE\\') || row.level >= CATEGORY_MAX_LEVEL,\\n click: row => void this.#router.navigate([\\'create\\'], { relativeTo: this.#route, queryParams: { parent: row.id } }),\\n },\\n {\\n title: \\'Xoá\\',\\n icon: \\'delete\\',\\n color: \\'error\\',\\n hidden: () => !this.#permission.hasPermission(\\'PATTERN_CATEGORY_D_DELETE\\'),\\n click: row => void this.#delete(row),\\n },\\n ],\\n },\\n };\\n\\n constructor() {\\n let changes = this.#categoryService.changes();\\n effect(() => {\\n const next = this.#categoryService.changes();\\n if (this.pageList().childActive() || next === changes) return;\\n changes = next;\\n untracked(() => void this.table().reload(true, false));\\n });\\n }\\n\\n async #delete(category: CategoryNodeDto): Promise<void> {\\n try {\\n await this.#confirm.confirm(`Xoá danh mục ${category.name}?`, {\\n title: \\'Xoá danh mục\\',\\n yesTitle: \\'Xoá\\',\\n noTitle: \\'Không xoá\\',\\n yesButtonColor: \\'error\\',\\n });\\n } catch {\\n return;\\n }\\n try {\\n await firstValueFrom(this.#categoryService.delete(category.id));\\n this.#notify.success(`Đã xoá danh mục ${category.name}.`);\\n await this.table().reload(true, false);\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không xoá được danh mục.\\'));\\n }\\n }\\n}\\n',\n 'features/category/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { entityResolver, parentResolver } from \\'./entity.resolver\\';\\nimport { CategoryService } from \\'./services/category.service\\';\\n\\n/** Tạo và cập nhật mở trong drawer (route con của bảng cây). */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [CategoryService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Danh mục\\',\\n data: { permission: \\'PATTERN_CATEGORY_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\'create\\',\\n data: { permission: \\'PATTERN_CATEGORY_C_CREATE\\' },\\n resolve: { parent: parentResolver },\\n runGuardsAndResolvers: \\'paramsOrQueryParamsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () =>\\n import(\\'./components/create-side-drawer/create-side-drawer.component\\').then(module => module.CreateSideDrawerComponent),\\n },\\n {\\n path: \\':id/update\\',\\n data: { permission: \\'PATTERN_CATEGORY_U_UPDATE\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () =>\\n import(\\'./components/update-side-drawer/update-side-drawer.component\\').then(module => module.UpdateSideDrawerComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n',\n 'features/category/services/category.model.ts': 'import type { SdBadgeData } from \\'@sdcorejs/angular/components/badge\\';\\n\\nexport type CategoryStatus = \\'active\\' | \\'inactive\\';\\n\\nexport const CATEGORY_STATUS_OPTIONS = [\\n { id: \\'active\\', name: \\'Đang dùng\\', color: \\'success\\' },\\n { id: \\'inactive\\', name: \\'Ngừng dùng\\', color: \\'secondary\\' },\\n] satisfies { id: CategoryStatus; name: string; color: SdBadgeData[\\'color\\'] }[];\\n\\n/** Danh mục có tối đa 3 cấp. */\\nexport const CATEGORY_MAX_LEVEL = 3;\\n\\nexport interface CategoryDto {\\n readonly id: string;\\n readonly code: string;\\n readonly name: string;\\n readonly parentId: string | null;\\n readonly status: CategoryStatus;\\n}\\n\\n/** Một nút của cây danh mục cho bảng cây. */\\nexport interface CategoryNodeDto extends CategoryDto {\\n /** 1 là cấp gốc. */\\n readonly level: number;\\n readonly productCount: number;\\n readonly children: readonly CategoryNodeDto[];\\n}\\n\\nexport interface CategorySaveReq {\\n readonly code: string;\\n readonly name: string;\\n readonly parentId: string | null;\\n readonly status: CategoryStatus;\\n}\\n\\nexport function categoryStatusBadge(status: CategoryStatus): SdBadgeData {\\n const option = CATEGORY_STATUS_OPTIONS.find(item => item.id === status);\\n return { type: \\'round\\', title: option?.name ?? status, color: option?.color };\\n}\\n',\n 'features/category/services/category.service.ts': 'import { Injectable, signal } from \\'@angular/core\\';\\nimport { tap, type Observable } from \\'rxjs\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type { CategoryDto, CategoryNodeDto, CategorySaveReq } from \\'./category.model\\';\\n\\n@Injectable()\\nexport class CategoryService extends BaseApiService {\\n readonly #changes = signal(0);\\n /** Tăng sau mỗi lần tạo, cập nhật hoặc xoá thành công: danh sách chỉ tải lại khi có thay đổi. */\\n readonly changes = this.#changes.asReadonly();\\n\\n /** Cả cây danh mục, các nút gốc theo thứ tự. */\\n tree(): Observable<CategoryNodeDto[]> {\\n return this.http.get<CategoryNodeDto[]>(this.apiUrl(\\'categories\\', \\'tree\\'));\\n }\\n\\n detail(id: string): Observable<CategoryDto> {\\n return this.http.get<CategoryDto>(this.apiUrl(\\'categories\\', id));\\n }\\n\\n create(req: CategorySaveReq): Observable<CategoryDto> {\\n return this.http.post<CategoryDto>(this.apiUrl(\\'categories\\'), req).pipe(tap(() => this.#changed()));\\n }\\n\\n update(id: string, req: CategorySaveReq): Observable<CategoryDto> {\\n return this.http.put<CategoryDto>(this.apiUrl(\\'categories\\', id), req).pipe(tap(() => this.#changed()));\\n }\\n\\n delete(id: string): Observable<void> {\\n return this.http.delete<void>(this.apiUrl(\\'categories\\', id)).pipe(tap(() => this.#changed()));\\n }\\n\\n #changed(): void {\\n this.#changes.update(count => count + 1);\\n }\\n}\\n',\n 'features/customer/components/create-side-drawer/create-side-drawer.component.ts': 'import {\\n afterNextRender,\\n ChangeDetectionStrategy,\\n Component,\\n DestroyRef,\\n ElementRef,\\n inject,\\n Injector,\\n signal,\\n viewChild,\\n} from \\'@angular/core\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerSaveReq } from \\'../../services/customer.model\\';\\nimport {\\n customerSaveReq,\\n GeneralInformationFormComponent,\\n invalidCustomerGroups,\\n type CustomerForm,\\n type CustomerFormGroup,\\n} from \\'../general-information-form/general-information-form.component\\';\\n\\n/**\\n * Tạo khách hàng trong drawer (route con `create` của danh sách). Ba nhóm, mỗi nhóm còn lỗi hiện `sd-inform`; BE báo\\n * trùng email ngay trên field. Lưu thành công thì đóng drawer, danh sách tải lại.\\n */\\n@Component({\\n selector: \\'create-side-drawer\\',\\n standalone: true,\\n imports: [SdSideDrawer, SdButton, GeneralInformationFormComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-side-drawer title=\"Tạo khách hàng\" width=\"600px\" autoId=\"customer-create\" [beforeClose]=\"beforeClose\" (sdClosed)=\"closed()\">\\n <general-information-form [form]=\"form\" [seed]=\"seed\" [errors]=\"apiErrors.errors()\" [invalidGroups]=\"invalidGroups()\" />\\n <div sdFooterRight class=\"d-flex align-items-center gap-8\">\\n <sd-button\\n title=\"Tạo khách hàng\"\\n prefixIcon=\"save\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"customer-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n </div>\\n </sd-side-drawer>\\n `,\\n})\\nexport class CreateSideDrawerComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #injector = inject(Injector);\\n private readonly drawer = viewChild.required(SdSideDrawer);\\n // why: sd-side-drawer chuyển nội dung ra body, nên tìm field lỗi trong form chứ không trong host của component.\\n private readonly formElement = viewChild.required(GeneralInformationFormComponent, { read: ElementRef });\\n protected readonly seed: CustomerSaveReq = {\\n name: \\'\\',\\n type: \\'individual\\',\\n tier: \\'standard\\',\\n email: \\'\\',\\n phone: \\'\\',\\n address: \\'\\',\\n taxCode: null,\\n status: \\'active\\',\\n note: null,\\n };\\n protected readonly form: CustomerForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n protected readonly invalidGroups = signal<CustomerFormGroup[]>([]);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'customer-create\\', dirty: \\'value\\' });\\n\\n /** Đóng khi còn thay đổi chưa lưu: hỏi, đồng ý thì bỏ thay đổi (guard rời route không hỏi lại). */\\n protected readonly beforeClose = async (): Promise<boolean> => {\\n if (!this.#unsaved.dirty() || this.saving()) return !this.saving();\\n try {\\n await this.#confirm.confirm(\\'Thay đổi chưa lưu sẽ bị mất.\\', {\\n title: \\'Đóng khi chưa lưu?\\',\\n yesTitle: \\'Bỏ thay đổi\\',\\n noTitle: \\'Tiếp tục sửa\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } catch {\\n return false;\\n }\\n this.#unsaved.markPristine();\\n return true;\\n };\\n\\n constructor() {\\n afterNextRender(() => this.drawer().open());\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected closed(): void {\\n void this.#router.navigate([\\'..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#showErrors();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n const customer = await firstValueFrom(this.#customerService.create(customerSaveReq(this.form)));\\n this.#unsaved.markPristine();\\n this.#notify.success(`Đã tạo khách hàng ${customer.code}.`);\\n this.saving.set(false);\\n this.drawer().close();\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#showErrors();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n /** `sd-inform` trong từng nhóm có lỗi, rồi focus field lỗi đầu tiên. */\\n #showErrors(): void {\\n this.invalidGroups.set(invalidCustomerGroups(this.form, this.apiErrors.errors()));\\n afterNextRender(() => focusFirstInvalid(this.formElement().nativeElement), { injector: this.#injector });\\n }\\n}\\n',\n 'features/customer/components/customer-select/customer-select.component.ts': 'import { booleanAttribute, ChangeDetectionStrategy, Component, inject, input, model } from \\'@angular/core\\';\\nimport type { FormGroup } from \\'@angular/forms\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdAvatar } from \\'@sdcorejs/angular/components/avatar\\';\\nimport { SdItemDefDefDirective } from \\'@sdcorejs/angular/forms/directives\\';\\nimport type { SdSearchReq } from \\'@sdcorejs/angular/forms/models\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport type { Filter } from \\'@sdcorejs/utils/models\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerDto } from \\'../../services/customer.model\\';\\n\\n/**\\n * Chọn khách hàng cho màn khác (đơn hàng). Lựa chọn mới chỉ gồm khách đang hoạt động; giá trị đã chọn tải theo ID\\n * (`VALUE`) nên khách đã ngừng vẫn hiện khi cập nhật. Option hai dòng có avatar: tên · mã · điện thoại.\\n */\\n@Component({\\n selector: \\'customer-select\\',\\n standalone: true,\\n imports: [SdSelect, SdItemDefDefDirective, SdAvatar],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-select\\n [label]=\"label()\"\\n [name]=\"name()\"\\n [form]=\"form()\"\\n [(model)]=\"model\"\\n [items]=\"search\"\\n valueField=\"id\"\\n displayField=\"name\"\\n [required]=\"required()\"\\n [autoId]=\"autoId()\">\\n <ng-template sdItemDef let-item=\"item\">\\n <div class=\"d-flex align-items-center gap-8\">\\n <sd-avatar [src]=\"null\" [name]=\"item.name\" [size]=\"28\" />\\n <div class=\"d-flex flex-column\">\\n <span>{{ item.name }}</span>\\n <small class=\"text-secondary\"\\n >{{ item.code }} · {{ item.phone }}{{ item.status === \\'inactive\\' ? \\' · Ngừng hoạt động\\' : \\'\\' }}</small\\n >\\n </div>\\n </div>\\n </ng-template>\\n </sd-select>`,\\n})\\nexport class CustomerSelectComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly form = input<FormGroup>();\\n readonly name = input(\\'customerId\\');\\n readonly label = input<string | undefined>(\\'Khách hàng\\');\\n readonly required = input(false, { transform: booleanAttribute });\\n readonly autoId = input<string>();\\n readonly model = model<string | null | undefined>();\\n\\n protected readonly search = async (req: SdSearchReq): Promise<CustomerDto[]> => {\\n if (req.type === \\'VALUE\\') {\\n const ids = (Array.isArray(req.value) ? req.value : [req.value]).filter((id): id is string => !!id);\\n return Promise.all(ids.map(id => firstValueFrom(this.#customerService.cachedDetail(id))));\\n }\\n const filters: Filter<CustomerDto>[] = [{ field: \\'status\\', operator: \\'EQUAL\\', data: \\'active\\' }];\\n if (req.searchText) {\\n filters.push({\\n operator: \\'OR\\',\\n data: [\\n { field: \\'name\\', operator: \\'CONTAIN\\', data: req.searchText },\\n { field: \\'code\\', operator: \\'CONTAIN\\', data: req.searchText },\\n { field: \\'phone\\', operator: \\'CONTAIN\\', data: req.searchText },\\n ],\\n });\\n }\\n const res = await firstValueFrom(this.#customerService.list({ pageNumber: 0, pageSize: 20, filters }));\\n return res.items;\\n };\\n}\\n',\n 'features/customer/components/customer-type-select/customer-type-select.component.ts': 'import { ChangeDetectionStrategy, Component, input, model } from \\'@angular/core\\';\\nimport type { FormGroup } from \\'@angular/forms\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport { CUSTOMER_TYPE_OPTIONS, type CustomerType } from \\'../../services/customer.model\\';\\n\\n/** Dropdown loại khách hàng. */\\n@Component({\\n selector: \\'customer-type-select\\',\\n standalone: true,\\n imports: [SdSelect],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-select\\n [label]=\"label()\"\\n [name]=\"name()\"\\n [form]=\"form()\"\\n [(model)]=\"model\"\\n [items]=\"options\"\\n valueField=\"id\"\\n displayField=\"name\"\\n [required]=\"required()\"\\n [clearable]=\"false\" />`,\\n})\\nexport class CustomerTypeSelectComponent {\\n readonly form = input<FormGroup>();\\n readonly name = input(\\'type\\');\\n readonly label = input(\\'Loại khách hàng\\');\\n readonly required = input(true);\\n readonly model = model<CustomerType | null | undefined>();\\n protected readonly options = CUSTOMER_TYPE_OPTIONS;\\n}\\n',\n 'features/customer/components/debts-view/debts-view.component.ts': 'import { ChangeDetectionStrategy, Component, inject, input } from \\'@angular/core\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdTable, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerDebtDto } from \\'../../services/customer.model\\';\\n\\n/** Tab Công nợ của hồ sơ 360°. */\\n@Component({\\n selector: \\'debts-view\\',\\n standalone: true,\\n imports: [SdTable],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-table autoId=\"customer-debts\" [option]=\"option\" />`,\\n})\\nexport class DebtsViewComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly customerId = input.required<string>();\\n protected readonly option: SdTableOption<CustomerDebtDto> = {\\n type: \\'server\\',\\n items: () => firstValueFrom(this.#customerService.debts(this.customerId())),\\n paginate: { pageSize: 10 },\\n columns: [\\n { field: \\'orderCode\\', title: \\'Đơn hàng\\', type: \\'string\\', width: \\'140px\\' },\\n { field: \\'dueDate\\', title: \\'Hạn thanh toán\\', type: \\'date\\', width: \\'160px\\' },\\n { field: \\'amount\\', title: \\'Còn nợ (₫)\\', type: \\'number\\', align: \\'right\\' },\\n ],\\n };\\n}\\n',\n 'features/customer/components/detail-side-drawer/detail-side-drawer.component.ts': 'import { afterNextRender, ChangeDetectionStrategy, Component, computed, inject, signal, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdBadge } from \\'@sdcorejs/angular/components/badge\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport { customerStatusBadge, customerTypeName, type CustomerDto } from \\'../../services/customer.model\\';\\nimport { GeneralInformationViewComponent } from \\'../general-information-view/general-information-view.component\\';\\n\\n/**\\n * Chi tiết khách hàng trong drawer (route con `:id/detail` của danh sách). Bản ghi do resolver tải bằng\\n * `detail(id)`, không lấy dữ liệu của dòng. Chỉ đóng bằng X (cùng Esc, backdrop): không có nút Đóng (E4).\\n * Xoá là tác vụ hiếm dùng và phá huỷ: nút chỉ có icon màu đỏ ở header, cạnh X; footer giữ tác vụ thường dùng.\\n */\\n@Component({\\n selector: \\'detail-side-drawer\\',\\n standalone: true,\\n imports: [RouterLink, SdSideDrawer, SdBadge, SdButton, SdPermissionDirective, GeneralInformationViewComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let customer = entity();\\n <sd-side-drawer width=\"600px\" autoId=\"customer-detail\" (sdClosed)=\"closed()\">\\n <div sdHeaderLeft class=\"d-flex flex-column\">\\n <div class=\"d-flex align-items-center gap-8\">\\n <span class=\"T16M\">Chi tiết khách hàng #{{ customer.code }}</span>\\n <sd-badge size=\"md\" [type]=\"badge().type ?? \\'round\\'\" [title]=\"badge().title\" [color]=\"badge().color\" />\\n </div>\\n <span class=\"T14R text-secondary\">{{ typeName() }} · {{ customer.phone }}</span>\\n </div>\\n <sd-button\\n sdHeaderRight\\n *sdPermission=\"\\'PATTERN_CUSTOMER_D_DELETE\\'\"\\n prefixIcon=\"delete\"\\n tooltip=\"Xoá khách hàng\"\\n type=\"text\"\\n color=\"error\"\\n autoId=\"customer-delete\"\\n [loading]=\"deleting()\"\\n (click)=\"delete()\" />\\n <general-information-view [customer]=\"customer\" />\\n <div sdFooterRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Hồ sơ 360°\" prefixIcon=\"contact_page\" type=\"outline\" autoId=\"customer-profile\" [routerLink]=\"[\\'../360\\']\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_CUSTOMER_U_UPDATE\\'\"\\n title=\"Cập nhật khách hàng\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"customer-update\"\\n [routerLink]=\"[\\'../update\\']\" />\\n </div>\\n </sd-side-drawer>\\n `,\\n})\\nexport class DetailSideDrawerComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly drawer = viewChild.required(SdSideDrawer);\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as CustomerDto)), { requireSync: true });\\n protected readonly badge = computed(() => customerStatusBadge(this.entity().status));\\n protected readonly typeName = computed(() => customerTypeName(this.entity().type));\\n protected readonly deleting = signal(false);\\n\\n constructor() {\\n afterNextRender(() => this.drawer().open());\\n }\\n\\n protected closed(): void {\\n // X, Esc, backdrop đều qua sdClosed; về danh sách bằng điều hướng để Back của trình duyệt cũng đóng được.\\n // Sang drawer cập nhật hay hồ sơ 360° thì drawer này bị huỷ cùng route, không phát sdClosed.\\n void this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async delete(): Promise<void> {\\n const customer = this.entity();\\n try {\\n await this.#confirm.confirm(`Xoá khách hàng ${customer.name}? Thao tác không hoàn tác được.`, {\\n title: \\'Xoá khách hàng\\',\\n yesTitle: \\'Xoá\\',\\n noTitle: \\'Không xoá\\',\\n yesButtonColor: \\'error\\',\\n });\\n } catch {\\n return;\\n }\\n this.deleting.set(true);\\n try {\\n await firstValueFrom(this.#customerService.delete(customer.id));\\n this.#notify.success(`Đã xoá khách hàng ${customer.name}.`);\\n this.drawer().close();\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không xoá được khách hàng.\\'));\\n } finally {\\n this.deleting.set(false);\\n }\\n }\\n}\\n',\n 'features/customer/components/documents-view/documents-view.component.ts': 'import { ChangeDetectionStrategy, Component, inject, input, OnInit, signal } from \\'@angular/core\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdDataState } from \\'@sdcorejs/angular/components/data-state\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerDocumentDto } from \\'../../services/customer.model\\';\\n\\n/** Tab Tài liệu của hồ sơ 360°: danh sách ngắn, trạng thái riêng bằng `sd-data-state`. */\\n@Component({\\n selector: \\'documents-view\\',\\n standalone: true,\\n imports: [SdDataState, SdSection, SdSectionItem, SdFormatNumberPipe],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-data-state\\n [state]=\"state()\"\\n retryable\\n title=\"\"\\n [message]=\"state() === \\'empty\\' ? \\'Khách hàng chưa có tài liệu.\\' : undefined\"\\n (sdRetry)=\"load()\">\\n <sd-section title=\"Tài liệu\">\\n @for (document of documents(); track document.id) {\\n <sd-section-item [label]=\"document.name\">{{ document.size / 1024 | sdFormatNumber: 0 }} KB</sd-section-item>\\n }\\n </sd-section>\\n </sd-data-state>\\n `,\\n})\\nexport class DocumentsViewComponent implements OnInit {\\n readonly #customerService = inject(CustomerService);\\n readonly customerId = input.required<string>();\\n protected readonly state = signal<\\'loading\\' | \\'empty\\' | \\'error\\' | \\'success\\'>(\\'loading\\');\\n protected readonly documents = signal<readonly CustomerDocumentDto[]>([]);\\n\\n ngOnInit(): void {\\n void this.load();\\n }\\n\\n protected async load(): Promise<void> {\\n this.state.set(\\'loading\\');\\n try {\\n const res = await firstValueFrom(this.#customerService.documents(this.customerId()));\\n this.documents.set(res.items);\\n this.state.set(res.items.length ? \\'success\\' : \\'empty\\');\\n } catch {\\n this.state.set(\\'error\\');\\n }\\n }\\n}\\n',\n 'features/customer/components/general-information-form/general-information-form.component.ts': 'import { ChangeDetectionStrategy, Component, input, linkedSignal } from \\'@angular/core\\';\\nimport type { FormControl, FormGroup } from \\'@angular/forms\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdSwitch } from \\'@sdcorejs/angular/forms/switch\\';\\nimport { SdTextarea } from \\'@sdcorejs/angular/forms/textarea\\';\\nimport type { CustomerSaveReq, CustomerStatus, CustomerTier, CustomerType } from \\'../../services/customer.model\\';\\nimport { CustomerTypeSelectComponent } from \\'../customer-type-select/customer-type-select.component\\';\\n\\n/** Các field Core tự đăng ký control qua `[form]` + `name`. */\\nexport type CustomerForm = FormGroup<{\\n name?: FormControl<string>;\\n type?: FormControl<CustomerType>;\\n taxCode?: FormControl<string | null>;\\n vip?: FormControl<boolean>;\\n email?: FormControl<string>;\\n phone?: FormControl<string>;\\n address?: FormControl<string>;\\n active?: FormControl<boolean>;\\n note?: FormControl<string | null>;\\n}>;\\n\\n/** Ba nhóm của form; nhóm còn lỗi sau khi bấm Lưu hiện `sd-inform` cảnh báo ngay trong nhóm. */\\nexport type CustomerFormGroup = \\'general\\' | \\'contact\\' | \\'other\\';\\n\\nconst GROUP_FIELDS: Readonly<Record<CustomerFormGroup, readonly string[]>> = {\\n general: [\\'name\\', \\'type\\', \\'taxCode\\', \\'vip\\'],\\n contact: [\\'email\\', \\'phone\\', \\'address\\'],\\n other: [\\'active\\', \\'note\\'],\\n};\\n\\n/** Nhóm có field không hợp lệ: field còn lỗi validate hoặc lỗi do API trả về. */\\nexport function invalidCustomerGroups(form: CustomerForm, apiErrors: Readonly<Record<string, string>>): CustomerFormGroup[] {\\n return (Object.keys(GROUP_FIELDS) as CustomerFormGroup[]).filter(group =>\\n GROUP_FIELDS[group].some(field => form.get(field)?.invalid || !!apiErrors[field])\\n );\\n}\\n\\n/** Giá trị form → request lưu. */\\nexport function customerSaveReq(form: CustomerForm): CustomerSaveReq {\\n const value = form.getRawValue();\\n const type: CustomerType = value.type ?? \\'individual\\';\\n const tier: CustomerTier = value.vip ? \\'vip\\' : \\'standard\\';\\n const status: CustomerStatus = value.active === false ? \\'inactive\\' : \\'active\\';\\n return {\\n name: value.name ?? \\'\\',\\n type,\\n tier,\\n email: value.email ?? \\'\\',\\n phone: value.phone ?? \\'\\',\\n address: value.address ?? \\'\\',\\n taxCode: type === \\'business\\' ? (value.taxCode ?? null) : null,\\n status,\\n note: value.note || null,\\n };\\n}\\n\\n/** Form khách hàng ba nhóm, dùng chung cho drawer tạo mới và cập nhật. */\\n@Component({\\n selector: \\'general-information-form\\',\\n standalone: true,\\n imports: [SdSection, SdInput, SdTextarea, SdSwitch, SdInform, CustomerTypeSelectComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let invalid = invalidGroups();\\n <div class=\"d-flex flex-column gap-16\">\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"d-flex flex-column gap-8 p-16\">\\n @if (invalid.includes(\\'general\\')) {\\n <sd-inform warning description=\"Kiểm tra tên và loại khách hàng.\" autoId=\"customer-general-warning\" />\\n }\\n <sd-input\\n label=\"Tên khách hàng\"\\n name=\"name\"\\n autoId=\"customer-name\"\\n [form]=\"form()\"\\n [model]=\"seed().name\"\\n [inlineError]=\"errors()[\\'name\\']\"\\n maxlength=\"120\"\\n required />\\n <customer-type-select [form]=\"form()\" [model]=\"seed().type\" (modelChange)=\"type.set($event ?? \\'individual\\')\" />\\n @if (type() === \\'business\\') {\\n <sd-input\\n label=\"Mã số thuế\"\\n name=\"taxCode\"\\n autoId=\"customer-tax-code\"\\n [form]=\"form()\"\\n [model]=\"seed().taxCode\"\\n [inlineError]=\"errors()[\\'taxCode\\']\"\\n maxlength=\"14\"\\n required />\\n }\\n <sd-switch label=\"Khách VIP\" name=\"vip\" [form]=\"form()\" [model]=\"seed().tier === \\'vip\\'\" />\\n </div>\\n </sd-section>\\n <sd-section title=\"Liên hệ\">\\n <div class=\"d-flex flex-column gap-8 p-16\">\\n @if (invalid.includes(\\'contact\\')) {\\n <sd-inform warning description=\"Kiểm tra email và số điện thoại.\" autoId=\"customer-contact-warning\" />\\n }\\n <sd-input\\n label=\"Email\"\\n name=\"email\"\\n autoId=\"customer-email\"\\n [form]=\"form()\"\\n [model]=\"seed().email\"\\n [inlineError]=\"errors()[\\'email\\']\"\\n pattern=\"EMAIL\"\\n required />\\n <sd-input\\n label=\"Điện thoại\"\\n name=\"phone\"\\n autoId=\"customer-phone\"\\n [form]=\"form()\"\\n [model]=\"seed().phone\"\\n [inlineError]=\"errors()[\\'phone\\']\"\\n maxlength=\"15\"\\n required />\\n <sd-input label=\"Địa chỉ\" name=\"address\" autoId=\"customer-address\" [form]=\"form()\" [model]=\"seed().address\" maxlength=\"200\" />\\n </div>\\n </sd-section>\\n <sd-section title=\"Khác\">\\n <div class=\"d-flex flex-column gap-8 p-16\">\\n <sd-switch label=\"Đang hoạt động\" name=\"active\" [form]=\"form()\" [model]=\"seed().status !== \\'inactive\\'\" />\\n <sd-textarea label=\"Ghi chú\" name=\"note\" [form]=\"form()\" [model]=\"seed().note\" maxlength=\"500\" />\\n </div>\\n </sd-section>\\n </div>\\n `,\\n})\\nexport class GeneralInformationFormComponent {\\n readonly form = input.required<CustomerForm>();\\n readonly seed = input.required<CustomerSaveReq>();\\n /** Lỗi theo field do API trả về. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n readonly invalidGroups = input<readonly CustomerFormGroup[]>([]);\\n /** Loại khách đang chọn: doanh nghiệp mới có mã số thuế. */\\n protected readonly type = linkedSignal(() => this.seed().type);\\n}\\n',\n 'features/customer/components/general-information-view/general-information-view.component.ts': 'import { ChangeDetectionStrategy, Component, computed, input } from \\'@angular/core\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdEmptyPipe, SdFormatDatePipe, SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { customerTypeName, type CustomerDto } from \\'../../services/customer.model\\';\\n\\n/** Thông tin khách hàng dạng hàng `sd-section-item`: nhãn bên trái, giá trị bên phải. */\\n@Component({\\n selector: \\'general-information-view\\',\\n standalone: true,\\n imports: [SdSection, SdSectionItem, SdEmptyPipe, SdFormatDatePipe, SdFormatNumberPipe],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let item = customer();\\n <div class=\"d-flex flex-column gap-16\">\\n <sd-section title=\"Thông tin chung\">\\n <sd-section-item label=\"Mã khách hàng\">{{ item.code }}</sd-section-item>\\n <sd-section-item label=\"Tên khách hàng\">{{ item.name }}</sd-section-item>\\n <sd-section-item label=\"Loại khách hàng\">{{ typeName() }}{{ item.tier === \\'vip\\' ? \\' · VIP\\' : \\'\\' }}</sd-section-item>\\n @if (item.type === \\'business\\') {\\n <sd-section-item label=\"Mã số thuế\">{{ item.taxCode | sdEmpty }}</sd-section-item>\\n }\\n <sd-section-item label=\"Ngày tạo\">{{ item.createdAt | sdFormatDate }}</sd-section-item>\\n </sd-section>\\n <sd-section title=\"Liên hệ\">\\n <sd-section-item label=\"Email\">{{ item.email }}</sd-section-item>\\n <sd-section-item label=\"Điện thoại\">{{ item.phone }}</sd-section-item>\\n <sd-section-item label=\"Địa chỉ\">{{ item.address | sdEmpty }}</sd-section-item>\\n </sd-section>\\n <sd-section title=\"Khác\">\\n <sd-section-item label=\"Công nợ (₫)\">{{ item.debt | sdFormatNumber: 0 }}</sd-section-item>\\n <sd-section-item label=\"Ghi chú\">{{ item.note | sdEmpty }}</sd-section-item>\\n </sd-section>\\n </div>\\n `,\\n})\\nexport class GeneralInformationViewComponent {\\n readonly customer = input.required<CustomerDto>();\\n protected readonly typeName = computed(() => customerTypeName(this.customer().type));\\n}\\n',\n 'features/customer/components/orders-view/orders-view.component.ts': 'import { ChangeDetectionStrategy, Component, inject, input } from \\'@angular/core\\';\\nimport { RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerOrderDto } from \\'../../services/customer.model\\';\\n\\n/** Tab Đơn hàng của hồ sơ 360°: tải khi tab được mở lần đầu; bảng tự có trạng thái đang tải, rỗng và lỗi. */\\n@Component({\\n selector: \\'orders-view\\',\\n standalone: true,\\n imports: [RouterLink, SdTable, SdTableCellDefDirective],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-table autoId=\"customer-orders\" [option]=\"option\">\\n <ng-template sdTableCellDef=\"code\" let-order=\"item\">\\n <a [routerLink]=\"[\\'../../../order\\', order.id, \\'detail\\']\">{{ order.code }}</a>\\n </ng-template>\\n </sd-table>\\n `,\\n})\\nexport class OrdersViewComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly customerId = input.required<string>();\\n protected readonly option: SdTableOption<CustomerOrderDto> = {\\n type: \\'server\\',\\n items: () => firstValueFrom(this.#customerService.orders(this.customerId())),\\n paginate: { pageSize: 10 },\\n columns: [\\n { field: \\'code\\', title: \\'Mã đơn\\', type: \\'string\\', width: \\'140px\\' },\\n { field: \\'createdAt\\', title: \\'Ngày tạo\\', type: \\'date\\', width: \\'160px\\' },\\n { field: \\'total\\', title: \\'Tổng tiền (₫)\\', type: \\'number\\', align: \\'right\\' },\\n ],\\n };\\n}\\n',\n 'features/customer/components/summary-cards/summary-cards.component.ts': 'import { ChangeDetectionStrategy, Component, computed, inject, input, linkedSignal, model } from \\'@angular/core\\';\\nimport { SdCard, SdCardGroup } from \\'@sdcorejs/angular/components/card\\';\\nimport { SD_PAGE_LIST } from \\'@sdcorejs/angular/modules/layout\\';\\nimport type { CustomerCounts, CustomerSegment } from \\'../../services/customer.model\\';\\n\\nconst CARDS: readonly { readonly key: \\'all\\' | CustomerSegment; readonly label: string }[] = [\\n { key: \\'all\\', label: \\'Tất cả khách hàng\\' },\\n { key: \\'individual\\', label: \\'Cá nhân\\' },\\n { key: \\'business\\', label: \\'Doanh nghiệp\\' },\\n { key: \\'vip\\', label: \\'Khách VIP\\' },\\n];\\n\\n/**\\n * Score card của danh sách khách hàng: mỗi thẻ là một nhóm khách và là bộ lọc của danh sách.\\n * Khi `sd-page-list` thu gọn (màn thấp), các thẻ thành một dòng 36px.\\n */\\n@Component({\\n selector: \\'summary-cards\\',\\n standalone: true,\\n imports: [SdCard, SdCardGroup],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-card-group\\n class=\"summary\"\\n autoId=\"customer-segments\"\\n aria-label=\"Nhóm khách hàng\"\\n [class.summary--compact]=\"compact()\"\\n [(model)]=\"selected\"\\n (sdChange)=\"choose($event)\">\\n @for (card of cards(); track card.key) {\\n <sd-card class=\"summary__card\" [value]=\"card.key\" [autoId]=\"\\'customer-segment-\\' + card.key\">\\n <span class=\"summary__label\">{{ card.label }}</span>\\n <strong class=\"summary__value\">{{ card.value }}</strong>\\n </sd-card>\\n }\\n </sd-card-group>\\n `,\\n styles: `\\n .summary {\\n display: grid;\\n grid-template-columns: repeat(4, minmax(0, 1fr));\\n gap: 12px;\\n }\\n .summary__card {\\n display: flex;\\n flex-direction: column;\\n gap: 4px;\\n padding: 12px 16px;\\n }\\n .summary__label {\\n color: var(--sd-text-secondary);\\n font-size: 13px;\\n }\\n .summary__value {\\n font-size: 22px;\\n line-height: 28px;\\n font-weight: 500;\\n font-variant-numeric: tabular-nums;\\n }\\n .summary--compact {\\n display: flex;\\n align-items: center;\\n gap: 8px;\\n height: 36px;\\n }\\n .summary--compact .summary__card {\\n flex-direction: row;\\n align-items: baseline;\\n gap: 6px;\\n padding: 4px 10px;\\n }\\n .summary--compact .summary__value {\\n font-size: 14px;\\n line-height: 20px;\\n }\\n @media (max-width: 767px) {\\n .summary {\\n grid-template-columns: repeat(2, minmax(0, 1fr));\\n }\\n }\\n `,\\n})\\nexport class SummaryCardsComponent {\\n readonly #list = inject(SD_PAGE_LIST);\\n readonly counts = input<CustomerCounts | null>(null);\\n /** Nhóm đang lọc; `null` là tất cả. */\\n readonly segment = model<CustomerSegment | null>(null);\\n protected readonly compact = this.#list.compact;\\n protected readonly selected = linkedSignal<\\'all\\' | CustomerSegment | null>(() => this.segment() ?? \\'all\\');\\n protected readonly cards = computed(() => {\\n const counts = this.counts();\\n return CARDS.map(card => ({ ...card, value: counts ? counts[card.key].toLocaleString(\\'vi-VN\\') : \\'…\\' }));\\n });\\n\\n protected choose(key: unknown): void {\\n // Bấm lại thẻ đang chọn (model về null) hoặc thẻ \"Tất cả\" đều là bỏ lọc.\\n const segment = key === null || key === \\'all\\' ? null : (key as CustomerSegment);\\n this.selected.set(segment ?? \\'all\\');\\n this.segment.set(segment);\\n }\\n}\\n',\n 'features/customer/components/update-side-drawer/update-side-drawer.component.ts': 'import {\\n afterNextRender,\\n ChangeDetectionStrategy,\\n Component,\\n DestroyRef,\\n ElementRef,\\n inject,\\n Injector,\\n signal,\\n viewChild,\\n} from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport type { CustomerDto } from \\'../../services/customer.model\\';\\nimport {\\n customerSaveReq,\\n GeneralInformationFormComponent,\\n invalidCustomerGroups,\\n type CustomerForm,\\n type CustomerFormGroup,\\n} from \\'../general-information-form/general-information-form.component\\';\\n\\n/**\\n * Cập nhật khách hàng trong drawer (route con `:id/update`). X, Esc và backdrop đi qua `beforeClose`: còn thay đổi\\n * thì hỏi trước khi bỏ. Lưu thành công thì đóng drawer; danh sách tải lại và focus trở về dòng đã mở.\\n */\\n@Component({\\n selector: \\'update-side-drawer\\',\\n standalone: true,\\n imports: [SdSideDrawer, SdButton, GeneralInformationFormComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-side-drawer\\n [title]=\"\\'Cập nhật khách hàng #\\' + entity().code\"\\n width=\"600px\"\\n autoId=\"customer-update\"\\n [beforeClose]=\"beforeClose\"\\n (sdClosed)=\"closed()\">\\n <general-information-form [form]=\"form\" [seed]=\"entity()\" [errors]=\"apiErrors.errors()\" [invalidGroups]=\"invalidGroups()\" />\\n <div sdFooterRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Lưu\" prefixIcon=\"save\" type=\"fill\" color=\"primary\" autoId=\"customer-save\" [loading]=\"saving()\" (click)=\"save()\" />\\n </div>\\n </sd-side-drawer>\\n `,\\n})\\nexport class UpdateSideDrawerComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #injector = inject(Injector);\\n private readonly drawer = viewChild.required(SdSideDrawer);\\n // why: sd-side-drawer chuyển nội dung ra body, nên tìm field lỗi trong form chứ không trong host của component.\\n private readonly formElement = viewChild.required(GeneralInformationFormComponent, { read: ElementRef });\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as CustomerDto)), { requireSync: true });\\n protected readonly form: CustomerForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n protected readonly invalidGroups = signal<CustomerFormGroup[]>([]);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'customer-update\\', dirty: \\'value\\' });\\n\\n /** Đóng khi còn thay đổi chưa lưu: hỏi, đồng ý thì bỏ thay đổi (guard rời route không hỏi lại). */\\n protected readonly beforeClose = async (): Promise<boolean> => {\\n if (!this.#unsaved.dirty() || this.saving()) return !this.saving();\\n try {\\n await this.#confirm.confirm(\\'Thay đổi chưa lưu sẽ bị mất.\\', {\\n title: \\'Đóng khi chưa lưu?\\',\\n yesTitle: \\'Bỏ thay đổi\\',\\n noTitle: \\'Tiếp tục sửa\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } catch {\\n return false;\\n }\\n this.#unsaved.markPristine();\\n return true;\\n };\\n\\n constructor() {\\n afterNextRender(() => this.drawer().open());\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected closed(): void {\\n void this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#showErrors();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n await firstValueFrom(this.#customerService.update(this.entity().id, customerSaveReq(this.form)));\\n this.#unsaved.markPristine();\\n this.#notify.success(\\'Đã cập nhật khách hàng.\\');\\n this.saving.set(false);\\n this.drawer().close();\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#showErrors();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n /** `sd-inform` trong từng nhóm có lỗi, rồi focus field lỗi đầu tiên. */\\n #showErrors(): void {\\n this.invalidGroups.set(invalidCustomerGroups(this.form, this.apiErrors.errors()));\\n afterNextRender(() => focusFirstInvalid(this.formElement().nativeElement), { injector: this.#injector });\\n }\\n}\\n',\n 'features/customer/entity.resolver.ts': 'import { HttpErrorResponse } from \\'@angular/common/http\\';\\nimport { inject } from \\'@angular/core\\';\\nimport type { ResolveFn } from \\'@angular/router\\';\\nimport { map, timeout } from \\'rxjs\\';\\nimport { CustomerService } from \\'./services/customer.service\\';\\nimport type { CustomerDto } from \\'./services/customer.model\\';\\n\\n/** Tải khách hàng bằng `detail(id)` trước khi mở drawer/trang; lỗi đi tới navigation error handler của host. */\\nexport const entityResolver: ResolveFn<CustomerDto> = route => {\\n const id = route.paramMap.get(\\'id\\');\\n if (!id?.trim()) throw new HttpErrorResponse({ status: 404 });\\n return inject(CustomerService)\\n .detail(id)\\n .pipe(\\n timeout(10_000),\\n map(entity => {\\n if (!entity || entity.id !== id) throw new HttpErrorResponse({ status: 404 });\\n return entity;\\n })\\n );\\n};\\n',\n 'features/customer/pages/list/list.component.html': '<sd-page-list title=\"Khách hàng\" description=\"Khách cá nhân và doanh nghiệp đang giao dịch.\" [detail]=\"detailMode()\">\\n <sd-button\\n headerRight\\n *sdPermission=\"\\'PATTERN_CUSTOMER_C_CREATE\\'\"\\n title=\"Tạo khách hàng\"\\n prefixIcon=\"add\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"customer-create\"\\n [routerLink]=\"[\\'create\\']\" />\\n\\n <summary-cards [counts]=\"counts()\" [(segment)]=\"segment\" />\\n\\n <sd-table autoId=\"customer-list\" [option]=\"tableOption\">\\n <ng-template sdTableCellDef=\"code\" let-customer=\"item\">\\n <a *sdPermission=\"\\'PATTERN_CUSTOMER_R_DETAIL\\'\" [routerLink]=\"[customer.id, \\'detail\\']\">{{ customer.code }}</a>\\n @if (!canOpenDetail) {\\n <span>{{ customer.code }}</span>\\n }\\n </ng-template>\\n </sd-table>\\n</sd-page-list>\\n',\n 'features/customer/pages/list/list.component.ts': 'import { ChangeDetectionStrategy, Component, effect, inject, signal, untracked, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, NavigationEnd, Router, RouterLink } from \\'@angular/router\\';\\nimport { filter, firstValueFrom, map, startWith } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { SdPageList, type SdPageListDetail } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective, SdPermissionService } from \\'@sdcorejs/angular/modules/permission\\';\\nimport type { Filter } from \\'@sdcorejs/utils/models\\';\\nimport { SummaryCardsComponent } from \\'../../components/summary-cards/summary-cards.component\\';\\nimport { CustomerService } from \\'../../services/customer.service\\';\\nimport {\\n CUSTOMER_STATUS_OPTIONS,\\n CUSTOMER_TYPE_OPTIONS,\\n customerStatusBadge,\\n type CustomerCounts,\\n type CustomerDto,\\n type CustomerSegment,\\n} from \\'../../services/customer.model\\';\\n\\n/** Điều kiện của nhóm khách đang chọn trên score card. */\\nconst SEGMENT_FILTER: Readonly<Record<CustomerSegment, Filter<CustomerDto>>> = {\\n individual: { field: \\'type\\', operator: \\'EQUAL\\', data: \\'individual\\' },\\n business: { field: \\'type\\', operator: \\'EQUAL\\', data: \\'business\\' },\\n vip: { field: \\'tier\\', operator: \\'EQUAL\\', data: \\'vip\\' },\\n};\\n\\n@Component({\\n selector: \\'list\\',\\n standalone: true,\\n templateUrl: \\'./list.component.html\\',\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [RouterLink, SdPageList, SdButton, SdTable, SdTableCellDefDirective, SdPermissionDirective, SummaryCardsComponent],\\n})\\nexport class ListComponent {\\n readonly #customerService = inject(CustomerService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly pageList = viewChild.required(SdPageList);\\n private readonly table = viewChild.required(SdTable);\\n protected readonly canOpenDetail = inject(SdPermissionService).hasPermission(\\'PATTERN_CUSTOMER_R_DETAIL\\');\\n\\n /** Một state cho score card và request: đổi nhóm thì đọc lại từ trang 1. */\\n protected readonly segment = signal<CustomerSegment | null>(null);\\n protected readonly counts = signal<CustomerCounts | null>(null);\\n /** Detail, create, update mở trong drawer; hồ sơ 360° (`data.detail: \\'page\\'`) thay chỗ danh sách. */\\n protected readonly detailMode = toSignal(\\n this.#router.events.pipe(\\n filter(event => event instanceof NavigationEnd),\\n startWith(null),\\n map((): SdPageListDetail => (this.#route.firstChild?.snapshot.data[\\'detail\\'] === \\'page\\' ? \\'page\\' : \\'drawer\\'))\\n ),\\n { requireSync: true }\\n );\\n\\n protected readonly tableOption: SdTableOption<CustomerDto> = {\\n type: \\'server\\',\\n rowKey: \\'id\\',\\n items: async (_, req) => {\\n const segment = untracked(this.segment);\\n // Số trên thẻ theo cùng bộ lọc của bảng, chưa tính nhóm đang chọn.\\n void firstValueFrom(this.#customerService.counts(req.filters ?? [])).then(counts => this.counts.set(counts));\\n const filters = segment ? [...(req.filters ?? []), SEGMENT_FILTER[segment]] : req.filters;\\n return firstValueFrom(this.#customerService.list({ ...req, filters }));\\n },\\n sort: { enable: true },\\n filter: {\\n quickSearch: { containFields: [\\'code\\', \\'name\\', \\'phone\\'], placeholder: \\'Tìm theo mã, tên hoặc số điện thoại\\' },\\n },\\n columns: [\\n { field: \\'code\\', title: \\'Mã khách hàng\\', type: \\'string\\', width: \\'150px\\', sortable: true },\\n { field: \\'name\\', title: \\'Tên khách hàng\\', type: \\'string\\', minWidth: \\'220px\\', sortable: true },\\n {\\n field: \\'type\\',\\n title: \\'Loại\\',\\n type: \\'values\\',\\n width: \\'140px\\',\\n option: { items: CUSTOMER_TYPE_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n // Score card là chỗ lọc theo loại khách: mỗi field chỉ một chỗ lọc (E6).\\n filter: { disabled: true },\\n },\\n { field: \\'phone\\', title: \\'Điện thoại\\', type: \\'string\\', width: \\'140px\\' },\\n { field: \\'email\\', title: \\'Email\\', type: \\'string\\', minWidth: \\'200px\\' },\\n { field: \\'debt\\', title: \\'Công nợ (₫)\\', type: \\'number\\', width: \\'150px\\', align: \\'right\\', sortable: true },\\n {\\n field: \\'status\\',\\n title: \\'Trạng thái\\',\\n type: \\'values\\',\\n width: \\'170px\\',\\n option: { items: CUSTOMER_STATUS_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: status => customerStatusBadge(status),\\n },\\n ],\\n };\\n\\n constructor() {\\n let segment = this.segment();\\n effect(() => {\\n const next = this.segment();\\n if (next === segment) return;\\n segment = next;\\n untracked(() => void this.table().reloadFirstPage());\\n });\\n // Chỉ tải lại danh sách khi drawer/trang con đã lưu thành công, không phải mỗi lần đóng.\\n let changes = this.#customerService.changes();\\n effect(() => {\\n const next = this.#customerService.changes();\\n if (this.pageList().childActive() || next === changes) return;\\n changes = next;\\n untracked(() => void this.table().reload(true, false));\\n });\\n }\\n}\\n',\n 'features/customer/pages/profile/profile.component.ts': 'import { ChangeDetectionStrategy, Component, computed, inject, linkedSignal, untracked } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdTab, SdTabGroup } from \\'@sdcorejs/angular/components/tab\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { DebtsViewComponent } from \\'../../components/debts-view/debts-view.component\\';\\nimport { DocumentsViewComponent } from \\'../../components/documents-view/documents-view.component\\';\\nimport { GeneralInformationViewComponent } from \\'../../components/general-information-view/general-information-view.component\\';\\nimport { OrdersViewComponent } from \\'../../components/orders-view/orders-view.component\\';\\nimport { customerStatusBadge, customerTypeName, type CustomerDto } from \\'../../services/customer.model\\';\\n\\nconst TABS = [\\n { key: \\'info\\', label: \\'Thông tin\\' },\\n { key: \\'orders\\', label: \\'Đơn hàng\\' },\\n { key: \\'debts\\', label: \\'Công nợ\\' },\\n { key: \\'documents\\', label: \\'Tài liệu\\' },\\n] as const;\\ntype TabKey = (typeof TABS)[number][\\'key\\'];\\n\\n/**\\n * Hồ sơ 360° (`:id/360`): thông tin chung và các quan hệ của khách hàng theo tab. Tab ghi trên URL (`?tab=`);\\n * mở tab nào mới tải tab đó, mỗi tab tự có trạng thái đang tải, rỗng và lỗi.\\n */\\n@Component({\\n selector: \\'profile\\',\\n standalone: true,\\n imports: [\\n RouterLink,\\n SdPageComponent,\\n SdButton,\\n SdTabGroup,\\n SdTab,\\n SdPermissionDirective,\\n GeneralInformationViewComponent,\\n OrdersViewComponent,\\n DebtsViewComponent,\\n DocumentsViewComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let customer = entity();\\n <sd-page-detail\\n [title]=\"\\'Hồ sơ khách hàng #\\' + customer.code\"\\n [description]=\"customer.name + \\' · \\' + typeName()\"\\n [badges]=\"badges()\"\\n [backLink]=\"[\\'../..\\']\">\\n <sd-button\\n headerRight\\n *sdPermission=\"\\'PATTERN_CUSTOMER_U_UPDATE\\'\"\\n title=\"Cập nhật khách hàng\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"customer-profile-update\"\\n [routerLink]=\"[\\'../update\\']\" />\\n <sd-tab-group sdSubheader [selectedIndex]=\"tabIndex()\" (selectedIndexChange)=\"selectTab($event)\">\\n @for (tab of tabs; track tab.key) {\\n <sd-tab [label]=\"tab.label\" />\\n }\\n </sd-tab-group>\\n <div class=\"py-16\">\\n @for (tab of tabs; track tab.key; let index = $index) {\\n @if (opened().has(tab.key)) {\\n <div [hidden]=\"tabIndex() !== index\" [attr.data-customer-tab]=\"tab.key\">\\n @switch (tab.key) {\\n @case (\\'info\\') {\\n <general-information-view [customer]=\"customer\" />\\n }\\n @case (\\'orders\\') {\\n <orders-view [customerId]=\"customer.id\" />\\n }\\n @case (\\'debts\\') {\\n <debts-view [customerId]=\"customer.id\" />\\n }\\n @case (\\'documents\\') {\\n <documents-view [customerId]=\"customer.id\" />\\n }\\n }\\n </div>\\n }\\n }\\n </div>\\n </sd-page-detail>\\n `,\\n})\\nexport class ProfileComponent {\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n protected readonly tabs = TABS;\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as CustomerDto)), { requireSync: true });\\n protected readonly badges = computed(() => [customerStatusBadge(this.entity().status)]);\\n protected readonly typeName = computed(() => customerTypeName(this.entity().type));\\n readonly #tabParam = toSignal(this.#route.queryParamMap.pipe(map(params => params.get(\\'tab\\'))), { requireSync: true });\\n protected readonly tabIndex = computed(() =>\\n Math.max(\\n 0,\\n TABS.findIndex(tab => tab.key === this.#tabParam())\\n )\\n );\\n /** Tab đã mở ít nhất một lần: giữ lại khi chuyển tab, không tải lại. Đổi khách hàng thì bắt đầu lại. */\\n protected readonly opened = linkedSignal<CustomerDto, ReadonlySet<TabKey>>({\\n source: this.entity,\\n // untracked: đổi tab không được đặt lại các tab đã mở; chỉ đổi khách hàng mới bắt đầu lại.\\n computation: () => new Set<TabKey>([TABS[untracked(this.tabIndex)].key]),\\n });\\n\\n protected selectTab(index: number): void {\\n const key = TABS[index]?.key ?? \\'info\\';\\n this.opened.update(opened => new Set([...opened, key]));\\n void this.#router.navigate([], {\\n relativeTo: this.#route,\\n queryParams: { tab: key === \\'info\\' ? null : key },\\n queryParamsHandling: \\'merge\\',\\n replaceUrl: true,\\n });\\n }\\n}\\n',\n 'features/customer/pipes/customer-detail.pipe.ts': 'import { inject, Pipe, type PipeTransform } from \\'@angular/core\\';\\nimport { of, type Observable } from \\'rxjs\\';\\nimport { CustomerService } from \\'../services/customer.service\\';\\nimport type { CustomerDto } from \\'../services/customer.model\\';\\n\\n/**\\n * Relation khách hàng theo ID: `@let customer = order.customerId | customerDetail | async;`.\\n * CustomerService cache và chia sẻ request theo ID; nơi dùng pipe phải có CustomerService trong injector.\\n */\\n@Pipe({ name: \\'customerDetail\\', standalone: true })\\nexport class CustomerDetailPipe implements PipeTransform {\\n readonly #customerService = inject(CustomerService);\\n\\n transform(id: CustomerDto[\\'id\\'] | null | undefined): Observable<CustomerDto | null> {\\n if (id === null || id === undefined || id === \\'\\') return of(null);\\n return this.#customerService.cachedDetail(id);\\n }\\n}\\n',\n 'features/customer/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { entityResolver } from \\'./entity.resolver\\';\\nimport { CustomerService } from \\'./services/customer.service\\';\\n\\n/**\\n * Chi tiết, tạo và cập nhật mở trong drawer (route con của danh sách); hồ sơ 360° là trang thay chỗ danh sách\\n * (`data.detail: \\'page\\'`). Đóng drawer hay quay lại đều giữ bộ lọc, trang và vị trí cuộn của danh sách.\\n */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [CustomerService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Khách hàng\\',\\n data: { permission: \\'PATTERN_CUSTOMER_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\'create\\',\\n data: { permission: \\'PATTERN_CUSTOMER_C_CREATE\\' },\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () =>\\n import(\\'./components/create-side-drawer/create-side-drawer.component\\').then(module => module.CreateSideDrawerComponent),\\n },\\n {\\n path: \\':id/detail\\',\\n data: { permission: \\'PATTERN_CUSTOMER_R_DETAIL\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () =>\\n import(\\'./components/detail-side-drawer/detail-side-drawer.component\\').then(module => module.DetailSideDrawerComponent),\\n },\\n {\\n path: \\':id/update\\',\\n data: { permission: \\'PATTERN_CUSTOMER_U_UPDATE\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () =>\\n import(\\'./components/update-side-drawer/update-side-drawer.component\\').then(module => module.UpdateSideDrawerComponent),\\n },\\n {\\n path: \\':id/360\\',\\n title: \\'Hồ sơ khách hàng\\',\\n data: { permission: \\'PATTERN_CUSTOMER_R_DETAIL\\', detail: \\'page\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () => import(\\'./pages/profile/profile.component\\').then(module => module.ProfileComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n',\n 'features/customer/services/customer.model.ts': 'import type { SdBadgeData } from \\'@sdcorejs/angular/components/badge\\';\\nimport type { PagingReq, PagingRes } from \\'@sdcorejs/utils/models\\';\\n\\nexport type CustomerType = \\'individual\\' | \\'business\\';\\nexport type CustomerTier = \\'standard\\' | \\'vip\\';\\nexport type CustomerStatus = \\'active\\' | \\'inactive\\';\\n\\nexport const CUSTOMER_TYPE_OPTIONS = [\\n { id: \\'individual\\', name: \\'Cá nhân\\' },\\n { id: \\'business\\', name: \\'Doanh nghiệp\\' },\\n] satisfies { id: CustomerType; name: string }[];\\n\\nexport const CUSTOMER_STATUS_OPTIONS = [\\n { id: \\'active\\', name: \\'Đang hoạt động\\', color: \\'success\\' },\\n { id: \\'inactive\\', name: \\'Ngừng hoạt động\\', color: \\'secondary\\' },\\n] satisfies { id: CustomerStatus; name: string; color: SdBadgeData[\\'color\\'] }[];\\n\\n/** Nhóm khách của score card; `null` là tất cả. */\\nexport type CustomerSegment = \\'individual\\' | \\'business\\' | \\'vip\\';\\n\\nexport interface CustomerDto {\\n readonly id: string;\\n readonly code: string;\\n readonly name: string;\\n readonly type: CustomerType;\\n readonly tier: CustomerTier;\\n readonly email: string;\\n readonly phone: string;\\n readonly address: string;\\n readonly taxCode: string | null;\\n readonly status: CustomerStatus;\\n /** Công nợ hiện tại (₫). */\\n readonly debt: number;\\n readonly createdAt: string;\\n readonly note: string | null;\\n}\\n\\nexport type CustomerListReq = PagingReq<CustomerDto>;\\nexport type CustomerListRes = PagingRes<CustomerDto>;\\n\\n/** Số khách theo nhóm, cùng bộ lọc với danh sách (trừ nhóm đang chọn). */\\nexport type CustomerCounts = Record<\\'all\\' | CustomerSegment, number>;\\n\\nexport interface CustomerSaveReq {\\n readonly name: string;\\n readonly type: CustomerType;\\n readonly tier: CustomerTier;\\n readonly email: string;\\n readonly phone: string;\\n readonly address: string;\\n readonly taxCode: string | null;\\n readonly status: CustomerStatus;\\n readonly note: string | null;\\n}\\n\\n/** Dòng của tab Đơn hàng trong hồ sơ 360°. */\\nexport interface CustomerOrderDto {\\n readonly id: string;\\n readonly code: string;\\n readonly createdAt: string;\\n readonly total: number;\\n readonly status: string;\\n}\\n\\n/** Dòng của tab Công nợ. */\\nexport interface CustomerDebtDto {\\n readonly id: string;\\n readonly orderCode: string;\\n readonly dueDate: string;\\n readonly amount: number;\\n}\\n\\n/** Dòng của tab Tài liệu. */\\nexport interface CustomerDocumentDto {\\n readonly id: string;\\n readonly name: string;\\n readonly size: number;\\n}\\n\\nexport function customerStatusBadge(status: CustomerStatus): SdBadgeData {\\n const option = CUSTOMER_STATUS_OPTIONS.find(item => item.id === status);\\n return { type: \\'round\\', title: option?.name ?? status, color: option?.color };\\n}\\n\\nexport function customerTypeName(type: CustomerType): string {\\n return CUSTOMER_TYPE_OPTIONS.find(item => item.id === type)?.name ?? type;\\n}\\n',\n 'features/customer/services/customer.service.ts': 'import { HttpParams } from \\'@angular/common/http\\';\\nimport { Injectable, signal } from \\'@angular/core\\';\\nimport { shareReplay, tap, type Observable } from \\'rxjs\\';\\nimport type { Filter, PagingRes } from \\'@sdcorejs/utils/models\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type {\\n CustomerCounts,\\n CustomerDebtDto,\\n CustomerDocumentDto,\\n CustomerDto,\\n CustomerListReq,\\n CustomerListRes,\\n CustomerOrderDto,\\n CustomerSaveReq,\\n} from \\'./customer.model\\';\\n\\n@Injectable()\\nexport class CustomerService extends BaseApiService {\\n readonly #details = new Map<string, Observable<CustomerDto>>();\\n readonly #changes = signal(0);\\n /** Tăng sau mỗi lần tạo, cập nhật hoặc xoá thành công: danh sách chỉ tải lại khi có thay đổi. */\\n readonly changes = this.#changes.asReadonly();\\n\\n list(req: CustomerListReq): Observable<CustomerListRes> {\\n return this.http.get<CustomerListRes>(this.apiUrl(\\'customers\\'), { params: this.buildPagingReq(req) });\\n }\\n\\n /** Số khách theo nhóm cho score card, theo cùng bộ lọc của danh sách. */\\n counts(filters: Filter<CustomerDto>[]): Observable<CustomerCounts> {\\n return this.http.get<CustomerCounts>(this.apiUrl(\\'customers\\', \\'counts\\'), {\\n params: new HttpParams().set(\\'filters\\', JSON.stringify(filters)),\\n });\\n }\\n\\n detail(id: string): Observable<CustomerDto> {\\n return this.http.get<CustomerDto>(this.apiUrl(\\'customers\\', id));\\n }\\n\\n /** `detail(id)` có cache, cho relation (`customerDetail`) và giá trị đã chọn của `customer-select`. */\\n cachedDetail(id: string): Observable<CustomerDto> {\\n let detail = this.#details.get(id);\\n if (!detail) {\\n detail = this.detail(id).pipe(shareReplay({ bufferSize: 1, refCount: false }));\\n this.#details.set(id, detail);\\n // Lỗi tra cứu không được cache: lần gọi sau hỏi lại.\\n detail.subscribe({ error: () => this.#details.delete(id) });\\n }\\n return detail;\\n }\\n\\n create(req: CustomerSaveReq): Observable<CustomerDto> {\\n return this.http.post<CustomerDto>(this.apiUrl(\\'customers\\'), req).pipe(tap(() => this.#changed()));\\n }\\n\\n update(id: string, req: CustomerSaveReq): Observable<CustomerDto> {\\n return this.http.put<CustomerDto>(this.apiUrl(\\'customers\\', id), req).pipe(tap(() => this.#changed(id)));\\n }\\n\\n delete(id: string): Observable<void> {\\n return this.http.delete<void>(this.apiUrl(\\'customers\\', id)).pipe(tap(() => this.#changed(id)));\\n }\\n\\n orders(id: string): Observable<PagingRes<CustomerOrderDto>> {\\n return this.http.get<PagingRes<CustomerOrderDto>>(this.apiUrl(\\'customers\\', id, \\'orders\\'));\\n }\\n\\n debts(id: string): Observable<PagingRes<CustomerDebtDto>> {\\n return this.http.get<PagingRes<CustomerDebtDto>>(this.apiUrl(\\'customers\\', id, \\'debts\\'));\\n }\\n\\n documents(id: string): Observable<PagingRes<CustomerDocumentDto>> {\\n return this.http.get<PagingRes<CustomerDocumentDto>>(this.apiUrl(\\'customers\\', id, \\'documents\\'));\\n }\\n\\n #changed(id?: string): void {\\n if (id) this.#details.delete(id);\\n this.#changes.update(count => count + 1);\\n }\\n}\\n',\n 'features/import/components/mapping-form/mapping-form.component.ts': 'import { ChangeDetectionStrategy, Component, computed, input, output } from \\'@angular/core\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport { IMPORT_FIELDS, type ImportField, type ImportMapping } from \\'../../services/import.model\\';\\n\\n/** Bước \"Nhận diện & ánh xạ\": chọn cột của nguồn cho từng field; mã và tên là bắt buộc. */\\n@Component({\\n selector: \\'mapping-form\\',\\n standalone: true,\\n imports: [SdSelect],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <div class=\"d-flex flex-column gap-8\">\\n @for (item of fields; track item.field) {\\n <sd-select\\n [label]=\"item.label\"\\n [items]=\"columns()\"\\n valueField=\"value\"\\n displayField=\"value\"\\n [required]=\"item.required\"\\n [autoId]=\"\\'import-map-\\' + item.field\"\\n [model]=\"mapping()[item.field]\"\\n [inlineError]=\"\\n item.required && showErrors() && !mapping()[item.field] ? \\'Chọn cột cho \\' + item.label.toLowerCase() + \\'.\\' : undefined\\n \"\\n (modelChange)=\"change(item.field, $event)\" />\\n }\\n </div>\\n `,\\n})\\nexport class MappingFormComponent {\\n readonly sourceColumns = input.required<readonly string[]>();\\n readonly mapping = input.required<ImportMapping>();\\n readonly showErrors = input(false);\\n readonly mappingChange = output<ImportMapping>();\\n protected readonly fields = IMPORT_FIELDS;\\n protected readonly columns = computed(() => this.sourceColumns().map(value => ({ value })));\\n\\n protected change(field: ImportField, value: unknown): void {\\n this.mappingChange.emit({ ...this.mapping(), [field]: typeof value === \\'string\\' && value ? value : null });\\n }\\n}\\n',\n 'features/import/components/preview-view/preview-view.component.ts': 'import { ChangeDetectionStrategy, Component, computed, input } from \\'@angular/core\\';\\nimport { SdTable, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport type { ImportPreviewRowDto } from \\'../../services/import.model\\';\\n\\nconst RESULTS = [\\n { id: \\'new\\', name: \\'Thêm mới\\', color: \\'success\\' },\\n { id: \\'duplicate\\', name: \\'Trùng mã\\', color: \\'warning\\' },\\n { id: \\'invalid\\', name: \\'Lỗi\\', color: \\'error\\' },\\n] as const;\\n\\n/** Bước \"Xem trước & xung đột\": từng dòng với kết quả kiểm tra của API. */\\n@Component({\\n selector: \\'preview-view\\',\\n standalone: true,\\n imports: [SdTable],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-table autoId=\"import-preview\" [option]=\"option()\" />`,\\n})\\nexport class PreviewViewComponent {\\n readonly rows = input.required<readonly ImportPreviewRowDto[]>();\\n protected readonly option = computed<SdTableOption<ImportPreviewRowDto>>(() => {\\n const rows = [...this.rows()];\\n return {\\n type: \\'local\\',\\n items: () => rows,\\n paginate: { pageSize: 50 },\\n filter: { hideInlineFilter: \\'auto\\' },\\n columns: [\\n { field: \\'code\\', title: \\'Mã\\', type: \\'string\\', width: \\'110px\\' },\\n { field: \\'name\\', title: \\'Tên sản phẩm\\', type: \\'string\\', minWidth: \\'180px\\' },\\n { field: \\'price\\', title: \\'Giá bán (₫)\\', type: \\'number\\', width: \\'120px\\', align: \\'right\\' },\\n {\\n field: \\'result\\',\\n title: \\'Kết quả\\',\\n type: \\'values\\',\\n width: \\'130px\\',\\n option: { items: [...RESULTS], valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: result => ({ type: \\'round\\', color: RESULTS.find(item => item.id === result)?.color }),\\n },\\n { field: \\'message\\', title: \\'Ghi chú\\', type: \\'string\\', minWidth: \\'160px\\' },\\n ],\\n };\\n });\\n}\\n',\n 'features/import/pages/flow/flow.component.ts': 'import { ChangeDetectionStrategy, Component, computed, inject, signal } from \\'@angular/core\\';\\nimport { FormControl, FormGroup, Validators } from \\'@angular/forms\\';\\nimport { RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdStep, SdStepper } from \\'@sdcorejs/angular/components/stepper\\';\\nimport { SdSegmentedComponent, type SdSegmentedItem, type SdSegmentedModel } from \\'@sdcorejs/angular/forms/segmented\\';\\nimport { SdTextarea } from \\'@sdcorejs/angular/forms/textarea\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { MappingFormComponent } from \\'../../components/mapping-form/mapping-form.component\\';\\nimport { PreviewViewComponent } from \\'../../components/preview-view/preview-view.component\\';\\nimport { ImportService } from \\'../../services/import.service\\';\\nimport {\\n guessMapping,\\n IMPORT_FIELDS,\\n IMPORT_SAMPLE,\\n parseCsv,\\n type ImportCommitRes,\\n type ImportDuplicatePolicy,\\n type ImportMapping,\\n type ImportPreviewRowDto,\\n} from \\'../../services/import.model\\';\\n\\nconst DUPLICATES: readonly SdSegmentedItem<ImportDuplicatePolicy>[] = [\\n { value: \\'skip\\', label: \\'Bỏ qua dòng trùng\\' },\\n { value: \\'overwrite\\', label: \\'Ghi đè sản phẩm đã có\\' },\\n];\\n\\n/**\\n * Pattern flow ngang: `sd-page` hẹp + `sd-stepper`, nút bước ở footer. Bốn bước giữ dữ liệu khi quay lại; mỗi bước\\n * kiểm tra điều kiện của chính nó trước khi sang bước sau, bước cuối mới ghi dữ liệu.\\n */\\n@Component({\\n selector: \\'flow\\',\\n standalone: true,\\n imports: [\\n RouterLink,\\n SdPageComponent,\\n SdStepper,\\n SdStep,\\n SdButton,\\n SdInform,\\n SdSection,\\n SdSectionItem,\\n SdSegmentedComponent,\\n SdTextarea,\\n MappingFormComponent,\\n PreviewViewComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-page title=\"Nhập dữ liệu sản phẩm\" description=\"Nhập danh mục sản phẩm từ tệp CSV.\" [backLink]=\"[\\'..\\']\" width=\"narrow\">\\n <sd-stepper linear [(selectedIndex)]=\"step\" animationDuration=\"0ms\" autoId=\"import-steps\">\\n <sd-step label=\"Nguồn dữ liệu\" [stepControl]=\"gates[0]\">\\n <div class=\"d-flex flex-column gap-8 py-16\">\\n <sd-inform type=\"tip\" description=\"Dán nội dung CSV có dòng tiêu đề, hoặc dùng dữ liệu mẫu.\" />\\n <sd-textarea\\n label=\"Nội dung CSV\"\\n name=\"source\"\\n autoId=\"import-source\"\\n [form]=\"sourceForm\"\\n [model]=\"source()\"\\n (modelChange)=\"editSource($event ?? \\'\\')\"\\n [inlineError]=\"showErrors() && !rows().length ? \\'Cần ít nhất một dòng dữ liệu dưới dòng tiêu đề.\\' : undefined\"\\n [maxlength]=\"20000\"\\n required />\\n <div>\\n <sd-button title=\"Dùng dữ liệu mẫu\" type=\"text\" prefixIcon=\"description\" autoId=\"import-sample\" (click)=\"useSample()\" />\\n </div>\\n </div>\\n </sd-step>\\n <sd-step label=\"Nhận diện & ánh xạ\" [stepControl]=\"gates[1]\">\\n <div class=\"py-16\">\\n <p class=\"T14R text-secondary mt-0\">Đọc được {{ rows().length }} dòng, {{ columns().length }} cột.</p>\\n <mapping-form\\n [sourceColumns]=\"columns()\"\\n [mapping]=\"mapping()\"\\n [showErrors]=\"showErrors()\"\\n (mappingChange)=\"mapping.set($event)\" />\\n </div>\\n </sd-step>\\n <sd-step label=\"Xem trước & xung đột\" [stepControl]=\"gates[2]\">\\n <div class=\"d-flex flex-column gap-12 py-16\">\\n @if (preview(); as rows) {\\n <p class=\"T14R m-0\">\\n {{ counts().new }} dòng mới · {{ counts().duplicate }} dòng trùng mã · {{ counts().invalid }} dòng lỗi (bỏ qua)\\n </p>\\n <preview-view [rows]=\"rows\" />\\n @if (counts().duplicate) {\\n <sd-segmented\\n ariaLabel=\"Xử lý dòng trùng\"\\n autoId=\"import-duplicates\"\\n [items]=\"duplicateItems\"\\n [model]=\"duplicates()\"\\n (sdChange)=\"setDuplicates($event)\" />\\n }\\n } @else {\\n <p class=\"T14R text-secondary\">Đang kiểm tra dữ liệu…</p>\\n }\\n </div>\\n </sd-step>\\n <sd-step label=\"Xác nhận\">\\n <div class=\"py-16\">\\n @if (result(); as done) {\\n <sd-inform\\n success\\n title=\"Đã nhập dữ liệu\"\\n [description]=\"done.created + \\' sản phẩm mới, \\' + done.updated + \\' cập nhật, \\' + done.skipped + \\' bỏ qua.\\'\" />\\n <a class=\"d-inline-block mt-12\" [routerLink]=\"[\\'../product\\']\">Xem danh sách sản phẩm</a>\\n } @else {\\n <sd-section title=\"Tóm tắt\">\\n <sd-section-item label=\"Thêm mới\">{{ counts().new }}</sd-section-item>\\n <sd-section-item label=\"Trùng mã\"\\n >{{ counts().duplicate }} ({{ duplicates() === \\'overwrite\\' ? \\'ghi đè\\' : \\'bỏ qua\\' }})</sd-section-item\\n >\\n <sd-section-item label=\"Lỗi, bỏ qua\">{{ counts().invalid }}</sd-section-item>\\n </sd-section>\\n }\\n </div>\\n </sd-step>\\n </sd-stepper>\\n <sd-button\\n sdFooterLeft\\n title=\"Quay lại\"\\n type=\"outline\"\\n autoId=\"import-previous\"\\n [disabled]=\"step() === 0 || !!result()\"\\n (click)=\"step.set(step() - 1)\" />\\n @if (step() < 3) {\\n <sd-button\\n sdFooterRight\\n title=\"Tiếp tục\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"import-next\"\\n [loading]=\"checking()\"\\n (click)=\"next()\" />\\n } @else if (!result()) {\\n <sd-button\\n sdFooterRight\\n title=\"Nhập dữ liệu\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"import-commit\"\\n [loading]=\"committing()\"\\n (click)=\"commit()\" />\\n }\\n </sd-page>\\n `,\\n})\\nexport class FlowComponent {\\n readonly #importService = inject(ImportService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n protected readonly duplicateItems = DUPLICATES;\\n protected readonly step = signal(0);\\n /**\\n * Một cổng cho mỗi bước: chỉ đúng sau khi bước đó qua kiểm tra, nên stepper `linear` không cho bấm tiêu đề để\\n * vượt qua bước chưa kiểm tra. Đổi nguồn dữ liệu thì đóng lại các bước sau.\\n */\\n protected readonly gates = [0, 1, 2].map(() => new FormControl(false, { nonNullable: true, validators: Validators.requiredTrue }));\\n protected readonly showErrors = signal(false);\\n /** Chỉ để đánh dấu đã chạm ô nguồn khi bấm Tiếp: lỗi của ô hiện ngay cả khi người dùng chưa gõ gì. */\\n protected readonly sourceForm = new FormGroup({});\\n protected readonly source = signal(\\'\\');\\n readonly #parsed = computed(() => parseCsv(this.source()));\\n protected readonly columns = computed(() => this.#parsed().columns);\\n protected readonly rows = computed(() => this.#parsed().rows);\\n protected readonly mapping = signal<ImportMapping>({ code: null, name: null, unit: null, price: null });\\n protected readonly preview = signal<readonly ImportPreviewRowDto[] | null>(null);\\n protected readonly duplicates = signal<ImportDuplicatePolicy>(\\'skip\\');\\n protected readonly checking = signal(false);\\n protected readonly committing = signal(false);\\n protected readonly result = signal<ImportCommitRes | null>(null);\\n protected readonly counts = computed(() => {\\n const rows = this.preview() ?? [];\\n return {\\n new: rows.filter(row => row.result === \\'new\\').length,\\n duplicate: rows.filter(row => row.result === \\'duplicate\\').length,\\n invalid: rows.filter(row => row.result === \\'invalid\\').length,\\n };\\n });\\n\\n protected useSample(): void {\\n this.editSource(IMPORT_SAMPLE);\\n }\\n\\n /** Đổi nguồn thì các bước sau phải kiểm tra lại. */\\n protected editSource(value: string): void {\\n this.source.set(value);\\n this.gates.forEach(gate => gate.setValue(false));\\n }\\n\\n protected setDuplicates(value: SdSegmentedModel<ImportDuplicatePolicy>): void {\\n if (value === \\'skip\\' || value === \\'overwrite\\') this.duplicates.set(value);\\n }\\n\\n protected async next(): Promise<void> {\\n const step = this.step();\\n if (step === 0) {\\n if (!this.rows().length) {\\n this.sourceForm.markAllAsTouched();\\n return this.showErrors.set(true);\\n }\\n // Nguồn mới: ánh xạ lại theo tên cột, bỏ kết quả kiểm tra cũ.\\n this.mapping.set(guessMapping(this.columns()));\\n this.preview.set(null);\\n this.gates.slice(1).forEach(gate => gate.setValue(false));\\n }\\n if (step === 1) {\\n const missing = IMPORT_FIELDS.some(field => field.required && !this.mapping()[field.field]);\\n if (missing) return this.showErrors.set(true);\\n if (!(await this.#check())) return;\\n }\\n this.showErrors.set(false);\\n this.gates[step].setValue(true);\\n this.step.set(step + 1);\\n }\\n\\n protected async commit(): Promise<void> {\\n const { new: created, duplicate } = this.counts();\\n const overwrite = this.duplicates() === \\'overwrite\\' ? duplicate : 0;\\n try {\\n await this.#confirm.confirm(`Thêm ${created} sản phẩm${overwrite ? `, ghi đè ${overwrite} sản phẩm` : \\'\\'}?`, {\\n title: \\'Nhập dữ liệu\\',\\n yesTitle: \\'Nhập dữ liệu\\',\\n noTitle: \\'Không\\',\\n });\\n } catch {\\n return;\\n }\\n this.committing.set(true);\\n try {\\n this.result.set(await firstValueFrom(this.#importService.commit(this.#mappedRows(), this.duplicates())));\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không nhập được dữ liệu. Thử lại.\\'));\\n } finally {\\n this.committing.set(false);\\n }\\n }\\n\\n async #check(): Promise<boolean> {\\n this.checking.set(true);\\n try {\\n this.preview.set((await firstValueFrom(this.#importService.preview(this.#mappedRows()))).rows);\\n return true;\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không kiểm tra được dữ liệu. Thử lại.\\'));\\n return false;\\n } finally {\\n this.checking.set(false);\\n }\\n }\\n\\n #mappedRows() {\\n const mapping = this.mapping();\\n return this.rows().map(row => ({\\n code: mapping.code ? (row[mapping.code] ?? \\'\\') : \\'\\',\\n name: mapping.name ? (row[mapping.name] ?? \\'\\') : \\'\\',\\n unit: mapping.unit ? (row[mapping.unit] ?? \\'\\') : \\'\\',\\n price: mapping.price ? (row[mapping.price] ?? \\'\\') : \\'0\\',\\n }));\\n }\\n}\\n',\n 'features/import/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { ImportService } from \\'./services/import.service\\';\\n\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [ImportService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Nhập dữ liệu sản phẩm\\',\\n data: { permission: \\'PATTERN_IMPORT_C_IMPORT\\' },\\n loadComponent: () => import(\\'./pages/flow/flow.component\\').then(module => module.FlowComponent),\\n },\\n ],\\n },\\n];\\n',\n 'features/import/services/import.model.ts': '/** Field của sản phẩm nhận dữ liệu nhập. */\\nexport type ImportField = \\'code\\' | \\'name\\' | \\'unit\\' | \\'price\\';\\n\\nexport const IMPORT_FIELDS: readonly {\\n readonly field: ImportField;\\n readonly label: string;\\n readonly required: boolean;\\n readonly aliases: readonly string[];\\n}[] = [\\n { field: \\'code\\', label: \\'Mã sản phẩm\\', required: true, aliases: [\\'mã\\', \\'ma\\', \\'code\\', \\'mã sản phẩm\\', \\'ma san pham\\'] },\\n { field: \\'name\\', label: \\'Tên sản phẩm\\', required: true, aliases: [\\'tên\\', \\'ten\\', \\'name\\', \\'tên sản phẩm\\', \\'ten san pham\\'] },\\n { field: \\'unit\\', label: \\'Đơn vị tính\\', required: false, aliases: [\\'đơn vị\\', \\'don vi\\', \\'đvt\\', \\'unit\\', \\'đơn vị tính\\'] },\\n { field: \\'price\\', label: \\'Giá bán\\', required: false, aliases: [\\'giá\\', \\'gia\\', \\'giá bán\\', \\'gia ban\\', \\'price\\'] },\\n];\\n\\n/** Cột của nguồn được chọn cho từng field; `null` là bỏ qua field đó. */\\nexport type ImportMapping = Record<ImportField, string | null>;\\n\\n/** Bảng đọc từ nguồn: tên cột và các dòng (giá trị theo tên cột). */\\nexport interface ImportSource {\\n readonly columns: readonly string[];\\n readonly rows: readonly Readonly<Record<string, string>>[];\\n}\\n\\n/** Kết quả xem trước của một dòng. */\\nexport interface ImportPreviewRowDto {\\n readonly index: number;\\n readonly code: string;\\n readonly name: string;\\n readonly unit: string;\\n readonly price: number;\\n readonly result: \\'new\\' | \\'duplicate\\' | \\'invalid\\';\\n readonly message?: string;\\n}\\n\\n/** Xử lý dòng trùng mã sản phẩm đã có. */\\nexport type ImportDuplicatePolicy = \\'skip\\' | \\'overwrite\\';\\n\\nexport interface ImportCommitRes {\\n readonly created: number;\\n readonly updated: number;\\n readonly skipped: number;\\n}\\n\\n/** Dữ liệu mẫu cho bước Nguồn dữ liệu: có dòng mới, dòng trùng mã và dòng lỗi. */\\nexport const IMPORT_SAMPLE = [\\n \\'Mã,Tên sản phẩm,Đơn vị,Giá bán\\',\\n \\'SP-001,Nước suối 500ml (mẫu mới),Chai,6000\\',\\n \\'SP-901,Sữa hạt óc chó 1L,Hộp,52000\\',\\n \\'SP-902,Bánh quy yến mạch,Gói,28000\\',\\n \\',Sản phẩm thiếu mã,Cái,1000\\',\\n \\'SP-903,Kẹo bạc hà,Gói,abc\\',\\n \\'SP-904,Nước tăng lực 250ml,Lon,12000\\',\\n].join(\\'\\\\n\\');\\n\\n/** Đọc CSV (dấu phẩy hoặc chấm phẩy) có dòng tiêu đề. */\\nexport function parseCsv(text: string): ImportSource {\\n const lines = text\\n .split(/\\\\r?\\\\n/)\\n .map(line => line.trim())\\n .filter(line => line.length > 0);\\n if (lines.length < 2) return { columns: [], rows: [] };\\n const separator = lines[0].includes(\\';\\') ? \\';\\' : \\',\\';\\n const split = (line: string) => line.split(separator).map(cell => cell.trim().replace(/^\"(.*)\"$/, \\'$1\\'));\\n const columns = split(lines[0]);\\n const rows = lines.slice(1).map(line => {\\n const cells = split(line);\\n return Object.fromEntries(columns.map((column, index) => [column, cells[index] ?? \\'\\']));\\n });\\n return { columns, rows };\\n}\\n\\n/** Ánh xạ tự động theo tên cột. */\\nexport function guessMapping(columns: readonly string[]): ImportMapping {\\n const normalized = columns.map(column => column.trim().toLowerCase());\\n const mapping = {} as ImportMapping;\\n for (const { field, aliases } of IMPORT_FIELDS) {\\n const index = normalized.findIndex(column => aliases.includes(column));\\n mapping[field] = index >= 0 ? columns[index] : null;\\n }\\n return mapping;\\n}\\n',\n 'features/import/services/import.service.ts': 'import { Injectable } from \\'@angular/core\\';\\nimport type { Observable } from \\'rxjs\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type { ImportCommitRes, ImportDuplicatePolicy, ImportPreviewRowDto } from \\'./import.model\\';\\n\\ntype ImportRowReq = Readonly<Record<\\'code\\' | \\'name\\' | \\'unit\\' | \\'price\\', string>>;\\n\\n/** Nhập sản phẩm theo lô: API phân loại từng dòng trước, rồi ghi theo cách xử lý dòng trùng. */\\n@Injectable()\\nexport class ImportService extends BaseApiService {\\n preview(rows: readonly ImportRowReq[]): Observable<{ rows: ImportPreviewRowDto[] }> {\\n return this.http.post<{ rows: ImportPreviewRowDto[] }>(this.apiUrl(\\'products\\', \\'import\\', \\'preview\\'), { rows });\\n }\\n\\n commit(rows: readonly ImportRowReq[], duplicates: ImportDuplicatePolicy): Observable<ImportCommitRes> {\\n return this.http.post<ImportCommitRes>(this.apiUrl(\\'products\\', \\'import\\'), { rows, duplicates });\\n }\\n}\\n',\n 'features/order/components/approval-steps/approval-steps.component.ts': 'import { ChangeDetectionStrategy, Component, input } from \\'@angular/core\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdFormatDatetimePipe } from \\'@sdcorejs/angular/pipes\\';\\nimport type { OrderApprovalStepDto } from \\'../../services/order.model\\';\\n\\nconst ACTION_NAME: Readonly<Record<OrderApprovalStepDto[\\'action\\'], string>> = {\\n submit: \\'Gửi duyệt\\',\\n approve: \\'Duyệt\\',\\n reject: \\'Từ chối\\',\\n};\\n\\n/** Quy trình duyệt của đơn, mới nhất ở cuối; dùng ở cột phụ của trang chi tiết. */\\n@Component({\\n selector: \\'approval-steps\\',\\n standalone: true,\\n imports: [SdSection, SdFormatDatetimePipe],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Quy trình duyệt\">\\n <ol class=\"approval-steps\">\\n <li class=\"approval-steps__item approval-steps__item--done\">\\n <span class=\"T14M\">Tạo đơn</span>\\n </li>\\n @for (step of steps(); track $index) {\\n <li class=\"approval-steps__item\" [class.approval-steps__item--rejected]=\"step.action === \\'reject\\'\">\\n <span class=\"T14M\">{{ actionName[step.action] }}</span>\\n <span class=\"T12R text-secondary\">{{ step.by }} · {{ step.at | sdFormatDatetime }}</span>\\n @if (step.reason) {\\n <span class=\"T12R\">Lý do: {{ step.reason }}</span>\\n }\\n </li>\\n } @empty {\\n <li class=\"approval-steps__item approval-steps__item--pending\">\\n <span class=\"T12R text-secondary\">Chưa gửi duyệt</span>\\n </li>\\n }\\n </ol>\\n </sd-section>\\n `,\\n styles: `\\n .approval-steps {\\n margin: 0;\\n padding: 16px 16px 16px 32px;\\n list-style: none;\\n }\\n .approval-steps__item {\\n position: relative;\\n display: flex;\\n flex-direction: column;\\n gap: 2px;\\n padding-bottom: 16px;\\n }\\n .approval-steps__item::before {\\n content: \\'\\';\\n position: absolute;\\n top: 4px;\\n left: -18px;\\n width: 10px;\\n height: 10px;\\n border-radius: 50%;\\n background: var(--sd-primary);\\n }\\n .approval-steps__item--rejected::before {\\n background: var(--sd-error, currentColor);\\n }\\n .approval-steps__item--pending::before {\\n background: var(--sd-border-strong);\\n }\\n `,\\n})\\nexport class ApprovalStepsComponent {\\n readonly steps = input.required<readonly OrderApprovalStepDto[]>();\\n protected readonly actionName = ACTION_NAME;\\n}\\n',\n 'features/order/components/bulk-result/bulk-result.component.ts': 'import { ChangeDetectionStrategy, Component, computed, input, output } from \\'@angular/core\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\n\\n/** Kết quả của một tác vụ hàng loạt: số thành công trên tổng và từng đơn lỗi. */\\nexport interface OrderBulkSummary {\\n /** Động từ của tác vụ, ví dụ \"Đã xác nhận\". */\\n readonly done: string;\\n readonly total: number;\\n readonly failed: readonly { readonly id: string; readonly code: string; readonly message: string }[];\\n}\\n\\n/** Báo kết quả từng phần (E13): \"Đã xác nhận 8/10. 2 đơn lỗi.\" kèm lỗi từng đơn và nút thử lại phần lỗi. */\\n@Component({\\n selector: \\'bulk-result\\',\\n standalone: true,\\n imports: [SdInform],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let _result = result();\\n <sd-inform\\n autoId=\"order-bulk-result\"\\n [color]=\"_result.failed.length ? \\'warning\\' : \\'success\\'\"\\n [title]=\"title()\"\\n [description]=\"failures()\"\\n [actionLabel]=\"_result.failed.length ? \\'Thử lại phần lỗi\\' : undefined\"\\n closable\\n (sdAction)=\"retry.emit()\"\\n (sdClosed)=\"dismiss.emit()\" />\\n `,\\n})\\nexport class BulkResultComponent {\\n readonly result = input.required<OrderBulkSummary>();\\n readonly retry = output<void>();\\n readonly dismiss = output<void>();\\n protected readonly title = computed(() => {\\n const { done, total, failed } = this.result();\\n return `${done} ${total - failed.length}/${total}.` + (failed.length ? ` ${failed.length} đơn lỗi.` : \\'\\');\\n });\\n // why: nội dung chiếu vào sd-inform thay cả tiêu đề lẫn nút hành động; lỗi từng đơn đi qua `description`.\\n protected readonly failures = computed(\\n () =>\\n this.result()\\n .failed.map(item => `${item.code}: ${item.message}`)\\n .join(\\' \\') || undefined\\n );\\n}\\n',\n 'features/order/components/general-information-form/general-information-form.component.ts': 'import { ChangeDetectionStrategy, Component, input } from \\'@angular/core\\';\\nimport type { FormArray, FormControl, FormGroup } from \\'@angular/forms\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport { CustomerSelectComponent } from \\'../../../customer/components/customer-select/customer-select.component\\';\\nimport { ORDER_CHANNELS, ORDER_PAYMENTS, ORDER_WAREHOUSES, type OrderLineDto, type OrderSaveReq } from \\'../../services/order.model\\';\\n\\n/** Form đơn hàng: field của đầu chứng từ do Core tự đăng ký; `lines` là FormArray do `lines-form` quản lý. */\\nexport type OrderForm = FormGroup<{\\n customerId?: FormControl<string | null>;\\n channel?: FormControl<string>;\\n warehouse?: FormControl<string>;\\n payment?: FormControl<string>;\\n note?: FormControl<string | null>;\\n lines?: FormArray<FormGroup>;\\n}>;\\n\\n/** Giá trị form → request lưu. */\\nexport function orderSaveReq(form: OrderForm): OrderSaveReq {\\n const value = form.getRawValue();\\n const lines = (value.lines ?? []) as Partial<OrderLineDto>[];\\n return {\\n customerId: value.customerId ?? \\'\\',\\n channel: value.channel ?? ORDER_CHANNELS[0],\\n warehouse: value.warehouse ?? ORDER_WAREHOUSES[0],\\n payment: value.payment ?? ORDER_PAYMENTS[0],\\n note: value.note || null,\\n lines: lines.map(line => ({\\n productId: line.productId ?? \\'\\',\\n quantity: Number(line.quantity ?? 0),\\n unitPrice: Number(line.unitPrice ?? 0),\\n })),\\n };\\n}\\n\\nconst options = (values: readonly string[]) => values.map(value => ({ value }));\\n\\n/** Nhóm \"Thông tin chung\" của đơn hàng. */\\n@Component({\\n selector: \\'general-information-form\\',\\n standalone: true,\\n imports: [SdSection, SdSelect, CustomerSelectComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"row px-16 pt-16 pb-8\">\\n <div class=\"col-12 col-md-6\">\\n <customer-select autoId=\"order-customer\" [form]=\"form()\" [model]=\"seed().customerId || null\" required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-select\\n label=\"Kênh bán\"\\n name=\"channel\"\\n [form]=\"form()\"\\n [model]=\"seed().channel\"\\n [items]=\"channels\"\\n valueField=\"value\"\\n displayField=\"value\"\\n [clearable]=\"false\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-select\\n label=\"Kho xuất\"\\n name=\"warehouse\"\\n [form]=\"form()\"\\n [model]=\"seed().warehouse\"\\n [items]=\"warehouses\"\\n valueField=\"value\"\\n displayField=\"value\"\\n [clearable]=\"false\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-select\\n label=\"Thanh toán\"\\n name=\"payment\"\\n [form]=\"form()\"\\n [model]=\"seed().payment\"\\n [items]=\"payments\"\\n valueField=\"value\"\\n displayField=\"value\"\\n [clearable]=\"false\"\\n required />\\n </div>\\n </div>\\n </sd-section>\\n `,\\n})\\nexport class GeneralInformationFormComponent {\\n readonly form = input.required<OrderForm>();\\n readonly seed = input.required<OrderSaveReq>();\\n protected readonly channels = options(ORDER_CHANNELS);\\n protected readonly warehouses = options(ORDER_WAREHOUSES);\\n protected readonly payments = options(ORDER_PAYMENTS);\\n}\\n',\n 'features/order/components/lines-form/lines-form.component.ts': 'import { ChangeDetectionStrategy, Component, input } from \\'@angular/core\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdInputNumber } from \\'@sdcorejs/angular/forms/input-number\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { ProductSelectComponent } from \\'../../../product/components/product-select/product-select.component\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\nimport type { OrderForm } from \\'../general-information-form/general-information-form.component\\';\\nimport { orderLines } from \\'./order-lines\\';\\n\\n/**\\n * Bảng dòng hàng nhập trực tiếp, dựng bằng `<table>`: mỗi dòng là một FormGroup trong `form.lines` (FormArray, do\\n * `orderLines()` quản lý), các field Core tự đăng ký vào dòng. Chọn sản phẩm điền đơn giá; thành tiền và tổng tự\\n * tính. Field trong ô dùng `size=\"sm\"` và `hideInlineError`: lỗi, kể cả lỗi API theo dòng (`lines.<i>.<field>`), là\\n * icon kèm tooltip ngay trên ô đó, dòng không cao thêm. Cùng bảng dựng bằng `sd-table`: `lines-table-form`.\\n */\\n@Component({\\n selector: \\'lines-form\\',\\n standalone: true,\\n imports: [SdSection, SdButton, SdInputNumber, SdFormatNumberPipe, ProductSelectComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Dòng hàng\">\\n <div sdHeaderRight>\\n <sd-button title=\"Thêm dòng\" prefixIcon=\"add\" type=\"text\" autoId=\"order-line-add\" (click)=\"lines.add()\" />\\n </div>\\n <div class=\"lines-scroll\">\\n <table class=\"lines\">\\n <colgroup>\\n <col />\\n <col class=\"lines__quantity\" />\\n <col class=\"lines__money\" />\\n <col class=\"lines__money\" />\\n <col class=\"lines__action\" />\\n </colgroup>\\n <thead>\\n <tr>\\n <th scope=\"col\">Sản phẩm <span class=\"text-error\" aria-hidden=\"true\">*</span></th>\\n <th scope=\"col\" class=\"lines__number\">Số lượng <span class=\"text-error\" aria-hidden=\"true\">*</span></th>\\n <th scope=\"col\" class=\"lines__number\">Đơn giá (₫) <span class=\"text-error\" aria-hidden=\"true\">*</span></th>\\n <th scope=\"col\" class=\"lines__number\">Thành tiền (₫)</th>\\n <th scope=\"col\" class=\"lines__action\"><span class=\"sd-visually-hidden\">Xoá dòng</span></th>\\n </tr>\\n </thead>\\n <tbody>\\n @for (row of lines.rows(); track row.key; let index = $index) {\\n <tr [attr.data-line]=\"index\">\\n <td>\\n <product-select\\n size=\"sm\"\\n hideInlineError\\n [label]=\"undefined\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.productId || null\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.productId\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-product\\'\"\\n (modelChange)=\"lines.pick(row, $event)\"\\n required />\\n </td>\\n <td class=\"lines__number\">\\n <sd-input-number\\n name=\"quantity\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.quantity\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.quantity\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-quantity\\'\"\\n required />\\n </td>\\n <td class=\"lines__number\">\\n <sd-input-number\\n name=\"unitPrice\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.unitPrice\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.unitPrice\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-unit-price\\'\"\\n required />\\n </td>\\n <td class=\"lines__number\" [attr.data-autoid]=\"\\'order-line-\\' + index + \\'-amount\\'\">\\n {{ lines.amounts()[index] | sdFormatNumber: 0 }}\\n </td>\\n <td class=\"lines__action\">\\n <sd-button\\n prefixIcon=\"delete\"\\n type=\"text\"\\n color=\"error\"\\n tooltip=\"Xoá dòng\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-remove\\'\"\\n [disabled]=\"lines.rows().length === 1\"\\n (click)=\"lines.remove(row)\" />\\n </td>\\n </tr>\\n }\\n </tbody>\\n <tfoot>\\n <tr>\\n <th scope=\"row\" colspan=\"3\" class=\"lines__number\">Tổng tiền (₫)</th>\\n <td class=\"lines__number lines__total\" data-autoid=\"order-total\">{{ lines.total() | sdFormatNumber: 0 }}</td>\\n <td class=\"lines__action\"></td>\\n </tr>\\n </tfoot>\\n </table>\\n </div>\\n </sd-section>\\n `,\\n styles: `\\n /* Màn hẹp thì cuộn ngang trong section thay vì bóp cột sản phẩm. */\\n .lines-scroll {\\n overflow-x: auto;\\n }\\n /* Cột cố định, sản phẩm lấy phần còn lại: vừa thân 576px của sd-page-form. */\\n .lines {\\n width: 100%;\\n min-width: 544px;\\n border-collapse: collapse;\\n table-layout: fixed;\\n }\\n .lines__quantity {\\n width: 88px;\\n }\\n .lines__money {\\n width: 120px;\\n }\\n .lines__action {\\n width: 48px;\\n }\\n .lines th,\\n .lines td {\\n padding: 8px;\\n text-align: left;\\n vertical-align: middle;\\n }\\n /* Cột đầu và cuối thẳng lề 16px với title và nút \"Thêm dòng\" của section. */\\n .lines th:first-child,\\n .lines td:first-child {\\n padding-left: 16px;\\n }\\n .lines th:last-child,\\n .lines td:last-child {\\n padding-right: 16px;\\n }\\n .lines thead th {\\n color: var(--sd-text-secondary);\\n font-size: 12px;\\n font-weight: 500;\\n border-bottom: 1px solid var(--sd-border);\\n }\\n .lines tbody tr:first-child td {\\n padding-top: 12px;\\n }\\n .lines tbody tr:last-child td {\\n padding-bottom: 12px;\\n }\\n .lines__number {\\n text-align: right !important;\\n }\\n .lines tfoot th,\\n .lines tfoot td {\\n padding-top: 12px;\\n padding-bottom: 12px;\\n border-top: 1px solid var(--sd-border);\\n }\\n .lines__total {\\n font-weight: 500;\\n }\\n `,\\n})\\nexport class LinesFormComponent {\\n readonly form = input.required<OrderForm>();\\n /** Dòng ban đầu (cập nhật) hoặc một dòng trống (tạo mới). */\\n readonly seed = input.required<readonly OrderLineDto[]>();\\n /** Lỗi theo field do API trả về, khoá dạng `lines.<index>.<field>`. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n protected readonly lines = orderLines(this.form, this.seed);\\n}\\n',\n 'features/order/components/lines-form/order-lines.ts': 'import { computed, DestroyRef, effect, inject, signal, untracked, type Signal } from \\'@angular/core\\';\\nimport { FormArray, FormGroup } from \\'@angular/forms\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { ProductService } from \\'../../../product/services/product.service\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\nimport type { OrderForm } from \\'../general-information-form/general-information-form.component\\';\\n\\n/** Một dòng đang nhập: field Core của dòng tự đăng ký vào `group`; `seed` là giá trị ban đầu của dòng. */\\nexport interface OrderLineRow {\\n readonly key: number;\\n readonly group: FormGroup;\\n readonly seed: OrderLineDto;\\n}\\n\\nexport interface OrderLines {\\n readonly rows: Signal<readonly OrderLineRow[]>;\\n /** Thành tiền theo thứ tự của `rows`. */\\n readonly amounts: Signal<readonly number[]>;\\n readonly total: Signal<number>;\\n add(): void;\\n remove(row: OrderLineRow): void;\\n /** Chọn sản phẩm thì điền đơn giá hiện hành của sản phẩm. */\\n pick(row: OrderLineRow, productId: string | null | undefined): Promise<void>;\\n /** Gắn `form.lines` vào form khi field của các dòng vừa nạp đã đăng ký; gọi lại khi đã gắn thì không làm gì. */\\n attach(): void;\\n}\\n\\n/**\\n * Dòng hàng của form đơn: mỗi dòng là một FormGroup trong `form.lines` (FormArray). Thành tiền và tổng tính lại khi\\n * giá trị đổi. `lines-form` (bảng HTML) và `lines-table-form` (`sd-table`) dùng chung, chỉ khác phần hiển thị.\\n * Gọi trong injection context của component.\\n *\\n * `registerSdUnsavedChangesForm(..., { dirty: \\'value\\' })` lấy giá trị của một control lúc nó vào form làm giá trị đã\\n * lưu, nên `form.lines` chỉ vào form khi field của các dòng đã đăng ký; vào sớm hơn thì form vừa mở đã bị coi là có\\n * thay đổi. `<table>` vẽ dòng ngay trong lượt change detection đó (`attach: \\'now\\'`); `sd-table` vẽ dòng sau lần đọc\\n * đầu, nên `lines-table-form` dùng `attach: \\'manual\\'` rồi gọi `attach()` khi bảng đã vẽ.\\n */\\nexport function orderLines(\\n form: Signal<OrderForm>,\\n seed: Signal<readonly OrderLineDto[]>,\\n options: { readonly attach: \\'now\\' | \\'manual\\' } = { attach: \\'now\\' }\\n): OrderLines {\\n const productService = inject(ProductService);\\n const array = new FormArray<FormGroup>([]);\\n const version = signal(0);\\n const rows = signal<readonly OrderLineRow[]>([]);\\n let nextKey = 0;\\n\\n const attach = (): void => {\\n if (form().get(\\'lines\\') !== array) form().setControl(\\'lines\\', array);\\n };\\n const push = (line: OrderLineDto): void => {\\n const group = new FormGroup({});\\n array.push(group);\\n rows.update(items => [...items, { key: nextKey++, group, seed: line }]);\\n };\\n const load = (lines: readonly OrderLineDto[]): void => {\\n // why: gỡ ra rồi gắn lại, để giá trị đã lưu của `lines` là các dòng mới chứ không phải dòng của đơn trước.\\n if (form().get(\\'lines\\') === array) form().removeControl(\\'lines\\');\\n array.clear();\\n rows.set([]);\\n (lines.length ? lines : [{ productId: \\'\\', quantity: 1, unitPrice: 0 }]).forEach(push);\\n if (options.attach === \\'now\\') attach();\\n };\\n\\n const subscription = array.valueChanges.subscribe(() => version.update(value => value + 1));\\n inject(DestroyRef).onDestroy(() => subscription.unsubscribe());\\n // why: trang cập nhật được dùng lại khi chỉ đổi `:id`; dòng hàng phải theo đơn mới, không giữ dòng của đơn trước.\\n effect(() => {\\n const lines = seed();\\n untracked(() => load(lines));\\n });\\n\\n const amounts = computed(() => {\\n version();\\n return rows().map(\\n row => Number(row.group.get(\\'quantity\\')?.value ?? row.seed.quantity) * Number(row.group.get(\\'unitPrice\\')?.value ?? row.seed.unitPrice)\\n );\\n });\\n\\n return {\\n rows: rows.asReadonly(),\\n amounts,\\n total: computed(() => amounts().reduce((sum, amount) => sum + amount, 0)),\\n add: () => push({ productId: \\'\\', quantity: 1, unitPrice: 0 }),\\n remove: row => {\\n const index = rows().indexOf(row);\\n if (index < 0) return;\\n // why: đánh dấu đã sửa TRƯỚC khi gỡ, để dirty theo giá trị so với danh sách dòng lúc trước.\\n array.markAsDirty();\\n array.removeAt(index);\\n rows.update(items => items.filter(item => item !== row));\\n },\\n pick: async (row, productId) => {\\n if (!productId) return;\\n const product = await firstValueFrom(productService.cachedDetail(productId));\\n row.group.get(\\'unitPrice\\')?.setValue(product.price);\\n },\\n attach,\\n };\\n}\\n',\n 'features/order/components/lines-table-form/lines-table-form.component.ts': 'import { afterNextRender, ChangeDetectionStrategy, Component, effect, inject, Injector, input, untracked, viewChild } from \\'@angular/core\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport {\\n SdTable,\\n SdTableCellDefDirective,\\n SdTableCommandHeaderDefDirective,\\n SdTableTitleDefDirective,\\n type SdTableOption,\\n} from \\'@sdcorejs/angular/components/table\\';\\nimport { SdInputNumber } from \\'@sdcorejs/angular/forms/input-number\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { ProductSelectComponent } from \\'../../../product/components/product-select/product-select.component\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\nimport type { OrderForm } from \\'../general-information-form/general-information-form.component\\';\\nimport { orderLines, type OrderLineRow } from \\'../lines-form/order-lines\\';\\n\\n/** Dòng của `sd-table`: dòng form cộng tên các cột. Ô của mọi cột vẽ bằng `sdTableCellDef` từ `group`/`seed`. */\\ninterface LineItem extends OrderLineRow {\\n readonly productId?: string;\\n readonly quantity?: number;\\n readonly unitPrice?: number;\\n readonly amount?: number;\\n}\\n\\n/**\\n * Dòng hàng nhập trực tiếp, dựng bằng `sd-table` thay cho `<table>` của `lines-form`; trạng thái dòng vẫn là\\n * `orderLines()`. Bảng local, không phân trang, không lọc. Nút thêm dòng nằm ở header cột command\\n * (`sdTableCommandHeaderDef`), ngay trên nút xoá của từng dòng; field trong ô dùng `size=\"sm\"` và `hideInlineError`,\\n * cột bắt buộc có `*` ở title; số dòng và tổng tiền ở dưới bảng. Dòng đổi thì `reload()` bảng; `rowKey` giữ view\\n * của các dòng còn lại nên giá trị đang nhập không mất. `form.lines` chỉ vào form khi bảng đã vẽ dòng (`attach`).\\n */\\n@Component({\\n selector: \\'lines-table-form\\',\\n standalone: true,\\n imports: [\\n SdSection,\\n SdButton,\\n SdTable,\\n SdTableCellDefDirective,\\n SdTableCommandHeaderDefDirective,\\n SdTableTitleDefDirective,\\n SdInputNumber,\\n SdFormatNumberPipe,\\n ProductSelectComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Dòng hàng\">\\n <sd-table autoId=\"order-lines\" [option]=\"option\">\\n <ng-template sdTableCommandHeaderDef>\\n <sd-button\\n tooltip=\"Thêm dòng\"\\n prefixIcon=\"add\"\\n size=\"sm\"\\n type=\"light\"\\n color=\"primary\"\\n autoId=\"order-line-add\"\\n (click)=\"lines.add()\" />\\n </ng-template>\\n <ng-template sdTableTitleDef=\"productId\">Sản phẩm <span class=\"text-error\" aria-hidden=\"true\">*</span></ng-template>\\n <ng-template sdTableTitleDef=\"quantity\">Số lượng <span class=\"text-error\" aria-hidden=\"true\">*</span></ng-template>\\n <ng-template sdTableTitleDef=\"unitPrice\">Đơn giá (₫) <span class=\"text-error\" aria-hidden=\"true\">*</span></ng-template>\\n <ng-template sdTableCellDef=\"productId\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <product-select\\n class=\"lines-table__input\"\\n size=\"sm\"\\n hideInlineError\\n [label]=\"undefined\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.productId || null\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.productId\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-product\\'\"\\n (modelChange)=\"lines.pick(row, $event)\"\\n required />\\n </ng-template>\\n <ng-template sdTableCellDef=\"quantity\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <sd-input-number\\n class=\"lines-table__input\"\\n name=\"quantity\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.quantity\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.quantity\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-quantity\\'\"\\n required />\\n </ng-template>\\n <ng-template sdTableCellDef=\"unitPrice\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <sd-input-number\\n class=\"lines-table__input\"\\n name=\"unitPrice\"\\n size=\"sm\"\\n hideInlineError\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"row.group\"\\n [model]=\"row.seed.unitPrice\"\\n [inlineError]=\"errors()[\\'lines.\\' + index + \\'.unitPrice\\']\"\\n [autoId]=\"\\'order-line-\\' + index + \\'-unit-price\\'\"\\n required />\\n </ng-template>\\n <ng-template sdTableCellDef=\"amount\" let-row=\"item\">\\n @let index = lines.rows().indexOf(row);\\n <strong class=\"lines-table__amount\" [attr.data-autoid]=\"\\'order-line-\\' + index + \\'-amount\\'\">\\n {{ lines.amounts()[index] | sdFormatNumber: 0 }}\\n </strong>\\n </ng-template>\\n </sd-table>\\n <div class=\"lines-table__summary\">\\n <span>{{ lines.rows().length }} dòng hàng</span>\\n <strong\\n >Tổng tiền: <span data-autoid=\"order-total\">{{ lines.total() | sdFormatNumber: 0 }}</span> ₫</strong\\n >\\n </div>\\n </sd-section>\\n `,\\n styles: `\\n /* Field trong dòng: 6px trên dưới để dòng 44px vẫn thoáng. */\\n .lines-table__input {\\n display: block;\\n padding-block: 6px;\\n }\\n .lines-table__amount {\\n display: block;\\n text-align: right;\\n font-variant-numeric: tabular-nums;\\n }\\n .lines-table__summary {\\n display: flex;\\n justify-content: space-between;\\n gap: 8px;\\n padding: 12px 16px;\\n color: var(--sd-text-secondary);\\n }\\n .lines-table__summary strong {\\n color: var(--sd-text);\\n }\\n `,\\n})\\nexport class LinesTableFormComponent {\\n readonly form = input.required<OrderForm>();\\n /** Dòng ban đầu (cập nhật) hoặc một dòng trống (tạo mới). */\\n readonly seed = input.required<readonly OrderLineDto[]>();\\n /** Lỗi theo field do API trả về, khoá dạng `lines.<index>.<field>`. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n readonly #injector = inject(Injector);\\n private readonly table = viewChild(SdTable<LineItem>);\\n protected readonly lines = orderLines(this.form, this.seed, { attach: \\'manual\\' });\\n protected readonly option: SdTableOption<LineItem> = {\\n type: \\'local\\',\\n items: () => [...this.lines.rows()],\\n rowKey: \\'key\\',\\n filter: { disabled: true },\\n paginate: { hidden: true, pageSize: 200 },\\n reload: {\\n visible: false,\\n // why: sd-table vẽ dòng sau lần đọc; field trong ô đăng ký xong thì mới gắn `form.lines` (xem `orderLines`).\\n onReload: () => {\\n afterNextRender(() => this.lines.attach(), { injector: this.#injector });\\n },\\n },\\n config: { visible: false },\\n columns: [\\n { field: \\'productId\\', title: \\'Sản phẩm\\', type: \\'string\\', minWidth: \\'180px\\' },\\n { field: \\'quantity\\', title: \\'Số lượng\\', type: \\'number\\', width: \\'88px\\' },\\n { field: \\'unitPrice\\', title: \\'Đơn giá (₫)\\', type: \\'number\\', width: \\'120px\\' },\\n { field: \\'amount\\', title: \\'Thành tiền (₫)\\', type: \\'number\\', width: \\'120px\\', align: \\'right\\' },\\n ],\\n command: {\\n commands: [\\n {\\n title: \\'Xoá dòng\\',\\n icon: \\'delete\\',\\n color: \\'error\\',\\n disabled: () => this.lines.rows().length === 1,\\n click: row => this.lines.remove(row),\\n },\\n ],\\n },\\n };\\n\\n constructor() {\\n // why: bảng local chỉ đọc `items` khi tải; thêm, xoá dòng hay nạp đơn khác đều phải `reload()` để vẽ lại. Gọi sau\\n // lượt render, khi `option` của bảng đã được gán.\\n effect(() => {\\n this.lines.rows();\\n untracked(() => afterNextRender(() => void this.table()?.reload(), { injector: this.#injector }));\\n });\\n }\\n}\\n',\n 'features/order/components/lines-view/lines-view.component.ts': 'import { AsyncPipe } from \\'@angular/common\\';\\nimport { ChangeDetectionStrategy, Component, computed, input } from \\'@angular/core\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { ProductDetailPipe } from \\'../../../product/pipes/product-detail.pipe\\';\\nimport type { OrderLineDto } from \\'../../services/order.model\\';\\n\\n/** Dòng hàng chỉ đọc; tên sản phẩm lấy qua relation `productDetail`, không hiện ID thô. */\\n@Component({\\n selector: \\'lines-view\\',\\n standalone: true,\\n imports: [AsyncPipe, SdSection, SdTable, SdTableCellDefDirective, ProductDetailPipe],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-section title=\"Dòng hàng\">\\n <sd-table autoId=\"order-lines\" [option]=\"option()\">\\n <ng-template sdTableCellDef=\"productId\" let-line=\"item\">\\n @let product = line.productId | productDetail | async;\\n {{ product?.name ?? \\'…\\' }}\\n </ng-template>\\n </sd-table>\\n </sd-section>\\n `,\\n})\\nexport class LinesViewComponent {\\n readonly lines = input.required<readonly OrderLineDto[]>();\\n protected readonly option = computed<SdTableOption<OrderLineDto & { amount: number }>>(() => {\\n const items = this.lines().map(line => ({ ...line, amount: line.quantity * line.unitPrice }));\\n return {\\n type: \\'local\\',\\n items: () => items,\\n paginate: { pageSize: 50 },\\n filter: { hideInlineFilter: \\'auto\\' },\\n columns: [\\n { field: \\'productId\\', title: \\'Sản phẩm\\', type: \\'string\\', minWidth: \\'200px\\' },\\n { field: \\'quantity\\', title: \\'Số lượng\\', type: \\'number\\', width: \\'110px\\', align: \\'right\\' },\\n { field: \\'unitPrice\\', title: \\'Đơn giá (₫)\\', type: \\'number\\', width: \\'140px\\', align: \\'right\\' },\\n { field: \\'amount\\', title: \\'Thành tiền (₫)\\', type: \\'number\\', width: \\'150px\\', align: \\'right\\' },\\n ],\\n };\\n });\\n}\\n',\n 'features/order/components/summary-cards/summary-cards.component.ts': 'import { ChangeDetectionStrategy, Component, computed, inject, input, linkedSignal, model } from \\'@angular/core\\';\\nimport { SdCard, SdCardGroup } from \\'@sdcorejs/angular/components/card\\';\\nimport { SD_PAGE_LIST } from \\'@sdcorejs/angular/modules/layout\\';\\nimport type { OrderCounts, OrderStatus } from \\'../../services/order.model\\';\\n\\ntype CardKey = \\'all\\' | \\'pending\\' | \\'shipping\\';\\n\\nconst CARDS: readonly { readonly key: CardKey; readonly label: string }[] = [\\n { key: \\'all\\', label: \\'Tổng đơn\\' },\\n { key: \\'pending\\', label: \\'Chờ xác nhận\\' },\\n { key: \\'shipping\\', label: \\'Đang giao\\' },\\n];\\n\\n/** 1.234.567.890 → \"1,2 tỷ\"; 350.000.000 → \"350 triệu\". */\\nfunction money(value: number): string {\\n if (value >= 1_000_000_000) return `${(value / 1_000_000_000).toLocaleString(\\'vi-VN\\', { maximumFractionDigits: 1 })} tỷ`;\\n return `${Math.round(value / 1_000_000).toLocaleString(\\'vi-VN\\')} triệu`;\\n}\\n\\n/**\\n * Score card của danh sách đơn: ba thẻ đầu lọc theo trạng thái, đồng bộ với tab vì cùng một state; thẻ doanh thu\\n * chỉ để xem. Khi `sd-page-list` thu gọn (màn thấp), các thẻ thành một dòng 36px.\\n */\\n@Component({\\n selector: \\'summary-cards\\',\\n standalone: true,\\n imports: [SdCard, SdCardGroup],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-card-group\\n class=\"summary\"\\n autoId=\"order-summary\"\\n aria-label=\"Tóm tắt đơn hàng\"\\n [class.summary--compact]=\"compact()\"\\n [(model)]=\"selected\"\\n (sdChange)=\"choose($event)\">\\n @for (card of cards(); track card.key) {\\n <sd-card class=\"summary__card\" [value]=\"card.key\" [autoId]=\"\\'order-summary-\\' + card.key\">\\n <span class=\"summary__label\">{{ card.label }}</span>\\n <strong class=\"summary__value\">{{ card.value }}</strong>\\n </sd-card>\\n }\\n <div class=\"summary__card summary__card--static\" data-autoid=\"order-summary-revenue\">\\n <span class=\"summary__label\">Doanh thu hoàn tất</span>\\n <strong class=\"summary__value\">{{ revenue() }}</strong>\\n </div>\\n </sd-card-group>\\n `,\\n styles: `\\n .summary {\\n display: grid;\\n grid-template-columns: repeat(4, minmax(0, 1fr));\\n gap: 12px;\\n }\\n .summary__card {\\n display: flex;\\n flex-direction: column;\\n gap: 4px;\\n padding: 12px 16px;\\n }\\n .summary__card--static {\\n border: 1px solid var(--sd-border);\\n border-radius: 8px;\\n background: var(--sd-surface);\\n }\\n .summary__label {\\n color: var(--sd-text-secondary);\\n font-size: 13px;\\n }\\n .summary__value {\\n font-size: 22px;\\n line-height: 28px;\\n font-weight: 500;\\n font-variant-numeric: tabular-nums;\\n }\\n .summary--compact {\\n display: flex;\\n align-items: center;\\n gap: 8px;\\n height: 36px;\\n }\\n .summary--compact .summary__card {\\n flex-direction: row;\\n align-items: baseline;\\n gap: 6px;\\n padding: 4px 10px;\\n }\\n .summary--compact .summary__card--static {\\n border: 0;\\n background: transparent;\\n }\\n .summary--compact .summary__value {\\n font-size: 14px;\\n line-height: 20px;\\n }\\n @media (max-width: 767px) {\\n .summary {\\n grid-template-columns: repeat(2, minmax(0, 1fr));\\n }\\n }\\n `,\\n})\\nexport class SummaryCardsComponent {\\n readonly counts = input<OrderCounts | null>(null);\\n /** Trạng thái đang lọc; `null` là tất cả. */\\n readonly status = model<OrderStatus | null>(null);\\n protected readonly cards = computed(() => {\\n const counts = this.counts();\\n return CARDS.map(card => ({ ...card, value: counts ? counts[card.key].toLocaleString(\\'vi-VN\\') : \\'…\\' }));\\n });\\n protected readonly compact = inject(SD_PAGE_LIST).compact;\\n /** Trạng thái chọn từ tab mà không có thẻ (Hoàn tất, Đã huỷ): không thẻ nào sáng. */\\n protected readonly selected = linkedSignal<CardKey | null>(() => {\\n const status = this.status();\\n return status === null ? \\'all\\' : status === \\'pending\\' || status === \\'shipping\\' ? status : null;\\n });\\n protected readonly revenue = computed(() => {\\n const counts = this.counts();\\n return counts ? money(counts.revenue) : \\'…\\';\\n });\\n\\n protected choose(key: unknown): void {\\n // Bấm lại thẻ đang chọn (model về null) hoặc thẻ Tổng đơn đều là bỏ lọc.\\n const card = (key as CardKey | null) ?? \\'all\\';\\n this.selected.set(card);\\n this.status.set(card === \\'all\\' ? null : card);\\n }\\n}\\n',\n 'features/order/entity.resolver.ts': 'import { HttpErrorResponse } from \\'@angular/common/http\\';\\nimport { inject } from \\'@angular/core\\';\\nimport { createUrlTreeFromSnapshot, RedirectCommand, type ResolveFn } from \\'@angular/router\\';\\nimport { map, timeout, type Observable } from \\'rxjs\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { OrderService } from \\'./services/order.service\\';\\nimport { canUpdateOrder, type OrderDto } from \\'./services/order.model\\';\\n\\n/** Tải đơn hàng bằng `detail(id)` trước khi mở chi tiết hoặc form; lỗi đi tới navigation error handler của host. */\\nexport const entityResolver: ResolveFn<OrderDto> = route => {\\n const id = route.paramMap.get(\\'id\\');\\n if (!id?.trim()) throw new HttpErrorResponse({ status: 404 });\\n return inject(OrderService)\\n .detail(id)\\n .pipe(\\n timeout(10_000),\\n map(entity => {\\n if (!entity || entity.id !== id) throw new HttpErrorResponse({ status: 404 });\\n return entity;\\n })\\n );\\n};\\n\\n/**\\n * Như `entityResolver`, cho trang cập nhật: đơn không còn sửa được (đã xác nhận, đang duyệt…) mở trang chi tiết, thay vì\\n * mở form rồi mới bị API từ chối khi lưu.\\n */\\nexport const updatableEntityResolver: ResolveFn<OrderDto> = (route, state) => {\\n const notify = inject(SdNotifyService);\\n return (entityResolver(route, state) as Observable<OrderDto>).pipe(\\n map(order => {\\n if (canUpdateOrder(order)) return order;\\n notify.info(`Đơn ${order.code} không còn sửa được.`);\\n return new RedirectCommand(createUrlTreeFromSnapshot(route, [\\'../detail\\']));\\n })\\n );\\n};\\n',\n 'features/order/pages/create/create.component.ts': 'import { afterNextRender, ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, Injector, signal } from \\'@angular/core\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdTextarea } from \\'@sdcorejs/angular/forms/textarea\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport {\\n GeneralInformationFormComponent,\\n orderSaveReq,\\n type OrderForm,\\n} from \\'../../components/general-information-form/general-information-form.component\\';\\nimport { LinesFormComponent } from \\'../../components/lines-form/lines-form.component\\';\\nimport { LinesTableFormComponent } from \\'../../components/lines-table-form/lines-table-form.component\\';\\nimport { OrderService } from \\'../../services/order.service\\';\\nimport { ORDER_CHANNELS, ORDER_PAYMENTS, ORDER_WAREHOUSES, type OrderSaveReq } from \\'../../services/order.model\\';\\n\\n/** Tạo đơn hàng: form nhiều nhóm có mục lục (`toc`), dòng hàng nhập trực tiếp, lưu xong sang chi tiết. */\\n@Component({\\n selector: \\'create\\',\\n standalone: true,\\n imports: [SdPageComponent, SdButton, SdSection, SdTextarea, GeneralInformationFormComponent, LinesFormComponent, LinesTableFormComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-page-form title=\"Tạo mới đơn hàng\" [backLink]=\"[\\'..\\']\" toc>\\n <div headerRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Huỷ\" type=\"outline\" autoId=\"order-cancel\" (click)=\"cancel()\" />\\n <sd-button\\n title=\"Tạo đơn hàng\"\\n prefixIcon=\"save\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"order-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n </div>\\n <div class=\"d-flex flex-column gap-16 py-16\">\\n <general-information-form [form]=\"form\" [seed]=\"seed\" />\\n @if (linesTable) {\\n <lines-table-form [form]=\"form\" [seed]=\"seed.lines\" [errors]=\"apiErrors.errors()\" />\\n } @else {\\n <lines-form [form]=\"form\" [seed]=\"seed.lines\" [errors]=\"apiErrors.errors()\" />\\n }\\n <sd-section title=\"Ghi chú\">\\n <div class=\"px-16 pt-16 pb-8\">\\n <sd-textarea label=\"Ghi chú nội bộ\" name=\"note\" [form]=\"form\" [model]=\"seed.note\" maxlength=\"500\" />\\n </div>\\n </sd-section>\\n </div>\\n </sd-page-form>\\n `,\\n})\\nexport class CreateComponent {\\n readonly #orderService = inject(OrderService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n /** `?lines=sd-table`: dòng hàng dựng bằng `sd-table` (`lines-table-form`) để so với `<table>`. Màn thật chọn một. */\\n protected readonly linesTable = this.#route.snapshot.queryParamMap.get(\\'lines\\') === \\'sd-table\\';\\n readonly #host: HTMLElement = inject(ElementRef).nativeElement;\\n readonly #injector = inject(Injector);\\n protected readonly seed: OrderSaveReq = {\\n customerId: \\'\\',\\n channel: ORDER_CHANNELS[0],\\n warehouse: ORDER_WAREHOUSES[0],\\n payment: ORDER_PAYMENTS[0],\\n note: null,\\n lines: [],\\n };\\n protected readonly form: OrderForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'order-create\\', dirty: \\'value\\' });\\n\\n constructor() {\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected cancel(): void {\\n void this.#router.navigate([\\'..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n const order = await firstValueFrom(this.#orderService.create(orderSaveReq(this.form)));\\n this.#unsaved.markPristine();\\n this.#notify.success(`Đã tạo đơn ${order.code}.`);\\n await this.#router.navigate([\\'..\\', order.id, \\'detail\\'], { relativeTo: this.#route, replaceUrl: true });\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.#host), { injector: this.#injector });\\n }\\n}\\n',\n 'features/order/pages/detail/detail.component.ts': 'import { AsyncPipe, NgTemplateOutlet } from \\'@angular/common\\';\\nimport { afterNextRender, ChangeDetectionStrategy, Component, computed, inject, linkedSignal, signal, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdBadge } from \\'@sdcorejs/angular/components/badge\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdSideDrawer } from \\'@sdcorejs/angular/components/side-drawer\\';\\nimport { SdView } from \\'@sdcorejs/angular/components/view\\';\\nimport { SD_PAGE_LIST, SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdEmptyPipe, SdFormatDatePipe, SdFormatDatetimePipe, SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { CustomerDetailPipe } from \\'../../../customer/pipes/customer-detail.pipe\\';\\nimport { ApprovalStepsComponent } from \\'../../components/approval-steps/approval-steps.component\\';\\nimport { LinesViewComponent } from \\'../../components/lines-view/lines-view.component\\';\\nimport { OrderService } from \\'../../services/order.service\\';\\nimport { canUpdateOrder, orderApprovalBadge, orderStatusBadge, type OrderAction, type OrderDto } from \\'../../services/order.model\\';\\n\\n/**\\n * Chi tiết đơn (`:id/detail`, route con của danh sách). Mở trong drawer 600px hoặc trang `sd-page-detail` theo\\n * `detail` của `sd-page-list`. Gửi duyệt, Duyệt và Từ chối đều hỏi xác nhận; Từ chối bắt buộc lý do (E13).\\n */\\n@Component({\\n selector: \\'detail\\',\\n standalone: true,\\n imports: [\\n AsyncPipe,\\n NgTemplateOutlet,\\n RouterLink,\\n SdPageComponent,\\n SdSideDrawer,\\n SdBadge,\\n SdButton,\\n SdSection,\\n SdSectionItem,\\n SdView,\\n SdPermissionDirective,\\n SdEmptyPipe,\\n SdFormatDatePipe,\\n SdFormatDatetimePipe,\\n SdFormatNumberPipe,\\n CustomerDetailPipe,\\n ApprovalStepsComponent,\\n LinesViewComponent,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let order = entity();\\n @let customer = order.customerId | customerDetail | async;\\n <ng-template #actions>\\n @if (order.approval === \\'submitted\\') {\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_REJECT\\'\"\\n title=\"Từ chối\"\\n prefixIcon=\"close\"\\n type=\"light\"\\n color=\"warning\"\\n autoId=\"order-reject\"\\n [disabled]=\"pending()\"\\n (click)=\"act(\\'reject\\')\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_APPROVE\\'\"\\n title=\"Duyệt\"\\n prefixIcon=\"check\"\\n type=\"fill\"\\n color=\"success\"\\n autoId=\"order-approve\"\\n [disabled]=\"pending()\"\\n (click)=\"act(\\'approve\\')\" />\\n }\\n @if (editable()) {\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_SUBMIT\\'\"\\n title=\"Gửi duyệt\"\\n prefixIcon=\"send\"\\n type=\"outline\"\\n autoId=\"order-submit\"\\n [disabled]=\"pending()\"\\n (click)=\"act(\\'submit\\')\" />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_U_UPDATE\\'\"\\n title=\"Cập nhật đơn hàng\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"order-update\"\\n [disabled]=\"pending()\"\\n [routerLink]=\"[\\'../update\\']\" />\\n }\\n </ng-template>\\n\\n @if (mode() === \\'drawer\\') {\\n <sd-side-drawer width=\"600px\" autoId=\"order-detail\" (sdClosed)=\"closed()\">\\n <div sdHeaderLeft class=\"d-flex align-items-center gap-8\">\\n <span class=\"T16M\">Đơn hàng {{ order.code }}</span>\\n <sd-badge size=\"md\" type=\"round\" [title]=\"statusBadge().title\" [color]=\"statusBadge().color\" />\\n </div>\\n <sd-section title=\"Thông tin chung\">\\n <sd-section-item label=\"Khách hàng\">{{ order.customer }}</sd-section-item>\\n <sd-section-item label=\"Kênh bán\">{{ order.channel }}</sd-section-item>\\n <sd-section-item label=\"Kho xuất\">{{ order.warehouse }}</sd-section-item>\\n <sd-section-item label=\"Thanh toán\">{{ order.payment }}</sd-section-item>\\n <sd-section-item label=\"Ngày tạo\">{{ order.createdAt | sdFormatDatetime }}</sd-section-item>\\n <sd-section-item label=\"Tổng tiền (₫)\">{{ order.total | sdFormatNumber: 0 }}</sd-section-item>\\n <sd-section-item label=\"Trạng thái\">\\n <div class=\"d-flex align-items-center gap-8 flex-wrap\">\\n @for (badge of badges(); track $index) {\\n <sd-badge [type]=\"badge.type\" [title]=\"badge.title\" [color]=\"badge.color\" />\\n }\\n </div>\\n </sd-section-item>\\n </sd-section>\\n <div sdFooterRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <ng-container [ngTemplateOutlet]=\"actions\" />\\n </div>\\n </sd-side-drawer>\\n } @else {\\n <sd-page-detail\\n [title]=\"\\'Chi tiết đơn hàng #\\' + order.code\"\\n [description]=\"order.customer + \\' · \\' + order.channel\"\\n [badges]=\"badges()\"\\n [backLink]=\"[\\'../..\\']\">\\n <div headerRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <ng-container [ngTemplateOutlet]=\"actions\" />\\n </div>\\n <div class=\"d-flex flex-column gap-16 py-16\">\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"row p-8\">\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Khách hàng\" [display]=\"order.customer\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Điện thoại\" [display]=\"customer?.phone\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Kênh bán\" [display]=\"order.channel\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Kho xuất\" [display]=\"order.warehouse\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Thanh toán\" [display]=\"order.payment\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Ngày tạo\" [display]=\"order.createdAt | sdFormatDatetime\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Ngày giao\" [display]=\"order.deliveredAt | sdFormatDate\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Mã vận đơn\" [display]=\"order.tracking\" /></div>\\n </div>\\n </sd-section>\\n <lines-view [lines]=\"order.lines\" />\\n <sd-section title=\"Thông tin phê duyệt\">\\n <sd-section-item label=\"Trạng thái duyệt\">\\n <sd-badge [type]=\"approvalBadge().type\" [title]=\"approvalBadge().title\" [color]=\"approvalBadge().color\" />\\n </sd-section-item>\\n <sd-section-item label=\"Người gửi duyệt\">{{ submitted()?.by | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Người duyệt\">{{ decided()?.by | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Lý do từ chối\">{{ decided()?.reason | sdEmpty }}</sd-section-item>\\n <sd-section-item label=\"Ghi chú\">{{ order.note | sdEmpty }}</sd-section-item>\\n </sd-section>\\n </div>\\n <approval-steps sdAside [steps]=\"order.approvalHistory\" />\\n </sd-page-detail>\\n }\\n `,\\n})\\nexport class DetailComponent {\\n readonly #orderService = inject(OrderService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly drawer = viewChild(SdSideDrawer);\\n protected readonly mode = inject(SD_PAGE_LIST).detail;\\n readonly #resolved = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as OrderDto)), { requireSync: true });\\n /** Đơn do resolver tải; sau mỗi tác vụ thay bằng đơn API trả về. */\\n protected readonly entity = linkedSignal(() => this.#resolved());\\n protected readonly pending = signal(false);\\n protected readonly statusBadge = computed(() => orderStatusBadge(this.entity().status));\\n protected readonly approvalBadge = computed(() => orderApprovalBadge(this.entity().approval));\\n /** Trạng thái đơn và trạng thái duyệt: title của trang, dòng \"Trạng thái\" của drawer. */\\n protected readonly badges = computed(() => [this.statusBadge(), this.approvalBadge()]);\\n protected readonly editable = computed(() => canUpdateOrder(this.entity()));\\n protected readonly submitted = computed(() => [...this.entity().approvalHistory].reverse().find(step => step.action === \\'submit\\'));\\n protected readonly decided = computed(() =>\\n this.entity().approval === \\'approved\\' || this.entity().approval === \\'rejected\\' ? this.entity().approvalHistory.at(-1) : undefined\\n );\\n\\n constructor() {\\n afterNextRender(() => this.drawer()?.open());\\n }\\n\\n protected closed(): void {\\n void this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n }\\n\\n /** Hỏi xác nhận (Từ chối kèm lý do), gọi API, rồi hiển thị đơn mới; lỗi giữ nguyên màn để thử lại. */\\n protected async act(action: Extract<OrderAction, \\'submit\\' | \\'approve\\' | \\'reject\\'>): Promise<void> {\\n const order = this.entity();\\n let reason: string | undefined;\\n try {\\n if (action === \\'reject\\') {\\n reason = await this.#confirm.withInput(`Từ chối đơn ${order.code}. Lý do được gửi cho người lập đơn.`, {\\n title: \\'Từ chối đơn hàng\\',\\n label: \\'Lý do từ chối\\',\\n required: true,\\n maxlength: 200,\\n yesTitle: \\'Từ chối\\',\\n noTitle: \\'Không\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } else {\\n await this.#confirm.confirm(action === \\'approve\\' ? `Duyệt đơn ${order.code}?` : `Gửi đơn ${order.code} cho người duyệt?`, {\\n title: action === \\'approve\\' ? \\'Duyệt đơn hàng\\' : \\'Gửi duyệt\\',\\n yesTitle: action === \\'approve\\' ? \\'Duyệt\\' : \\'Gửi duyệt\\',\\n noTitle: \\'Không\\',\\n });\\n }\\n } catch {\\n return;\\n }\\n this.pending.set(true);\\n try {\\n this.entity.set(await firstValueFrom(this.#orderService.act(action, { id: order.id, reason })));\\n this.#notify.success(action === \\'approve\\' ? \\'Đã duyệt đơn.\\' : action === \\'reject\\' ? \\'Đã từ chối đơn.\\' : \\'Đã gửi duyệt.\\');\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error));\\n } finally {\\n this.pending.set(false);\\n }\\n }\\n}\\n',\n 'features/order/pages/list/list.component.html': '@let _settings = settings();\\n<sd-page-list title=\"Đơn hàng\" description=\"Đơn bán lẻ từ mọi kênh.\" [detail]=\"detailMode()\" [autoCompact]=\"_settings.autoCompact\">\\n <div headerRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <!-- Chỉ có ở /pattern. -->\\n <sd-pattern-settings-button />\\n <sd-button\\n *sdPermission=\"\\'PATTERN_ORDER_C_CREATE\\'\"\\n title=\"Tạo đơn hàng\"\\n prefixIcon=\"add\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"order-create\"\\n [routerLink]=\"[\\'create\\']\" />\\n </div>\\n\\n @if (_settings.tabs) {\\n <sd-tab-group sdSubheader [selectedIndex]=\"tabIndex()\" (selectedIndexChange)=\"selectTab($event)\">\\n @for (tab of tabs; track tab.label) {\\n <sd-tab [label]=\"tab.label\" [badge]=\"counts()?.[tab.status ?? \\'all\\']\" />\\n }\\n </sd-tab-group>\\n }\\n @if (_settings.score) {\\n <summary-cards [counts]=\"counts()\" [(status)]=\"status\" />\\n }\\n @if (bulkResult(); as result) {\\n <bulk-result [result]=\"result\" (retry)=\"retryFailed()\" (dismiss)=\"bulkResult.set(null)\" />\\n }\\n\\n <sd-table autoId=\"orders\" [option]=\"option()\">\\n <ng-template sdTableCellDef=\"code\" let-order=\"item\">\\n <a *sdPermission=\"\\'PATTERN_ORDER_R_DETAIL\\'\" [routerLink]=\"[order.id, \\'detail\\']\">{{ order.code }}</a>\\n @if (!canOpenDetail) {\\n <span>{{ order.code }}</span>\\n }\\n </ng-template>\\n </sd-table>\\n</sd-page-list>\\n',\n 'features/order/pages/list/list.component.ts': 'import { ChangeDetectionStrategy, Component, computed, effect, inject, signal, untracked, viewChild } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, NavigationEnd, Router, RouterLink } from \\'@angular/router\\';\\nimport { filter, firstValueFrom, map, startWith } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdTab, SdTabGroup } from \\'@sdcorejs/angular/components/tab\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableColumn, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { SdPageList, type SdPageListDetail } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective, SdPermissionService } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport type { PagingReq } from \\'@sdcorejs/utils/models\\';\\n// Chỉ có ở /pattern: drawer \"Tuỳ chỉnh hiển thị\" bật/tắt các vùng của màn. Màn thật chọn sẵn một cấu hình.\\nimport { PatternSettingsButtonComponent } from \\'../../../../core/pattern-shell/settings/settings-button.component\\';\\nimport { PatternSettingsStore, type PatternOrderSettings } from \\'../../../../core/pattern-shell/settings/pattern-settings.store\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { BulkResultComponent, type OrderBulkSummary } from \\'../../components/bulk-result/bulk-result.component\\';\\nimport { SummaryCardsComponent } from \\'../../components/summary-cards/summary-cards.component\\';\\nimport { OrderService } from \\'../../services/order.service\\';\\nimport {\\n ORDER_CHANNELS,\\n ORDER_PAYMENTS,\\n ORDER_STATUS_OPTIONS,\\n ORDER_WAREHOUSES,\\n orderStatusBadge,\\n type OrderAction,\\n type OrderActionReq,\\n type OrderCounts,\\n type OrderDto,\\n type OrderStatus,\\n} from \\'../../services/order.model\\';\\n\\ntype SelectorAction = NonNullable<NonNullable<SdTableOption<OrderDto>[\\'selector\\']>[\\'actions\\']>[number];\\n\\nconst TABS: readonly { readonly label: string; readonly status: OrderStatus | null }[] = [\\n { label: \\'Tất cả\\', status: null },\\n ...ORDER_STATUS_OPTIONS.map(option => ({ label: option.name, status: option.id })),\\n];\\n\\nconst values = (items: readonly string[]) => ({ items: items.map(value => ({ value })), valueField: \\'value\\', displayField: \\'value\\' });\\n\\n/** Cột của danh sách; `withTabs`: có tab trạng thái thì không lọc trạng thái dưới cột (E6). */\\nfunction columns(withTabs: boolean): SdTableColumn<OrderDto>[] {\\n return [\\n { field: \\'code\\', title: \\'Mã đơn\\', type: \\'string\\', width: \\'130px\\', sortable: true },\\n { field: \\'customer\\', title: \\'Khách hàng\\', type: \\'string\\', minWidth: \\'180px\\' },\\n { field: \\'channel\\', title: \\'Kênh\\', type: \\'values\\', width: \\'130px\\', option: values(ORDER_CHANNELS) },\\n { field: \\'createdAt\\', title: \\'Ngày tạo\\', type: \\'date\\', width: \\'170px\\', filter: { type: \\'daterange\\' }, sortable: true },\\n { field: \\'total\\', title: \\'Tổng tiền (₫)\\', type: \\'number\\', width: \\'130px\\', align: \\'right\\', sortable: true },\\n {\\n field: \\'status\\',\\n title: \\'Trạng thái\\',\\n type: \\'values\\',\\n width: \\'150px\\',\\n option: { items: ORDER_STATUS_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: status => orderStatusBadge(status),\\n filter: withTabs ? { disabled: true } : undefined,\\n },\\n ];\\n}\\n\\n@Component({\\n selector: \\'list\\',\\n standalone: true,\\n templateUrl: \\'./list.component.html\\',\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [\\n RouterLink,\\n SdPageList,\\n SdButton,\\n SdTabGroup,\\n SdTab,\\n SdTable,\\n SdTableCellDefDirective,\\n SdPermissionDirective,\\n SummaryCardsComponent,\\n BulkResultComponent,\\n PatternSettingsButtonComponent,\\n ],\\n})\\nexport class ListComponent {\\n readonly #orderService = inject(OrderService);\\n readonly #permission = inject(SdPermissionService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly pageList = viewChild.required(SdPageList);\\n private readonly table = viewChild.required(SdTable);\\n protected readonly canOpenDetail = this.#permission.hasPermission(\\'PATTERN_ORDER_R_DETAIL\\');\\n readonly #canExport = this.#permission.hasPermission(\\'PATTERN_ORDER_R_EXPORT\\');\\n protected readonly settings = inject(PatternSettingsStore).settings;\\n protected readonly tabs = TABS;\\n\\n // #region state\\n /** Một state cho tab, score card và request: đổi trạng thái thì đọc lại từ trang 1. */\\n protected readonly status = signal<OrderStatus | null>(null);\\n protected readonly tabIndex = computed(() => TABS.findIndex(tab => tab.status === this.status()));\\n protected readonly counts = signal<OrderCounts | null>(null);\\n // #endregion\\n protected readonly bulkResult = signal<OrderBulkSummary | null>(null);\\n #lastBulk: { readonly action: OrderAction; readonly reqs: readonly OrderActionReq[] } | null = null;\\n\\n /** Tạo và cập nhật (`data.detail: \\'page\\'`) thay chỗ danh sách; chi tiết mở theo cấu hình (drawer mặc định). */\\n readonly #childMode = toSignal(\\n this.#router.events.pipe(\\n filter(event => event instanceof NavigationEnd),\\n startWith(null),\\n map(() => this.#route.firstChild?.snapshot.data[\\'detail\\'] as SdPageListDetail | undefined)\\n ),\\n { requireSync: true }\\n );\\n protected readonly detailMode = computed<SdPageListDetail>(() => this.#childMode() ?? this.settings().detail);\\n\\n protected readonly option = computed(() => this.#tableOption(this.settings()));\\n\\n constructor() {\\n let status = this.status();\\n effect(() => {\\n const next = this.status();\\n if (next === status) return;\\n status = next;\\n untracked(() => void this.table().reloadFirstPage());\\n });\\n // Bật/tắt tab trạng thái thì về \"Tất cả\".\\n let tabs = this.settings().tabs;\\n effect(() => {\\n const next = this.settings().tabs;\\n if (next === tabs) return;\\n tabs = next;\\n untracked(() => this.status.set(null));\\n });\\n // Lưu hoặc đổi trạng thái ở màn con xong rồi quay về: tải lại trang hiện tại, giữ bộ lọc.\\n let changes = this.#orderService.changes();\\n effect(() => {\\n const next = this.#orderService.changes();\\n if (this.pageList().childActive() || next === changes) return;\\n changes = next;\\n untracked(() => void this.table().reload(true, false));\\n });\\n }\\n\\n protected selectTab(index: number): void {\\n this.status.set(TABS[index]?.status ?? null);\\n }\\n\\n protected retryFailed(): void {\\n const last = this.#lastBulk;\\n const failed = new Set(this.bulkResult()?.failed.map(item => item.id) ?? []);\\n if (last && failed.size)\\n void this.#runBulk(\\n last.action,\\n last.reqs.filter(req => failed.has(req.id))\\n );\\n }\\n\\n async #read(req: PagingReq<OrderDto>) {\\n const status = untracked(this.status);\\n // Số trên tab và thẻ theo cùng bộ lọc của bảng, chưa tính trạng thái đang chọn.\\n void firstValueFrom(this.#orderService.counts(req.filters ?? []))\\n .then(counts => this.counts.set(counts))\\n .catch(() => this.counts.set(null));\\n const filters = status ? [...(req.filters ?? []), { field: \\'status\\' as const, operator: \\'EQUAL\\' as const, data: status }] : req.filters;\\n return firstValueFrom(this.#orderService.list({ ...req, filters }));\\n }\\n\\n #tableOption(settings: PatternOrderSettings): SdTableOption<OrderDto> {\\n return {\\n type: \\'server\\',\\n rowKey: \\'id\\',\\n items: (_, req) => this.#read(req),\\n sort: { enable: true },\\n columns: columns(settings.tabs),\\n paginate: { pageSize: settings.pageSize, pages: [10, 20, 50] },\\n selector: settings.selector ? { visible: true, preserveSelection: true, actions: this.#selectorActions() } : { visible: false },\\n reload: { visible: settings.footerButtons },\\n export: settings.footerButtons && this.#canExport ? { visible: \\'EXCEL\\' } : undefined,\\n config: { visible: settings.footerButtons },\\n filter: {\\n hideInlineFilter: !settings.inlineFilter ? true : settings.autoHide ? \\'auto\\' : false,\\n quickSearch: settings.quickSearch\\n ? {\\n placeholder: \\'Tìm theo mã đơn, khách hàng\\',\\n containFields: [\\'code\\', \\'customer\\'],\\n filters: settings.warehouse\\n ? [{ field: \\'warehouse\\', title: \\'Kho xuất\\', type: \\'values\\', option: values(ORDER_WAREHOUSES) }]\\n : [],\\n }\\n : undefined,\\n // External filter chỉ chứa field không có cột (E6).\\n externalFilters: settings.externalFilter\\n ? [\\n { field: \\'payment\\', title: \\'Thanh toán\\', type: \\'values\\', option: values(ORDER_PAYMENTS) },\\n { field: \\'creator\\', title: \\'Người tạo\\', type: \\'string\\' },\\n { field: \\'deliveredAt\\', title: \\'Ngày giao\\', type: \\'daterange\\' },\\n { field: \\'source\\', title: \\'Nguồn đơn\\', type: \\'string\\' },\\n { field: \\'tracking\\', title: \\'Mã vận đơn\\', type: \\'string\\' },\\n { field: \\'note\\', title: \\'Ghi chú nội bộ\\', type: \\'string\\' },\\n ]\\n : undefined,\\n externalFilterPerRow: settings.externalFilterPerRow,\\n externalFilterCollapsed: settings.externalFilterCollapsed || undefined,\\n manualFilter: settings.manualFilter,\\n },\\n } as SdTableOption<OrderDto>;\\n }\\n\\n /** Tác vụ trên các dòng đã chọn, theo quyền (đã nạp trước khi mở màn). */\\n #selectorActions(): SelectorAction[] {\\n const can = (code: string) => this.#permission.hasPermission(code);\\n return [\\n { title: \\'Xác nhận\\', icon: \\'check\\', hidden: !can(\\'PATTERN_ORDER_U_CONFIRM\\'), click: items => void this.#confirmOrders(items ?? []) },\\n { title: \\'In phiếu giao\\', icon: \\'print\\', hidden: !can(\\'PATTERN_ORDER_R_PRINT\\'), click: items => this.#print(items ?? []) },\\n {\\n title: \\'Huỷ đơn\\',\\n icon: \\'cancel\\',\\n color: \\'error\\',\\n hidden: !can(\\'PATTERN_ORDER_U_CANCEL\\'),\\n click: items => void this.#cancelOrders(items ?? []),\\n },\\n ];\\n }\\n\\n async #confirmOrders(orders: readonly OrderDto[]): Promise<void> {\\n try {\\n await this.#confirm.confirm(`Xác nhận ${orders.length} đơn hàng đã chọn? Đơn chuyển sang Đang giao.`, {\\n title: \\'Xác nhận đơn hàng\\',\\n yesTitle: \\'Xác nhận\\',\\n noTitle: \\'Không\\',\\n });\\n } catch {\\n return;\\n }\\n await this.#runBulk(\\n \\'confirm\\',\\n orders.map(order => ({ id: order.id }))\\n );\\n }\\n\\n async #cancelOrders(orders: readonly OrderDto[]): Promise<void> {\\n let reason: string;\\n try {\\n reason = await this.#confirm.withInput(`Huỷ ${orders.length} đơn hàng đã chọn. Lý do được ghi vào từng đơn.`, {\\n title: \\'Huỷ đơn hàng\\',\\n label: \\'Lý do huỷ\\',\\n required: true,\\n maxlength: 200,\\n yesTitle: \\'Huỷ đơn\\',\\n noTitle: \\'Không huỷ\\',\\n yesButtonColor: \\'error\\',\\n });\\n } catch {\\n return;\\n }\\n await this.#runBulk(\\n \\'cancel\\',\\n orders.map(order => ({ id: order.id, reason }))\\n );\\n }\\n\\n #print(orders: readonly OrderDto[]): void {\\n this.#notify.info(`Đã gửi ${orders.length} phiếu giao tới máy in.`);\\n }\\n\\n /** Chạy tác vụ hàng loạt, báo kết quả từng phần, giữ các dòng lỗi đang chọn và cho thử lại phần lỗi. */\\n async #runBulk(action: OrderAction, reqs: readonly OrderActionReq[]): Promise<void> {\\n const table = this.table();\\n const selected = table.selectedTableItems();\\n const codeOf = (id: string) => selected.find(item => item.data.id === id)?.data.code ?? id;\\n try {\\n const { results } = await firstValueFrom(this.#orderService.bulk(action, reqs));\\n const failed = results.filter(result => !result.ok);\\n const succeeded = new Set(results.filter(result => result.ok).map(result => result.id));\\n this.#lastBulk = { action, reqs };\\n this.bulkResult.set({\\n done: action === \\'confirm\\' ? \\'Đã xác nhận\\' : \\'Đã huỷ\\',\\n total: results.length,\\n failed: failed.map(result => ({ id: result.id, code: codeOf(result.id), message: result.message ?? \\'Không thực hiện được.\\' })),\\n });\\n // Bỏ chọn đúng các đơn đã xong; đơn lỗi vẫn được chọn sau khi tải lại (preserveSelection).\\n for (const item of selected) {\\n if (!succeeded.has(item.data.id)) continue;\\n item.meta.selector!.isSelected = false;\\n table.onSelect(item);\\n }\\n await table.reload(true, false);\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error));\\n }\\n }\\n}\\n',\n 'features/order/pages/update/update.component.ts': 'import {\\n afterNextRender,\\n ChangeDetectionStrategy,\\n Component,\\n DestroyRef,\\n effect,\\n ElementRef,\\n inject,\\n Injector,\\n signal,\\n untracked,\\n} from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdTextarea } from \\'@sdcorejs/angular/forms/textarea\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport {\\n GeneralInformationFormComponent,\\n orderSaveReq,\\n type OrderForm,\\n} from \\'../../components/general-information-form/general-information-form.component\\';\\nimport { LinesFormComponent } from \\'../../components/lines-form/lines-form.component\\';\\nimport { LinesTableFormComponent } from \\'../../components/lines-table-form/lines-table-form.component\\';\\nimport { OrderService } from \\'../../services/order.service\\';\\nimport type { OrderDto } from \\'../../services/order.model\\';\\n\\n/**\\n * Cập nhật đơn hàng: khách đã ngừng hoạt động vẫn hiện (`customer-select` tải theo ID), lỗi của API trên một dòng\\n * hiện ngay ở dòng đó. Lưu xong sang chi tiết.\\n */\\n@Component({\\n selector: \\'update\\',\\n standalone: true,\\n imports: [SdPageComponent, SdButton, SdSection, SdTextarea, GeneralInformationFormComponent, LinesFormComponent, LinesTableFormComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n <sd-page-form [title]=\"\\'Cập nhật đơn hàng #\\' + entity().code\" [backLink]=\"[\\'../detail\\']\" toc>\\n <div headerRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Huỷ\" type=\"outline\" autoId=\"order-cancel\" (click)=\"cancel()\" />\\n <sd-button title=\"Lưu\" prefixIcon=\"save\" type=\"fill\" color=\"primary\" autoId=\"order-save\" [loading]=\"saving()\" (click)=\"save()\" />\\n </div>\\n <div class=\"d-flex flex-column gap-16 py-16\">\\n <general-information-form [form]=\"form\" [seed]=\"entity()\" />\\n @if (linesTable) {\\n <lines-table-form [form]=\"form\" [seed]=\"entity().lines\" [errors]=\"apiErrors.errors()\" />\\n } @else {\\n <lines-form [form]=\"form\" [seed]=\"entity().lines\" [errors]=\"apiErrors.errors()\" />\\n }\\n <sd-section title=\"Ghi chú\">\\n <div class=\"px-16 pt-16 pb-8\">\\n <sd-textarea label=\"Ghi chú nội bộ\" name=\"note\" [form]=\"form\" [model]=\"entity().note\" maxlength=\"500\" />\\n </div>\\n </sd-section>\\n </div>\\n </sd-page-form>\\n `,\\n})\\nexport class UpdateComponent {\\n readonly #orderService = inject(OrderService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n /** `?lines=sd-table`: dòng hàng dựng bằng `sd-table` (`lines-table-form`) để so với `<table>`. Màn thật chọn một. */\\n protected readonly linesTable = this.#route.snapshot.queryParamMap.get(\\'lines\\') === \\'sd-table\\';\\n readonly #host: HTMLElement = inject(ElementRef).nativeElement;\\n readonly #injector = inject(Injector);\\n /** Đơn do resolver tải; draft khởi tạo từ đây. */\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as OrderDto)), { requireSync: true });\\n protected readonly form: OrderForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'order-update\\', dirty: \\'value\\' });\\n\\n constructor() {\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n // why: chỉ đổi `:id` thì trang được dùng lại; khi đơn mới đã vào form, nó là mốc so sánh mới và lỗi cũ bỏ đi.\\n let loaded = this.entity();\\n effect(() => {\\n const entity = this.entity();\\n if (entity === loaded) return;\\n loaded = entity;\\n untracked(() => {\\n this.apiErrors.clear();\\n afterNextRender(() => this.#unsaved.markPristine(), { injector: this.#injector });\\n });\\n });\\n }\\n\\n protected cancel(): void {\\n void this.#router.navigate([\\'../detail\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n await firstValueFrom(this.#orderService.update(this.entity().id, orderSaveReq(this.form)));\\n this.#unsaved.markPristine();\\n this.#notify.success(\\'Đã cập nhật đơn hàng.\\');\\n await this.#router.navigate([\\'../detail\\'], { relativeTo: this.#route, replaceUrl: true });\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.#host), { injector: this.#injector });\\n }\\n}\\n',\n 'features/order/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { CustomerService } from \\'../customer/services/customer.service\\';\\nimport { ProductService } from \\'../product/services/product.service\\';\\nimport { entityResolver, updatableEntityResolver } from \\'./entity.resolver\\';\\nimport { OrderService } from \\'./services/order.service\\';\\n\\n/**\\n * Chi tiết là route con của danh sách (drawer hoặc trang theo `detail`); tạo và cập nhật là trang thay chỗ danh sách\\n * (`data.detail: \\'page\\'`). CustomerService và ProductService được cấp ở đây cho `customer-select`, `product-select`\\n * và các pipe relation: đơn hàng dùng wrapper của feature sở hữu entity, không tự gọi API của entity khác.\\n */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [OrderService, CustomerService, ProductService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\'create\\',\\n title: \\'Tạo mới đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_C_CREATE\\', detail: \\'page\\' },\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/create/create.component\\').then(module => module.CreateComponent),\\n },\\n {\\n path: \\':id/detail\\',\\n title: \\'Chi tiết đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_R_DETAIL\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () => import(\\'./pages/detail/detail.component\\').then(module => module.DetailComponent),\\n },\\n {\\n path: \\':id/update\\',\\n title: \\'Cập nhật đơn hàng\\',\\n data: { permission: \\'PATTERN_ORDER_U_UPDATE\\', detail: \\'page\\' },\\n resolve: { entity: updatableEntityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/update/update.component\\').then(module => module.UpdateComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n',\n 'features/order/services/order.model.ts': 'import type { SdBadgeData } from \\'@sdcorejs/angular/components/badge\\';\\nimport type { PagingReq, PagingRes } from \\'@sdcorejs/utils/models\\';\\n\\nexport type OrderStatus = \\'pending\\' | \\'shipping\\' | \\'done\\' | \\'cancelled\\';\\nexport type OrderApproval = \\'draft\\' | \\'submitted\\' | \\'approved\\' | \\'rejected\\';\\n\\nexport const ORDER_STATUS_OPTIONS = [\\n { id: \\'pending\\', name: \\'Chờ xác nhận\\', color: \\'warning\\' },\\n { id: \\'shipping\\', name: \\'Đang giao\\', color: \\'info\\' },\\n { id: \\'done\\', name: \\'Hoàn tất\\', color: \\'success\\' },\\n { id: \\'cancelled\\', name: \\'Đã huỷ\\', color: \\'secondary\\' },\\n] satisfies { id: OrderStatus; name: string; color: SdBadgeData[\\'color\\'] }[];\\n\\nexport const ORDER_APPROVAL_OPTIONS = [\\n { id: \\'draft\\', name: \\'Nháp\\', color: \\'secondary\\' },\\n { id: \\'submitted\\', name: \\'Chờ duyệt\\', color: \\'warning\\' },\\n { id: \\'approved\\', name: \\'Đã duyệt\\', color: \\'success\\' },\\n { id: \\'rejected\\', name: \\'Bị từ chối\\', color: \\'error\\' },\\n] satisfies { id: OrderApproval; name: string; color: SdBadgeData[\\'color\\'] }[];\\n\\nexport const ORDER_CHANNELS = [\\'Online\\', \\'Cửa hàng\\', \\'Đại lý\\'] as const;\\nexport const ORDER_WAREHOUSES = [\\'Hà Nội\\', \\'TP.HCM\\', \\'Đà Nẵng\\'] as const;\\nexport const ORDER_PAYMENTS = [\\'Tiền mặt\\', \\'Chuyển khoản\\', \\'COD\\'] as const;\\n\\nexport interface OrderLineDto {\\n readonly productId: string;\\n readonly quantity: number;\\n readonly unitPrice: number;\\n}\\n\\nexport interface OrderApprovalStepDto {\\n readonly action: \\'submit\\' | \\'approve\\' | \\'reject\\';\\n readonly by: string;\\n readonly at: string;\\n readonly reason?: string;\\n}\\n\\nexport interface OrderDto {\\n readonly id: string;\\n readonly code: string;\\n readonly customerId: string;\\n /** Tên khách lúc lập đơn: chứng từ giữ snapshot, không đổi theo danh mục khách hàng. */\\n readonly customer: string;\\n readonly channel: string;\\n readonly warehouse: string;\\n readonly payment: string;\\n readonly createdAt: string;\\n readonly deliveredAt: string | null;\\n /** Tổng tiền (₫). */\\n readonly total: number;\\n readonly status: OrderStatus;\\n readonly approval: OrderApproval;\\n readonly approvalHistory: readonly OrderApprovalStepDto[];\\n readonly lines: readonly OrderLineDto[];\\n readonly creator: string;\\n readonly source: string;\\n readonly tracking: string | null;\\n readonly note: string | null;\\n readonly cancelReason: string | null;\\n}\\n\\nexport type OrderListReq = PagingReq<OrderDto>;\\nexport type OrderListRes = PagingRes<OrderDto>;\\n\\n/** Số đơn theo trạng thái và doanh thu hoàn tất, cùng bộ lọc với danh sách (trừ trạng thái đang chọn). */\\nexport type OrderCounts = Record<\\'all\\' | OrderStatus | \\'revenue\\', number>;\\n\\nexport interface OrderSaveReq {\\n readonly customerId: string;\\n readonly channel: string;\\n readonly warehouse: string;\\n readonly payment: string;\\n readonly note: string | null;\\n readonly lines: readonly OrderLineDto[];\\n}\\n\\n/** Tác vụ đổi trạng thái của đơn; `cancel` và `reject` bắt buộc lý do. */\\nexport type OrderAction = \\'confirm\\' | \\'cancel\\' | \\'submit\\' | \\'approve\\' | \\'reject\\';\\n\\nexport interface OrderActionReq {\\n readonly id: string;\\n readonly reason?: string;\\n}\\n\\n/** Kết quả từng đơn của một tác vụ hàng loạt: API trả đủ thành công lẫn thất bại. */\\nexport interface OrderBulkItemRes {\\n readonly id: string;\\n readonly ok: boolean;\\n readonly message?: string;\\n}\\n\\nexport interface OrderBulkRes {\\n readonly results: readonly OrderBulkItemRes[];\\n}\\n\\nexport function orderStatusBadge(status: OrderStatus): SdBadgeData {\\n const option = ORDER_STATUS_OPTIONS.find(item => item.id === status);\\n return { type: \\'round\\', title: option?.name ?? status, color: option?.color };\\n}\\n\\nexport function orderApprovalBadge(approval: OrderApproval): SdBadgeData {\\n const option = ORDER_APPROVAL_OPTIONS.find(item => item.id === approval);\\n return { type: \\'tag\\', title: option?.name ?? approval, color: option?.color };\\n}\\n\\n/** Đơn còn sửa được: chờ xác nhận, chưa gửi duyệt hoặc đã bị từ chối. */\\nexport function canUpdateOrder(order: OrderDto): boolean {\\n return order.status === \\'pending\\' && (order.approval === \\'draft\\' || order.approval === \\'rejected\\');\\n}\\n',\n 'features/order/services/order.service.ts': 'import { HttpParams } from \\'@angular/common/http\\';\\nimport { Injectable, signal } from \\'@angular/core\\';\\nimport { tap, type Observable } from \\'rxjs\\';\\nimport type { Filter } from \\'@sdcorejs/utils/models\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type {\\n OrderAction,\\n OrderActionReq,\\n OrderBulkRes,\\n OrderCounts,\\n OrderDto,\\n OrderListReq,\\n OrderListRes,\\n OrderSaveReq,\\n} from \\'./order.model\\';\\n\\n@Injectable()\\nexport class OrderService extends BaseApiService {\\n readonly #changes = signal(0);\\n /** Tăng sau mỗi lần lưu hoặc đổi trạng thái thành công: danh sách chỉ tải lại khi có thay đổi. */\\n readonly changes = this.#changes.asReadonly();\\n\\n list(req: OrderListReq): Observable<OrderListRes> {\\n return this.http.get<OrderListRes>(this.apiUrl(\\'orders\\'), { params: this.buildPagingReq(req) });\\n }\\n\\n /** Số đơn của tab và score card, theo cùng bộ lọc của danh sách. */\\n counts(filters: Filter<OrderDto>[]): Observable<OrderCounts> {\\n return this.http.get<OrderCounts>(this.apiUrl(\\'orders\\', \\'counts\\'), {\\n params: new HttpParams().set(\\'filters\\', JSON.stringify(filters)),\\n });\\n }\\n\\n detail(id: string): Observable<OrderDto> {\\n return this.http.get<OrderDto>(this.apiUrl(\\'orders\\', id));\\n }\\n\\n create(req: OrderSaveReq): Observable<OrderDto> {\\n return this.http.post<OrderDto>(this.apiUrl(\\'orders\\'), req).pipe(tap(() => this.#changed()));\\n }\\n\\n update(id: string, req: OrderSaveReq): Observable<OrderDto> {\\n return this.http.put<OrderDto>(this.apiUrl(\\'orders\\', id), req).pipe(tap(() => this.#changed()));\\n }\\n\\n /** Một tác vụ trên một đơn; trả đơn sau khi đổi trạng thái. */\\n act(action: OrderAction, req: OrderActionReq): Observable<OrderDto> {\\n const { id, ...body } = req;\\n return this.http.post<OrderDto>(this.apiUrl(\\'orders\\', id, action), body).pipe(tap(() => this.#changed()));\\n }\\n\\n /**\\n * Một tác vụ trên nhiều đơn. API không có transaction cho cả lô: kết quả có từng đơn thành công hoặc thất bại,\\n * nên luôn đọc `results` thay vì coi request thành công là thành công toàn bộ.\\n */\\n bulk(action: OrderAction, reqs: readonly OrderActionReq[]): Observable<OrderBulkRes> {\\n return this.http.post<OrderBulkRes>(this.apiUrl(\\'orders\\', \\'bulk\\', action), { items: reqs }).pipe(tap(() => this.#changed()));\\n }\\n\\n #changed(): void {\\n this.#changes.update(count => count + 1);\\n }\\n}\\n',\n 'features/partner/pages/create/create.component.ts': 'import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, signal } from \\'@angular/core\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, merge } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdInform } from \\'@sdcorejs/angular/components/inform\\';\\nimport { SdSection, SdSectionItem } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdStep, SdStepper } from \\'@sdcorejs/angular/components/stepper\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdSegmentedComponent } from \\'@sdcorejs/angular/forms/segmented\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdFormatDatetimePipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { SdConfirmService } from \\'@sdcorejs/angular/services/confirm\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { apiErrorMessage, apiFieldErrors } from \\'../../../../utils/api-error\\';\\nimport { PartnerService } from \\'../../services/partner.service\\';\\nimport { PARTNER_TYPE_OPTIONS, type PartnerSaveReq, type PartnerType } from \\'../../services/partner.model\\';\\n\\n/** Bản nháp giữ trong tab trình duyệt: tải lại trang vẫn tiếp tục được. */\\ninterface PartnerDraft extends PartnerSaveReq {\\n readonly step: number;\\n readonly savedAt: string;\\n}\\n\\nconst DRAFT_KEY = \\'pattern.partner.create.draft\\';\\nconst EMPTY: PartnerSaveReq = {\\n code: \\'\\',\\n type: \\'individual\\',\\n name: \\'\\',\\n identity: \\'\\',\\n representative: null,\\n email: \\'\\',\\n phone: \\'\\',\\n address: \\'\\',\\n};\\n\\nfunction readDraft(): PartnerDraft | null {\\n try {\\n const raw = sessionStorage.getItem(DRAFT_KEY);\\n return raw ? (JSON.parse(raw) as PartnerDraft) : null;\\n } catch {\\n return null;\\n }\\n}\\n\\nfunction writeDraft(draft: PartnerDraft | null): void {\\n try {\\n if (draft) sessionStorage.setItem(DRAFT_KEY, JSON.stringify(draft));\\n else sessionStorage.removeItem(DRAFT_KEY);\\n } catch {\\n // Không lưu được nháp (chế độ riêng tư, hết dung lượng): flow vẫn chạy, chỉ không khôi phục sau khi tải lại.\\n }\\n}\\n\\n/**\\n * Pattern flow dọc: `sd-page` hẹp + `sd-stepper` dọc, nút bước ở footer. Bước 2 rẽ nhánh theo loại đối tác; rời bước 1\\n * thì kiểm tra trùng mã với API; mọi thay đổi được lưu nháp và khôi phục khi tải lại trang.\\n */\\n@Component({\\n selector: \\'create\\',\\n standalone: true,\\n imports: [\\n SdPageComponent,\\n SdStepper,\\n SdStep,\\n SdButton,\\n SdInform,\\n SdSection,\\n SdSectionItem,\\n SdInput,\\n SdSegmentedComponent,\\n SdFormatDatetimePipe,\\n ],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let value = seed();\\n <sd-page title=\"Tạo đối tác\" description=\"Đối tác cá nhân hoặc doanh nghiệp.\" [backLink]=\"[\\'../..\\']\" width=\"narrow\">\\n @if (restored(); as draft) {\\n <sd-inform\\n info\\n class=\"mt-16\"\\n autoId=\"partner-draft\"\\n [description]=\"\\'Đã khôi phục bản nháp lưu lúc \\' + (draft.savedAt | sdFormatDatetime) + \\'.\\'\"\\n actionLabel=\"Bỏ nháp\"\\n (sdAction)=\"discard()\" />\\n }\\n <sd-stepper linear orientation=\"vertical\" animationDuration=\"0ms\" autoId=\"partner-steps\" [(selectedIndex)]=\"step\">\\n <sd-step label=\"Loại và mã đối tác\" [stepControl]=\"kind\">\\n <div class=\"d-flex flex-column gap-8 py-8\">\\n <sd-segmented\\n name=\"type\"\\n ariaLabel=\"Loại đối tác\"\\n autoId=\"partner-type\"\\n [form]=\"kind\"\\n [items]=\"types\"\\n [model]=\"value.type\"\\n (sdChange)=\"type.set($any($event) ?? \\'individual\\')\" />\\n <sd-input\\n label=\"Mã đối tác\"\\n name=\"code\"\\n autoId=\"partner-code\"\\n [form]=\"kind\"\\n [model]=\"value.code\"\\n [inlineError]=\"codeError() ?? undefined\"\\n maxlength=\"20\"\\n required />\\n </div>\\n </sd-step>\\n <sd-step [label]=\"type() === \\'business\\' ? \\'Thông tin doanh nghiệp\\' : \\'Thông tin cá nhân\\'\" [stepControl]=\"identity\">\\n <div class=\"d-flex flex-column gap-8 py-8\">\\n @if (type() === \\'business\\') {\\n <sd-input label=\"Tên doanh nghiệp\" name=\"name\" autoId=\"partner-name\" [form]=\"identity\" [model]=\"value.name\" required />\\n <sd-input\\n label=\"Mã số thuế\"\\n name=\"identity\"\\n autoId=\"partner-identity\"\\n [form]=\"identity\"\\n [model]=\"value.identity\"\\n maxlength=\"14\"\\n required />\\n <sd-input\\n label=\"Người đại diện\"\\n name=\"representative\"\\n autoId=\"partner-representative\"\\n [form]=\"identity\"\\n [model]=\"value.representative\"\\n required />\\n } @else {\\n <sd-input label=\"Họ và tên\" name=\"name\" autoId=\"partner-name\" [form]=\"identity\" [model]=\"value.name\" required />\\n <sd-input\\n label=\"Số CCCD\"\\n name=\"identity\"\\n autoId=\"partner-identity\"\\n [form]=\"identity\"\\n [model]=\"value.identity\"\\n maxlength=\"12\"\\n required />\\n }\\n </div>\\n </sd-step>\\n <sd-step label=\"Liên hệ\" [stepControl]=\"contact\">\\n <div class=\"d-flex flex-column gap-8 py-8\">\\n <sd-input label=\"Email\" name=\"email\" autoId=\"partner-email\" [form]=\"contact\" [model]=\"value.email\" pattern=\"EMAIL\" required />\\n <sd-input\\n label=\"Điện thoại\"\\n name=\"phone\"\\n autoId=\"partner-phone\"\\n [form]=\"contact\"\\n [model]=\"value.phone\"\\n maxlength=\"15\"\\n required />\\n <sd-input label=\"Địa chỉ\" name=\"address\" autoId=\"partner-address\" [form]=\"contact\" [model]=\"value.address\" maxlength=\"200\" />\\n </div>\\n </sd-step>\\n <sd-step label=\"Xác nhận\">\\n @let summary = request();\\n <sd-section title=\"Kiểm tra lại\" class=\"d-block my-8\">\\n <sd-section-item label=\"Mã đối tác\">{{ summary.code }}</sd-section-item>\\n <sd-section-item label=\"Loại\">{{ summary.type === \\'business\\' ? \\'Doanh nghiệp\\' : \\'Cá nhân\\' }}</sd-section-item>\\n <sd-section-item label=\"Tên\">{{ summary.name }}</sd-section-item>\\n <sd-section-item [label]=\"summary.type === \\'business\\' ? \\'Mã số thuế\\' : \\'Số CCCD\\'\">{{ summary.identity }}</sd-section-item>\\n @if (summary.type === \\'business\\') {\\n <sd-section-item label=\"Người đại diện\">{{ summary.representative }}</sd-section-item>\\n }\\n <sd-section-item label=\"Email\">{{ summary.email }}</sd-section-item>\\n <sd-section-item label=\"Điện thoại\">{{ summary.phone }}</sd-section-item>\\n </sd-section>\\n </sd-step>\\n </sd-stepper>\\n <sd-button\\n sdFooterLeft\\n title=\"Quay lại\"\\n type=\"outline\"\\n autoId=\"partner-previous\"\\n [disabled]=\"step() === 0\"\\n (click)=\"step.set(step() - 1)\" />\\n @if (step() < 3) {\\n <sd-button\\n sdFooterRight\\n title=\"Tiếp tục\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"partner-next\"\\n [loading]=\"checking()\"\\n (click)=\"next()\" />\\n } @else {\\n <sd-button\\n sdFooterRight\\n title=\"Tạo đối tác\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"partner-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n }\\n </sd-page>\\n `,\\n})\\nexport class CreateComponent {\\n readonly #partnerService = inject(PartnerService);\\n readonly #confirm = inject(SdConfirmService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #draft = readDraft();\\n protected readonly types = PARTNER_TYPE_OPTIONS;\\n /** Giá trị ban đầu của các field: bản nháp nếu có. */\\n protected readonly seed = signal<PartnerSaveReq>(this.#draft ?? EMPTY);\\n protected readonly restored = signal<PartnerDraft | null>(this.#draft);\\n protected readonly step = signal(this.#draft?.step ?? 0);\\n protected readonly type = signal<PartnerType>(this.#draft?.type ?? \\'individual\\');\\n // Mỗi bước một FormGroup: stepper `linear` không cho sang bước sau khi bước hiện tại còn lỗi.\\n protected readonly kind = new FormGroup({});\\n protected readonly identity = new FormGroup({});\\n protected readonly contact = new FormGroup({});\\n protected readonly codeError = signal<string | null>(null);\\n protected readonly checking = signal(false);\\n protected readonly saving = signal(false);\\n readonly #values = signal(0);\\n /** Đã tạo xong: khi trang đóng, field gỡ control khỏi form và phát valueChanges; không được ghi lại nháp vừa xoá. */\\n #created = false;\\n protected readonly request = computed<PartnerSaveReq>(() => {\\n this.#values();\\n // why: nội dung bước chỉ tạo khi bước được mở; bước chưa mở lại sau khi khôi phục nháp lấy giá trị của nháp.\\n const value = {\\n ...this.seed(),\\n ...this.kind.getRawValue(),\\n ...this.identity.getRawValue(),\\n ...this.contact.getRawValue(),\\n } as Partial<PartnerSaveReq>;\\n const type = this.type();\\n return {\\n code: (value.code ?? \\'\\').trim().toUpperCase(),\\n type,\\n name: value.name ?? \\'\\',\\n identity: value.identity ?? \\'\\',\\n representative: type === \\'business\\' ? (value.representative ?? \\'\\') : null,\\n email: value.email ?? \\'\\',\\n phone: value.phone ?? \\'\\',\\n address: value.address ?? \\'\\',\\n };\\n });\\n\\n constructor() {\\n // Mỗi thay đổi lưu nháp; mã đổi thì bỏ lỗi trùng mã cũ.\\n const subscription = merge(this.kind.valueChanges, this.identity.valueChanges, this.contact.valueChanges).subscribe(() => {\\n if (this.#created) return;\\n this.#values.update(count => count + 1);\\n this.#saveDraft();\\n });\\n const code = this.kind.valueChanges.subscribe(() => this.codeError.set(null));\\n inject(DestroyRef).onDestroy(() => {\\n subscription.unsubscribe();\\n code.unsubscribe();\\n });\\n }\\n\\n protected async next(): Promise<void> {\\n const step = this.step();\\n const group = [this.kind, this.identity, this.contact][step];\\n group.markAllAsTouched();\\n if (group.invalid) return;\\n if (step === 0 && !(await this.#codeAvailable())) return;\\n this.step.set(step + 1);\\n this.#saveDraft();\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.saving.set(true);\\n try {\\n const partner = await firstValueFrom(this.#partnerService.create(this.request()));\\n this.#created = true;\\n writeDraft(null);\\n this.#notify.success(`Đã tạo đối tác ${partner.code}.`);\\n await this.#router.navigate([\\'../..\\'], { relativeTo: this.#route });\\n } catch (error) {\\n const fields = apiFieldErrors(error);\\n if (fields[\\'code\\']) {\\n // Mã vừa bị người khác dùng: quay lại bước nhập mã, dữ liệu các bước khác giữ nguyên.\\n this.codeError.set(fields[\\'code\\']);\\n this.step.set(0);\\n } else this.#notify.error(apiErrorMessage(error, \\'Không tạo được đối tác. Dữ liệu vẫn được giữ trong bản nháp.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n protected async discard(): Promise<void> {\\n try {\\n await this.#confirm.confirm(\\'Xoá bản nháp và nhập lại từ đầu?\\', {\\n title: \\'Bỏ nháp\\',\\n yesTitle: \\'Bỏ nháp\\',\\n noTitle: \\'Giữ lại\\',\\n yesButtonColor: \\'warning\\',\\n });\\n } catch {\\n return;\\n }\\n writeDraft(null);\\n this.restored.set(null);\\n this.step.set(0);\\n this.type.set(\\'individual\\');\\n this.seed.set({ ...EMPTY });\\n }\\n\\n async #codeAvailable(): Promise<boolean> {\\n this.checking.set(true);\\n try {\\n const { available } = await firstValueFrom(this.#partnerService.checkCode(this.request().code));\\n if (!available) this.codeError.set(`Mã ${this.request().code} đã được dùng.`);\\n return available;\\n } catch (error) {\\n this.#notify.error(apiErrorMessage(error, \\'Không kiểm tra được mã. Thử lại.\\'));\\n return false;\\n } finally {\\n this.checking.set(false);\\n }\\n }\\n\\n #saveDraft(): void {\\n writeDraft({ ...this.request(), step: this.step(), savedAt: new Date().toISOString() });\\n }\\n}\\n',\n 'features/partner/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { PartnerService } from \\'./services/partner.service\\';\\n\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [PartnerService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n { path: \\'\\', pathMatch: \\'full\\', redirectTo: \\'create\\' },\\n {\\n path: \\'create\\',\\n title: \\'Tạo đối tác\\',\\n data: { permission: \\'PATTERN_PARTNER_C_CREATE\\' },\\n loadComponent: () => import(\\'./pages/create/create.component\\').then(module => module.CreateComponent),\\n },\\n ],\\n },\\n];\\n',\n 'features/partner/services/partner.model.ts': 'export type PartnerType = \\'individual\\' | \\'business\\';\\n\\nexport const PARTNER_TYPE_OPTIONS = [\\n { value: \\'individual\\', label: \\'Cá nhân\\' },\\n { value: \\'business\\', label: \\'Doanh nghiệp\\' },\\n] satisfies { value: PartnerType; label: string }[];\\n\\nexport interface PartnerDto {\\n readonly id: string;\\n readonly code: string;\\n readonly type: PartnerType;\\n readonly name: string;\\n /** CCCD của cá nhân hoặc mã số thuế của doanh nghiệp. */\\n readonly identity: string;\\n readonly representative: string | null;\\n readonly email: string;\\n readonly phone: string;\\n readonly address: string;\\n}\\n\\nexport interface PartnerSaveReq {\\n readonly code: string;\\n readonly type: PartnerType;\\n readonly name: string;\\n readonly identity: string;\\n readonly representative: string | null;\\n readonly email: string;\\n readonly phone: string;\\n readonly address: string;\\n}\\n',\n 'features/partner/services/partner.service.ts': 'import { HttpParams } from \\'@angular/common/http\\';\\nimport { Injectable } from \\'@angular/core\\';\\nimport type { Observable } from \\'rxjs\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type { PartnerDto, PartnerSaveReq } from \\'./partner.model\\';\\n\\n@Injectable()\\nexport class PartnerService extends BaseApiService {\\n /** Mã còn dùng được không; gọi khi rời bước nhập mã, API vẫn kiểm tra lại lúc lưu. */\\n checkCode(code: string): Observable<{ available: boolean }> {\\n return this.http.get<{ available: boolean }>(this.apiUrl(\\'partners\\', \\'check-code\\'), { params: new HttpParams().set(\\'code\\', code) });\\n }\\n\\n create(req: PartnerSaveReq): Observable<PartnerDto> {\\n return this.http.post<PartnerDto>(this.apiUrl(\\'partners\\'), req);\\n }\\n}\\n',\n 'features/product/components/general-information-form/general-information-form.component.ts': 'import { ChangeDetectionStrategy, Component, input } from \\'@angular/core\\';\\nimport type { FormControl, FormGroup } from \\'@angular/forms\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdInputNumber } from \\'@sdcorejs/angular/forms/input-number\\';\\nimport type { ProductSaveReq, ProductStatus } from \\'../../services/product.model\\';\\nimport { ProductStatusSelectComponent } from \\'../product-status-select/product-status-select.component\\';\\n\\n/** Các field Core tự đăng ký control qua `[form]` + `name`; page không khai báo trước control trùng tên. */\\nexport type ProductForm = FormGroup<{\\n code?: FormControl<string>;\\n name?: FormControl<string>;\\n unit?: FormControl<string>;\\n price?: FormControl<number>;\\n status?: FormControl<ProductStatus>;\\n}>;\\n\\n/** Giá trị form → request lưu. `code` truyền vào khi cập nhật (mã bị khoá). */\\nexport function productSaveReq(form: ProductForm, code?: string): ProductSaveReq {\\n const value = form.getRawValue();\\n return {\\n code: code ?? value.code ?? \\'\\',\\n name: value.name ?? \\'\\',\\n unit: value.unit ?? \\'\\',\\n price: value.price ?? 0,\\n status: value.status ?? \\'active\\',\\n };\\n}\\n\\n/** Nhóm \"Thông tin chung\" của form sản phẩm, dùng chung cho tạo mới và cập nhật. */\\n@Component({\\n selector: \\'general-information-form\\',\\n standalone: true,\\n imports: [SdInput, SdInputNumber, SdSection, ProductStatusSelectComponent],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-section title=\"Thông tin chung\">\\n <div class=\"row px-16 pt-16 pb-8\">\\n <div class=\"col-12 col-md-6\">\\n <sd-input\\n label=\"Mã sản phẩm\"\\n name=\"code\"\\n autoId=\"product-code\"\\n [form]=\"form()\"\\n [model]=\"seed().code\"\\n [disabled]=\"editing()\"\\n [inlineError]=\"errors()[\\'code\\']\"\\n maxlength=\"20\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input\\n label=\"Tên sản phẩm\"\\n name=\"name\"\\n autoId=\"product-name\"\\n [form]=\"form()\"\\n [model]=\"seed().name\"\\n [inlineError]=\"errors()[\\'name\\']\"\\n maxlength=\"100\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input label=\"Đơn vị tính\" name=\"unit\" autoId=\"product-unit\" [form]=\"form()\" [model]=\"seed().unit\" maxlength=\"20\" />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input-number\\n label=\"Giá bán (₫)\"\\n name=\"price\"\\n autoId=\"product-price\"\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"form()\"\\n [model]=\"seed().price\"\\n [inlineError]=\"errors()[\\'price\\']\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <product-status-select [form]=\"form()\" [model]=\"seed().status\" />\\n </div>\\n </div>\\n </sd-section>`,\\n})\\nexport class GeneralInformationFormComponent {\\n readonly form = input.required<FormGroup>();\\n readonly seed = input.required<ProductSaveReq>();\\n readonly editing = input(false);\\n /** Lỗi theo field do API trả về. */\\n readonly errors = input<Readonly<Record<string, string>>>({});\\n}\\n',\n 'features/product/components/product-select/product-select.component.ts': 'import { booleanAttribute, ChangeDetectionStrategy, Component, inject, input, model } from \\'@angular/core\\';\\nimport type { FormGroup } from \\'@angular/forms\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdItemDefDefDirective } from \\'@sdcorejs/angular/forms/directives\\';\\nimport type { SdSearchReq } from \\'@sdcorejs/angular/forms/models\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport type { Filter, Size } from \\'@sdcorejs/utils/models\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport type { ProductDto } from \\'../../services/product.model\\';\\n\\n/**\\n * Chọn sản phẩm cho màn khác (dòng đơn hàng). Lựa chọn mới chỉ gồm sản phẩm đang hoạt động; giá trị đã chọn\\n * được tải theo ID (`VALUE`) nên sản phẩm đã ngừng vẫn hiển thị khi cập nhật. Option hai dòng: tên · mã · đơn vị.\\n * `size`, `hideInlineError` và `inlineError` chuyển thẳng xuống `sd-select`, để dùng được trong ô của bảng.\\n */\\n@Component({\\n selector: \\'product-select\\',\\n standalone: true,\\n imports: [SdSelect, SdItemDefDefDirective],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-select\\n [label]=\"label()\"\\n [name]=\"name()\"\\n [form]=\"form()\"\\n [(model)]=\"model\"\\n [items]=\"search\"\\n valueField=\"id\"\\n displayField=\"name\"\\n [required]=\"required()\"\\n [size]=\"size()\"\\n [hideInlineError]=\"hideInlineError()\"\\n [inlineError]=\"inlineError()\"\\n [autoId]=\"autoId()\">\\n <ng-template sdItemDef let-item=\"item\">\\n <div class=\"d-flex flex-column\">\\n <span>{{ item.name }}</span>\\n <small class=\"text-secondary\">{{ item.code }} · {{ item.unit }}{{ item.status === \\'inactive\\' ? \\' · Ngừng hoạt động\\' : \\'\\' }}</small>\\n </div>\\n </ng-template>\\n </sd-select>`,\\n})\\nexport class ProductSelectComponent {\\n readonly #productService = inject(ProductService);\\n readonly form = input<FormGroup>();\\n readonly name = input(\\'productId\\');\\n readonly label = input<string | undefined>(\\'Sản phẩm\\');\\n readonly required = input(false, { transform: booleanAttribute });\\n readonly size = input<Size>(\\'md\\');\\n readonly hideInlineError = input(false, { transform: booleanAttribute });\\n /** Lỗi của API cho field này (vd `lines.0.productId`). */\\n readonly inlineError = input<string>();\\n readonly autoId = input<string>();\\n readonly model = model<string | null | undefined>();\\n\\n protected readonly search = async (req: SdSearchReq): Promise<ProductDto[]> => {\\n if (req.type === \\'VALUE\\') {\\n const ids = (Array.isArray(req.value) ? req.value : [req.value]).filter((id): id is string => !!id);\\n return Promise.all(ids.map(id => firstValueFrom(this.#productService.cachedDetail(id))));\\n }\\n const filters: Filter<ProductDto>[] = [{ field: \\'status\\', operator: \\'EQUAL\\', data: \\'active\\' }];\\n if (req.searchText) {\\n filters.push({\\n operator: \\'OR\\',\\n data: [\\n { field: \\'name\\', operator: \\'CONTAIN\\', data: req.searchText },\\n { field: \\'code\\', operator: \\'CONTAIN\\', data: req.searchText },\\n ],\\n });\\n }\\n const res = await firstValueFrom(this.#productService.list({ pageNumber: 0, pageSize: 20, filters }));\\n return res.items;\\n };\\n}\\n',\n 'features/product/components/product-status-select/product-status-select.component.ts': 'import { ChangeDetectionStrategy, Component, input, model } from \\'@angular/core\\';\\nimport type { FormGroup } from \\'@angular/forms\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport { PRODUCT_STATUS_OPTIONS, type ProductStatus } from \\'../../services/product.model\\';\\n\\n/** Dropdown trạng thái sản phẩm: options và label thuộc feature, nơi dùng chỉ bind model/form. */\\n@Component({\\n selector: \\'product-status-select\\',\\n standalone: true,\\n imports: [SdSelect],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `<sd-select\\n [label]=\"label()\"\\n [name]=\"name()\"\\n [form]=\"form()\"\\n [(model)]=\"model\"\\n [items]=\"options\"\\n valueField=\"id\"\\n displayField=\"name\"\\n [required]=\"required()\"\\n [clearable]=\"false\" />`,\\n})\\nexport class ProductStatusSelectComponent {\\n readonly form = input<FormGroup>();\\n readonly name = input(\\'status\\');\\n readonly label = input(\\'Trạng thái\\');\\n readonly required = input(true);\\n readonly model = model<ProductStatus | null | undefined>();\\n protected readonly options = PRODUCT_STATUS_OPTIONS;\\n}\\n',\n 'features/product/entity.resolver.ts': 'import { HttpErrorResponse } from \\'@angular/common/http\\';\\nimport { inject } from \\'@angular/core\\';\\nimport type { ResolveFn } from \\'@angular/router\\';\\nimport { map, timeout } from \\'rxjs\\';\\nimport { ProductService } from \\'./services/product.service\\';\\nimport type { ProductDto } from \\'./services/product.model\\';\\n\\n/** Tải sản phẩm trước khi mở detail/update; lỗi (404, 403, timeout) đi tới navigation error handler của host. */\\nexport const entityResolver: ResolveFn<ProductDto> = route => {\\n const id = route.paramMap.get(\\'id\\');\\n if (!id?.trim()) throw new HttpErrorResponse({ status: 404 });\\n return inject(ProductService)\\n .detail(id)\\n .pipe(\\n timeout(10_000),\\n map(entity => {\\n if (!entity || entity.id !== id) throw new HttpErrorResponse({ status: 404 });\\n return entity;\\n })\\n );\\n};\\n',\n 'features/product/pages/create/create.component.ts': 'import { afterNextRender, ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, Injector, signal } from \\'@angular/core\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport {\\n GeneralInformationFormComponent,\\n productSaveReq,\\n type ProductForm,\\n} from \\'../../components/general-information-form/general-information-form.component\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport type { ProductSaveReq } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'create\\',\\n standalone: true,\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [SdPageComponent, SdButton, GeneralInformationFormComponent],\\n template: `\\n <sd-page-form title=\"Tạo mới sản phẩm\" [backLink]=\"[\\'..\\']\">\\n <div headerRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Huỷ\" type=\"outline\" autoId=\"product-cancel\" (click)=\"cancel()\" />\\n <sd-button\\n title=\"Tạo sản phẩm\"\\n prefixIcon=\"save\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"product-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n </div>\\n <div class=\"py-16\">\\n <general-information-form [form]=\"form\" [seed]=\"seed\" [errors]=\"apiErrors.errors()\" />\\n </div>\\n </sd-page-form>\\n `,\\n})\\nexport class CreateComponent {\\n readonly #productService = inject(ProductService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #host: HTMLElement = inject(ElementRef).nativeElement;\\n readonly #injector = inject(Injector);\\n protected readonly seed: ProductSaveReq = { code: \\'\\', name: \\'\\', unit: \\'Cái\\', price: 0, status: \\'active\\' };\\n protected readonly form: ProductForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n // Dirty theo giá trị: gõ rồi xoá về như cũ thì rời trang không bị hỏi.\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'product-create\\', dirty: \\'value\\' });\\n\\n constructor() {\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected cancel(): void {\\n void this.#router.navigate([\\'..\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n const product = await firstValueFrom(this.#productService.create(productSaveReq(this.form)));\\n this.#unsaved.markPristine();\\n this.#notify.success(`Đã tạo sản phẩm ${product.code}.`);\\n // replaceUrl: Back ở trang chi tiết về danh sách, không quay lại form tạo mới.\\n await this.#router.navigate([\\'..\\', product.id, \\'detail\\'], { relativeTo: this.#route, replaceUrl: true });\\n } catch (error) {\\n // Lưu lỗi: giữ nguyên dữ liệu đã nhập; lỗi theo field hiện ngay trên field.\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.#host), { injector: this.#injector });\\n }\\n}\\n',\n 'features/product/pages/detail/detail.component.ts': 'import { ChangeDetectionStrategy, Component, computed, inject } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { ActivatedRoute, RouterLink } from \\'@angular/router\\';\\nimport { map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdView } from \\'@sdcorejs/angular/components/view\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdFormatNumberPipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { PRODUCT_STATUS_OPTIONS, productStatusBadge, type ProductDto } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'detail\\',\\n standalone: true,\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [RouterLink, SdPageComponent, SdButton, SdSection, SdView, SdPermissionDirective, SdFormatNumberPipe],\\n template: `\\n @let product = entity();\\n <sd-page-detail [title]=\"\\'Chi tiết sản phẩm #\\' + product.code\" [description]=\"product.name\" [badges]=\"badges()\" [backLink]=\"[\\'../..\\']\">\\n <sd-button\\n headerRight\\n *sdPermission=\"\\'PATTERN_PRODUCT_U_UPDATE\\'\"\\n title=\"Cập nhật sản phẩm\"\\n prefixIcon=\"edit\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"product-update\"\\n [routerLink]=\"[\\'../update\\']\" />\\n <div class=\"d-flex flex-column gap-16 py-16\">\\n <sd-section title=\"Thông tin chung\">\\n <div class=\"row p-8\">\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Mã sản phẩm\" [display]=\"product.code\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Tên sản phẩm\" [display]=\"product.name\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Trạng thái\" [display]=\"statusName()\" /></div>\\n </div>\\n </sd-section>\\n <sd-section title=\"Giá bán\">\\n <div class=\"row p-8\">\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Giá bán (₫)\" [display]=\"product.price | sdFormatNumber: 0\" /></div>\\n <div class=\"col-12 col-md-6 p-8\"><sd-view label=\"Đơn vị tính\" [display]=\"product.unit\" /></div>\\n </div>\\n </sd-section>\\n </div>\\n </sd-page-detail>\\n `,\\n})\\nexport class DetailComponent {\\n /** Sản phẩm do resolver tải trước khi mở trang; đổi ID thì nhận bản ghi mới. */\\n protected readonly entity = toSignal(inject(ActivatedRoute).data.pipe(map(data => data[\\'entity\\'] as ProductDto)), { requireSync: true });\\n protected readonly badges = computed(() => [productStatusBadge(this.entity().status)]);\\n protected readonly statusName = computed(() => PRODUCT_STATUS_OPTIONS.find(option => option.id === this.entity().status)?.name);\\n}\\n',\n 'features/product/pages/list/list.component.html': '<sd-page-list title=\"Sản phẩm\" description=\"Danh mục sản phẩm đang kinh doanh.\">\\n <div headerRight class=\"d-flex align-items-center gap-8 flex-wrap\">\\n <sd-button\\n *sdPermission=\"\\'PATTERN_PRODUCT_R_MENU\\'\"\\n title=\"Nhập/Xuất\"\\n suffixIcon=\"expand_more\"\\n type=\"outline\"\\n autoId=\"product-data-menu\">\\n <sd-button-item *sdPermission=\"\\'PATTERN_PRODUCT_C_IMPORT\\'\" prefixIcon=\"upload\" (click)=\"openImport()\">Nhập dữ liệu</sd-button-item>\\n <sd-button-item *sdPermission=\"\\'PATTERN_PRODUCT_R_EXPORT\\'\" prefixIcon=\"download\" (click)=\"exportData()\">Xuất dữ liệu</sd-button-item>\\n </sd-button>\\n <sd-button\\n *sdPermission=\"\\'PATTERN_PRODUCT_C_CREATE\\'\"\\n title=\"Tạo mới\"\\n prefixIcon=\"add\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"product-create\"\\n [routerLink]=\"[\\'create\\']\" />\\n </div>\\n\\n <sd-table autoId=\"product-list\" [option]=\"tableOption\">\\n <ng-template sdTableCellDef=\"code\" let-product=\"item\">\\n <a *sdPermission=\"\\'PATTERN_PRODUCT_R_DETAIL\\'\" [routerLink]=\"[product.id, \\'detail\\']\">{{ product.code }}</a>\\n @if (!canOpenDetail) {\\n <span>{{ product.code }}</span>\\n }\\n </ng-template>\\n </sd-table>\\n</sd-page-list>\\n',\n 'features/product/pages/list/list.component.ts': 'import { ChangeDetectionStrategy, Component, effect, inject, untracked, viewChild } from \\'@angular/core\\';\\nimport { ActivatedRoute, Router, RouterLink } from \\'@angular/router\\';\\nimport { firstValueFrom } from \\'rxjs\\';\\nimport { SdButton, SdButtonItem } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdTable, SdTableCellDefDirective, type SdTableOption } from \\'@sdcorejs/angular/components/table\\';\\nimport { SdPageList } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective, SdPermissionService } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport { PRODUCT_STATUS_OPTIONS, productStatusBadge, type ProductDto } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'list\\',\\n standalone: true,\\n templateUrl: \\'./list.component.html\\',\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [RouterLink, SdPageList, SdButton, SdButtonItem, SdTable, SdTableCellDefDirective, SdPermissionDirective],\\n})\\nexport class ListComponent {\\n readonly #productService = inject(ProductService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n private readonly pageList = viewChild.required(SdPageList);\\n private readonly table = viewChild.required(SdTable);\\n // Route guard đã nạp quyền trước khi tạo page; dùng cho text thay link khi thiếu quyền xem chi tiết.\\n protected readonly canOpenDetail = inject(SdPermissionService).hasPermission(\\'PATTERN_PRODUCT_R_DETAIL\\');\\n\\n protected readonly tableOption: SdTableOption<ProductDto> = {\\n type: \\'server\\',\\n items: (_, req) => firstValueFrom(this.#productService.list(req)),\\n sort: { enable: true },\\n filter: {\\n quickSearch: {\\n containFields: [\\'code\\', \\'name\\'],\\n placeholder: \\'Tìm theo mã hoặc tên sản phẩm\\',\\n },\\n },\\n columns: [\\n { field: \\'code\\', title: \\'Mã sản phẩm\\', type: \\'string\\', width: \\'160px\\', sortable: true },\\n { field: \\'name\\', title: \\'Tên sản phẩm\\', type: \\'string\\', minWidth: \\'240px\\', sortable: true },\\n { field: \\'unit\\', title: \\'Đơn vị tính\\', type: \\'string\\', width: \\'140px\\' },\\n { field: \\'price\\', title: \\'Giá bán (₫)\\', type: \\'number\\', width: \\'150px\\', align: \\'right\\', sortable: true },\\n {\\n field: \\'status\\',\\n title: \\'Trạng thái\\',\\n type: \\'values\\',\\n width: \\'180px\\',\\n option: { items: PRODUCT_STATUS_OPTIONS, valueField: \\'id\\', displayField: \\'name\\' },\\n useBadge: status => productStatusBadge(status),\\n },\\n ],\\n };\\n\\n constructor() {\\n // Lưu ở trang con xong rồi quay về: tải lại đúng trang, bộ lọc và vị trí cuộn đang có.\\n let seen = this.#productService.changes();\\n effect(() => {\\n const changes = this.#productService.changes();\\n if (this.pageList().childActive() || changes === seen) return;\\n seen = changes;\\n untracked(() => void this.table().reload(true, false));\\n });\\n }\\n\\n protected openImport(): void {\\n void this.#router.navigate([\\'../import\\'], { relativeTo: this.#route });\\n }\\n\\n protected exportData(): void {\\n this.table().exportExcel();\\n }\\n}\\n',\n 'features/product/pages/update/update.component.ts': 'import { afterNextRender, ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, Injector, signal } from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute, Router } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport {\\n GeneralInformationFormComponent,\\n productSaveReq,\\n type ProductForm,\\n} from \\'../../components/general-information-form/general-information-form.component\\';\\nimport { ProductService } from \\'../../services/product.service\\';\\nimport type { ProductDto } from \\'../../services/product.model\\';\\n\\n@Component({\\n selector: \\'update\\',\\n standalone: true,\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n imports: [SdPageComponent, SdButton, GeneralInformationFormComponent],\\n template: `\\n <sd-page-form [title]=\"\\'Cập nhật sản phẩm #\\' + entity().code\" [backLink]=\"[\\'../detail\\']\">\\n <div headerRight class=\"d-flex align-items-center gap-8\">\\n <sd-button title=\"Huỷ\" type=\"outline\" autoId=\"product-cancel\" (click)=\"cancel()\" />\\n <sd-button title=\"Lưu\" prefixIcon=\"save\" type=\"fill\" color=\"primary\" autoId=\"product-save\" [loading]=\"saving()\" (click)=\"save()\" />\\n </div>\\n <div class=\"py-16\">\\n <general-information-form [form]=\"form\" [seed]=\"entity()\" [editing]=\"true\" [errors]=\"apiErrors.errors()\" />\\n </div>\\n </sd-page-form>\\n `,\\n})\\nexport class UpdateComponent {\\n readonly #productService = inject(ProductService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #router = inject(Router);\\n readonly #route = inject(ActivatedRoute);\\n readonly #host: HTMLElement = inject(ElementRef).nativeElement;\\n readonly #injector = inject(Injector);\\n /** Sản phẩm do resolver tải; draft khởi tạo từ đây, sửa draft không đổi bản ghi trước khi lưu thành công. */\\n protected readonly entity = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as ProductDto)), { requireSync: true });\\n protected readonly form: ProductForm = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n readonly #unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'product-update\\', dirty: \\'value\\' });\\n\\n constructor() {\\n inject(DestroyRef).onDestroy(() => this.#unsaved.destroy());\\n }\\n\\n protected cancel(): void {\\n void this.#router.navigate([\\'../detail\\'], { relativeTo: this.#route });\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n // Mã bị khoá sau khi tạo: gửi mã của bản ghi, không lấy từ form.\\n await firstValueFrom(this.#productService.update(this.entity().id, productSaveReq(this.form, this.entity().code)));\\n this.#unsaved.markPristine();\\n this.#notify.success(\\'Đã cập nhật sản phẩm.\\');\\n await this.#router.navigate([\\'../detail\\'], { relativeTo: this.#route, replaceUrl: true });\\n } catch (error) {\\n // Lưu lỗi: giữ nguyên draft để sửa và thử lại.\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Dữ liệu đã nhập vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.#host), { injector: this.#injector });\\n }\\n}\\n',\n 'features/product/pipes/product-detail.pipe.ts': 'import { inject, Pipe, type PipeTransform } from \\'@angular/core\\';\\nimport { of, type Observable } from \\'rxjs\\';\\nimport { ProductService } from \\'../services/product.service\\';\\nimport type { ProductDto } from \\'../services/product.model\\';\\n\\n/**\\n * Relation sản phẩm theo ID: `@let product = line.productId | productDetail | async;`.\\n * ProductService cache và chia sẻ request theo ID; nơi dùng pipe phải có ProductService trong injector.\\n */\\n@Pipe({ name: \\'productDetail\\', standalone: true })\\nexport class ProductDetailPipe implements PipeTransform {\\n readonly #productService = inject(ProductService);\\n\\n transform(id: ProductDto[\\'id\\'] | null | undefined): Observable<ProductDto | null> {\\n if (id === null || id === undefined || id === \\'\\') return of(null);\\n return this.#productService.cachedDetail(id);\\n }\\n}\\n',\n 'features/product/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { entityResolver } from \\'./entity.resolver\\';\\nimport { ProductService } from \\'./services/product.service\\';\\n\\n/** Detail, create và update là route con của danh sách: quay lại vẫn giữ bộ lọc, trang và vị trí cuộn. */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [ProductService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_R_LIST\\' },\\n loadComponent: () => import(\\'./pages/list/list.component\\').then(module => module.ListComponent),\\n children: [\\n {\\n path: \\'create\\',\\n title: \\'Tạo sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_C_CREATE\\' },\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/create/create.component\\').then(module => module.CreateComponent),\\n },\\n {\\n path: \\':id/detail\\',\\n title: \\'Chi tiết sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_R_DETAIL\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n loadComponent: () => import(\\'./pages/detail/detail.component\\').then(module => module.DetailComponent),\\n },\\n {\\n path: \\':id/update\\',\\n title: \\'Cập nhật sản phẩm\\',\\n data: { permission: \\'PATTERN_PRODUCT_U_UPDATE\\' },\\n resolve: { entity: entityResolver },\\n runGuardsAndResolvers: \\'paramsChange\\',\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/update/update.component\\').then(module => module.UpdateComponent),\\n },\\n ],\\n },\\n ],\\n },\\n];\\n',\n 'features/product/services/product.model.ts': 'import type { SdBadgeData } from \\'@sdcorejs/angular/components/badge\\';\\nimport type { PagingReq, PagingRes } from \\'@sdcorejs/utils/models\\';\\n\\nexport type ProductStatus = \\'active\\' | \\'inactive\\';\\n\\nexport const PRODUCT_STATUS_OPTIONS = [\\n { id: \\'active\\', name: \\'Đang hoạt động\\', color: \\'success\\' },\\n { id: \\'inactive\\', name: \\'Ngừng hoạt động\\', color: \\'secondary\\' },\\n] satisfies { id: ProductStatus; name: string; color: SdBadgeData[\\'color\\'] }[];\\n\\nexport interface ProductDto {\\n readonly id: string;\\n readonly code: string;\\n readonly name: string;\\n readonly status: ProductStatus;\\n /** Đơn vị tính. */\\n readonly unit: string;\\n /** Giá bán (₫). */\\n readonly price: number;\\n}\\n\\n/** PagingReq dùng pageNumber bắt đầu từ 0. */\\nexport type ProductListReq = PagingReq<ProductDto>;\\nexport type ProductListRes = PagingRes<ProductDto>;\\n\\nexport interface ProductSaveReq {\\n readonly code: string;\\n readonly name: string;\\n readonly status: ProductStatus;\\n readonly unit: string;\\n readonly price: number;\\n}\\n\\n/** Badge trạng thái cạnh title của chi tiết. */\\nexport function productStatusBadge(status: ProductStatus): SdBadgeData {\\n const option = PRODUCT_STATUS_OPTIONS.find(item => item.id === status);\\n return { type: \\'round\\', title: option?.name ?? status, color: option?.color };\\n}\\n',\n 'features/product/services/product.service.ts': 'import { Injectable, signal } from \\'@angular/core\\';\\nimport { shareReplay, tap, type Observable } from \\'rxjs\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type { ProductDto, ProductListReq, ProductListRes, ProductSaveReq } from \\'./product.model\\';\\n\\n@Injectable()\\nexport class ProductService extends BaseApiService {\\n /** Một request cho mỗi ID trong phạm vi service: pipe và select dùng chung kết quả. */\\n readonly #details = new Map<string, Observable<ProductDto>>();\\n readonly #changes = signal(0);\\n /** Tăng sau mỗi lần tạo hoặc cập nhật thành công: danh sách tải lại khi quay về. */\\n readonly changes = this.#changes.asReadonly();\\n\\n list(req: ProductListReq): Observable<ProductListRes> {\\n return this.http.get<ProductListRes>(this.apiUrl(\\'products\\'), {\\n params: this.buildPagingReq(req),\\n });\\n }\\n\\n detail(id: string): Observable<ProductDto> {\\n return this.http.get<ProductDto>(this.apiUrl(\\'products\\', id));\\n }\\n\\n /** `detail(id)` có cache, cho relation (`productDetail`) và giá trị đã chọn của `product-select`. */\\n cachedDetail(id: string): Observable<ProductDto> {\\n let detail = this.#details.get(id);\\n if (!detail) {\\n detail = this.detail(id).pipe(shareReplay({ bufferSize: 1, refCount: false }));\\n this.#details.set(id, detail);\\n // Lỗi tra cứu không được cache: lần gọi sau hỏi lại.\\n detail.subscribe({ error: () => this.#details.delete(id) });\\n }\\n return detail;\\n }\\n\\n create(req: ProductSaveReq): Observable<ProductDto> {\\n return this.http.post<ProductDto>(this.apiUrl(\\'products\\'), req).pipe(tap(() => this.#changes.update(count => count + 1)));\\n }\\n\\n update(id: string, req: ProductSaveReq): Observable<ProductDto> {\\n return this.http.put<ProductDto>(this.apiUrl(\\'products\\', id), req).pipe(\\n tap(() => {\\n this.#details.delete(id);\\n this.#changes.update(count => count + 1);\\n })\\n );\\n }\\n}\\n',\n 'features/settings/pages/update/update.component.ts': 'import {\\n afterNextRender,\\n ChangeDetectionStrategy,\\n Component,\\n DestroyRef,\\n ElementRef,\\n inject,\\n Injector,\\n linkedSignal,\\n signal,\\n} from \\'@angular/core\\';\\nimport { toSignal } from \\'@angular/core/rxjs-interop\\';\\nimport { FormGroup } from \\'@angular/forms\\';\\nimport { ActivatedRoute } from \\'@angular/router\\';\\nimport { firstValueFrom, map } from \\'rxjs\\';\\nimport { SdButton } from \\'@sdcorejs/angular/components/button\\';\\nimport { SdSection } from \\'@sdcorejs/angular/components/section\\';\\nimport { SdInput } from \\'@sdcorejs/angular/forms/input\\';\\nimport { SdInputNumber } from \\'@sdcorejs/angular/forms/input-number\\';\\nimport { SdSelect } from \\'@sdcorejs/angular/forms/select\\';\\nimport { SdSwitch } from \\'@sdcorejs/angular/forms/switch\\';\\nimport { SdPageComponent } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionDirective, SdPermissionService } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SdFormatDatetimePipe } from \\'@sdcorejs/angular/pipes\\';\\nimport { SdNotifyService } from \\'@sdcorejs/angular/services/notify\\';\\nimport { registerSdUnsavedChangesForm, SdUnsavedChangesService } from \\'@sdcorejs/angular/services/unsaved-changes\\';\\nimport { apiErrorMessage } from \\'../../../../utils/api-error\\';\\nimport { focusFirstInvalid } from \\'../../../../utils/focus-first-invalid\\';\\nimport { formApiErrors } from \\'../../../../utils/form-api-errors\\';\\nimport { SettingsService } from \\'../../services/settings.service\\';\\nimport type { SettingsDto, SettingsSaveReq } from \\'../../services/settings.model\\';\\n\\nconst CURRENCIES = [\\n { value: \\'VND\\', label: \\'Việt Nam đồng (VND)\\' },\\n { value: \\'USD\\', label: \\'Đô la Mỹ (USD)\\' },\\n];\\n\\n/**\\n * Cài đặt một bản ghi: `sd-page-form` có mục lục, nhiều nhóm. Lưu xong vẫn ở trang; footer báo trạng thái lưu, rời\\n * trang khi còn thay đổi thì hỏi. Vai trò chỉ có quyền xem thấy form ở chế độ xem.\\n */\\n@Component({\\n selector: \\'update\\',\\n standalone: true,\\n imports: [SdPageComponent, SdButton, SdSection, SdInput, SdInputNumber, SdSelect, SdSwitch, SdPermissionDirective, SdFormatDatetimePipe],\\n changeDetection: ChangeDetectionStrategy.OnPush,\\n template: `\\n @let value = entity();\\n @let errors = apiErrors.errors();\\n <sd-page-form title=\"Cài đặt cửa hàng\" description=\"Áp dụng cho mọi chi nhánh.\" toc>\\n <sd-button\\n headerRight\\n *sdPermission=\"\\'PATTERN_SETTINGS_U_UPDATE\\'\"\\n title=\"Lưu\"\\n prefixIcon=\"save\"\\n type=\"fill\"\\n color=\"primary\"\\n autoId=\"settings-save\"\\n [loading]=\"saving()\"\\n (click)=\"save()\" />\\n <div class=\"d-flex flex-column gap-16 py-16\">\\n <sd-section title=\"Thông tin cửa hàng\">\\n <div class=\"row px-16 pt-16 pb-8\">\\n <div class=\"col-12 col-md-6\">\\n <sd-input\\n label=\"Tên cửa hàng\"\\n name=\"storeName\"\\n autoId=\"settings-store-name\"\\n [form]=\"form\"\\n [model]=\"value.storeName\"\\n [viewed]=\"!canEdit\"\\n [inlineError]=\"errors[\\'storeName\\']\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input label=\"Hotline\" name=\"hotline\" [form]=\"form\" [model]=\"value.hotline\" [viewed]=\"!canEdit\" />\\n </div>\\n <div class=\"col-12\">\\n <sd-input label=\"Địa chỉ\" name=\"address\" [form]=\"form\" [model]=\"value.address\" [viewed]=\"!canEdit\" />\\n </div>\\n </div>\\n </sd-section>\\n <sd-section title=\"Bán hàng\">\\n <div class=\"row px-16 pt-16 pb-8\">\\n <div class=\"col-12 col-md-6\">\\n <sd-select\\n label=\"Tiền tệ\"\\n name=\"currency\"\\n [form]=\"form\"\\n [model]=\"value.currency\"\\n [items]=\"currencies\"\\n valueField=\"value\"\\n displayField=\"label\"\\n [viewed]=\"!canEdit\"\\n [clearable]=\"false\" />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input\\n label=\"Tiền tố mã đơn\"\\n name=\"orderPrefix\"\\n autoId=\"settings-order-prefix\"\\n [form]=\"form\"\\n [model]=\"value.orderPrefix\"\\n [viewed]=\"!canEdit\"\\n [inlineError]=\"errors[\\'orderPrefix\\']\"\\n maxlength=\"5\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6\">\\n <sd-input-number\\n label=\"Ngưỡng cảnh báo tồn kho\"\\n name=\"lowStockThreshold\"\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"form\"\\n [model]=\"value.lowStockThreshold\"\\n [viewed]=\"!canEdit\" />\\n </div>\\n <div class=\"col-12 col-md-6 d-flex align-items-center\">\\n <sd-switch\\n label=\"Tự xác nhận đơn online\"\\n name=\"autoConfirm\"\\n [form]=\"form\"\\n [model]=\"value.autoConfirm\"\\n [disabled]=\"!canEdit\" />\\n </div>\\n </div>\\n </sd-section>\\n <sd-section title=\"Thông báo\">\\n <div class=\"row px-16 pt-16 pb-8\">\\n <div class=\"col-12 col-md-6 d-flex align-items-center\">\\n <sd-switch\\n label=\"Gửi email\"\\n name=\"emailNotify\"\\n [form]=\"form\"\\n [model]=\"value.emailNotify\"\\n [disabled]=\"!canEdit\"\\n (modelChange)=\"emailNotify.set(!!$event)\" />\\n </div>\\n <div class=\"col-12 col-md-6 d-flex align-items-center\">\\n <sd-switch label=\"Gửi SMS\" name=\"smsNotify\" [form]=\"form\" [model]=\"value.smsNotify\" [disabled]=\"!canEdit\" />\\n </div>\\n <div class=\"col-12\">\\n <sd-input\\n label=\"Email nhận thông báo\"\\n name=\"notifyEmail\"\\n [form]=\"form\"\\n [model]=\"value.notifyEmail\"\\n pattern=\"EMAIL\"\\n [viewed]=\"!canEdit\"\\n [required]=\"emailNotify()\" />\\n </div>\\n </div>\\n </sd-section>\\n <sd-section title=\"Bảo mật\">\\n <div class=\"row px-16 pt-16 pb-8\">\\n <div class=\"col-12 col-md-6\">\\n <sd-input-number\\n label=\"Hết phiên sau (phút)\"\\n name=\"sessionMinutes\"\\n autoId=\"settings-session\"\\n type=\"positive\"\\n [precision]=\"0\"\\n [form]=\"form\"\\n [model]=\"value.sessionMinutes\"\\n [viewed]=\"!canEdit\"\\n [inlineError]=\"errors[\\'sessionMinutes\\']\"\\n required />\\n </div>\\n <div class=\"col-12 col-md-6 d-flex align-items-center\">\\n <sd-switch label=\"Xác thực hai bước\" name=\"twoFactor\" [form]=\"form\" [model]=\"value.twoFactor\" [disabled]=\"!canEdit\" />\\n </div>\\n </div>\\n </sd-section>\\n </div>\\n <span sdFooterLeft class=\"T14R text-secondary\" role=\"status\" data-autoid=\"settings-save-state\">\\n {{ unsaved.dirty() ? \\'Có thay đổi chưa lưu\\' : \\'Đã lưu lúc \\' + (value.updatedAt | sdFormatDatetime) }}\\n </span>\\n </sd-page-form>\\n `,\\n})\\nexport class UpdateComponent {\\n readonly #settingsService = inject(SettingsService);\\n readonly #notify = inject(SdNotifyService);\\n readonly #route = inject(ActivatedRoute);\\n readonly #host: HTMLElement = inject(ElementRef).nativeElement;\\n readonly #injector = inject(Injector);\\n protected readonly canEdit = inject(SdPermissionService).hasPermission(\\'PATTERN_SETTINGS_U_UPDATE\\');\\n protected readonly currencies = CURRENCIES;\\n readonly #resolved = toSignal(this.#route.data.pipe(map(data => data[\\'entity\\'] as SettingsDto)), { requireSync: true });\\n /** Bản ghi đã lưu gần nhất: sau khi lưu thay bằng bản API trả về. */\\n protected readonly entity = linkedSignal(() => this.#resolved());\\n protected readonly emailNotify = linkedSignal(() => this.entity().emailNotify);\\n protected readonly form = new FormGroup({});\\n protected readonly saving = signal(false);\\n protected readonly apiErrors = formApiErrors(this.form);\\n protected readonly unsaved = registerSdUnsavedChangesForm(inject(SdUnsavedChangesService), this.form, { id: \\'settings\\', dirty: \\'value\\' });\\n\\n constructor() {\\n inject(DestroyRef).onDestroy(() => this.unsaved.destroy());\\n }\\n\\n protected async save(): Promise<void> {\\n if (this.saving()) return;\\n this.form.markAllAsTouched();\\n if (this.form.invalid) {\\n this.#focusFirstInvalid();\\n return;\\n }\\n this.saving.set(true);\\n try {\\n const saved = await firstValueFrom(this.#settingsService.update({ ...this.entity(), ...this.form.getRawValue() } as SettingsSaveReq));\\n this.entity.set(saved);\\n // Ở lại trang: giá trị vừa lưu là mốc so sánh mới (`markPristine()` ở chế độ value), sửa tiếp vẫn được bảo vệ khi rời trang.\\n this.unsaved.markPristine();\\n this.#notify.success(\\'Đã lưu cài đặt.\\');\\n } catch (error) {\\n if (this.apiErrors.set(error)) this.#focusFirstInvalid();\\n else this.#notify.error(apiErrorMessage(error, \\'Không thể lưu. Thay đổi vẫn được giữ.\\'));\\n } finally {\\n this.saving.set(false);\\n }\\n }\\n\\n #focusFirstInvalid(): void {\\n afterNextRender(() => focusFirstInvalid(this.#host), { injector: this.#injector });\\n }\\n}\\n',\n 'features/settings/routes.ts': 'import type { Routes } from \\'@angular/router\\';\\nimport { sdPageFormLeaveGuard } from \\'@sdcorejs/angular/modules/layout\\';\\nimport { SdPermissionGuard } from \\'@sdcorejs/angular/modules/permission\\';\\nimport { SettingsService } from \\'./services/settings.service\\';\\nimport { settingsResolver } from \\'./settings.resolver\\';\\n\\n/** Một bản ghi: vào thẳng trang cập nhật; người chỉ có quyền xem thấy form ở chế độ xem. */\\nexport const routes: Routes = [\\n {\\n path: \\'\\',\\n providers: [SettingsService],\\n canActivateChild: [SdPermissionGuard],\\n children: [\\n {\\n path: \\'\\',\\n title: \\'Cài đặt\\',\\n data: { permission: \\'PATTERN_SETTINGS_R_DETAIL\\' },\\n resolve: { entity: settingsResolver },\\n canDeactivate: [sdPageFormLeaveGuard],\\n loadComponent: () => import(\\'./pages/update/update.component\\').then(module => module.UpdateComponent),\\n },\\n ],\\n },\\n];\\n',\n 'features/settings/services/settings.model.ts': '/** Cài đặt cửa hàng: một bản ghi, không có danh sách. */\\nexport interface SettingsDto {\\n readonly storeName: string;\\n readonly hotline: string;\\n readonly address: string;\\n readonly currency: string;\\n readonly orderPrefix: string;\\n readonly autoConfirm: boolean;\\n readonly lowStockThreshold: number;\\n readonly emailNotify: boolean;\\n readonly smsNotify: boolean;\\n readonly notifyEmail: string;\\n readonly sessionMinutes: number;\\n readonly twoFactor: boolean;\\n readonly updatedAt: string;\\n}\\n\\nexport type SettingsSaveReq = Omit<SettingsDto, \\'updatedAt\\'>;\\n',\n 'features/settings/services/settings.service.ts': 'import { Injectable } from \\'@angular/core\\';\\nimport type { Observable } from \\'rxjs\\';\\nimport { BaseApiService } from \\'../../../services/base-api.service\\';\\nimport type { SettingsDto, SettingsSaveReq } from \\'./settings.model\\';\\n\\n@Injectable()\\nexport class SettingsService extends BaseApiService {\\n detail(): Observable<SettingsDto> {\\n return this.http.get<SettingsDto>(this.apiUrl(\\'settings\\'));\\n }\\n\\n update(req: SettingsSaveReq): Observable<SettingsDto> {\\n return this.http.put<SettingsDto>(this.apiUrl(\\'settings\\'), req);\\n }\\n}\\n',\n 'features/settings/settings.resolver.ts': 'import { inject } from \\'@angular/core\\';\\nimport type { ResolveFn } from \\'@angular/router\\';\\nimport { timeout } from \\'rxjs\\';\\nimport { SettingsService } from \\'./services/settings.service\\';\\nimport type { SettingsDto } from \\'./services/settings.model\\';\\n\\n/** Tải cài đặt trước khi mở trang; lỗi đi tới navigation error handler của host. */\\nexport const settingsResolver: ResolveFn<SettingsDto> = () => inject(SettingsService).detail().pipe(timeout(10_000));\\n',\n 'README.md': '# `@sdcorejs/angular/modules/pattern`\\n\\nMàn mẫu theo entity, chạy trên Core thật với mock API. Mỗi màn là code Angular hoàn chỉnh trong `features/`, theo cấu trúc project-structure của Angular Portal Blueprint. Tài liệu trong `docs/` giữ quy tắc và lý do; mọi khối code trong đó được trích từ `features/` khi build (`npm run pattern:docs`), nên không có code minh hoạ tách rời code chạy thật.\\n\\nĐọc theo thứ tự: README này → `docs/<pattern>.md` của loại màn cần làm → thư mục `features/<entity>/` gần nhất. Gói npm mang theo cả ba (`node_modules/@sdcorejs/angular/modules/pattern/`).\\n\\n## Chọn pattern theo loại màn\\n\\n| Loại màn | Pattern | Selector / thành phần | Route mẫu |\\n| --- | --- | --- | --- |\\n| Danh sách có bảng | [list](docs/list.md) | `sd-page-list` + `sd-table` | `product`, `order`, `customer`, `category` |\\n| Xem một bản ghi | [detail](docs/detail.md) | `sd-page-detail` | `product/:id/detail`, `order/:id/detail`, `customer/:id/360` |\\n| Tạo / cập nhật một bước | [form](docs/form.md) | `sd-page-form` (`toc` khi nhiều nhóm) | `product/create`, `order/create`, `settings` |\\n| Quy trình nhiều bước | [flow](docs/flow.md) | `sd-page` hẹp + `sd-stepper`, nút bước ở footer | `import`, `partner/create` |\\n| Xem / sửa ngay trên danh sách | [drawer](docs/drawer.md) | `sd-side-drawer` trong route con | `customer/create`, `customer/:id/detail`, `category/:id/update` |\\n| Xử lý nhanh từng mục | [split](docs/split.md) | `sd-page-list detail=\"none\"` + `sd-splitter` | `approval` |\\n| Chọn entity / enum | [select](docs/select.md) | wrapper `<entity>-select` của feature sở hữu entity | `product-select`, `customer-select` |\\n| Hiện quan hệ theo ID | [relation](docs/relation.md) | pipe `<entity>Detail` | `customerDetail`, `productDetail` |\\n| Nút ở header | [header-actions](docs/header-actions.md) | `headerRight`, Action Popover của `sd-button` | `product` (menu Nhập/Xuất) |\\n| Đang tải, rỗng, lỗi, thiếu quyền | [states](docs/states.md) | `sd-table`, `sd-data-state`, resolver, guard | mọi route |\\n\\nKhông có loại màn phù hợp: dùng `sd-page` và ghép các pattern trên. Có màn thứ ba cùng loại mới tách thành selector hoặc pattern riêng.\\n\\n## Gắn vào portal\\n\\nRoute `pattern` của host lazy-load `SD_PATTERN_ROUTES` và đặt `provideSdPatterns({ mockApi: true })` trong `providers` của chính route đó. Interceptor mock chỉ chạy trên `HttpClient` con của route này; quyền mẫu (`SdPermissionService`, `SdPermissionGuard`, `SD_PERMISSION_CONFIGURATION`) cũng được cấp lại ở đây nên không đụng quyền của host. `mockApi: false` + `apiBaseUrl` cho service gọi API thật. Lỗi tải bản ghi trước khi mở trang (404, 403, timeout) đi tới navigation error handler của host; `forbiddenUrl` là trang host mở khi vai trò thiếu quyền vào route.\\n\\nThanh công cụ dưới cùng của `/pattern` (vai trò, độ trễ, lỗi giả lập, khôi phục dữ liệu, xem source) và drawer \"Tuỳ chỉnh hiển thị\" của `/pattern/order` thuộc `core/pattern-shell`, không phải code của feature: không chép sang màn thật.\\n\\n## Cấu trúc một feature\\n\\n```text\\nfeatures/<entity>/\\n routes.ts route list + route con (create, :id/detail, :id/update), service cấp ở đây\\n entity.resolver.ts tải bản ghi bằng detail(id) trước khi mở trang\\n services/<entity>.model.ts DTO, Req, const/enum, badge\\n services/<entity>.service.ts gọi API qua BaseApiService; không biết có mock hay không\\n pages/list|detail|create|update/ trang có route\\n components/ -form, -view, -select, *-side-drawer của entity\\n pipes/<entity>-detail.pipe.ts relation theo ID cho màn khác\\n```\\n\\nTên feature đã có trong đường dẫn, không lặp lại trong tên file bên trong. Dựng feature mới: chép thư mục entity gần nhất rồi đổi tên.\\n\\n## Quyết định đã chốt\\n\\n| Mã | Quyết định |\\n| --- | --- |\\n| E1 | Danh sách vừa khít màn hình, không có scrollbar ngoài; chỉ vùng dữ liệu của bảng cuộn. Feature không viết chiều cao hay SCSS cho danh sách. |\\n| E2 | `backLink` hiện nút ← trước title; title, mô tả và tối đa hai badge truyền qua input. |\\n| E3 | Nút Lưu của page nằm ở `headerRight`; drawer và flow đặt nút ở footer. |\\n| E4 | Drawer chỉ đóng bằng X (cùng Esc, backdrop); không có nút Đóng/Huỷ thường trực. |\\n| E5 | Dùng \"Cập nhật <entity>\", không dùng \"Chỉnh sửa\". |\\n| E6 | Không dùng quick search cùng external filter trên một màn; mỗi field chỉ một chỗ lọc. |\\n| E7 | Giữ mặc định `hideInlineFilter: false`; màn ít dữ liệu dùng `\\'auto\\'`; không dùng `true`. |\\n| E8 | Flow là pattern: `sd-page` + `sd-stepper`, giữ dữ liệu khi đổi bước. |\\n| E9 | Drawer 480px mặc định, 600px cho chi tiết và form thường, tối đa 800px. |\\n| E10 | Code trong tài liệu được trích từ `features/`; khối lệch code thì kiểm tra trong CI thất bại. |\\n| E11 | Tài liệu không ghi chú theo version; khác biệt giữa version ghi ở CHANGELOG. |\\n| E12 | `features/*` theo cấu trúc project-structure của Blueprint. |\\n| E13 | Sau lưu: page sang chi tiết, drawer đóng và danh sách tải lại. Lưu lỗi: focus field lỗi đầu tiên, lỗi API gắn vào field. Xoá, duyệt, từ chối, mọi tác vụ đổi trạng thái đều hỏi xác nhận, cả từng bản ghi lẫn hàng loạt; hàng loạt báo kết quả từng phần và cho thử lại phần lỗi. |\\n\\n## Mã quyền\\n\\n`PATTERN_<ENTITY>_<R|C|U|D>_<ACTION>`: R đọc, C tạo, U đổi một bản ghi (cập nhật và mọi tác vụ trạng thái), D xoá. Feature ghi thẳng mã trong `data.permission` và `*sdPermission`; vai trò mẫu (Quản trị, Nhân viên không xoá không duyệt, Chỉ xem) nằm trong `core/permission`.\\n\\n## Đóng góp\\n\\nThêm hoặc sửa một màn mẫu:\\n\\n- [ ] Route trong `SD_PATTERN_ROUTES` và dòng trong mục lục `/pattern` (`core/pattern-shell/catalog`).\\n- [ ] Resource của mock API trong `core/mock-api/resources`, seed cố định.\\n- [ ] Mã quyền mới có trong `core/permission/pattern-permission.ts`; mã không còn dùng thì xoá.\\n- [ ] Tài liệu trong `docs/` trỏ tới file của feature bằng marker `@source`; chạy `npm run pattern:docs` (cập nhật cả manifest của tab Source).\\n- [ ] Playwright cho route trong `showcase/e2e/pattern/`.\\n- [ ] Quy tắc review: không có chiều cao hay `overflow` tự viết trong danh sách, không có `hideInlineFilter: true`, không có nút Đóng thường trực trong drawer, không có chữ \"Chỉnh sửa\".\\n',\n};\n"],"names":[],"mappings":"AAAA;AACA;AACO,MAAM,cAAc,GAAqC;AAC9D,IAAA,gBAAgB,EAAE,k2VAAk2V;AACp3V,IAAA,gBAAgB,EAAE,mkrBAAmkrB;AACrlrB,IAAA,cAAc,EAAE,+2yBAA+2yB;AAC/3yB,IAAA,cAAc,EAAE,m9mCAAm9mC;AACn+mC,IAAA,wBAAwB,EAAE,qufAAquf;AAC/vf,IAAA,cAAc,EAAE,49VAA49V;AAC5+V,IAAA,kBAAkB,EAAE,08OAA08O;AAC99O,IAAA,gBAAgB,EAAE,40SAA40S;AAC91S,IAAA,eAAe,EAAE,6+eAA6+e;AAC9/e,IAAA,gBAAgB,EAAE,gmOAAgmO;AAClnO,IAAA,sCAAsC,EAAE,+1BAA+1B;AACv4B,IAAA,oDAAoD,EAAE,k2LAAk2L;AACx5L,IAAA,gDAAgD,EAAE,wYAAwY;AAC1b,IAAA,kDAAkD,EAAE,+uCAA+uC;AACnyC,IAAA,gDAAgD,EAAE,ysMAAysM;AAC3vM,IAAA,6BAA6B,EAAE,smCAAsmC;AACroC,IAAA,8CAA8C,EAAE,24CAA24C;AAC37C,IAAA,gDAAgD,EAAE,0+BAA0+B;AAC5hC,IAAA,iFAAiF,EAAE,ylKAAylK;AAC5qK,IAAA,6FAA6F,EAAE,85EAA85E;AAC7/E,IAAA,iFAAiF,EAAE,mtKAAmtK;AACtyK,IAAA,sCAAsC,EAAE,wpCAAwpC;AAChsC,IAAA,kDAAkD,EAAE,krBAAkrB;AACtuB,IAAA,gDAAgD,EAAE,2lJAA2lJ;AAC7oJ,IAAA,6BAA6B,EAAE,2uDAA2uD;AAC1wD,IAAA,8CAA8C,EAAE,0xCAA0xC;AAC10C,IAAA,gDAAgD,EAAE,y5CAAy5C;AAC38C,IAAA,iFAAiF,EAAE,i2KAAi2K;AACp7K,IAAA,2EAA2E,EAAE,+lGAA+lG;AAC5qG,IAAA,qFAAqF,EAAE,whCAAwhC;AAC/mC,IAAA,iEAAiE,EAAE,2uCAA2uC;AAC9yC,IAAA,iFAAiF,EAAE,42JAA42J;AAC/7J,IAAA,yEAAyE,EAAE,y/DAAy/D;AACpkE,IAAA,6FAA6F,EAAE,q2LAAq2L;AACp8L,IAAA,6FAA6F,EAAE,6kEAA6kE;AAC5qE,IAAA,mEAAmE,EAAE,wmDAAwmD;AAC7qD,IAAA,uEAAuE,EAAE,w4GAAw4G;AACj9G,IAAA,iFAAiF,EAAE,wyKAAwyK;AAC33K,IAAA,sCAAsC,EAAE,g2BAAg2B;AACx4B,IAAA,kDAAkD,EAAE,+xBAA+xB;AACn1B,IAAA,gDAAgD,EAAE,swKAAswK;AACxzK,IAAA,sDAAsD,EAAE,65JAA65J;AACr9J,IAAA,iDAAiD,EAAE,g2BAAg2B;AACn5B,IAAA,6BAA6B,EAAE,0jFAA0jF;AACzlF,IAAA,8CAA8C,EAAE,w0FAAw0F;AACx3F,IAAA,gDAAgD,EAAE,8kGAA8kG;AAChoG,IAAA,mEAAmE,EAAE,gsDAAgsD;AACrwD,IAAA,mEAAmE,EAAE,02DAA02D;AAC/6D,IAAA,8CAA8C,EAAE,s4VAAs4V;AACt7V,IAAA,2BAA2B,EAAE,mmBAAmmB;AAChoB,IAAA,0CAA0C,EAAE,2vGAA2vG;AACvyG,IAAA,4CAA4C,EAAE,u8BAAu8B;AACr/B,IAAA,sEAAsE,EAAE,o9EAAo9E;AAC5hF,IAAA,gEAAgE,EAAE,oyDAAoyD;AACt2D,IAAA,0FAA0F,EAAE,sgHAAsgH;AAClmH,IAAA,8DAA8D,EAAE,8jOAA8jO;AAC9nO,IAAA,qDAAqD,EAAE,45IAA45I;AACn9I,IAAA,0EAA0E,EAAE,63PAA63P;AACz8P,IAAA,8DAA8D,EAAE,w/DAAw/D;AACxjE,IAAA,oEAAoE,EAAE,47IAA47I;AAClgJ,IAAA,mCAAmC,EAAE,skDAAskD;AAC3mD,IAAA,iDAAiD,EAAE,2kKAA2kK;AAC9nK,IAAA,iDAAiD,EAAE,0mVAA0mV;AAC7pV,IAAA,+CAA+C,EAAE,44CAA44C;AAC77C,IAAA,6CAA6C,EAAE,6tZAA6tZ;AAC5wZ,IAAA,iDAAiD,EAAE,0jLAA0jL;AAC7mL,IAAA,0BAA0B,EAAE,m+EAAm+E;AAC//E,IAAA,wCAAwC,EAAE,ipIAAipI;AAC3rI,IAAA,0CAA0C,EAAE,g6EAAg6E;AAC58E,IAAA,mDAAmD,EAAE,s9YAAs9Y;AAC3gZ,IAAA,4BAA4B,EAAE,6qBAA6qB;AAC3sB,IAAA,4CAA4C,EAAE,i4BAAi4B;AAC/6B,IAAA,8CAA8C,EAAE,kyBAAkyB;AACl1B,IAAA,4FAA4F,EAAE,6tGAA6tG;AAC3zG,IAAA,wEAAwE,EAAE,qsGAAqsG;AAC/wG,IAAA,sFAAsF,EAAE,4lCAA4lC;AACprC,IAAA,qCAAqC,EAAE,21BAA21B;AACl4B,IAAA,mDAAmD,EAAE,+hIAA+hI;AACplI,IAAA,mDAAmD,EAAE,myFAAmyF;AACx1F,IAAA,iDAAiD,EAAE,4tCAA4tC;AAC/wC,IAAA,+CAA+C,EAAE,qqGAAqqG;AACttG,IAAA,mDAAmD,EAAE,qkIAAqkI;AAC1nI,IAAA,+CAA+C,EAAE,60BAA60B;AAC93B,IAAA,4BAA4B,EAAE,u/DAAu/D;AACrhE,IAAA,4CAA4C,EAAE,g0CAAg0C;AAC92C,IAAA,8CAA8C,EAAE,o8DAAo8D;AACp/D,IAAA,oDAAoD,EAAE,k5SAAk5S;AACx8S,IAAA,6BAA6B,EAAE,w6BAAw6B;AACv8B,IAAA,8CAA8C,EAAE,0kBAA0kB;AAC1nB,IAAA,gDAAgD,EAAE,ijBAAijB;AACnmB,IAAA,wCAAwC,EAAE,udAAud;AACjgB,IAAA,WAAW,EAAE,mhMAAmhM;;;"}
|