{"version":3,"file":"keycloakify-angular-login-components-add-remove-buttons-multi-valued-attribute.mjs","names":[],"sources":["../../src/login/components/add-remove-buttons-multi-valued-attribute/add-remove-buttons-multi-valued-attribute.component.ts","../../src/login/components/add-remove-buttons-multi-valued-attribute/add-remove-buttons-multi-valued-attribute.component.html"],"sourcesContent":["import { ChangeDetectionStrategy, Component, computed, inject, input, output } from '@angular/core';\nimport { getButtonToDisplayForMultivaluedAttributeField, type FormAction } from '@keycloakify/angular/login/services/user-profile-form';\nimport { LOGIN_I18N } from '@keycloakify/angular/login/tokens/i18n';\nimport type { Attribute } from 'keycloakify/login/KcContext';\nimport type { I18n } from '@keycloakify/angular/login/i18n';\n\n@Component({\n    styles: [\n        `\n            :host {\n                display: contents;\n            }\n        `\n    ],\n    selector: 'kc-add-remove-buttons-multi-valued-attribute',\n    templateUrl: 'add-remove-buttons-multi-valued-attribute.component.html',\n    changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class AddRemoveButtonsMultiValuedAttributeComponent {\n    i18n = inject<I18n>(LOGIN_I18N);\n    attribute = input<Attribute>();\n    values = input<string[]>();\n    fieldIndex = input<number>();\n    dispatchFormAction = output<FormAction>();\n\n    hasRemove = computed(() => {\n        const attribute = this.attribute();\n        const values = this.values();\n        const fieldIndex = this.fieldIndex();\n        if (attribute && values && fieldIndex) {\n            return getButtonToDisplayForMultivaluedAttributeField({\n                attribute,\n                values,\n                fieldIndex\n            }).hasRemove;\n        }\n        return false;\n    });\n    hasAdd = computed(() => {\n        const attribute = this.attribute();\n        const values = this.values();\n        const fieldIndex = this.fieldIndex();\n        if (attribute && values && fieldIndex) {\n            return getButtonToDisplayForMultivaluedAttributeField({\n                attribute,\n                values,\n                fieldIndex\n            }).hasAdd;\n        }\n        return false;\n    });\n\n    onAdd() {\n        this.dispatchFormAction.emit({\n            action: 'update',\n            name: this.attribute()?.name ?? '',\n            valueOrValues: [...(this.values() ?? []), '']\n        });\n    }\n\n    onRemove() {\n        this.dispatchFormAction.emit({\n            action: 'update',\n            name: this.attribute()?.name ?? '',\n            valueOrValues: (this.values() ?? []).filter((_, i) => i !== this.fieldIndex())\n        });\n    }\n}\n","@let idPostfix = attribute()?.name ?? '' + '-' + (fieldIndex() ?? 0 + 1);\n@if (hasRemove()) {\n    <button\n        type=\"button\"\n        class=\"pf-c-button pf-m-inline pf-m-link\"\n        [id]=\"'kc-remove-' + idPostfix\"\n        (click)=\"onRemove()\"\n    >\n        {{ i18n.msgStr('remove') }}\n    </button>\n    @if (hasAdd()) {\n        &nbsp;|&nbsp;\n    }\n}\n@if (hasAdd()) {\n    <button\n        type=\"button\"\n        class=\"pf-c-button pf-m-inline pf-m-link\"\n        [id]=\"'kc-add-' + idPostfix\"\n        (click)=\"onAdd()\"\n    >\n        {{ i18n.msgStr('addValue') }}\n    </button>\n}\n"],"mappings":";;;;AAkBA,IAAa,gDAAb,MAAa,8CAA6C;CAZ1D,cAAA;EAaI,KAAA,OAAO,OAAa,UAAU;EAC9B,KAAA,YAAY,MAAkB,GAAA,YAAA,CAAA,QAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;EAC9B,KAAA,SAAS,MAAiB,GAAA,YAAA,CAAA,QAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;EAC1B,KAAA,aAAa,MAAe,GAAA,YAAA,CAAA,QAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;EAC5B,KAAA,qBAAqB,OAAM;EAE3B,KAAA,YAAY,eAAc;GACtB,MAAM,YAAY,KAAK,UAAS;GAChC,MAAM,SAAS,KAAK,OAAM;GAC1B,MAAM,aAAa,KAAK,WAAU;GAClC,IAAI,aAAa,UAAU,YACvB,OAAO,+CAA+C;IAClD;IACA;IACA;GACH,CAAA,CAAC,CAAC;GAEP,OAAO;EACX,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;EACF,KAAA,SAAS,eAAc;GACnB,MAAM,YAAY,K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