import { useWeAppAuthStore } from '@/common'
import { getApiLoading } from '@/common/libraries/apiLoading'
import { Apis } from '@/gen/Apis'
import useModel from './model'
const auth = useWeAppAuthStore()

const getList = () => {
  getApiLoading(Apis.Attendance.AttendanceSchedules.GetAttendanceSchedules, {}).then(res => {
    useModel.showData.value = res?.data || undefined
  })
}

export default {
  getList,
  loadMore(res: any) {
    useModel.formData.value.page = res?.page
    getList()
  },
  async uploadMedia(data: any) {
    let res = await Apis.Customer.CustomerMoments.UploadMedia(data)
    return res?.data
  },
  calculationCurrent(res: any) {
    if (res?.checkin_status?.start?.checked && res?.checkin_status?.end?.checked) {
      return 3
    }
    if (res?.checkin_status?.start?.checked) {
      return 1
    }
    return null
  },
  toDetaile(res: any) {
    uni.navigateTo({
      url: `/ME/attendance/sign_clock_in/index?attendance_schedules_id=${useModel?.showData?.value?.schedule_id}&attendance_shift_periods_id=${res?.id}&checkin_type=${res?.type}&date=${useModel?.showData?.value?.schedule_date}`
    })
  }
}
