import * as i0 from '@angular/core';
import { Component, ChangeDetectionStrategy, Input, EventEmitter, Directive, Output, NgModule } from '@angular/core';
import { isNullOrUndefined } from '@ironsource/fusion-ui/utils';
import * as i1 from '@ironsource/fusion-ui/components/icon/v1';
import { IconModule } from '@ironsource/fusion-ui/components/icon/v1';
import { CommonModule } from '@angular/common';

class AccordionContentComponent {
    constructor() {
        this.iconPosition = 'right';
    }
    static { this.ɵfac = function AccordionContentComponent_Factory(t) { return new (t || AccordionContentComponent)(); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: AccordionContentComponent, selectors: [["fusion-accordion-content"]], inputs: { text: "text", iconPosition: "iconPosition" }, decls: 2, vars: 3, consts: [[1, "accordion-content"]], template: function AccordionContentComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵtext(1);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵclassProp("icon-position-left", ctx.iconPosition === "left");
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate1(" ", ctx.text, "\n");
        } }, styles: ["[_nghost-%COMP%]   .accordion-content[_ngcontent-%COMP%]{font-size:12px;font-family:HelveticaNeue,helvetica,sans-serif;font-weight:400;letter-spacing:.04px}[_nghost-%COMP%]{display:block;border-bottom:solid 1px var(--fu-light-300, #e5e7e9)}[_nghost-%COMP%]   .accordion-content[_ngcontent-%COMP%]{padding:1px 12px 12px;color:var(--fu-dark-300, #313d91)}[_nghost-%COMP%]   .accordion-content.icon-position-left[_ngcontent-%COMP%]{padding-left:29px}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AccordionContentComponent, [{
        type: Component,
        args: [{ selector: 'fusion-accordion-content', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"accordion-content\" [class.icon-position-left]=\"iconPosition === 'left'\">\n    {{ text }}\n</div>\n", styles: [":host .accordion-content{font-size:12px;font-family:HelveticaNeue,helvetica,sans-serif;font-weight:400;letter-spacing:.04px}:host{display:block;border-bottom:solid 1px var(--fu-light-300, #e5e7e9)}:host .accordion-content{padding:1px 12px 12px;color:var(--fu-dark-300, #313d91)}:host .accordion-content.icon-position-left{padding-left:29px}\n"] }]
    }], null, { text: [{
            type: Input
        }], iconPosition: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(AccordionContentComponent, { className: "AccordionContentComponent", filePath: "accordion-content/accordion-content.component.ts", lineNumber: 9 }); })();

const _c0 = () => ({ iconName: "arrow-right", iconVersion: "v1" });
class AccordionHeaderComponent {
    constructor() {
        this.iconPosition = 'right';
    }
    static { this.ɵfac = function AccordionHeaderComponent_Factory(t) { return new (t || AccordionHeaderComponent)(); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: AccordionHeaderComponent, selectors: [["fusion-accordion-header"]], inputs: { isOpen: "isOpen", text: "text", iconPosition: "iconPosition" }, decls: 3, vars: 7, consts: [[1, "accordion-header"], [1, "open-close", 3, "name"]], template: function AccordionHeaderComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵtext(1);
            i0.ɵɵelement(2, "fusion-icon", 1);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵclassProp("opened", ctx.isOpen)("icon-position-left", ctx.iconPosition === "left");
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate1(" ", ctx.text, " ");
            i0.ɵɵadvance();
            i0.ɵɵproperty("name", i0.ɵɵpureFunction0(6, _c0));
        } }, dependencies: [i1.IconComponent], styles: ["[_nghost-%COMP%]   .accordion-header[_ngcontent-%COMP%]{font-size:12px;font-family:HelveticaNeue,helvetica,sans-serif;font-weight:400;letter-spacing:.04px}[_nghost-%COMP%]   *[_ngcontent-%COMP%]{box-sizing:border-box}[_nghost-%COMP%]   fusion-icon.open-close[_ngcontent-%COMP%]{position:absolute;right:11px}[_nghost-%COMP%]   fusion-icon.open-close[_ngcontent-%COMP%]     svg{width:8px;height:8px}[_nghost-%COMP%]   fusion-icon.open-close[_ngcontent-%COMP%]     svg *{fill:var(--fu-dark-300, #313d91)}[_nghost-%COMP%]   .accordion-header[_ngcontent-%COMP%]{border-bottom:solid 1px var(--fu-light-300, #e5e7e9);display:block;height:40px;color:var(--fu-dark-300, #313d91);padding:10px;position:relative}[_nghost-%COMP%]   .accordion-header[_ngcontent-%COMP%]:hover{background-color:var(--fu-light-100, #f7f8f9);cursor:pointer}[_nghost-%COMP%]   .accordion-header.opened[_ngcontent-%COMP%]{border-bottom-color:transparent}[_nghost-%COMP%]   .accordion-header.opened[_ngcontent-%COMP%]   fusion-icon.open-close[_ngcontent-%COMP%]     svg{width:8px;height:8px;transform:rotate(90deg)}[_nghost-%COMP%]   .accordion-header.opened[_ngcontent-%COMP%]   fusion-icon.open-close[_ngcontent-%COMP%]     svg *{fill:var(--fu-dark-300, #313d91)}[_nghost-%COMP%]   .accordion-header.icon-position-left[_ngcontent-%COMP%]{padding-left:29px}[_nghost-%COMP%]   .accordion-header.icon-position-left[_ngcontent-%COMP%]   .open-close[_ngcontent-%COMP%]{left:11px}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AccordionHeaderComponent, [{
        type: Component,
        args: [{ selector: 'fusion-accordion-header', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"accordion-header\" [class.opened]=\"isOpen\" [class.icon-position-left]=\"iconPosition === 'left'\">\n    {{ text }}\n    <fusion-icon class=\"open-close\" [name]=\"{iconName: 'arrow-right', iconVersion: 'v1'}\"></fusion-icon>\n</div>\n", styles: [":host .accordion-header{font-size:12px;font-family:HelveticaNeue,helvetica,sans-serif;font-weight:400;letter-spacing:.04px}:host *{box-sizing:border-box}:host fusion-icon.open-close{position:absolute;right:11px}:host fusion-icon.open-close ::ng-deep svg{width:8px;height:8px}:host fusion-icon.open-close ::ng-deep svg *{fill:var(--fu-dark-300, #313d91)}:host .accordion-header{border-bottom:solid 1px var(--fu-light-300, #e5e7e9);display:block;height:40px;color:var(--fu-dark-300, #313d91);padding:10px;position:relative}:host .accordion-header:hover{background-color:var(--fu-light-100, #f7f8f9);cursor:pointer}:host .accordion-header.opened{border-bottom-color:transparent}:host .accordion-header.opened fusion-icon.open-close ::ng-deep svg{width:8px;height:8px;transform:rotate(90deg)}:host .accordion-header.opened fusion-icon.open-close ::ng-deep svg *{fill:var(--fu-dark-300, #313d91)}:host .accordion-header.icon-position-left{padding-left:29px}:host .accordion-header.icon-position-left .open-close{left:11px}\n"] }]
    }], null, { isOpen: [{
            type: Input
        }], text: [{
            type: Input
        }], iconPosition: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(AccordionHeaderComponent, { className: "AccordionHeaderComponent", filePath: "accordion-header/accordion-header.component.ts", lineNumber: 9 }); })();

