import drawImage, { drawScaleImage } from '../util/drawImage.js'
import { modalCloseBtnArea } from '../conf/data.js'

export default class Modal {
  constructor() {
    this.scale = 1
  }
  draw = () => {
    let ctx = this.context
    //mask 
    return drawImage(ctx, 'images/popup/bg_mask@2x.png', 0, 0, screenWidth, screenHeight).then(() => {
      // win
      return drawScaleImage(ctx, this.bg_pop_win, screenWidth / 2, screenHeight / 2, 'center middle', this.scale).then((dimension) => {
        this.win_dimension = dimension
        return drawImage(ctx, 'images/popup/btn_close@2x.png', dimension.endX - 20, dimension.startY, 'right').then((dimension) => {
          modalCloseBtnArea[0] = {...dimension}
          return dimension
        })
      })
    }).then(()=>{

      return this.drawContent()
    }).then(() => {
      GameGlobal.canvas.getContext('2d').drawImage(this.canvas, 0, 0)
      return ctx
    })
  }
  drawContent = () => {
    throw new Error('need implement drawContent by yourself')
  }
  destroy = () => {
    removeEventListener(this.closeHandler)
    // need reStart
  }
}