import { AXTextBoxModule } from '@acorex/components/text-box';
import { NgTemplateOutlet, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { input, signal, effect, ViewEncapsulation, Component, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AXComponent } from '@acorex/cdk/common';

class JsonViewerComponent {
    constructor() {
        this.json = input.required(...(ngDevMode ? [{ debugName: "json" }] : []));
        this.convertedObject = signal(null, ...(ngDevMode ? [{ debugName: "convertedObject" }] : []));
        this.primitiveData = signal(null, ...(ngDevMode ? [{ debugName: "primitiveData" }] : []));
        this.#effect = effect(() => {
            if (typeof this.json() === 'object') {
                const deeplyNestedArray = this.convertNestedToArray(this.json());
                this.convertedObject.set(deeplyNestedArray);
            }
            else {
                this.primitiveData.set(this.json());
            }
        }, ...(ngDevMode ? [{ debugName: "#effect" }] : []));
    }
    #effect;
    convertNestedToArray(obj) {
        return Object.keys(obj).map((key) => ({
            key: key,
            value: this.isDate(obj[key])
                ? obj[key].toISOString()
                : typeof obj[key] === 'object'
                    ? this.convertNestedToArray(obj[key])
                    : obj[key],
        }));
    }
    isArray(arry) {
        return Array.isArray(arry);
    }
    isNumber(i) {
        return typeof i === 'number';
    }
    isDate(value) {
        return value instanceof Date;
    }
    isBoolean(value) {
        return typeof value === 'boolean';
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: JsonViewerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.3", type: JsonViewerComponent, isStandalone: true, selector: "ax-json-viewer", inputs: { json: { classPropertyName: "json", publicName: "json", isSignal: true, isRequired: true, transformFunction: null } }, providers: [{ provide: AXComponent, useExisting: JsonViewerComponent }], ngImport: i0, template: "<ng-container [ngTemplateOutlet]=\"Recursion\" [ngTemplateOutletContext]=\"{ list: convertedObject() }\"></ng-container>\n\n<ng-template #Recursion let-list=\"list\">\n  @for (item of list; track $index) {\n    @if (isArray(item.value)) {\n      <details>\n        <summary>\"{{ item.key }}\"</summary>\n        <div class=\"ax-indent-details\">\n          <ng-container [ngTemplateOutlet]=\"Recursion\" [ngTemplateOutletContext]=\"{ list: item.value }\"></ng-container>\n        </div>\n      </details>\n    } @else {\n      <div class=\"ax-flex-container\">\n        <p class=\"ax-nowrap ax-margin\">\"{{ item.key }}\"<span>:</span></p>\n\n        <p\n          class=\"ax-nowrap ax-indent {{\n            isNumber(item.value) || isBoolean(item.value) ? 'ax-number-color' : 'ax-string-color'\n          }}\"\n        >\n          @if (isNumber(item.value) || isBoolean(item.value)) {\n            {{ item.value }}\n          } @else {\n            ''{{ item.value }}''\n          }\n        </p>\n      </div>\n    }\n  }\n</ng-template>\n\n@if (primitiveData()) {\n  <p\n    class=\"ax-nowrap ax-indent {{\n      isNumber(primitiveData()) || isBoolean(primitiveData()) ? 'ax-number-color' : 'ax-string-color'\n    }}\"\n  >\n    @if (isNumber(primitiveData()) || isBoolean(primitiveData())) {\n      {{ primitiveData() }}\n    } @else {\n      ''{{ primitiveData() }}''\n    }\n  </p>\n}\n", styles: ["ax-json-viewer{--ax-comp-json-viewer-string-color-light: rgb(217, 57, 62);--ax-comp-json-viewer-string-color-dark: rgba(92, 213, 251, 255);--ax-comp-json-viewer-number-color-dark: rgba(var(--ax-sys-color-on-lightest-surface));--ax-comp-json-viewer-number-color-light: rgba(var(--ax-sys-color-on-lightest-surface));--ax-comp-json-viewer-key-color-dark: rgba(124, 172, 248, 255);--ax-comp-json-viewer-key-color-light: rgba(var(--ax-sys-color-on-lightest-surface))}ax-json-viewer{padding:1.5rem;overflow-x:auto;display:block}ax-json-viewer .ax-number-color{color:var(--ax-comp-json-viewer-number-color-light)}ax-json-viewer .ax-number-color input::-webkit-outer-spin-button,ax-json-viewer .ax-number-color input::-webkit-inner-spin-button{-webkit-appearance:none}ax-json-viewer .ax-string-color{color:var(--ax-comp-json-viewer-string-color-light)}ax-json-viewer .ax-indent{margin:0;padding:0;height:fit-content}ax-json-viewer .ax-margin{margin-inline-end:.3rem}ax-json-viewer .ax-indent-details{margin:0 2rem;height:fit-content}ax-json-viewer .ax-flex-container{display:flex;justify-content:flex-start;align-items:center;gap:.25rem}ax-json-viewer summary,ax-json-viewer p{color:var(--ax-comp-json-viewer-key-color-light)}ax-json-viewer summary::marker,ax-json-viewer span{color:rgb(var(--ax-sys-body-text-color))}ax-json-viewer details{margin-inline-start:-1rem}ax-json-viewer .ax-nowrap{white-space:nowrap}.ax-dark ax-json-viewer summary,.ax-dark ax-json-viewer p{color:var(--ax-comp-json-viewer-key-color-dark)}.ax-dark ax-json-viewer .ax-string-color{color:var(--ax-comp-json-viewer-string-color-dark)}.ax-dark ax-json-viewer .ax-number-color{color:var(--ax-comp-json-viewer-number-color-dark)}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: JsonViewerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-json-viewer', encapsulation: ViewEncapsulation.None, imports: [NgTemplateOutlet], providers: [{ provide: AXComponent, useExisting: JsonViewerComponent }], template: "<ng-container [ngTemplateOutlet]=\"Recursion\" [ngTemplateOutletContext]=\"{ list: convertedObject() }\"></ng-container>\n\n<ng-template #Recursion let-list=\"list\">\n  @for (item of list; track $index) {\n    @if (isArray(item.value)) {\n      <details>\n        <summary>\"{{ item.key }}\"</summary>\n        <div class=\"ax-indent-details\">\n          <ng-container [ngTemplateOutlet]=\"Recursion\" [ngTemplateOutletContext]=\"{ list: item.value }\"></ng-container>\n        </div>\n      </details>\n    } @else {\n      <div class=\"ax-flex-container\">\n        <p class=\"ax-nowrap ax-margin\">\"{{ item.key }}\"<span>:</span></p>\n\n        <p\n          class=\"ax-nowrap ax-indent {{\n            isNumber(item.value) || isBoolean(item.value) ? 'ax-number-color' : 'ax-string-color'\n          }}\"\n        >\n          @if (isNumber(item.value) || isBoolean(item.value)) {\n            {{ item.value }}\n          } @else {\n            ''{{ item.value }}''\n          }\n        </p>\n      </div>\n    }\n  }\n</ng-template>\n\n@if (primitiveData()) {\n  <p\n    class=\"ax-nowrap ax-indent {{\n      isNumber(primitiveData()) || isBoolean(primitiveData()) ? 'ax-number-color' : 'ax-string-color'\n    }}\"\n  >\n    @if (isNumber(primitiveData()) || isBoolean(primitiveData())) {\n      {{ primitiveData() }}\n    } @else {\n      ''{{ primitiveData() }}''\n    }\n  </p>\n}\n", styles: ["ax-json-viewer{--ax-comp-json-viewer-string-color-light: rgb(217, 57, 62);--ax-comp-json-viewer-string-color-dark: rgba(92, 213, 251, 255);--ax-comp-json-viewer-number-color-dark: rgba(var(--ax-sys-color-on-lightest-surface));--ax-comp-json-viewer-number-color-light: rgba(var(--ax-sys-color-on-lightest-surface));--ax-comp-json-viewer-key-color-dark: rgba(124, 172, 248, 255);--ax-comp-json-viewer-key-color-light: rgba(var(--ax-sys-color-on-lightest-surface))}ax-json-viewer{padding:1.5rem;overflow-x:auto;display:block}ax-json-viewer .ax-number-color{color:var(--ax-comp-json-viewer-number-color-light)}ax-json-viewer .ax-number-color input::-webkit-outer-spin-button,ax-json-viewer .ax-number-color input::-webkit-inner-spin-button{-webkit-appearance:none}ax-json-viewer .ax-string-color{color:var(--ax-comp-json-viewer-string-color-light)}ax-json-viewer .ax-indent{margin:0;padding:0;height:fit-content}ax-json-viewer .ax-margin{margin-inline-end:.3rem}ax-json-viewer .ax-indent-details{margin:0 2rem;height:fit-content}ax-json-viewer .ax-flex-container{display:flex;justify-content:flex-start;align-items:center;gap:.25rem}ax-json-viewer summary,ax-json-viewer p{color:var(--ax-comp-json-viewer-key-color-light)}ax-json-viewer summary::marker,ax-json-viewer span{color:rgb(var(--ax-sys-body-text-color))}ax-json-viewer details{margin-inline-start:-1rem}ax-json-viewer .ax-nowrap{white-space:nowrap}.ax-dark ax-json-viewer summary,.ax-dark ax-json-viewer p{color:var(--ax-comp-json-viewer-key-color-dark)}.ax-dark ax-json-viewer .ax-string-color{color:var(--ax-comp-json-viewer-string-color-dark)}.ax-dark ax-json-viewer .ax-number-color{color:var(--ax-comp-json-viewer-number-color-dark)}\n"] }]
        }] });

const COMPONENT = [JsonViewerComponent];
const MODULES = [AXTextBoxModule, FormsModule, CommonModule];
class AXJsonViewerModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: AXJsonViewerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.3", ngImport: i0, type: AXJsonViewerModule, imports: [AXTextBoxModule, FormsModule, CommonModule, JsonViewerComponent], exports: [JsonViewerComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: AXJsonViewerModule, imports: [MODULES] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: AXJsonViewerModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [...MODULES, ...COMPONENT],
                    exports: [...COMPONENT],
                    providers: [],
                }]
        }] });

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

export { AXJsonViewerModule, JsonViewerComponent };
//# sourceMappingURL=acorex-components-json-viewer.mjs.map