const DEFAULT_CONFIGURATION = {
    iconPosition: 'right',
    header: { component: AccordionHeaderComponent },
    content: { component: AccordionContentComponent }
};
class AccordionBaseComponent {
    constructor() {
        this.stateChange = new EventEmitter();
        this.accordionBoxes = [];
        this.accordionConfiguration = DEFAULT_CONFIGURATION;
    }
    set data(value) {
        this.accordionBoxes = Array.isArray(value) ? value : [];
    }
    set configuration(value) {
        if (!isNullOrUndefined(value)) {
            if (!value.hasOwnProperty('header')) {
                Object.assign(value, { header: { component: AccordionHeaderComponent } });
            }
            if (!value.hasOwnProperty('content')) {
                Object.assign(value, { content: { component: AccordionContentComponent } });
            }
        }
        else {
            value = DEFAULT_CONFIGURATION;
        }
        this.accordionConfiguration = value;
    }
    onClick(index) {
        if (!this.isOpened(index)) {
            this.accordionConfiguration.opened = index;
            this.stateChange.emit({ opened: index });
        }
        else {
            this.accordionConfiguration.opened = null;
            this.stateChange.emit({ closed: index });
        }
    }
    /**
     * Get Accordion Item dynamic config
     * @param index - index of target Accordion Item
     * @param type - Accordion Item type ('header' | 'content')
     */
    getItemConfiguration(index, type) {
        return { ...this.applyItemOptions(index, this.accordionBoxes[index][type + 'Data'], this.accordionConfiguration[type]) };
    }
    isOpened(index) {
        return this.accordionConfiguration.opened === index;
    }
    getItemData(boxData, index) {
        return Object.assign(this.getData(boxData), {
            isAccordion: true,
            isOpen: this.isOpened(index),
            iconPosition: this.accordionConfiguration.iconPosition || 'right'
        });
    }
    getData(boxData) {
        return typeof boxData === 'string' ? { text: boxData } : boxData;
    }
    applyItemOptions(index, boxData, boxDynamicConfig) {
        if (boxDynamicConfig.hasOwnProperty('component')) {
            return {
                component: {
                    type: boxDynamicConfig.component,
                    data: this.getItemData(boxData, index)
                }
            };
        }
        else if (boxDynamicConfig.hasOwnProperty('renderElement')) {
            // In case Node element
            return {
                element: boxDynamicConfig.renderElement(this.getItemData(boxData, index))
            };
        }
        else {
            // in unsupported case
            return null;
        }
    }
    static { this.ɵfac = function AccordionBaseComponent_Factory(t) { return new (t || AccordionBaseComponent)(); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: AccordionBaseComponent, inputs: { data: "data", configuration: "configuration" }, outputs: { stateChange: "stateChange" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AccordionBaseComponent, [{
        type: Directive
    }], null, { data: [{
            type: Input
        }], configuration: [{
            type: Input
        }], stateChange: [{
            type: Output
        }] }); })();

class AccordionHeaderModule {
    static { this.ɵfac = function AccordionHeaderModule_Factory(t) { return new (t || AccordionHeaderModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: AccordionHeaderModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule, IconModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AccordionHeaderModule, [{
        type: NgModule,
        args: [{
                declarations: [AccordionHeaderComponent],
                imports: [CommonModule, IconModule]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(AccordionHeaderModule, { declarations: [AccordionHeaderComponent], imports: [CommonModule, IconModule] }); })();

class AccordionContentModule {
    static { this.ɵfac = function AccordionContentModule_Factory(t) { return new (t || AccordionContentModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: AccordionContentModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AccordionContentModule, [{
        type: NgModule,
        args: [{
                declarations: [AccordionContentComponent],
                imports: [CommonModule]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(AccordionContentModule, { declarations: [AccordionContentComponent], imports: [CommonModule] }); })();

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

export { AccordionBaseComponent, AccordionContentComponent, AccordionContentModule, AccordionHeaderComponent, AccordionHeaderModule };
//# sourceMappingURL=ironsource-fusion-ui-components-accordion-common-base.mjs.map
