package com.adealink.weparty.room.guide

import android.view.Gravity
import android.view.View
import com.adealink.frame.guide.BaseGuide
import com.adealink.frame.guide.core.GuideController
import com.adealink.frame.guide.core.GuidePage
import com.adealink.frame.guide.core.NewbieGuide
import com.adealink.frame.guide.core.highlight.MarginInfo
import com.adealink.frame.guide.core.highlight.Offset
import com.adealink.frame.guide.core.highlight.RelativeGuide
import com.adealink.weparty.commonui.ext.dpf
import com.adealink.weparty.room.R

class HowToOrderGuide(
    private val onBeforeShowPageListener: ((String?) -> Unit)? = null,
    private var pageShowListener: ((String?) -> Unit)? = null,
    private var pageDismissListener: ((String?) -> Unit)? = null
) : BaseGuide() {
    override fun buildGuide(): GuideController {
        return NewbieGuide.with(activity)
            .alwaysShow(true)
            .addGuidePage(
                GuidePage().apply {
                    setLabel(RoomGuideLabel.HOW_TO_ORDER_1)
                    addHighLight(
                        R.string.tag_how_to_order_guide_1,
                        object : RelativeGuide(
                            R.layout.layout_how_to_guide_1,
                            Gravity.TOP or Gravity.END,
                            true
                        ) {
                            override fun onMarginInfo(
                                relativeView: View,
                                marginInfo: MarginInfo,
                                outOffset: Offset,
                            ) {
                                super.onMarginInfo(relativeView, marginInfo, outOffset)
//                                outOffset.top += VERTICAL_OFFSET
//                                outOffset.start += START_OFFSET
                            }
                        }, round = 12.dpf(), enableHighLightDecor = true, enableHighLightDecorPath = false
                    )
                }
            )
            .addGuidePage(
                GuidePage().apply {
                    setLabel(RoomGuideLabel.HOW_TO_ORDER_2)
                    addHighLight(
                        R.string.tag_how_to_order_guide_2,
                        object : RelativeGuide(
                            R.layout.layout_how_to_guide_2,
                            Gravity.BOTTOM or Gravity.END,
                            true
                        ) {
                            override fun onMarginInfo(
                                relativeView: View,
                                marginInfo: MarginInfo,
                                outOffset: Offset,
                            ) {
                                super.onMarginInfo(relativeView, marginInfo, outOffset)
//                                outOffset.top += VERTICAL_OFFSET
//                                outOffset.start += START_OFFSET
                            }
                        }, round = 12.dpf(), enableHighLightDecor = true, enableHighLightDecorPath = false
                    )
                }
            )
            .addGuidePage(
                GuidePage().apply {
                    setLabel(RoomGuideLabel.HOW_TO_ORDER_3)
                    addHighLight(
                        R.string.tag_how_to_order_guide_3,
                        object : RelativeGuide(
                            R.layout.layout_how_to_guide_3,
                            Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL,
                            true
                        ) {
                            override fun onMarginInfo(
                                relativeView: View,
                                marginInfo: MarginInfo,
                                outOffset: Offset,
                            ) {
                                super.onMarginInfo(relativeView, marginInfo, outOffset)
//                                outOffset.top += VERTICAL_OFFSET
//                                outOffset.start += START_OFFSET
                            }
                        }, round = 12.dpf(), enableHighLightDecor = true, enableHighLightDecorPath = false
                    )
                }
            )
            .addGuidePage(
                GuidePage().apply {
                    setLabel(RoomGuideLabel.HOW_TO_ORDER_4)
                    addHighLight(
                        R.string.tag_how_to_order_guide_4,
                        object : RelativeGuide(
                            R.layout.layout_how_to_guide_4,
                            Gravity.TOP or Gravity.CENTER_HORIZONTAL,
                            true
                        ) {
                            override fun onMarginInfo(
                                relativeView: View,
                                marginInfo: MarginInfo,
                                outOffset: Offset,
                            ) {
                                super.onMarginInfo(relativeView, marginInfo, outOffset)
//                                outOffset.top += VERTICAL_OFFSET
//                                outOffset.start += START_OFFSET
                            }
                        }, round = 12.dpf(), enableHighLightDecor = true, enableHighLightDecorPath = false
                    )
                }
            )
            .setBeforeShowPageListener {
                onBeforeShowPageListener?.invoke(it)
            }
            .setPageShowListener {
                pageShowListener?.invoke(it)
            }
            .setPageDismissListener {
                pageDismissListener?.invoke(it)
            }
            .build()
    }

    override fun interceptGuide(): Boolean {
        return false
    }

    override fun guideType(): String {
        return RoomGuideType.HOW_TO_ORDER
    }
}