package com.kdanmobile.reader.view

import android.content.Context
import android.graphics.Color
import android.os.Build
import androidx.core.content.ContextCompat
import android.widget.LinearLayout
import android.widget.PopupWindow
import androidx.cardview.widget.MyRoundRectDrawableWithShadow
import com.kdanmobile.reader.R

class AnnotationAttributeWindow(context: Context, isSimpleMode: Boolean) : PopupWindow(context) {
    val annotationAttributeView: AnnotationAttributeView

    init {
        width = LinearLayout.LayoutParams.WRAP_CONTENT
        height = LinearLayout.LayoutParams.WRAP_CONTENT
        isOutsideTouchable = true
        isFocusable = true
        annotationAttributeView = AnnotationAttributeView(context)
        annotationAttributeView.isSimpleMode = isSimpleMode
        contentView = annotationAttributeView

        val elevationSize = context.resources.getDimension(R.dimen.reader_annotation_property_setting_window_elevation)
        when {
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> elevation = elevationSize
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN -> contentView.background = MyRoundRectDrawableWithShadow(context.resources, Color.TRANSPARENT, 0f, elevationSize, elevationSize)
            else -> contentView.setBackgroundDrawable(MyRoundRectDrawableWithShadow(context.resources, Color.TRANSPARENT, 0f, elevationSize, elevationSize))
        }
        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.bg_annotation_property_setting_window))
    }
}