import * as i0 from '@angular/core';
import { input, booleanAttribute, contentChild, TemplateRef, signal, inject, ChangeDetectionStrategy, Component } from '@angular/core';
import { Validators, NgControl, FormsModule } from '@angular/forms';
import { RadioCards } from '@masterteam/components/radio-cards';
import { FieldValidation } from '@masterteam/components/field-validation';

class RadioCardsField {
    circle = input(false, { ...(ngDevMode ? { debugName: "circle" } : {}), transform: booleanAttribute });
    label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : []));
    required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : []));
    color = input('primary', ...(ngDevMode ? [{ debugName: "color" }] : []));
    size = input('medium', ...(ngDevMode ? [{ debugName: "size" }] : []));
    options = input.required(...(ngDevMode ? [{ debugName: "options" }] : []));
    itemTemplate = contentChild('option', { ...(ngDevMode ? { debugName: "itemTemplate" } : {}), read: TemplateRef });
    selectedId = signal(null, ...(ngDevMode ? [{ debugName: "selectedId" }] : []));
    isDisabled = signal(false, ...(ngDevMode ? [{ debugName: "isDisabled" }] : []));
    requiredValidator = Validators.required;
    ngControl = null;
    constructor() {
        try {
            this.ngControl = inject(NgControl, { self: true, optional: true });
            if (this.ngControl) {
                this.ngControl.valueAccessor = this;
            }
        }
        catch (_e) {
            this.ngControl = null;
        }
    }
    // --- CVA Methods ---
    onChange = () => { };
    onTouched = () => { };
    writeValue(value) {
        this.selectedId.set(value);
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(isDisabled) {
        this.isDisabled.set(isDisabled);
    }
    onSelectionChange(selectedItem) {
        if (!this.isDisabled()) {
            const newId = selectedItem.id;
            this.selectedId.set(newId);
            this.onChange(newId);
            this.onTouched();
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: RadioCardsField, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: RadioCardsField, isStandalone: true, selector: "mt-radio-cards-field", inputs: { circle: { classPropertyName: "circle", publicName: "circle", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: true, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, providers: [], queries: [{ propertyName: "itemTemplate", first: true, predicate: ["option"], descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "@if (label()) {\r\n  <label\r\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\r\n    [for]=\"ngControl?.name || label()\"\r\n    >{{ label() }}</label\r\n  >\r\n}\r\n<div\r\n  class=\"relative\"\r\n  [class.opacity-50]=\"isDisabled()\"\r\n  [class.pointer-events-none]=\"isDisabled()\"\r\n  [id]=\"ngControl?.name || label()\"\r\n>\r\n  <mt-radio-cards\r\n    [options]=\"options()\"\r\n    [activeId]=\"selectedId()\"\r\n    [color]=\"color()\"\r\n    [size]=\"size()\"\r\n    [circle]=\"circle()\"\r\n    (selectionChange)=\"onSelectionChange($event)\"\r\n    [itemTemplate]=\"itemTemplate()\"\r\n  ></mt-radio-cards>\r\n</div>\r\n\r\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "component", type: RadioCards, selector: "mt-radio-cards", inputs: ["circle", "color", "size", "options", "activeId", "itemTemplate"], outputs: ["optionsChange", "activeIdChange", "selectionChange"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: RadioCardsField, decorators: [{
            type: Component,
            args: [{ selector: 'mt-radio-cards-field', standalone: true, imports: [FormsModule, RadioCards, FieldValidation], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'grid gap-1',
                    }, providers: [], template: "@if (label()) {\r\n  <label\r\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\r\n    [for]=\"ngControl?.name || label()\"\r\n    >{{ label() }}</label\r\n  >\r\n}\r\n<div\r\n  class=\"relative\"\r\n  [class.opacity-50]=\"isDisabled()\"\r\n  [class.pointer-events-none]=\"isDisabled()\"\r\n  [id]=\"ngControl?.name || label()\"\r\n>\r\n  <mt-radio-cards\r\n    [options]=\"options()\"\r\n    [activeId]=\"selectedId()\"\r\n    [color]=\"color()\"\r\n    [size]=\"size()\"\r\n    [circle]=\"circle()\"\r\n    (selectionChange)=\"onSelectionChange($event)\"\r\n    [itemTemplate]=\"itemTemplate()\"\r\n  ></mt-radio-cards>\r\n</div>\r\n\r\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\r\n" }]
        }], ctorParameters: () => [], propDecorators: { circle: [{ type: i0.Input, args: [{ isSignal: true, alias: "circle", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: true }] }], itemTemplate: [{ type: i0.ContentChild, args: ['option', { ...{ read: TemplateRef }, isSignal: true }] }] } });

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

export { RadioCardsField };
//# sourceMappingURL=masterteam-components-radio-cards-field.mjs.map
