import { Injectable } from '@angular/core';
import { ToastrService, IndividualConfig } from 'ngx-toastr';
import { Router } from '@angular/router';
import { Subject, BehaviorSubject } from 'rxjs';
import { DashboardService } from './dashboard.service';
import { environment } from 'src/environments/environment';
export enum MARKET_STATUS { Open = 1, InActive = 2, Suspended = 3, Closed = 4, Settled = 5, InPlay = 6, BallStart = 9, ReSetSession = 10 }
export enum WITHDRAWAL_STATUS { Pandding = 1, Approved = 2, Declined = 3 }
export enum WITHDRAWAL_TYPE { Bank = 1, Paytm = 2 }
export enum SITE_PERMISSION_CODE {
export enum APIStautusCode { Success = 0, Warning = 1, Error = 2, Info = 3 }
export class SharedService {
getChipSettings: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
isClientsSideRegistrationAllow: boolean;
isWithdrawalAllow: boolean;
liabilityDetail: any = [];
sitePermissionForUser: number;
refreshMarketPage: Subject<any> = new Subject<any>();
getNewUserCaptcha: Subject<any> = new Subject<any>();
onGetNewUserCaptcha: Subject<any> = new Subject<any>();
sitePermissionForWeb: number;
BottomWidePoster: string,
RightSideTopVerticalPoster: string,
RightSideBottomVerticalPoster: string,
RightSideTopVerticalPoster: '',
RightSideBottomVerticalPoster: ''
reCaptchaUserKey: string;
private userProfileInfo: any;
private toastr: ToastrService,
private dashboardService: DashboardService
this.isOnline = navigator.onLine;
getCaptcha(event = null) {
const loggedInUser = localStorage.getItem('loggedInUser');
return JSON.parse(atob(loggedInUser));
localStorage.removeItem('loggedInUser');
if (this.router.url != '/') {
this.router.navigate(['/']);
if (this.router.url != '/') {
this.router.navigate(['/']);
if (this.newsData.filter(x => x.NewsTitle).length > 0) {
const newsDataList = localStorage.getItem(btoa('newsData'));
this.newsData = newsDataList ? JSON.parse(atob(newsDataList)) : [];
if (this.userProfileInfo) {
return this.userProfileInfo;
const userProfile = localStorage.getItem(btoa('userProfileInfo'));
this.userProfileInfo = userProfile ? JSON.parse(atob(userProfile)) : [];
return this.userProfileInfo;
set profileDetail(value) {
this.userProfileInfo = value;
getBalanceAndLiability(UserId) {
this.dashboardService.getBalanceAndLiability(UserId).subscribe(({ RunningBalance, Liability, Status }) => {
if (Status && Status.code == 0) {
this.balance = RunningBalance;
this.liabilityDetail = Liability;
if (this.liabilityDetail && this.liabilityDetail.length > 0) {
this.liabilityDetail.map(e => e.Liability).reduce((prev, next) => prev + next, 0);
this.router.navigateByUrl('/');
this.dashboardService.getMenuDetails().subscribe(data => {
if (data && data.Status && data.Status.code === 0) {
this.menuItem = data.Menu;
localStorage.setItem('MenuItem', btoa(JSON.stringify(this.menuItem)));
this.SiteData = data.SiteData;
const adsPosterJson = this.SiteData ? this.SiteData.AdsPosterJson : '[]';
const adsPosterArray = adsPosterJson ? JSON.parse(adsPosterJson) : [];
const objTopWidePoster = adsPosterArray.find(item => String(item.Key).toLowerCase() == 'topwideposter');
this.adsPosterUrls.TopWidePoster = objTopWidePoster ? objTopWidePoster.Value : '';
const objBottomWidePoster = adsPosterArray.find(item => String(item.Key).toLowerCase() == 'bottomwideposter');
this.adsPosterUrls.BottomWidePoster = objBottomWidePoster ? objBottomWidePoster.Value : '';
const objRightSideTopVerticalPoster = adsPosterArray.find(item => String(item.Key).toLowerCase() == 'rightsidetopverticalposter');
this.adsPosterUrls.RightSideTopVerticalPoster += objRightSideTopVerticalPoster ? objRightSideTopVerticalPoster.Value : '';
const objRightSideBottomVerticalPoster = adsPosterArray.find(item => String(item.Key).toLowerCase() == 'rightsidebottomverticalposter');
this.adsPosterUrls.RightSideBottomVerticalPoster = objRightSideBottomVerticalPoster ? objRightSideBottomVerticalPoster.Value : '';
localStorage.setItem('SiteData', btoa(JSON.stringify(this.SiteData)));
this.showToastr(2, data.Status.returnMessage);
getAuthorizationToken() {
let loggedInUser: any = localStorage.getItem('loggedInUser');
loggedInUser = JSON.parse(atob(loggedInUser));
return loggedInUser.AuthToken;
localStorage.removeItem('loggedInUser');
if (this.router.url != '/') {
this.router.navigate(['/']);
if (this.router.url != '/') {
this.router.navigate(['/']);
const token = localStorage.getItem(btoa('BetToken'));
showToastr(responseCode: APIStautusCode, message: string, enableHtml: boolean = false, timeOut: number = 5000) {
const toastSetting: Partial<IndividualConfig> = {
if (responseCode === 0) {
this.toastr.success(message, 'Success', toastSetting);
} else if (responseCode === 1) {
this.toastr.warning(message, 'Warning', toastSetting);
} else if (responseCode === 2) {
this.toastr.error(message, 'Error', toastSetting);
} else if (responseCode === 3) {
this.toastr.info(message, 'Info', toastSetting);
this.toastr.error(message, 'Error', toastSetting);
if ((!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode === 8)))) {
checkDecimalNumber(event) {
const regex: RegExp = new RegExp(/^\d*\.?\d{0,2}$/g);
const specialKeys: Array<string> = ['Backspace', 'Tab', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'Del', 'Delete'];
if (specialKeys.indexOf(event.key) !== -1) {
const current: string = event.currentTarget.value;
const position = event.currentTarget.selectionStart;
const next: string = [current.slice(0, position), event.key == 'Decimal' ? '.' : event.key, current.slice(position)].join('');
if (next && !String(next).match(regex)) {
checkTextFormat(val: string) {
const TextReg = /^[a-zA-Z ]*$/g;
if (!TextReg.test(val)) {
isNumber(mobileNumber: any) {
const mobile = /^[0-9]*$/g;
return mobile.test(mobileNumber);
return arr.reduce((rv, x) => {
(rv[x[key]] = rv[x[key]] || []).push(x);
getDefaultChipSetting() {
{ name: '50', value: '50' },
{ name: '100', value: '100' },
{ name: '250', value: '250' },
{ name: '500', value: '500' },
{ name: '1000', value: '1000' },
{ name: '5000', value: '5000' },
CheckEmailFormat(Email: string) {
if (!Email || Email === '') {
this.showToastr(1, 'Please enter email');
const EmailReg = /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/g;
if (!EmailReg.test(Email)) {
this.showToastr(1, 'Please enter valid email');
getMarketStatusNameById(id) {
case MARKET_STATUS.InActive:
case MARKET_STATUS.Suspended:
case MARKET_STATUS.Closed:
case MARKET_STATUS.Settled:
case MARKET_STATUS.InPlay:
case MARKET_STATUS.BallStart:
case MARKET_STATUS.ReSetSession:
return 'Reseting Session';