/**
 * Made by mkcomponent.sh
 * * Change to Fileheader info *
*/

// Core imports
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'

// Services


@Component({
    moduleId: module.id+ '',
    selector: 'product-options',
    templateUrl: './template/t--options.pug',
    styleUrls: ['sty.options.scss']
})

export class OptionsComponent implements OnInit {

    // ---- Variables ---- \\
    @Input('option') option: any
    @Output('result') result = new EventEmitter

    constructor( ) { }


    // ---- Lifecycle hooks ---- \\
    ngOnInit() {}


    // ---- Functions ---- \\
    selectOption(event) {
        
        let selected = this.option.options.find((element) => {
            if(element.id == event.value)
                return element
        })


        this.result.emit({
            id: this.option.id,
            value: event.value,
            title: selected.title,
            price: selected.price,
            type: selected.priceType
        })
    }

}
