//import db from '../lib/database.js'

let handler = async (m, { conn, usedPrefix, command, args, isOwner, isAdmin, isROwner }) => {
	

  let isEnable = /true|enable|(turn)?on|1/i.test(command)
  let chat = global.db.data.chats[m.chat]
  let user = global.db.data.users[m.sender]
  let bot = global.db.data.settings[conn.user.jid] || {}
  let type = (args[0] || '').toLowerCase()
  let isAll = false, isUser = false
  switch (type) {
    case 'welcome':
      if (!m.isGroup) {
        if (!isOwner) {
          global.dfail('group', m, conn)
          throw false
        }
      } else if (!isAdmin) {
        global.dfail('admin', m, conn)
        throw false
      }
      chat.welcome = isEnable
      break
     case 'jarvis':
     case 'autotalk':
      if (m.isGroup) {
        if (!(isAdmin || isOwner)) {
          global.dfail('admin', m, conn)
           throw false
          }}
      chat.jarvis = isEnable
     break
	case 'pmblocker':
	case 'pbm':
isAll = true
if (!isROwner) {
global.dfail('rowner', m, conn)
throw false
}
bot.pmblocker = isEnable
break	  
case 'autobio':
  isAll = true
  if (!isROwner) {
  global.dfail('rowner', m, conn)
  throw false
  }
  bot.autoBio = isEnable
  break	 
      case 'detect':
      case 'detector':
        if (!m.isGroup) {
         if (!isOwner) {
           global.dfail('group', m, conn)
          throw false
        }
       } else if (!isAdmin) {
         global.dfail('admin', m, conn)
         throw false
       }
       chat.detect = isEnable
     break
      case 'autosticker':
      if (m.isGroup) {
        if (!(isAdmin || isOwner)) {
          global.dfail('admin', m, conn)
          throw false
        }
      }
      chat.autosticker = isEnable
      break
      case 'antispam':
      if (m.isGroup) {
        if (!(isAdmin || isOwner)) {
          global.dfail('admin', m, conn)
          throw false
        }
      }
      chat.antiSpam = isEnable
      break
    case 'antidelete':
    case 'delete':
      if (m.isGroup) {
        if (!(isAdmin || isOwner)) {
          global.dfail('admin', m, conn)
          throw false
        }
      }
      chat.delete = !isEnable
      break
      case 'antitoxic':
    case 'antibadword':
      if (m.isGroup) {
        if (!(isAdmin || isOwner)) {
          global.dfail('admin', m, conn)
          throw false
        }
      }
      chat.antiToxic = isEnable
      break

    case 'document':
    case 'documento':
    if (m.isGroup) {
        if (!(isAdmin || isOwner)) return dfail('admin', m, conn)
      }
    chat.useDocument = isEnable
    break
    case 'autostatus':
      isAll = true
      if (!isROwner) {
        global.dfail('rowner', m, conn)
        throw false
      }
      chat.viewStory = isEnable
      break

    case 'antilink':
    case 'antilinkwa':
    case 'antilinkwha':
      if (m.isGroup) {
        if (!(isAdmin || isOwner)) {
          global.dfail('admin', m, conn)
          throw false
        }
      }
      chat.antiLink = isEnable
      break
      
      
      case 'nsfw':
      case '+18':
       if (m.isGroup) {
         if (!(isAdmin || isOwner)) {
           global.dfail('admin', m, conn)
            throw false
           }}
    chat.nsfw = isEnable          
    break

    case 'autolevelup':
    isUser = true
     user.autolevelup = isEnable
     break
     
     case 'chatbot':
      if (m.isGroup) {
        if (!(isAdmin || isOwner)) {
          global.dfail('admin', m, conn)
          throw false
        }
      }
      chat.chatbot = isEnable
      break
     
    case 'restrict':
    case 'restringir':
      isAll = true
      if (!isOwner) {
        global.dfail('owner', m, conn)
        throw false
      }
      bot.restrict = isEnable
      break
      case 'autotype':
    case 'alwaysonline':
      isAll = true
      if (!isOwner) {
        global.dfail('owner', m, conn)
        throw false
      }
      chat.autotype = isEnable
      break
      
      case 'anticall':
        case 'nocall':
          isAll = true
          if (!isOwner) {
            global.dfail('owner', m, conn)
            throw false
          }
          bot.antiCall = isEnable
          break
    case 'onlypv':
    case 'onlydm':
    case 'onlymd':
    case 'solopv':
      isAll = true
      if (!isROwner) {
        global.dfail('rowner', m, conn)
        throw false
      }
      global.opts['pconly'] = isEnable
      break
      
    case 'gponly':
    case 'onlygp':
    case 'grouponly':
    case 'sologp':
    case 'sologrupo':
      isAll = true
      if (!isROwner) {
        global.dfail('rowner', m, conn)
        throw false
      }
      global.opts['gconly'] = isEnable
      break
      
    default:
     if (!/[01]/.test(command)) return m.reply(`
â•­â”�âŠ±âŠ±âŠ±ã€Ž *ðŸª©á´�É´/á´�Ò“Ò“ á´�á´‡É´á´œðŸª©* ã€�âŠ±âŠ±âŠ±â”�â•®

â•­â”�â”�â”�â”�âŠ±ã€Ž *á´�á´¡É´á´‡Ê€*ã€�âŠ±â”�â”�â”�â”�â•®
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´˜á´�Ê™ÊŸá´�á´„á´‹á´‡Ê€
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´�É´ÊŸÊ�á´…á´�
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ É¢Ê€á´�á´œá´˜á´�É´ÊŸÊ�
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´€á´œá´›á´�á´›Ê�á´˜á´‡
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´€á´œá´›á´�Ê™Éªá´�
â•°â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â•¯
â•­â”�â”�â”�â”�âŠ±ã€Ž *Aá´…á´�ÉªÉ´*ã€�âŠ±â”�â”�â”�â”�â•®
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´¡á´‡ÊŸá´„á´�á´�á´‡
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´€É´á´›ÉªÊŸÉªÉ´á´‹
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´€á´œá´›á´�sá´›Éªá´„á´‹á´‡Ê€
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´…á´‡á´›á´‡á´„á´›
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´Šá´€Ê€á´ Éªs
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´€É´á´›Éªsá´˜á´€á´�
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´€É´á´›Éªá´›á´�xÉªá´„
â•°â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â•¯
â•­â”�â”�â”�â”�âŠ±ã€Ž *á´œsá´‡Ê€s*ã€�âŠ±â”�â”�â”�â”�â•®
â”‚â›Š ${usedPrefix}á´�É´/á´�Ò“Ò“ á´„Êœá´€á´›Ê™á´�á´› 
â•°â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â•¯
*ðŸ”»Exá´€á´�á´˜ÊŸá´‡ðŸ”» :*
*${usedPrefix}á´�É´* á´¡á´‡ÊŸá´„á´�á´�á´‡
*${usedPrefix}á´�Ò“Ò“* á´¡á´‡ÊŸá´„á´�á´�á´‡
`)
      throw false
  }

m.reply(`âœ… *${type}* ð�™·ð�šŠð�šœ ð�š‹ð�šŽð�šŽð�š— *${isEnable ? 'ð�™°ð�šŒð�š�ð�š’ð�šŸð�šŠð�š�ð�šŽð�š�' : 'ð�™³ð�šŽð�šŠð�šŒð�š�ð�š’ð�šŸð�šŠð�š�ð�šŽð�š�'}* ${isAll ? 'ð�™µð�š˜ð�š› ð�š�ð�š‘ð�š’ð�šœ ð�™¶ð�š›ð�š˜ð�šžð�š™' : isUser ? '' : 'ð�™µð�š˜ð�š› ð�š�ð�š‘ð�š’ð�šœ ð�™²ð�š‘ð�šŠð�š�'}
`.trim()) 

}
handler.help = ['en', 'dis'].map(v => v + 'able <option>')
handler.tags = ['config']
handler.command = /^((en|dis)able|(turn)?o(n|ff)|[01])$/i

export default handler
