package com.abbidot.tracker.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import com.haibin.calendarview.Calendar
import com.haibin.calendarview.MonthView
import java.lang.String
import kotlin.Boolean
import kotlin.Int

/**
 *Created  by .yzq on 2024/1/9/009.
 * @link
 * @description:
 */
class MyMonthView(context: Context) : MonthView(context) {

    /**
     * 绘制选中的日子
     *
     * @param canvas    canvas
     * @param calendar  日历日历calendar
     * @param x         日历Card x起点坐标
     * @param y         日历Card y起点坐标
     * @param hasScheme hasScheme 非标记的日期
     * @return 返回true 则绘制onDrawScheme，因为这里背景色不是是互斥的，所以返回true
     */
    override fun onDrawSelected(
        canvas: Canvas, calendar: Calendar, x: Int, y: Int, hasScheme: Boolean
    ): Boolean {
        mSelectedPaint.style = Paint.Style.FILL
        canvas.drawCircle(
            x + mItemWidth / 2f, y + mItemHeight / 2f, mItemWidth / 2.5f, mSelectedPaint
        )
        return false
    }

    /**
     * 绘制标记的事件日子
     *
     * @param canvas   canvas
     * @param calendar 日历calendar
     * @param x        日历Card x起点坐标
     * @param y        日历Card y起点坐标
     */
    override fun onDrawScheme(canvas: Canvas, calendar: Calendar, x: Int, y: Int) {
    }

    /**
     * 绘制文本
     *
     * @param canvas     canvas
     * @param calendar   日历calendar
     * @param x          日历Card x起点坐标
     * @param y          日历Card y起点坐标
     * @param hasScheme  是否是标记的日期
     * @param isSelected 是否选中
     */
    override fun onDrawText(
        canvas: Canvas, calendar: Calendar, x: Int, y: Int, hasScheme: Boolean, isSelected: Boolean
    ) {
        val cx = x + mItemWidth / 2

        val isInRange = isInRange(calendar)

        if (isSelected) {
            canvas.drawText(
                String.valueOf(calendar.day), cx.toFloat(), mTextBaseLine + y, mSelectTextPaint
            )
//            canvas.drawText(
//                calendar.lunar,
//                cx.toFloat(),
//                mTextBaseLine + y + mItemHeight / 10,
//                mSelectedLunarTextPaint
//            )
        } else if (hasScheme) {
            canvas.drawText(
                String.valueOf(calendar.day),
                cx.toFloat(),
                mTextBaseLine + y,
                if (calendar.isCurrentMonth && isInRange) mSchemeTextPaint else mOtherMonthTextPaint
            )
//            canvas.drawText(
//                calendar.lunar,
//                cx.toFloat(),
//                mTextBaseLine + y + mItemHeight / 10,
//                mCurMonthLunarTextPaint
//            )
        } else {
            canvas.drawText(
                String.valueOf(calendar.day),
                cx.toFloat(),
                mTextBaseLine + y,
                if (calendar.isCurrentDay) mCurDayTextPaint else if (calendar.isCurrentMonth && isInRange) mCurMonthTextPaint else mOtherMonthTextPaint
            )
//            canvas.drawText(
//                calendar.lunar,
//                cx.toFloat(),
//                mTextBaseLine + y + mItemHeight / 10,
//                if (calendar.isCurrentDay && isInRange) mCurDayLunarTextPaint else if (calendar.isCurrentMonth) mCurMonthLunarTextPaint else mOtherMonthLunarTextPaint
//            )
        }
    }
}