const _Component = require("../../__antmove/component/componentClass.js")(
    "Component"
);
const _my = require("../../__antmove/api/index.js")(my);
my.setStorageSync({
    key: "activeComponent",
    data: {
        is: "dist/cell/index"
    }
});

const warn = (msg, getValue) => {
    console.warn(msg);
    console.log("接受到的值为：", getValue);
};

_Component({
    externalClasses: ["i-class"],
    options: {
        multipleSlots: true
    },
    relations: {
        "../cell-group/index": {
            type: "parent"
        }
    },
    properties: {
        // 左侧标题
        title: {
            type: String
        },
        // 标题下方的描述信息
        label: {
            type: String
        },
        // 右侧内容
        value: {
            type: String
        },
        // 只有点击 footer 区域才触发 tab 事件
        onlyTapFooter: {
            type: Boolean
        },
        // 是否展示右侧箭头并开启尝试以 url 跳转
        isLink: {
            type: null,
            value: ""
        },
        // 链接类型，可选值为 navigateTo，redirectTo，switchTab，reLaunch
        linkType: {
            type: String,
            value: "navigateTo"
        },
        url: {
            type: String,
            value: ""
        }
    },
    data: {
        isLastCell: true
    },
    methods: {
        navigateTo() {
            const { url } = this.data;
            const type = typeof this.data.isLink;
            this.triggerEvent("click", {});
            if (!this.data.isLink || !url || url === "true" || url === "false")
                return;

            if (type !== "boolean" && type !== "string") {
                warn("isLink 属性值必须是一个字符串或布尔值", this.data.isLink);
                return;
            }

            if (
                ["navigateTo", "redirectTo", "switchTab", "reLaunch"].indexOf(
                    this.data.linkType
                ) === -1
            ) {
                warn(
                    "linkType 属性可选值为 navigateTo，redirectTo，switchTab，reLaunch",
                    this.data.linkType
                );
                return;
            }

            _my[this.data.linkType].call(_my, {
                url
            });
        },

        handleTap() {
            if (!this.data.onlyTapFooter) {
                this.navigateTo();
            }
        },

        updateIsLastCell(isLastCell) {
            this.setData({
                isLastCell
            });
        }
    }
});
