package com.bomostory.sceneeditmodule.view

import android.content.Context
import android.support.constraint.ConstraintLayout
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.CompoundButton
import android.widget.SeekBar
import com.bomostory.sceneeditmodule.basicdata.Music
import com.bomostory.sceneeditmodule.basicdata.Scene
import com.bomostory.sceneeditmodule.basicdata.Story
import com.example.tfat.myapplication.R
import kotlinx.android.synthetic.main.movie_edit_view.view.*

class MovieEditView : ConstraintLayout {

    var story: Story? = null
        set(value) {
            movieSelectView.story = value
        }

    var scene: Scene? = null
        set(value) {
            movieSeekView.scene = value
            value?.record?.period?.let {
                audioTrackGroupView.scenePeriod = it
            }
        }

    var playTime: Long = 0
        set(value) {
            movieSeekView.playTime = value
        }

    var currentAudioPosition = 0
        set(value) {
            audioTrackGroupView.currentPosition = value
        }

    var onPlayClickListener: OnClickListener? = null
        set(value) {
            movieSeekView.onPlayClickListener = value
        }

    var onPauseClickListener: OnClickListener? = null
        set(value) {
            movieSeekView.onPauseClickListener = value
        }

    var onSeekBarChangeListener: SeekBar.OnSeekBarChangeListener? = null
        set(value) {
            movieSeekView.onSeekBarChangeListener = value
        }

    var onMovieSelectListener: MovieSelectView.OnMovieSelectListener? = null
        set(value) {
            movieSelectView.onMovieSelectListener = value
        }

    var onAddMusicClickListener: OnClickListener? = null
        set(value) {
            movieEditBtnPanel.onAddMusicClickListener = value
        }

    var onEditMusicClickListener: OnClickListener? = null
        set(value) {
            movieEditBtnPanel.onEditMusicClickListener = value
        }

    var onSaveMovieClickListener: OnClickListener? = null
        set(value) {
            movieEditBtnPanel.onSaveMovieClickListener = value
        }

    var onAudioTrackSelectListener: AudioTrackGroupView.OnAudioTrackSelectListener? = null
        set(value) {
            audioTrackGroupView.onAudioTrackSelectListener = value
        }

    var onAudioTrackScrollListener: AudioTrackGroupView.OnAudioTrackScrollListener? = null
        set(value) {
            audioTrackGroupView.onAudioTrackScrollListener = value
        }

    var onDeleteMusicClickListener: OnClickListener? = null
        set(value) {
            movieEditBtnPanel.onDeleteMusicClickListener = value
        }

    var onLoopSwitchChangedListener: CompoundButton.OnCheckedChangeListener? = null
        set(value) {
            movieEditBtnPanel.onLoopSwitchChangedListener = value
        }

    var musics = ArrayList<Music>()
        set(value) {
            movieEditBtnPanel.isMusicEmpty = value.isEmpty()
            audioTrackGroupView.musics = value
            if (value.isNotEmpty()) {
                audioTrackGroupView.visibility = View.VISIBLE
            } else {
                audioTrackGroupView.visibility = View.GONE
            }
        }

    var isLoop = false
        set(value) {
            audioTrackGroupView.isLoop = value
        }

    var isBtnPanelEnable = true
        set(value) {
            movieEditBtnPanel.isEnable = value
        }

    constructor(context: Context) : super(context) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
        initView()
    }

    private fun initView() {
        LayoutInflater.from(context).inflate(R.layout.movie_edit_view, this)
    }
}