import { Component, Input } from '@angular/core';
import { AppFunc } from '../../interface/AppFunc';

@Component({
    selector: 'app-icon',
    templateUrl: 'app-icon.html',
    styleUrls: ['app-icon.scss']
})
export class AppIcon {
    /**
     * 菜单项
     *
     * @memberof AppIcon
     */
    @Input()
    set item(val: AppFunc) {
        if (val) {
            if (val.iconcls && !Object.is(val.iconcls, '')) {
                this.icon = val.iconcls;
                this.iconType = 1;
            } else if (val.icon && !Object.is(val.icon, '')) {
                this.icon = val.icon;
                if (val.icon.lastIndexOf('.svg') === (val.icon.length - 4)) {
                    this.iconType = 2;
                } else {
                    this.iconType = 3;
                }
            }
        }
    }
    /**
     * ionic图标名称
     *
     * @memberof AppIcon
     */
    @Input()
    set iconName(val: string) {
        if (val && !Object.is(val, '')) {
            this.icon = val;
            this.iconType = 1;
        }
    }
    /**
     * 图片路径
     *
     * @memberof AppIcon
     */
    @Input()
    set iconSrc(val: string) {
        if (val && !Object.is(val, '')) {
            this.icon = val;
            if (this.icon.lastIndexOf('.svg') === (this.icon.length - 4)) {
                this.iconType = 2;
            } else {
                this.iconType = 3;
            }
        }
    }
    /**
     * 默认图标
     *
     * @type {string}
     * @memberof AppIcon
     */
    @Input()
    defaultIcon: string = 'pricetags';
    /**
     * 当未输入时，是否显示默认图标
     *
     * @type {boolean}
     * @memberof AppIcon
     */
    @Input()
    isDefault: boolean = false;
    /**
     * 图标展示模式
     *
     * @type {(0 | 1 | 2 | 3)} 0: 无图标, 1: ionic自带图标, 2: svg图片图标, 3: 指定路径图片图标
     * @memberof AppIcon
     */
    public iconType: 0 | 1 | 2 | 3 = 0;
    /**
     * 图标
     *
     * @type {string}
     * @memberof AppIcon
     */
    public icon: string;
}