function r(_0x1d2b45, _0x345f3c, _0x5637f2) {
  chrome.tabs.query({
    url: _0x1d2b45
  }, function (_0x320165) {
    if (_0x320165.length > 0) {
      _0x320165.forEach(_0xf2c61f => {
        chrome.tabs.sendMessage(_0xf2c61f.id, {
          action: _0x345f3c,
          dados: _0x5637f2
        });
      });
    }
  });
}
async function h(_0x16ee58) {
  return new Promise((_0x56c9f8, _0x3749e3) => {
    chrome.storage.local.get([_0x16ee58], function (_0x20825c) {
      if (_0x20825c[_0x16ee58] === undefined) {
        _0x3749e3();
      } else {
        _0x56c9f8(_0x20825c[_0x16ee58]);
      }
    });
  });
}
function d(_0x5851d6) {
  const _0x2fb7bf = new Date(_0x5851d6);
  const _0x228bd7 = new Date();
  const _0x4a7445 = _0x2fb7bf.getTime() - _0x228bd7.getTime();
  return _0x4a7445 <= 120000 || _0x4a7445 < 0;
}
async function w() {
  const _0x1c7ffd = await h("notifications");
  const _0x2092bf = [];
  const _0x2802db = [];
  let _0x47af20 = 0;
  for (let _0x10f96b of _0x1c7ffd) {
    if (!_0x10f96b.timeOut && d(_0x10f96b.date + "T" + _0x10f96b.time)) {
      _0x10f96b.timeOut = true;
      _0x2802db.push(_0x10f96b);
    }
    if (_0x10f96b.timeOut && !_0x10f96b.read) {
      _0x47af20++;
    }
    _0x2092bf.push(_0x10f96b);
  }
  r("https://web.whatsapp.com/*", "Update_Notificação", {
    update: _0x2092bf,
    dispart: _0x2802db,
    tam: _0x47af20
  });
}
const f = {
  name: "watidy",
  version: "4.3.25",
  cript_key: "ffce211a-7b07-4d91-ba5d-c40bb4034a83",
  backend_plugin: "https://wacrmext.in/",
  backend: "https://xx.xxyz.be/",
  backend_utils: "https://xx.xxyz.be/",
  webSocket: {
    "multi-atendimento": "https://multi-atendimento.wascript.com.br",
    "api-whatsapp": "https://api-whatsapp.wascript.com.br"
  },
  painel_cliente: "https://datazoomtrade.com",
  audio_transcriber: "https://xx.xxyz.be/transcription",
  domSelector: "https://xx.xxyz.be/api/domSelector",
  midiaLimit: 50
};
async function b() {
  try {
    const _0x1fa6ac = await (await fetch(f.domSelector)).json();
    if (typeof _0x1fa6ac == "object" && typeof _0x1fa6ac.version == "string") {
      r("https://web.whatsapp.com/*", "Update_DomSelector", {
        version: _0x1fa6ac.version
      });
    }
  } catch (_0x16cbfc) {
    console.error("Error ao tentar Capturar o Dom Selector virtual", _0x16cbfc);
  }
}
function c() {
  chrome.alarms.get("One_Minute", _0x279f14 => {
    if (!_0x279f14) {
      chrome.alarms.create("One_Minute", {
        periodInMinutes: 1
      });
    }
  });
  chrome.alarms.get("Five_Minutes", _0x5bca26 => {
    if (!_0x5bca26) {
      chrome.alarms.create("Five_Minutes", {
        periodInMinutes: 5
      });
    }
  });
  chrome.alarms.get("Ten_Minutes", _0x45c03d => {
    if (!_0x45c03d) {
      chrome.alarms.create("Ten_Minutes", {
        periodInMinutes: 10
      });
    }
  });
  chrome.alarms.get("Thirty_Minutes", _0x2a6a31 => {
    if (!_0x2a6a31) {
      chrome.alarms.create("Thirty_Minutes", {
        periodInMinutes: 30
      });
    }
  });
}
chrome.alarms.onAlarm.addListener(_0x314be0 => {
  switch (_0x314be0.name) {
    case "One_Minute":
      r("https://web.whatsapp.com/*", "Update_Agendamento", {});
      r("https://web.whatsapp.com/*", "Update_Status", {});
      r("https://web.whatsapp.com/*", "Update_BackupAutomatico", {});
      r("https://web.whatsapp.com/*", "Update_MeetAoVivo", {});
      w();
      break;
    case "Five_Minutes":
      r("https://web.whatsapp.com/*", "license_update", {});
      r("https://web.whatsapp.com/*", "dispatch_timing_follow", {});
      break;
    case "Ten_Minutes":
      b();
      break;
    case "Thirty_Minutes":
      r("https://web.whatsapp.com/*", "Remote-Notificacao", {});
      r("https://web.whatsapp.com/*", "license_free_update", {});
      break;
    case "keepAwake":
      chrome.runtime.getPlatformInfo();
      break;
  }
});
const g = () => {
  const _0x59f52c = new Date();
  _0x59f52c.setDate(_0x59f52c.getDate() + 1);
  const _0x1977e6 = _0x59f52c.getFullYear();
  const _0x4a8b3a = String(_0x59f52c.getMonth() + 1).padStart(2, "0");
  const _0xcbd627 = String(_0x59f52c.getDate()).padStart(2, "0");
  return _0x1977e6 + "-" + _0x4a8b3a + "-" + _0xcbd627;
};
const _ = {
  date: g(),
  items: ["respostasRapidas", "respostasRapidasAcao", "categoria", "agendamentos", "agendamentosNaoDisparados", "sendAfterWhatsAppOpens", "crm", "contatos", "notes", "notifications", "perfil", "userTabs", "agrupamentos", "relatorio", "encomendas", "autoatendimento", "webhook", "IA", "status", "pinChat", "atendimento", "backupAutomatico", "whatsApi", "replacementStorage", "FollowUp", "fluxo"],
  recurrency: "diario",
  time: "10:30"
};
async function k() {
  chrome.storage.local.get(null, _0x4a34d7 => {
    chrome.storage.local.set({
      agendamentos: _0x4a34d7.agendamentos || [],
      agendamentosNaoDisparados: _0x4a34d7.agendamentosNaoDisparados || [],
      sendAfterWhatsAppOpens: _0x4a34d7.sendAfterWhatsAppOpens || !1,
      notifications: _0x4a34d7.notifications || [],
      userTabs: _0x4a34d7.userTabs || [],
      contatos: _0x4a34d7.contatos || [],
      notes: _0x4a34d7.notes || [],
      agendaMsg: _0x4a34d7.agendaMsg || [],
      perfil: _0x4a34d7.perfil || [],
      categoria: _0x4a34d7.categoria || [],
      initSystem: _0x4a34d7.initSystem || !1,
      backupAutomatico: _0x4a34d7.backupAutomatico || _,
      crm: _0x4a34d7.crm || [],
      fluxo: _0x4a34d7.fluxo || {
        workflows: [],
        currentWorkflow: null
      },
      fluxoFiles: _0x4a34d7.fluxoFiles || [],
      relatorio: _0x4a34d7.relatorio || [],
      encomendas: _0x4a34d7.encomendas || [],
      autoatendimento: _0x4a34d7.autoatendimento || [],
      FollowUp: _0x4a34d7.FollowUp || [],
      webhook: _0x4a34d7.webhook || [],
      IA: _0x4a34d7.IA || {
        activeIA: "Gemini",
        keyGemini: "",
        keyGPT: "",
        keyGroq: "",
        instance: null
      },
      status: _0x4a34d7.status || [],
      pinChat: _0x4a34d7.pinChat || [],
      atendimento: _0x4a34d7.atendimento || undefined,
      whatsApi: _0x4a34d7.whatsApi || {
        active: !1,
        token: "",
        userID: ""
      },
      replacementStorage: _0x4a34d7.replacementStorage || {
        items: [],
        isEnabled: !0
      },
      initDate: _0x4a34d7.initDate || !1,
      modalLead: _0x4a34d7.modalLead || {},
      agrupamentos: _0x4a34d7.agrupamentos || [],
      groupments: _0x4a34d7.groupments || [],
      guardaMsg: _0x4a34d7.guardaMsg || [],
      medias: _0x4a34d7.medias || [],
      respostasRapidas: _0x4a34d7.respostasRapidas || [],
      respostasRapidasAcao: _0x4a34d7.respostasRapidasAcao || []
    });
  });
}
function l() {
  chrome.tabs.query({
    url: "https://web.whatsapp.com/*"
  }, function (_0x5134df) {
    if (_0x5134df.length > 0 && _0x5134df[0].id !== undefined) {
      chrome.tabs.reload(_0x5134df[0].id);
    } else {
      chrome.tabs.create({
        url: "https://web.whatsapp.com"
      });
    }
  });
}
function M() {
  chrome.runtime.setUninstallURL("https://datazoomtrade.com");
}
function A(_0x11185c) {
  if (_0x11185c.reason === "install") {
    fetch("https://web.whatsapp.com").then(_0xad866e => {
      if (!_0xad866e.ok) {
        throw new Error("Erro na requisição: " + _0xad866e.status);
      }
      return _0xad866e.json();
    }).then(_0x11e243 => {
      if (_0x11e243.success) {
        chrome.tabs.create({
          url: _0x11e243.url
        });
      }
    }).catch(_0x44c8ab => {
      console.error("Erro ao fazer a requisição:", _0x44c8ab);
    });
  }
}
function n(_0x57b3c7) {
  const _0x22b628 = chrome.runtime.getURL(_0x57b3c7 + "/src/index.html");
  chrome.tabs.query({
    url: _0x22b628
  }, function (_0x3db37d) {
    if (_0x3db37d.length > 0) {
      _0x3db37d.forEach(_0x2c15f5 => {
        if (_0x2c15f5.id !== undefined) {
          chrome.tabs.remove(_0x2c15f5.id);
        }
      });
    }
    chrome.tabs.create({
      url: _0x22b628
    });
  });
}
const i = new Map();
const m = (_0x5d0b0d, _0x56332b, _0x153b8a) => {
  if (_0x153b8a.url) {
    i.set(_0x5d0b0d, _0x153b8a.url);
  }
};
const u = _0x42cd49 => {
  const _0x55abf6 = i.get(_0x42cd49);
  i.delete(_0x42cd49);
  if (_0x55abf6 && _0x55abf6.includes("https://web.whatsapp")) {
    chrome.runtime.sendMessage({
      action: "whatsIsClosed"
    });
  }
};
const p = () => {
  try {
    chrome.tabs.onUpdated.removeListener(m);
    chrome.tabs.onRemoved.removeListener(u);
  } catch (_0x1b1112) {
    console.error("erro ao remover os ouvintes do WhatsIsOpen", _0x1b1112);
  } finally {
    chrome.tabs.onUpdated.addListener(m);
    chrome.tabs.onRemoved.addListener(u);
  }
};
const v = () => {
  fetch("https://xx.xxyz.be/api/urls/active-notes/" + chrome.runtime.id).then(_0xf2599 => {
    if (!_0xf2599.ok) {
      throw new Error("Erro na requisição: " + _0xf2599.status);
    }
    return _0xf2599.json();
  }).then(_0x49fa65 => {
    if (_0x49fa65.success && _0x49fa65.path_note_update.redirect) {
      chrome.tabs.create({
        url: "https://xx.xxyz.be/api/urls/notes/" + chrome.runtime.id
      });
    }
  }).catch(_0x2661d0 => {
    console.error("Erro ao fazer a requisição:", _0x2661d0);
  });
};
const y = () => {
  chrome.runtime.onMessageExternal.addListener(async (_0x50e2f8, _0x52f021, _0x15dcab) => {
    switch (_0x50e2f8.action) {
      case "is_instaled":
        _0x15dcab({
          success: !0
        });
        break;
      case "user_auth":
        r("https://web.whatsapp.com/*", "user_auth_callback", {
          bearer_token: _0x50e2f8.bearer_token
        });
        chrome.tabs.query({
          url: "https://web.whatsapp.com/*"
        }, _0x40e488 => {
          if (_0x40e488 && _0x40e488.length > 0) {
            const _0x9f94ca = _0x40e488[0];
            chrome.windows.update(_0x9f94ca.windowId, {
              focused: !0
            });
            chrome.tabs.update(_0x9f94ca.id, {
              active: !0
            });
          }
        });
        if (_0x50e2f8.close_painel && _0x52f021.tab && _0x52f021.tab.id) {
          setTimeout(() => {
            chrome.tabs.remove(_0x52f021.tab.id);
          }, 100);
        }
        break;
      case "open_whatsapp":
        await chrome.storage.local.set({
          redirect_painel: {
            bearer: _0x50e2f8.bearer,
            timer: Math.floor(Date.now() / 60000)
          }
        });
        chrome.tabs.query({
          url: "https://web.whatsapp.com/*"
        }, _0x3f6dfc => {
          if (_0x3f6dfc && _0x3f6dfc.length > 0) {
            const _0x403749 = _0x3f6dfc[0];
            chrome.windows.update(_0x403749.windowId, {
              focused: !0
            });
            chrome.tabs.update(_0x403749.id, {
              active: !0
            });
            r("https://web.whatsapp.com/*", "redirect_painel", {});
          } else {
            chrome.tabs.create({
              url: "https://web.whatsapp.com/"
            });
          }
        });
        break;
    }
    return !0;
  });
};
y();
c();
p();
chrome.action.onClicked.addListener(() => {
  c();
  p();
  l();
});
chrome.runtime.onInstalled.addListener(async function (_0x1ac835) {
  A(_0x1ac835);
  l();
  c();
  k();
  p();
  M();
  if (_0x1ac835.reason === "update") {
    v();
  }
});
chrome.runtime.onMessage.addListener((_0x4cc1af, _0x3938da, _0x55f09f) => {
  switch (_0x4cc1af.message) {
    case "CRM":
      n("crm");
      break;
    case "FLOW":
      n("fluxo");
      break;
    case "funnil":
      n("funnil");
      break;
    case "promotional":
      chrome.tabs.create({
        url: _0x4cc1af.path
      });
      break;
  }
});