import{t as e}from"./http-BrugN6o-.js";import{n as t,t as n}from"./notification-BM55Quw3.js";var r=(r=!1)=>{let a=r?window.pinia.defineStore:t,{global:o}=window.i18n;return a(`auth`,{state:()=>({status:``,loginData:{email:``,password:``,remember:``}}),actions:{login(t){return new Promise((n,r)=>{e.get(`/sanctum/csrf-cookie`).then(a=>{a&&e.post(`/login`,t).then(e=>{n(e),setTimeout(()=>{this.loginData.email=``,this.loginData.password=``},1e3)}).catch(e=>{i(e),r(e)})})})},logout(){return new Promise((t,r)=>{e.post(`/auth/logout`).then(async r=>{n().showNotification({type:`success`,message:`Logged out successfully.`}),window.Ls.remove(`auth.token`),window.Ls.remove(`selectedCompany`),await e.get(`/sanctum/csrf-cookie`).catch(()=>{}),window.router.push(`/login`),t(r)}).catch(t=>{i(t),window.Ls.remove(`auth.token`),window.Ls.remove(`selectedCompany`),e.get(`/sanctum/csrf-cookie`).catch(()=>{}),window.router.push(`/login`),r(t)})})}}})()},i=e=>{let t=r(),i=n();if(!e.response)i.showNotification({type:`error`,message:`Please check your internet connection or wait until servers are back online.`});else if(e.response.data&&(e.response.statusText===`Unauthorized`||e.response.data===` Unauthorized.`))o(e.response.data.message?e.response.data.message:`Unauthorized`),t.logout();else if(e.response.data.errors){let t=JSON.parse(JSON.stringify(e.response.data.errors));for(let e in t)a(t[e][0])}else e.response.data.error?typeof e.response.data.error==`boolean`?a(e.response.data?.message):a(e.response.data.error):a(e.response.data.message)},a=e=>{switch(e){case`These credentials do not match our records.`:o(`errors.login_invalid_credentials`);break;case`invalid_key`:o(`errors.invalid_provider_key`);break;case`This feature is available on Starter plan and onwards!`:o(`errors.starter_plan`);break;case`taxes_attached`:o(`settings.tax_types.already_in_use`);break;case`expense_attached`:o(`settings.expense_category.already_in_use`);break;case`payments_attached`:o(`settings.payment_modes.payments_attached`);break;case`expenses_attached`:o(`settings.payment_modes.expenses_attached`);break;case`role_attached_to_users`:o(`settings.roles.already_in_use`);break;case`items_attached`:o(`settings.customization.items.already_in_use`);break;case`payment_attached_message`:o(`invoices.payment_attached_message`);break;case`The email has already been taken.`:o(`validation.email_already_taken`);break;case`Relation estimateItems exists.`:o(`items.item_attached_message`);break;case`Relation invoiceItems exists.`:o(`items.item_attached_message`);break;case`Relation taxes exists.`:o(`settings.tax_types.already_in_use`);break;case`Relation taxes exists.`:o(`settings.tax_types.already_in_use`);break;case`Relation payments exists.`:o(`errors.payment_attached`);break;case`The estimate number has already been taken.`:o(`errors.estimate_number_used`);break;case`The payment number has already been taken.`:o(`errors.estimate_number_used`);break;case`The invoice number has already been taken.`:o(`errors.invoice_number_used`);break;case`The name has already been taken.`:o(`errors.name_already_taken`);break;case`total_invoice_amount_must_be_more_than_paid_amount`:o(`invoices.invalid_due_amount_message`);break;case`you_cannot_edit_currency`:o(`customers.edit_currency_not_allowed`);break;case`receipt_does_not_exist`:o(`errors.receipt_does_not_exist`);break;case`customer_cannot_be_changed_after_payment_is_added`:o(`errors.customer_cannot_be_changed_after_payment_is_added`);break;case`invalid_credentials`:o(`errors.invalid_credentials`);break;case`not_allowed`:o(`errors.not_allowed`);break;case`invalid_key`:o(`errors.invalid_key`);break;case`invalid_state`:o(`errors.invalid_state`);break;case`invalid_city`:o(`errors.invalid_city`);break;case`invalid_postal_code`:o(`errors.invalid_postal_code`);break;case`invalid_format`:o(`errors.invalid_format`);break;case`api_error`:o(`errors.api_error`);break;case`feature_not_enabled`:o(`errors.feature_not_enabled`);break;case`request_limit_met`:o(`errors.request_limit_met`);break;case`address_incomplete`:o(`errors.address_incomplete`);break;case`invalid_address`:o(`errors.invalid_address`);break;case`Email could not be sent to this email address.`:o(`errors.email_could_not_be_sent`);break;default:o(e,!1);break}},o=(e,t=!0)=>{let{global:r}=window.i18n;n().showNotification({type:`error`,message:t?r.t(e):e})};export{r as n,i as t};