import * as i0 from '@angular/core';
import { model, input, computed, Component } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { InteractiveContentDirective } from '@seniorsistemas/angular-components/interactive-content';

class StarRatingComponent {
    onChange = () => { };
    onTouched = () => { };
    selectedStar = model(0);
    starsRange = input(5);
    justifyContent = input('center');
    disabled = model(false);
    elementsRender = computed(() => {
        const elements = this.starsRange();
        return Array.from({ length: elements }).map((_x, $index) => $index);
    });
    writeValue(obj) {
        if (obj !== null) {
            this.selectedStar.set(obj);
        }
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(isDisabled) {
        this.disabled.set(isDisabled);
    }
    onSelectStar(selectedIndex) {
        this.storeValue(selectedIndex);
    }
    storeValue(selectedIndex) {
        if (this.disabled()) {
            return;
        }
        if (selectedIndex === this.selectedStar()) {
            selectedIndex = 0;
        }
        this.writeValue(selectedIndex);
        this.onChange(selectedIndex);
        this.onTouched(selectedIndex);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: StarRatingComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: StarRatingComponent, isStandalone: true, selector: "s-star-rating", inputs: { selectedStar: { classPropertyName: "selectedStar", publicName: "selectedStar", isSignal: true, isRequired: false, transformFunction: null }, starsRange: { classPropertyName: "starsRange", publicName: "starsRange", isSignal: true, isRequired: false, transformFunction: null }, justifyContent: { classPropertyName: "justifyContent", publicName: "justifyContent", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selectedStar: "selectedStarChange", disabled: "disabledChange" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: StarRatingComponent,
                multi: true,
            },
        ], ngImport: i0, template: "@let justifyContentClassName = 'justify-' + justifyContent();\n<section [class]=\"justifyContentClassName\" class=\"flex gap-2\" [class.opacity-50]=\"disabled()\">\n    @for(item of elementsRender(); track item) {\n        @let isActivated = selectedStar() <= item;\n        <i\n            [class.fas]=\"!isActivated\"\n            [class.far]=\"isActivated\"\n            [class.cursor-pointer]=\"!disabled()\"\n            class=\"fa-star text-[#F5A319] cursor-pointer\"\n            (sInteractiveContent)=\"onSelectStar(item + 1)\">\n        </i>\n    }\n</section>\n", styles: [""], dependencies: [{ kind: "directive", type: InteractiveContentDirective, selector: "[sInteractiveContent]", inputs: ["focusable", "disabled", "stopPropagation"], outputs: ["sInteractiveContent"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: StarRatingComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-star-rating', standalone: true, imports: [InteractiveContentDirective], providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: StarRatingComponent,
                            multi: true,
                        },
                    ], template: "@let justifyContentClassName = 'justify-' + justifyContent();\n<section [class]=\"justifyContentClassName\" class=\"flex gap-2\" [class.opacity-50]=\"disabled()\">\n    @for(item of elementsRender(); track item) {\n        @let isActivated = selectedStar() <= item;\n        <i\n            [class.fas]=\"!isActivated\"\n            [class.far]=\"isActivated\"\n            [class.cursor-pointer]=\"!disabled()\"\n            class=\"fa-star text-[#F5A319] cursor-pointer\"\n            (sInteractiveContent)=\"onSelectStar(item + 1)\">\n        </i>\n    }\n</section>\n" }]
        }] });

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

export { StarRatingComponent };
//# sourceMappingURL=seniorsistemas-angular-components-star-rating.mjs.map
