Plugin Directory

Changeset 3195461


Ignore:
Timestamp:
11/23/2024 11:33:08 AM (16 months ago)
Author:
melioze
Message:

new version 1.4.4

Location:
my-easy-compta
Files:
793 added
4 edited

Legend:

Unmodified
Added
Removed
  • my-easy-compta/trunk/assets/dist/index.min.js

    r3195036 r3195461  
    1 import{_ as ne,o as h,c as m,n as I,a as r,t as d,g,w as K,i as D,k as W,F,r as L,p as ri,l as C,j as ue,v as ai,s as li,u as Ct,q as ci,x as di,y as eo,z as ui,A as Rt,B as je,h as to,C as Cn,D as hi,E as mi,d as N,e as P,m as me,G as no,H as fi}from"./plugin-vue_export-helper.min.js";import{C as Ze,R as qt}from"./RemoveAlert.min.js";import{T as hn}from"./VueSearchSelect.min.js";import{V as Nt}from"./vue-datepicker.min.js";import{f as mn,c as so,a as oo,g as io,b as ro,s as ao}from"./api.min.js";import{v as mt}from"./vue3-editor.common.min.js";function lo(t,e){return function(){return t.apply(e,arguments)}}const{toString:pi}=Object.prototype,{getPrototypeOf:ts}=Object,fn=(t=>e=>{const s=pi.call(e);return t[s]||(t[s]=s.slice(8,-1).toLowerCase())})(Object.create(null)),De=t=>(t=t.toLowerCase(),e=>fn(e)===t),pn=t=>e=>typeof e===t,{isArray:ft}=Array,jt=pn("undefined");function _i(t){return t!==null&&!jt(t)&&t.constructor!==null&&!jt(t.constructor)&&xe(t.constructor.isBuffer)&&t.constructor.isBuffer(t)}const co=De("ArrayBuffer");function gi(t){let e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&co(t.buffer),e}const yi=pn("string"),xe=pn("function"),uo=pn("number"),_n=t=>t!==null&&typeof t=="object",bi=t=>t===!0||t===!1,Qt=t=>{if(fn(t)!=="object")return!1;const e=ts(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)},vi=De("Date"),wi=De("File"),xi=De("Blob"),Ei=De("FileList"),Ci=t=>_n(t)&&xe(t.pipe),Ti=t=>{let e;return t&&(typeof FormData=="function"&&t instanceof FormData||xe(t.append)&&((e=fn(t))==="formdata"||e==="object"&&xe(t.toString)&&t.toString()==="[object FormData]"))},Ii=De("URLSearchParams"),[ki,Si,Ai,Di]=["ReadableStream","Request","Response","Headers"].map(De),Pi=t=>t.trim?t.trim():t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Bt(t,e,{allOwnKeys:s=!1}={}){if(t===null||typeof t=="undefined")return;let i,n;if(typeof t!="object"&&(t=[t]),ft(t))for(i=0,n=t.length;i<n;i++)e.call(null,t[i],i,t);else{const o=s?Object.getOwnPropertyNames(t):Object.keys(t),a=o.length;let c;for(i=0;i<a;i++)c=o[i],e.call(null,t[c],c,t)}}function ho(t,e){e=e.toLowerCase();const s=Object.keys(t);let i=s.length,n;for(;i-- >0;)if(n=s[i],e===n.toLowerCase())return n;return null}const mo=(()=>typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:typeof window!="undefined"?window:global)(),fo=t=>!jt(t)&&t!==mo;function Un(){const{caseless:t}=fo(this)&&this||{},e={},s=(i,n)=>{const o=t&&ho(e,n)||n;Qt(e[o])&&Qt(i)?e[o]=Un(e[o],i):Qt(i)?e[o]=Un({},i):ft(i)?e[o]=i.slice():e[o]=i};for(let i=0,n=arguments.length;i<n;i++)arguments[i]&&Bt(arguments[i],s);return e}const Ri=(t,e,s,{allOwnKeys:i}={})=>(Bt(e,(n,o)=>{s&&xe(n)?t[o]=lo(n,s):t[o]=n},{allOwnKeys:i}),t),ji=t=>(t.charCodeAt(0)===65279&&(t=t.slice(1)),t),Oi=(t,e,s,i)=>{t.prototype=Object.create(e.prototype,i),t.prototype.constructor=t,Object.defineProperty(t,"super",{value:e.prototype}),s&&Object.assign(t.prototype,s)},Mi=(t,e,s,i)=>{let n,o,a;const c={};if(e=e||{},t==null)return e;do{for(n=Object.getOwnPropertyNames(t),o=n.length;o-- >0;)a=n[o],(!i||i(a,t,e))&&!c[a]&&(e[a]=t[a],c[a]=!0);t=s!==!1&&ts(t)}while(t&&(!s||s(t,e))&&t!==Object.prototype);return e},qi=(t,e,s)=>{t=String(t),(s===void 0||s>t.length)&&(s=t.length),s-=e.length;const i=t.indexOf(e,s);return i!==-1&&i===s},Ni=t=>{if(!t)return null;if(ft(t))return t;let e=t.length;if(!uo(e))return null;const s=new Array(e);for(;e-- >0;)s[e]=t[e];return s},Bi=(t=>e=>t&&e instanceof t)(typeof Uint8Array!="undefined"&&ts(Uint8Array)),Vi=(t,e)=>{const i=(t&&t[Symbol.iterator]).call(t);let n;for(;(n=i.next())&&!n.done;){const o=n.value;e.call(t,o[0],o[1])}},Fi=(t,e)=>{let s;const i=[];for(;(s=t.exec(e))!==null;)i.push(s);return i},Ui=De("HTMLFormElement"),Li=t=>t.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(s,i,n){return i.toUpperCase()+n}),ps=(({hasOwnProperty:t})=>(e,s)=>t.call(e,s))(Object.prototype),Wi=De("RegExp"),po=(t,e)=>{const s=Object.getOwnPropertyDescriptors(t),i={};Bt(s,(n,o)=>{let a;(a=e(n,o,t))!==!1&&(i[o]=a||n)}),Object.defineProperties(t,i)},Xi=t=>{po(t,(e,s)=>{if(xe(t)&&["arguments","caller","callee"].indexOf(s)!==-1)return!1;const i=t[s];if(!!xe(i)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+s+"'")})}})},Hi=(t,e)=>{const s={},i=n=>{n.forEach(o=>{s[o]=!0})};return ft(t)?i(t):i(String(t).split(e)),s},zi=()=>{},Qi=(t,e)=>t!=null&&Number.isFinite(t=+t)?t:e,Tn="abcdefghijklmnopqrstuvwxyz",_s="0123456789",_o={DIGIT:_s,ALPHA:Tn,ALPHA_DIGIT:Tn+Tn.toUpperCase()+_s},Gi=(t=16,e=_o.ALPHA_DIGIT)=>{let s="";const{length:i}=e;for(;t--;)s+=e[Math.random()*i|0];return s};function Ji(t){return!!(t&&xe(t.append)&&t[Symbol.toStringTag]==="FormData"&&t[Symbol.iterator])}const Yi=t=>{const e=new Array(10),s=(i,n)=>{if(_n(i)){if(e.indexOf(i)>=0)return;if(!("toJSON"in i)){e[n]=i;const o=ft(i)?[]:{};return Bt(i,(a,c)=>{const f=s(a,n+1);!jt(f)&&(o[c]=f)}),e[n]=void 0,o}}return i};return s(t,0)},Ki=De("AsyncFunction"),Zi=t=>t&&(_n(t)||xe(t))&&xe(t.then)&&xe(t.catch);var b={isArray:ft,isArrayBuffer:co,isBuffer:_i,isFormData:Ti,isArrayBufferView:gi,isString:yi,isNumber:uo,isBoolean:bi,isObject:_n,isPlainObject:Qt,isReadableStream:ki,isRequest:Si,isResponse:Ai,isHeaders:Di,isUndefined:jt,isDate:vi,isFile:wi,isBlob:xi,isRegExp:Wi,isFunction:xe,isStream:Ci,isURLSearchParams:Ii,isTypedArray:Bi,isFileList:Ei,forEach:Bt,merge:Un,extend:Ri,trim:Pi,stripBOM:ji,inherits:Oi,toFlatObject:Mi,kindOf:fn,kindOfTest:De,endsWith:qi,toArray:Ni,forEachEntry:Vi,matchAll:Fi,isHTMLForm:Ui,hasOwnProperty:ps,hasOwnProp:ps,reduceDescriptors:po,freezeMethods:Xi,toObjectSet:Hi,toCamelCase:Li,noop:zi,toFiniteNumber:Qi,findKey:ho,global:mo,isContextDefined:fo,ALPHABET:_o,generateString:Gi,isSpecCompliantForm:Ji,toJSONObject:Yi,isAsyncFn:Ki,isThenable:Zi};function V(t,e,s,i,n){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=t,this.name="AxiosError",e&&(this.code=e),s&&(this.config=s),i&&(this.request=i),n&&(this.response=n)}b.inherits(V,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:b.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const go=V.prototype,yo={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(t=>{yo[t]={value:t}});Object.defineProperties(V,yo);Object.defineProperty(go,"isAxiosError",{value:!0});V.from=(t,e,s,i,n,o)=>{const a=Object.create(go);return b.toFlatObject(t,a,function(f){return f!==Error.prototype},c=>c!=="isAxiosError"),V.call(a,t.message,e,s,i,n),a.cause=t,a.name=t.name,o&&Object.assign(a,o),a};var $i=null;function Ln(t){return b.isPlainObject(t)||b.isArray(t)}function bo(t){return b.endsWith(t,"[]")?t.slice(0,-2):t}function gs(t,e,s){return t?t.concat(e).map(function(n,o){return n=bo(n),!s&&o?"["+n+"]":n}).join(s?".":""):e}function er(t){return b.isArray(t)&&!t.some(Ln)}const tr=b.toFlatObject(b,{},null,function(e){return/^is[A-Z]/.test(e)});function gn(t,e,s){if(!b.isObject(t))throw new TypeError("target must be an object");e=e||new FormData,s=b.toFlatObject(s,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,R){return!b.isUndefined(R[x])});const i=s.metaTokens,n=s.visitor||l,o=s.dots,a=s.indexes,f=(s.Blob||typeof Blob!="undefined"&&Blob)&&b.isSpecCompliantForm(e);if(!b.isFunction(n))throw new TypeError("visitor must be a function");function u(v){if(v===null)return"";if(b.isDate(v))return v.toISOString();if(!f&&b.isBlob(v))throw new V("Blob is not supported. Use a Buffer instead.");return b.isArrayBuffer(v)||b.isTypedArray(v)?f&&typeof Blob=="function"?new Blob([v]):Buffer.from(v):v}function l(v,x,R){let M=v;if(v&&!R&&typeof v=="object"){if(b.endsWith(x,"{}"))x=i?x:x.slice(0,-2),v=JSON.stringify(v);else if(b.isArray(v)&&er(v)||(b.isFileList(v)||b.endsWith(x,"[]"))&&(M=b.toArray(v)))return x=bo(x),M.forEach(function(k,z){!(b.isUndefined(k)||k===null)&&e.append(a===!0?gs([x],z,o):a===null?x:x+"[]",u(k))}),!1}return Ln(v)?!0:(e.append(gs(R,x,o),u(v)),!1)}const _=[],p=Object.assign(tr,{defaultVisitor:l,convertValue:u,isVisitable:Ln});function y(v,x){if(!b.isUndefined(v)){if(_.indexOf(v)!==-1)throw Error("Circular reference detected in "+x.join("."));_.push(v),b.forEach(v,function(M,A){(!(b.isUndefined(M)||M===null)&&n.call(e,M,b.isString(A)?A.trim():A,x,p))===!0&&y(M,x?x.concat(A):[A])}),_.pop()}}if(!b.isObject(t))throw new TypeError("data must be an object");return y(t),e}function ys(t){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'()~]|%20|%00/g,function(i){return e[i]})}function ns(t,e){this._pairs=[],t&&gn(t,this,e)}const vo=ns.prototype;vo.append=function(e,s){this._pairs.push([e,s])};vo.toString=function(e){const s=e?function(i){return e.call(this,i,ys)}:ys;return this._pairs.map(function(n){return s(n[0])+"="+s(n[1])},"").join("&")};function nr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function wo(t,e,s){if(!e)return t;const i=s&&s.encode||nr,n=s&&s.serialize;let o;if(n?o=n(e,s):o=b.isURLSearchParams(e)?e.toString():new ns(e,s).toString(i),o){const a=t.indexOf("#");a!==-1&&(t=t.slice(0,a)),t+=(t.indexOf("?")===-1?"?":"&")+o}return t}class sr{constructor(){this.handlers=[]}use(e,s,i){return this.handlers.push({fulfilled:e,rejected:s,synchronous:i?i.synchronous:!1,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){b.forEach(this.handlers,function(i){i!==null&&e(i)})}}var bs=sr,xo={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},or=typeof URLSearchParams!="undefined"?URLSearchParams:ns,ir=typeof FormData!="undefined"?FormData:null,rr=typeof Blob!="undefined"?Blob:null,ar={isBrowser:!0,classes:{URLSearchParams:or,FormData:ir,Blob:rr},protocols:["http","https","file","blob","url","data"]};const ss=typeof window!="undefined"&&typeof document!="undefined",lr=(t=>ss&&["ReactNative","NativeScript","NS"].indexOf(t)<0)(typeof navigator!="undefined"&&navigator.product),cr=(()=>typeof WorkerGlobalScope!="undefined"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),dr=ss&&window.location.href||"http://localhost";var ur=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ss,hasStandardBrowserWebWorkerEnv:cr,hasStandardBrowserEnv:lr,origin:dr},Symbol.toStringTag,{value:"Module"})),ke={...ur,...ar};function hr(t,e){return gn(t,new ke.classes.URLSearchParams,Object.assign({visitor:function(s,i,n,o){return ke.isNode&&b.isBuffer(s)?(this.append(i,s.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},e))}function mr(t){return b.matchAll(/\w+|\[(\w*)]/g,t).map(e=>e[0]==="[]"?"":e[1]||e[0])}function fr(t){const e={},s=Object.keys(t);let i;const n=s.length;let o;for(i=0;i<n;i++)o=s[i],e[o]=t[o];return e}function Eo(t){function e(s,i,n,o){let a=s[o++];if(a==="__proto__")return!0;const c=Number.isFinite(+a),f=o>=s.length;return a=!a&&b.isArray(n)?n.length:a,f?(b.hasOwnProp(n,a)?n[a]=[n[a],i]:n[a]=i,!c):((!n[a]||!b.isObject(n[a]))&&(n[a]=[]),e(s,i,n[a],o)&&b.isArray(n[a])&&(n[a]=fr(n[a])),!c)}if(b.isFormData(t)&&b.isFunction(t.entries)){const s={};return b.forEachEntry(t,(i,n)=>{e(mr(i),n,s,0)}),s}return null}function pr(t,e,s){if(b.isString(t))try{return(e||JSON.parse)(t),b.trim(t)}catch(i){if(i.name!=="SyntaxError")throw i}return(s||JSON.stringify)(t)}const os={transitional:xo,adapter:["xhr","http","fetch"],transformRequest:[function(e,s){const i=s.getContentType()||"",n=i.indexOf("application/json")>-1,o=b.isObject(e);if(o&&b.isHTMLForm(e)&&(e=new FormData(e)),b.isFormData(e))return n?JSON.stringify(Eo(e)):e;if(b.isArrayBuffer(e)||b.isBuffer(e)||b.isStream(e)||b.isFile(e)||b.isBlob(e)||b.isReadableStream(e))return e;if(b.isArrayBufferView(e))return e.buffer;if(b.isURLSearchParams(e))return s.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let c;if(o){if(i.indexOf("application/x-www-form-urlencoded")>-1)return hr(e,this.formSerializer).toString();if((c=b.isFileList(e))||i.indexOf("multipart/form-data")>-1){const f=this.env&&this.env.FormData;return gn(c?{"files[]":e}:e,f&&new f,this.formSerializer)}}return o||n?(s.setContentType("application/json",!1),pr(e)):e}],transformResponse:[function(e){const s=this.transitional||os.transitional,i=s&&s.forcedJSONParsing,n=this.responseType==="json";if(b.isResponse(e)||b.isReadableStream(e))return e;if(e&&b.isString(e)&&(i&&!this.responseType||n)){const a=!(s&&s.silentJSONParsing)&&n;try{return JSON.parse(e)}catch(c){if(a)throw c.name==="SyntaxError"?V.from(c,V.ERR_BAD_RESPONSE,this,null,this.response):c}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:ke.classes.FormData,Blob:ke.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};b.forEach(["delete","get","head","post","put","patch"],t=>{os.headers[t]={}});var is=os;const _r=b.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);var gr=t=>{const e={};let s,i,n;return t&&t.split(`
    2 `).forEach(function(a){n=a.indexOf(":"),s=a.substring(0,n).trim().toLowerCase(),i=a.substring(n+1).trim(),!(!s||e[s]&&_r[s])&&(s==="set-cookie"?e[s]?e[s].push(i):e[s]=[i]:e[s]=e[s]?e[s]+", "+i:i)}),e};const vs=Symbol("internals");function bt(t){return t&&String(t).trim().toLowerCase()}function Gt(t){return t===!1||t==null?t:b.isArray(t)?t.map(Gt):String(t)}function yr(t){const e=Object.create(null),s=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let i;for(;i=s.exec(t);)e[i[1]]=i[2];return e}const br=t=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(t.trim());function In(t,e,s,i,n){if(b.isFunction(i))return i.call(this,e,s);if(n&&(e=s),!!b.isString(e)){if(b.isString(i))return e.indexOf(i)!==-1;if(b.isRegExp(i))return i.test(e)}}function vr(t){return t.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,s,i)=>s.toUpperCase()+i)}function wr(t,e){const s=b.toCamelCase(" "+e);["get","set","has"].forEach(i=>{Object.defineProperty(t,i+s,{value:function(n,o,a){return this[i].call(this,e,n,o,a)},configurable:!0})})}class yn{constructor(e){e&&this.set(e)}set(e,s,i){const n=this;function o(c,f,u){const l=bt(f);if(!l)throw new Error("header name must be a non-empty string");const _=b.findKey(n,l);(!_||n[_]===void 0||u===!0||u===void 0&&n[_]!==!1)&&(n[_||f]=Gt(c))}const a=(c,f)=>b.forEach(c,(u,l)=>o(u,l,f));if(b.isPlainObject(e)||e instanceof this.constructor)a(e,s);else if(b.isString(e)&&(e=e.trim())&&!br(e))a(gr(e),s);else if(b.isHeaders(e))for(const[c,f]of e.entries())o(f,c,i);else e!=null&&o(s,e,i);return this}get(e,s){if(e=bt(e),e){const i=b.findKey(this,e);if(i){const n=this[i];if(!s)return n;if(s===!0)return yr(n);if(b.isFunction(s))return s.call(this,n,i);if(b.isRegExp(s))return s.exec(n);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,s){if(e=bt(e),e){const i=b.findKey(this,e);return!!(i&&this[i]!==void 0&&(!s||In(this,this[i],i,s)))}return!1}delete(e,s){const i=this;let n=!1;function o(a){if(a=bt(a),a){const c=b.findKey(i,a);c&&(!s||In(i,i[c],c,s))&&(delete i[c],n=!0)}}return b.isArray(e)?e.forEach(o):o(e),n}clear(e){const s=Object.keys(this);let i=s.length,n=!1;for(;i--;){const o=s[i];(!e||In(this,this[o],o,e,!0))&&(delete this[o],n=!0)}return n}normalize(e){const s=this,i={};return b.forEach(this,(n,o)=>{const a=b.findKey(i,o);if(a){s[a]=Gt(n),delete s[o];return}const c=e?vr(o):String(o).trim();c!==o&&delete s[o],s[c]=Gt(n),i[c]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const s=Object.create(null);return b.forEach(this,(i,n)=>{i!=null&&i!==!1&&(s[n]=e&&b.isArray(i)?i.join(", "):i)}),s}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,s])=>e+": "+s).join(`
    3 `)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...s){const i=new this(e);return s.forEach(n=>i.set(n)),i}static accessor(e){const i=(this[vs]=this[vs]={accessors:{}}).accessors,n=this.prototype;function o(a){const c=bt(a);i[c]||(wr(n,a),i[c]=!0)}return b.isArray(e)?e.forEach(o):o(e),this}}yn.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);b.reduceDescriptors(yn.prototype,({value:t},e)=>{let s=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(i){this[s]=i}}});b.freezeMethods(yn);var Se=yn;function kn(t,e){const s=this||is,i=e||s,n=Se.from(i.headers);let o=i.data;return b.forEach(t,function(c){o=c.call(s,o,n.normalize(),e?e.status:void 0)}),n.normalize(),o}function Co(t){return!!(t&&t.__CANCEL__)}function pt(t,e,s){V.call(this,t==null?"canceled":t,V.ERR_CANCELED,e,s),this.name="CanceledError"}b.inherits(pt,V,{__CANCEL__:!0});function To(t,e,s){const i=s.config.validateStatus;!s.status||!i||i(s.status)?t(s):e(new V("Request failed with status code "+s.status,[V.ERR_BAD_REQUEST,V.ERR_BAD_RESPONSE][Math.floor(s.status/100)-4],s.config,s.request,s))}function xr(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}function Er(t,e){t=t||10;const s=new Array(t),i=new Array(t);let n=0,o=0,a;return e=e!==void 0?e:1e3,function(f){const u=Date.now(),l=i[o];a||(a=u),s[n]=f,i[n]=u;let _=o,p=0;for(;_!==n;)p+=s[_++],_=_%t;if(n=(n+1)%t,n===o&&(o=(o+1)%t),u-a<e)return;const y=l&&u-l;return y?Math.round(p*1e3/y):void 0}}function Cr(t,e){let s=0;const i=1e3/e;let n=null;return function(){const a=this===!0,c=Date.now();if(a||c-s>i)return n&&(clearTimeout(n),n=null),s=c,t.apply(null,arguments);n||(n=setTimeout(()=>(n=null,s=Date.now(),t.apply(null,arguments)),i-(c-s)))}}var tn=(t,e,s=3)=>{let i=0;const n=Er(50,250);return Cr(o=>{const a=o.loaded,c=o.lengthComputable?o.total:void 0,f=a-i,u=n(f),l=a<=c;i=a;const _={loaded:a,total:c,progress:c?a/c:void 0,bytes:f,rate:u||void 0,estimated:u&&c&&l?(c-a)/u:void 0,event:o,lengthComputable:c!=null};_[e?"download":"upload"]=!0,t(_)},s)},Tr=ke.hasStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),s=document.createElement("a");let i;function n(o){let a=o;return e&&(s.setAttribute("href",a),a=s.href),s.setAttribute("href",a),{href:s.href,protocol:s.protocol?s.protocol.replace(/:$/,""):"",host:s.host,search:s.search?s.search.replace(/^\?/,""):"",hash:s.hash?s.hash.replace(/^#/,""):"",hostname:s.hostname,port:s.port,pathname:s.pathname.charAt(0)==="/"?s.pathname:"/"+s.pathname}}return i=n(window.location.href),function(a){const c=b.isString(a)?n(a):a;return c.protocol===i.protocol&&c.host===i.host}}():function(){return function(){return!0}}(),Ir=ke.hasStandardBrowserEnv?{write(t,e,s,i,n,o){const a=[t+"="+encodeURIComponent(e)];b.isNumber(s)&&a.push("expires="+new Date(s).toGMTString()),b.isString(i)&&a.push("path="+i),b.isString(n)&&a.push("domain="+n),o===!0&&a.push("secure"),document.cookie=a.join("; ")},read(t){const e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove(t){this.write(t,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function kr(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}function Sr(t,e){return e?t.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):t}function Io(t,e){return t&&!kr(e)?Sr(t,e):e}const ws=t=>t instanceof Se?{...t}:t;function nt(t,e){e=e||{};const s={};function i(u,l,_){return b.isPlainObject(u)&&b.isPlainObject(l)?b.merge.call({caseless:_},u,l):b.isPlainObject(l)?b.merge({},l):b.isArray(l)?l.slice():l}function n(u,l,_){if(b.isUndefined(l)){if(!b.isUndefined(u))return i(void 0,u,_)}else return i(u,l,_)}function o(u,l){if(!b.isUndefined(l))return i(void 0,l)}function a(u,l){if(b.isUndefined(l)){if(!b.isUndefined(u))return i(void 0,u)}else return i(void 0,l)}function c(u,l,_){if(_ in e)return i(u,l);if(_ in t)return i(void 0,u)}const f={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,withXSRFToken:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:c,headers:(u,l)=>n(ws(u),ws(l),!0)};return b.forEach(Object.keys(Object.assign({},t,e)),function(l){const _=f[l]||n,p=_(t[l],e[l],l);b.isUndefined(p)&&_!==c||(s[l]=p)}),s}var ko=t=>{const e=nt({},t);let{data:s,withXSRFToken:i,xsrfHeaderName:n,xsrfCookieName:o,headers:a,auth:c}=e;e.headers=a=Se.from(a),e.url=wo(Io(e.baseURL,e.url),t.params,t.paramsSerializer),c&&a.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):"")));let f;if(b.isFormData(s)){if(ke.hasStandardBrowserEnv||ke.hasStandardBrowserWebWorkerEnv)a.setContentType(void 0);else if((f=a.getContentType())!==!1){const[u,...l]=f?f.split(";").map(_=>_.trim()).filter(Boolean):[];a.setContentType([u||"multipart/form-data",...l].join("; "))}}if(ke.hasStandardBrowserEnv&&(i&&b.isFunction(i)&&(i=i(e)),i||i!==!1&&Tr(e.url))){const u=n&&o&&Ir.read(o);u&&a.set(n,u)}return e};const Ar=typeof XMLHttpRequest!="undefined";var Dr=Ar&&function(t){return new Promise(function(s,i){const n=ko(t);let o=n.data;const a=Se.from(n.headers).normalize();let{responseType:c}=n,f;function u(){n.cancelToken&&n.cancelToken.unsubscribe(f),n.signal&&n.signal.removeEventListener("abort",f)}let l=new XMLHttpRequest;l.open(n.method.toUpperCase(),n.url,!0),l.timeout=n.timeout;function _(){if(!l)return;const y=Se.from("getAllResponseHeaders"in l&&l.getAllResponseHeaders()),x={data:!c||c==="text"||c==="json"?l.responseText:l.response,status:l.status,statusText:l.statusText,headers:y,config:t,request:l};To(function(M){s(M),u()},function(M){i(M),u()},x),l=null}"onloadend"in l?l.onloadend=_:l.onreadystatechange=function(){!l||l.readyState!==4||l.status===0&&!(l.responseURL&&l.responseURL.indexOf("file:")===0)||setTimeout(_)},l.onabort=function(){!l||(i(new V("Request aborted",V.ECONNABORTED,n,l)),l=null)},l.onerror=function(){i(new V("Network Error",V.ERR_NETWORK,n,l)),l=null},l.ontimeout=function(){let v=n.timeout?"timeout of "+n.timeout+"ms exceeded":"timeout exceeded";const x=n.transitional||xo;n.timeoutErrorMessage&&(v=n.timeoutErrorMessage),i(new V(v,x.clarifyTimeoutError?V.ETIMEDOUT:V.ECONNABORTED,n,l)),l=null},o===void 0&&a.setContentType(null),"setRequestHeader"in l&&b.forEach(a.toJSON(),function(v,x){l.setRequestHeader(x,v)}),b.isUndefined(n.withCredentials)||(l.withCredentials=!!n.withCredentials),c&&c!=="json"&&(l.responseType=n.responseType),typeof n.onDownloadProgress=="function"&&l.addEventListener("progress",tn(n.onDownloadProgress,!0)),typeof n.onUploadProgress=="function"&&l.upload&&l.upload.addEventListener("progress",tn(n.onUploadProgress)),(n.cancelToken||n.signal)&&(f=y=>{!l||(i(!y||y.type?new pt(null,t,l):y),l.abort(),l=null)},n.cancelToken&&n.cancelToken.subscribe(f),n.signal&&(n.signal.aborted?f():n.signal.addEventListener("abort",f)));const p=xr(n.url);if(p&&ke.protocols.indexOf(p)===-1){i(new V("Unsupported protocol "+p+":",V.ERR_BAD_REQUEST,t));return}l.send(o||null)})};const Pr=(t,e)=>{let s=new AbortController,i;const n=function(f){if(!i){i=!0,a();const u=f instanceof Error?f:this.reason;s.abort(u instanceof V?u:new pt(u instanceof Error?u.message:u))}};let o=e&&setTimeout(()=>{n(new V(`timeout ${e} of ms exceeded`,V.ETIMEDOUT))},e);const a=()=>{t&&(o&&clearTimeout(o),o=null,t.forEach(f=>{f&&(f.removeEventListener?f.removeEventListener("abort",n):f.unsubscribe(n))}),t=null)};t.forEach(f=>f&&f.addEventListener&&f.addEventListener("abort",n));const{signal:c}=s;return c.unsubscribe=a,[c,()=>{o&&clearTimeout(o),o=null}]};var Rr=Pr;const jr=function*(t,e){let s=t.byteLength;if(!e||s<e){yield t;return}let i=0,n;for(;i<s;)n=i+e,yield t.slice(i,n),i=n},Or=async function*(t,e,s){for await(const i of t)yield*jr(ArrayBuffer.isView(i)?i:await s(String(i)),e)},xs=(t,e,s,i,n)=>{const o=Or(t,e,n);let a=0;return new ReadableStream({type:"bytes",async pull(c){const{done:f,value:u}=await o.next();if(f){c.close(),i();return}let l=u.byteLength;s&&s(a+=l),c.enqueue(new Uint8Array(u))},cancel(c){return i(c),o.return()}},{highWaterMark:2})},Es=(t,e)=>{const s=t!=null;return i=>setTimeout(()=>e({lengthComputable:s,total:t,loaded:i}))},bn=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",So=bn&&typeof ReadableStream=="function",Wn=bn&&(typeof TextEncoder=="function"?(t=>e=>t.encode(e))(new TextEncoder):async t=>new Uint8Array(await new Response(t).arrayBuffer())),Mr=So&&(()=>{let t=!1;const e=new Request(ke.origin,{body:new ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type");return t&&!e})(),Cs=64*1024,Xn=So&&!!(()=>{try{return b.isReadableStream(new Response("").body)}catch{}})(),nn={stream:Xn&&(t=>t.body)};bn&&(t=>{["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!nn[e]&&(nn[e]=b.isFunction(t[e])?s=>s[e]():(s,i)=>{throw new V(`Response type '${e}' is not supported`,V.ERR_NOT_SUPPORT,i)})})})(new Response);const qr=async t=>{if(t==null)return 0;if(b.isBlob(t))return t.size;if(b.isSpecCompliantForm(t))return(await new Request(t).arrayBuffer()).byteLength;if(b.isArrayBufferView(t))return t.byteLength;if(b.isURLSearchParams(t)&&(t=t+""),b.isString(t))return(await Wn(t)).byteLength},Nr=async(t,e)=>{const s=b.toFiniteNumber(t.getContentLength());return s==null?qr(e):s};var Br=bn&&(async t=>{let{url:e,method:s,data:i,signal:n,cancelToken:o,timeout:a,onDownloadProgress:c,onUploadProgress:f,responseType:u,headers:l,withCredentials:_="same-origin",fetchOptions:p}=ko(t);u=u?(u+"").toLowerCase():"text";let[y,v]=n||o||a?Rr([n,o],a):[],x,R;const M=()=>{!x&&setTimeout(()=>{y&&y.unsubscribe()}),x=!0};let A;try{if(f&&Mr&&s!=="get"&&s!=="head"&&(A=await Nr(l,i))!==0){let J=new Request(e,{method:"POST",body:i,duplex:"half"}),Y;b.isFormData(i)&&(Y=J.headers.get("content-type"))&&l.setContentType(Y),J.body&&(i=xs(J.body,Cs,Es(A,tn(f)),null,Wn))}b.isString(_)||(_=_?"cors":"omit"),R=new Request(e,{...p,signal:y,method:s.toUpperCase(),headers:l.normalize().toJSON(),body:i,duplex:"half",withCredentials:_});let k=await fetch(R);const z=Xn&&(u==="stream"||u==="response");if(Xn&&(c||z)){const J={};["status","statusText","headers"].forEach(Pe=>{J[Pe]=k[Pe]});const Y=b.toFiniteNumber(k.headers.get("content-length"));k=new Response(xs(k.body,Cs,c&&Es(Y,tn(c,!0)),z&&M,Wn),J)}u=u||"text";let le=await nn[b.findKey(nn,u)||"text"](k,t);return!z&&M(),v&&v(),await new Promise((J,Y)=>{To(J,Y,{data:le,headers:Se.from(k.headers),status:k.status,statusText:k.statusText,config:t,request:R})})}catch(k){throw M(),k&&k.name==="TypeError"&&/fetch/i.test(k.message)?Object.assign(new V("Network Error",V.ERR_NETWORK,t,R),{cause:k.cause||k}):V.from(k,k&&k.code,t,R)}});const Hn={http:$i,xhr:Dr,fetch:Br};b.forEach(Hn,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch{}Object.defineProperty(t,"adapterName",{value:e})}});const Ts=t=>`- ${t}`,Vr=t=>b.isFunction(t)||t===null||t===!1;var Ao={getAdapter:t=>{t=b.isArray(t)?t:[t];const{length:e}=t;let s,i;const n={};for(let o=0;o<e;o++){s=t[o];let a;if(i=s,!Vr(s)&&(i=Hn[(a=String(s)).toLowerCase()],i===void 0))throw new V(`Unknown adapter '${a}'`);if(i)break;n[a||"#"+o]=i}if(!i){const o=Object.entries(n).map(([c,f])=>`adapter ${c} `+(f===!1?"is not supported by the environment":"is not available in the build"));let a=e?o.length>1?`since :
     1import{_ as ne,o as u,c as h,n as I,a as r,t as c,g,w as J,i as D,k as W,F,r as U,p as ai,l as C,j as ue,v as li,s as ci,u as Ct,q as di,x as ui,y as eo,z as hi,A as jt,B as Re,h as to,C as Cn,D as mi,E as fi,d as O,e as P,m as me,G as no,H as pi}from"./plugin-vue_export-helper.min.js";import{C as Ze,R as qt}from"./RemoveAlert.min.js";import{T as hn}from"./VueSearchSelect.min.js";import{V as Nt}from"./vue-datepicker.min.js";import{f as mn,c as so,a as oo,g as io,b as ro,s as ao}from"./api.min.js";import{v as mt}from"./vue3-editor.common.min.js";function lo(t,e){return function(){return t.apply(e,arguments)}}const{toString:_i}=Object.prototype,{getPrototypeOf:ts}=Object,fn=(t=>e=>{const s=_i.call(e);return t[s]||(t[s]=s.slice(8,-1).toLowerCase())})(Object.create(null)),De=t=>(t=t.toLowerCase(),e=>fn(e)===t),pn=t=>e=>typeof e===t,{isArray:ft}=Array,Rt=pn("undefined");function gi(t){return t!==null&&!Rt(t)&&t.constructor!==null&&!Rt(t.constructor)&&xe(t.constructor.isBuffer)&&t.constructor.isBuffer(t)}const co=De("ArrayBuffer");function yi(t){let e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&co(t.buffer),e}const bi=pn("string"),xe=pn("function"),uo=pn("number"),_n=t=>t!==null&&typeof t=="object",vi=t=>t===!0||t===!1,Qt=t=>{if(fn(t)!=="object")return!1;const e=ts(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)},wi=De("Date"),xi=De("File"),Ei=De("Blob"),Ci=De("FileList"),Ti=t=>_n(t)&&xe(t.pipe),Ii=t=>{let e;return t&&(typeof FormData=="function"&&t instanceof FormData||xe(t.append)&&((e=fn(t))==="formdata"||e==="object"&&xe(t.toString)&&t.toString()==="[object FormData]"))},ki=De("URLSearchParams"),[Ai,Si,Di,Pi]=["ReadableStream","Request","Response","Headers"].map(De),ji=t=>t.trim?t.trim():t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Bt(t,e,{allOwnKeys:s=!1}={}){if(t===null||typeof t=="undefined")return;let i,n;if(typeof t!="object"&&(t=[t]),ft(t))for(i=0,n=t.length;i<n;i++)e.call(null,t[i],i,t);else{const o=s?Object.getOwnPropertyNames(t):Object.keys(t),a=o.length;let l;for(i=0;i<a;i++)l=o[i],e.call(null,t[l],l,t)}}function ho(t,e){e=e.toLowerCase();const s=Object.keys(t);let i=s.length,n;for(;i-- >0;)if(n=s[i],e===n.toLowerCase())return n;return null}const mo=(()=>typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:typeof window!="undefined"?window:global)(),fo=t=>!Rt(t)&&t!==mo;function Un(){const{caseless:t}=fo(this)&&this||{},e={},s=(i,n)=>{const o=t&&ho(e,n)||n;Qt(e[o])&&Qt(i)?e[o]=Un(e[o],i):Qt(i)?e[o]=Un({},i):ft(i)?e[o]=i.slice():e[o]=i};for(let i=0,n=arguments.length;i<n;i++)arguments[i]&&Bt(arguments[i],s);return e}const Ri=(t,e,s,{allOwnKeys:i}={})=>(Bt(e,(n,o)=>{s&&xe(n)?t[o]=lo(n,s):t[o]=n},{allOwnKeys:i}),t),Mi=t=>(t.charCodeAt(0)===65279&&(t=t.slice(1)),t),Oi=(t,e,s,i)=>{t.prototype=Object.create(e.prototype,i),t.prototype.constructor=t,Object.defineProperty(t,"super",{value:e.prototype}),s&&Object.assign(t.prototype,s)},qi=(t,e,s,i)=>{let n,o,a;const l={};if(e=e||{},t==null)return e;do{for(n=Object.getOwnPropertyNames(t),o=n.length;o-- >0;)a=n[o],(!i||i(a,t,e))&&!l[a]&&(e[a]=t[a],l[a]=!0);t=s!==!1&&ts(t)}while(t&&(!s||s(t,e))&&t!==Object.prototype);return e},Ni=(t,e,s)=>{t=String(t),(s===void 0||s>t.length)&&(s=t.length),s-=e.length;const i=t.indexOf(e,s);return i!==-1&&i===s},Bi=t=>{if(!t)return null;if(ft(t))return t;let e=t.length;if(!uo(e))return null;const s=new Array(e);for(;e-- >0;)s[e]=t[e];return s},Vi=(t=>e=>t&&e instanceof t)(typeof Uint8Array!="undefined"&&ts(Uint8Array)),Fi=(t,e)=>{const i=(t&&t[Symbol.iterator]).call(t);let n;for(;(n=i.next())&&!n.done;){const o=n.value;e.call(t,o[0],o[1])}},Ui=(t,e)=>{let s;const i=[];for(;(s=t.exec(e))!==null;)i.push(s);return i},Li=De("HTMLFormElement"),Wi=t=>t.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(s,i,n){return i.toUpperCase()+n}),ps=(({hasOwnProperty:t})=>(e,s)=>t.call(e,s))(Object.prototype),Xi=De("RegExp"),po=(t,e)=>{const s=Object.getOwnPropertyDescriptors(t),i={};Bt(s,(n,o)=>{let a;(a=e(n,o,t))!==!1&&(i[o]=a||n)}),Object.defineProperties(t,i)},Hi=t=>{po(t,(e,s)=>{if(xe(t)&&["arguments","caller","callee"].indexOf(s)!==-1)return!1;const i=t[s];if(!!xe(i)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+s+"'")})}})},zi=(t,e)=>{const s={},i=n=>{n.forEach(o=>{s[o]=!0})};return ft(t)?i(t):i(String(t).split(e)),s},Qi=()=>{},Gi=(t,e)=>t!=null&&Number.isFinite(t=+t)?t:e,Tn="abcdefghijklmnopqrstuvwxyz",_s="0123456789",_o={DIGIT:_s,ALPHA:Tn,ALPHA_DIGIT:Tn+Tn.toUpperCase()+_s},Ji=(t=16,e=_o.ALPHA_DIGIT)=>{let s="";const{length:i}=e;for(;t--;)s+=e[Math.random()*i|0];return s};function Yi(t){return!!(t&&xe(t.append)&&t[Symbol.toStringTag]==="FormData"&&t[Symbol.iterator])}const Ki=t=>{const e=new Array(10),s=(i,n)=>{if(_n(i)){if(e.indexOf(i)>=0)return;if(!("toJSON"in i)){e[n]=i;const o=ft(i)?[]:{};return Bt(i,(a,l)=>{const f=s(a,n+1);!Rt(f)&&(o[l]=f)}),e[n]=void 0,o}}return i};return s(t,0)},Zi=De("AsyncFunction"),$i=t=>t&&(_n(t)||xe(t))&&xe(t.then)&&xe(t.catch);var b={isArray:ft,isArrayBuffer:co,isBuffer:gi,isFormData:Ii,isArrayBufferView:yi,isString:bi,isNumber:uo,isBoolean:vi,isObject:_n,isPlainObject:Qt,isReadableStream:Ai,isRequest:Si,isResponse:Di,isHeaders:Pi,isUndefined:Rt,isDate:wi,isFile:xi,isBlob:Ei,isRegExp:Xi,isFunction:xe,isStream:Ti,isURLSearchParams:ki,isTypedArray:Vi,isFileList:Ci,forEach:Bt,merge:Un,extend:Ri,trim:ji,stripBOM:Mi,inherits:Oi,toFlatObject:qi,kindOf:fn,kindOfTest:De,endsWith:Ni,toArray:Bi,forEachEntry:Fi,matchAll:Ui,isHTMLForm:Li,hasOwnProperty:ps,hasOwnProp:ps,reduceDescriptors:po,freezeMethods:Hi,toObjectSet:zi,toCamelCase:Wi,noop:Qi,toFiniteNumber:Gi,findKey:ho,global:mo,isContextDefined:fo,ALPHABET:_o,generateString:Ji,isSpecCompliantForm:Yi,toJSONObject:Ki,isAsyncFn:Zi,isThenable:$i};function V(t,e,s,i,n){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=t,this.name="AxiosError",e&&(this.code=e),s&&(this.config=s),i&&(this.request=i),n&&(this.response=n)}b.inherits(V,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:b.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const go=V.prototype,yo={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(t=>{yo[t]={value:t}});Object.defineProperties(V,yo);Object.defineProperty(go,"isAxiosError",{value:!0});V.from=(t,e,s,i,n,o)=>{const a=Object.create(go);return b.toFlatObject(t,a,function(f){return f!==Error.prototype},l=>l!=="isAxiosError"),V.call(a,t.message,e,s,i,n),a.cause=t,a.name=t.name,o&&Object.assign(a,o),a};var er=null;function Ln(t){return b.isPlainObject(t)||b.isArray(t)}function bo(t){return b.endsWith(t,"[]")?t.slice(0,-2):t}function gs(t,e,s){return t?t.concat(e).map(function(n,o){return n=bo(n),!s&&o?"["+n+"]":n}).join(s?".":""):e}function tr(t){return b.isArray(t)&&!t.some(Ln)}const nr=b.toFlatObject(b,{},null,function(e){return/^is[A-Z]/.test(e)});function gn(t,e,s){if(!b.isObject(t))throw new TypeError("target must be an object");e=e||new FormData,s=b.toFlatObject(s,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,j){return!b.isUndefined(j[x])});const i=s.metaTokens,n=s.visitor||m,o=s.dots,a=s.indexes,f=(s.Blob||typeof Blob!="undefined"&&Blob)&&b.isSpecCompliantForm(e);if(!b.isFunction(n))throw new TypeError("visitor must be a function");function d(v){if(v===null)return"";if(b.isDate(v))return v.toISOString();if(!f&&b.isBlob(v))throw new V("Blob is not supported. Use a Buffer instead.");return b.isArrayBuffer(v)||b.isTypedArray(v)?f&&typeof Blob=="function"?new Blob([v]):Buffer.from(v):v}function m(v,x,j){let q=v;if(v&&!j&&typeof v=="object"){if(b.endsWith(x,"{}"))x=i?x:x.slice(0,-2),v=JSON.stringify(v);else if(b.isArray(v)&&tr(v)||(b.isFileList(v)||b.endsWith(x,"[]"))&&(q=b.toArray(v)))return x=bo(x),q.forEach(function(k,z){!(b.isUndefined(k)||k===null)&&e.append(a===!0?gs([x],z,o):a===null?x:x+"[]",d(k))}),!1}return Ln(v)?!0:(e.append(gs(j,x,o),d(v)),!1)}const p=[],y=Object.assign(nr,{defaultVisitor:m,convertValue:d,isVisitable:Ln});function _(v,x){if(!b.isUndefined(v)){if(p.indexOf(v)!==-1)throw Error("Circular reference detected in "+x.join("."));p.push(v),b.forEach(v,function(q,S){(!(b.isUndefined(q)||q===null)&&n.call(e,q,b.isString(S)?S.trim():S,x,y))===!0&&_(q,x?x.concat(S):[S])}),p.pop()}}if(!b.isObject(t))throw new TypeError("data must be an object");return _(t),e}function ys(t){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'()~]|%20|%00/g,function(i){return e[i]})}function ns(t,e){this._pairs=[],t&&gn(t,this,e)}const vo=ns.prototype;vo.append=function(e,s){this._pairs.push([e,s])};vo.toString=function(e){const s=e?function(i){return e.call(this,i,ys)}:ys;return this._pairs.map(function(n){return s(n[0])+"="+s(n[1])},"").join("&")};function sr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function wo(t,e,s){if(!e)return t;const i=s&&s.encode||sr,n=s&&s.serialize;let o;if(n?o=n(e,s):o=b.isURLSearchParams(e)?e.toString():new ns(e,s).toString(i),o){const a=t.indexOf("#");a!==-1&&(t=t.slice(0,a)),t+=(t.indexOf("?")===-1?"?":"&")+o}return t}class or{constructor(){this.handlers=[]}use(e,s,i){return this.handlers.push({fulfilled:e,rejected:s,synchronous:i?i.synchronous:!1,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){b.forEach(this.handlers,function(i){i!==null&&e(i)})}}var bs=or,xo={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ir=typeof URLSearchParams!="undefined"?URLSearchParams:ns,rr=typeof FormData!="undefined"?FormData:null,ar=typeof Blob!="undefined"?Blob:null,lr={isBrowser:!0,classes:{URLSearchParams:ir,FormData:rr,Blob:ar},protocols:["http","https","file","blob","url","data"]};const ss=typeof window!="undefined"&&typeof document!="undefined",cr=(t=>ss&&["ReactNative","NativeScript","NS"].indexOf(t)<0)(typeof navigator!="undefined"&&navigator.product),dr=(()=>typeof WorkerGlobalScope!="undefined"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),ur=ss&&window.location.href||"http://localhost";var hr=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ss,hasStandardBrowserWebWorkerEnv:dr,hasStandardBrowserEnv:cr,origin:ur},Symbol.toStringTag,{value:"Module"})),ke={...hr,...lr};function mr(t,e){return gn(t,new ke.classes.URLSearchParams,Object.assign({visitor:function(s,i,n,o){return ke.isNode&&b.isBuffer(s)?(this.append(i,s.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},e))}function fr(t){return b.matchAll(/\w+|\[(\w*)]/g,t).map(e=>e[0]==="[]"?"":e[1]||e[0])}function pr(t){const e={},s=Object.keys(t);let i;const n=s.length;let o;for(i=0;i<n;i++)o=s[i],e[o]=t[o];return e}function Eo(t){function e(s,i,n,o){let a=s[o++];if(a==="__proto__")return!0;const l=Number.isFinite(+a),f=o>=s.length;return a=!a&&b.isArray(n)?n.length:a,f?(b.hasOwnProp(n,a)?n[a]=[n[a],i]:n[a]=i,!l):((!n[a]||!b.isObject(n[a]))&&(n[a]=[]),e(s,i,n[a],o)&&b.isArray(n[a])&&(n[a]=pr(n[a])),!l)}if(b.isFormData(t)&&b.isFunction(t.entries)){const s={};return b.forEachEntry(t,(i,n)=>{e(fr(i),n,s,0)}),s}return null}function _r(t,e,s){if(b.isString(t))try{return(e||JSON.parse)(t),b.trim(t)}catch(i){if(i.name!=="SyntaxError")throw i}return(s||JSON.stringify)(t)}const os={transitional:xo,adapter:["xhr","http","fetch"],transformRequest:[function(e,s){const i=s.getContentType()||"",n=i.indexOf("application/json")>-1,o=b.isObject(e);if(o&&b.isHTMLForm(e)&&(e=new FormData(e)),b.isFormData(e))return n?JSON.stringify(Eo(e)):e;if(b.isArrayBuffer(e)||b.isBuffer(e)||b.isStream(e)||b.isFile(e)||b.isBlob(e)||b.isReadableStream(e))return e;if(b.isArrayBufferView(e))return e.buffer;if(b.isURLSearchParams(e))return s.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let l;if(o){if(i.indexOf("application/x-www-form-urlencoded")>-1)return mr(e,this.formSerializer).toString();if((l=b.isFileList(e))||i.indexOf("multipart/form-data")>-1){const f=this.env&&this.env.FormData;return gn(l?{"files[]":e}:e,f&&new f,this.formSerializer)}}return o||n?(s.setContentType("application/json",!1),_r(e)):e}],transformResponse:[function(e){const s=this.transitional||os.transitional,i=s&&s.forcedJSONParsing,n=this.responseType==="json";if(b.isResponse(e)||b.isReadableStream(e))return e;if(e&&b.isString(e)&&(i&&!this.responseType||n)){const a=!(s&&s.silentJSONParsing)&&n;try{return JSON.parse(e)}catch(l){if(a)throw l.name==="SyntaxError"?V.from(l,V.ERR_BAD_RESPONSE,this,null,this.response):l}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:ke.classes.FormData,Blob:ke.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};b.forEach(["delete","get","head","post","put","patch"],t=>{os.headers[t]={}});var is=os;const gr=b.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);var yr=t=>{const e={};let s,i,n;return t&&t.split(`
     2`).forEach(function(a){n=a.indexOf(":"),s=a.substring(0,n).trim().toLowerCase(),i=a.substring(n+1).trim(),!(!s||e[s]&&gr[s])&&(s==="set-cookie"?e[s]?e[s].push(i):e[s]=[i]:e[s]=e[s]?e[s]+", "+i:i)}),e};const vs=Symbol("internals");function bt(t){return t&&String(t).trim().toLowerCase()}function Gt(t){return t===!1||t==null?t:b.isArray(t)?t.map(Gt):String(t)}function br(t){const e=Object.create(null),s=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let i;for(;i=s.exec(t);)e[i[1]]=i[2];return e}const vr=t=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(t.trim());function In(t,e,s,i,n){if(b.isFunction(i))return i.call(this,e,s);if(n&&(e=s),!!b.isString(e)){if(b.isString(i))return e.indexOf(i)!==-1;if(b.isRegExp(i))return i.test(e)}}function wr(t){return t.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,s,i)=>s.toUpperCase()+i)}function xr(t,e){const s=b.toCamelCase(" "+e);["get","set","has"].forEach(i=>{Object.defineProperty(t,i+s,{value:function(n,o,a){return this[i].call(this,e,n,o,a)},configurable:!0})})}class yn{constructor(e){e&&this.set(e)}set(e,s,i){const n=this;function o(l,f,d){const m=bt(f);if(!m)throw new Error("header name must be a non-empty string");const p=b.findKey(n,m);(!p||n[p]===void 0||d===!0||d===void 0&&n[p]!==!1)&&(n[p||f]=Gt(l))}const a=(l,f)=>b.forEach(l,(d,m)=>o(d,m,f));if(b.isPlainObject(e)||e instanceof this.constructor)a(e,s);else if(b.isString(e)&&(e=e.trim())&&!vr(e))a(yr(e),s);else if(b.isHeaders(e))for(const[l,f]of e.entries())o(f,l,i);else e!=null&&o(s,e,i);return this}get(e,s){if(e=bt(e),e){const i=b.findKey(this,e);if(i){const n=this[i];if(!s)return n;if(s===!0)return br(n);if(b.isFunction(s))return s.call(this,n,i);if(b.isRegExp(s))return s.exec(n);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,s){if(e=bt(e),e){const i=b.findKey(this,e);return!!(i&&this[i]!==void 0&&(!s||In(this,this[i],i,s)))}return!1}delete(e,s){const i=this;let n=!1;function o(a){if(a=bt(a),a){const l=b.findKey(i,a);l&&(!s||In(i,i[l],l,s))&&(delete i[l],n=!0)}}return b.isArray(e)?e.forEach(o):o(e),n}clear(e){const s=Object.keys(this);let i=s.length,n=!1;for(;i--;){const o=s[i];(!e||In(this,this[o],o,e,!0))&&(delete this[o],n=!0)}return n}normalize(e){const s=this,i={};return b.forEach(this,(n,o)=>{const a=b.findKey(i,o);if(a){s[a]=Gt(n),delete s[o];return}const l=e?wr(o):String(o).trim();l!==o&&delete s[o],s[l]=Gt(n),i[l]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const s=Object.create(null);return b.forEach(this,(i,n)=>{i!=null&&i!==!1&&(s[n]=e&&b.isArray(i)?i.join(", "):i)}),s}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,s])=>e+": "+s).join(`
     3`)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...s){const i=new this(e);return s.forEach(n=>i.set(n)),i}static accessor(e){const i=(this[vs]=this[vs]={accessors:{}}).accessors,n=this.prototype;function o(a){const l=bt(a);i[l]||(xr(n,a),i[l]=!0)}return b.isArray(e)?e.forEach(o):o(e),this}}yn.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);b.reduceDescriptors(yn.prototype,({value:t},e)=>{let s=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(i){this[s]=i}}});b.freezeMethods(yn);var Ae=yn;function kn(t,e){const s=this||is,i=e||s,n=Ae.from(i.headers);let o=i.data;return b.forEach(t,function(l){o=l.call(s,o,n.normalize(),e?e.status:void 0)}),n.normalize(),o}function Co(t){return!!(t&&t.__CANCEL__)}function pt(t,e,s){V.call(this,t==null?"canceled":t,V.ERR_CANCELED,e,s),this.name="CanceledError"}b.inherits(pt,V,{__CANCEL__:!0});function To(t,e,s){const i=s.config.validateStatus;!s.status||!i||i(s.status)?t(s):e(new V("Request failed with status code "+s.status,[V.ERR_BAD_REQUEST,V.ERR_BAD_RESPONSE][Math.floor(s.status/100)-4],s.config,s.request,s))}function Er(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}function Cr(t,e){t=t||10;const s=new Array(t),i=new Array(t);let n=0,o=0,a;return e=e!==void 0?e:1e3,function(f){const d=Date.now(),m=i[o];a||(a=d),s[n]=f,i[n]=d;let p=o,y=0;for(;p!==n;)y+=s[p++],p=p%t;if(n=(n+1)%t,n===o&&(o=(o+1)%t),d-a<e)return;const _=m&&d-m;return _?Math.round(y*1e3/_):void 0}}function Tr(t,e){let s=0;const i=1e3/e;let n=null;return function(){const a=this===!0,l=Date.now();if(a||l-s>i)return n&&(clearTimeout(n),n=null),s=l,t.apply(null,arguments);n||(n=setTimeout(()=>(n=null,s=Date.now(),t.apply(null,arguments)),i-(l-s)))}}var tn=(t,e,s=3)=>{let i=0;const n=Cr(50,250);return Tr(o=>{const a=o.loaded,l=o.lengthComputable?o.total:void 0,f=a-i,d=n(f),m=a<=l;i=a;const p={loaded:a,total:l,progress:l?a/l:void 0,bytes:f,rate:d||void 0,estimated:d&&l&&m?(l-a)/d:void 0,event:o,lengthComputable:l!=null};p[e?"download":"upload"]=!0,t(p)},s)},Ir=ke.hasStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),s=document.createElement("a");let i;function n(o){let a=o;return e&&(s.setAttribute("href",a),a=s.href),s.setAttribute("href",a),{href:s.href,protocol:s.protocol?s.protocol.replace(/:$/,""):"",host:s.host,search:s.search?s.search.replace(/^\?/,""):"",hash:s.hash?s.hash.replace(/^#/,""):"",hostname:s.hostname,port:s.port,pathname:s.pathname.charAt(0)==="/"?s.pathname:"/"+s.pathname}}return i=n(window.location.href),function(a){const l=b.isString(a)?n(a):a;return l.protocol===i.protocol&&l.host===i.host}}():function(){return function(){return!0}}(),kr=ke.hasStandardBrowserEnv?{write(t,e,s,i,n,o){const a=[t+"="+encodeURIComponent(e)];b.isNumber(s)&&a.push("expires="+new Date(s).toGMTString()),b.isString(i)&&a.push("path="+i),b.isString(n)&&a.push("domain="+n),o===!0&&a.push("secure"),document.cookie=a.join("; ")},read(t){const e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove(t){this.write(t,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Ar(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}function Sr(t,e){return e?t.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):t}function Io(t,e){return t&&!Ar(e)?Sr(t,e):e}const ws=t=>t instanceof Ae?{...t}:t;function nt(t,e){e=e||{};const s={};function i(d,m,p){return b.isPlainObject(d)&&b.isPlainObject(m)?b.merge.call({caseless:p},d,m):b.isPlainObject(m)?b.merge({},m):b.isArray(m)?m.slice():m}function n(d,m,p){if(b.isUndefined(m)){if(!b.isUndefined(d))return i(void 0,d,p)}else return i(d,m,p)}function o(d,m){if(!b.isUndefined(m))return i(void 0,m)}function a(d,m){if(b.isUndefined(m)){if(!b.isUndefined(d))return i(void 0,d)}else return i(void 0,m)}function l(d,m,p){if(p in e)return i(d,m);if(p in t)return i(void 0,d)}const f={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,withXSRFToken:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:l,headers:(d,m)=>n(ws(d),ws(m),!0)};return b.forEach(Object.keys(Object.assign({},t,e)),function(m){const p=f[m]||n,y=p(t[m],e[m],m);b.isUndefined(y)&&p!==l||(s[m]=y)}),s}var ko=t=>{const e=nt({},t);let{data:s,withXSRFToken:i,xsrfHeaderName:n,xsrfCookieName:o,headers:a,auth:l}=e;e.headers=a=Ae.from(a),e.url=wo(Io(e.baseURL,e.url),t.params,t.paramsSerializer),l&&a.set("Authorization","Basic "+btoa((l.username||"")+":"+(l.password?unescape(encodeURIComponent(l.password)):"")));let f;if(b.isFormData(s)){if(ke.hasStandardBrowserEnv||ke.hasStandardBrowserWebWorkerEnv)a.setContentType(void 0);else if((f=a.getContentType())!==!1){const[d,...m]=f?f.split(";").map(p=>p.trim()).filter(Boolean):[];a.setContentType([d||"multipart/form-data",...m].join("; "))}}if(ke.hasStandardBrowserEnv&&(i&&b.isFunction(i)&&(i=i(e)),i||i!==!1&&Ir(e.url))){const d=n&&o&&kr.read(o);d&&a.set(n,d)}return e};const Dr=typeof XMLHttpRequest!="undefined";var Pr=Dr&&function(t){return new Promise(function(s,i){const n=ko(t);let o=n.data;const a=Ae.from(n.headers).normalize();let{responseType:l}=n,f;function d(){n.cancelToken&&n.cancelToken.unsubscribe(f),n.signal&&n.signal.removeEventListener("abort",f)}let m=new XMLHttpRequest;m.open(n.method.toUpperCase(),n.url,!0),m.timeout=n.timeout;function p(){if(!m)return;const _=Ae.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders()),x={data:!l||l==="text"||l==="json"?m.responseText:m.response,status:m.status,statusText:m.statusText,headers:_,config:t,request:m};To(function(q){s(q),d()},function(q){i(q),d()},x),m=null}"onloadend"in m?m.onloadend=p:m.onreadystatechange=function(){!m||m.readyState!==4||m.status===0&&!(m.responseURL&&m.responseURL.indexOf("file:")===0)||setTimeout(p)},m.onabort=function(){!m||(i(new V("Request aborted",V.ECONNABORTED,n,m)),m=null)},m.onerror=function(){i(new V("Network Error",V.ERR_NETWORK,n,m)),m=null},m.ontimeout=function(){let v=n.timeout?"timeout of "+n.timeout+"ms exceeded":"timeout exceeded";const x=n.transitional||xo;n.timeoutErrorMessage&&(v=n.timeoutErrorMessage),i(new V(v,x.clarifyTimeoutError?V.ETIMEDOUT:V.ECONNABORTED,n,m)),m=null},o===void 0&&a.setContentType(null),"setRequestHeader"in m&&b.forEach(a.toJSON(),function(v,x){m.setRequestHeader(x,v)}),b.isUndefined(n.withCredentials)||(m.withCredentials=!!n.withCredentials),l&&l!=="json"&&(m.responseType=n.responseType),typeof n.onDownloadProgress=="function"&&m.addEventListener("progress",tn(n.onDownloadProgress,!0)),typeof n.onUploadProgress=="function"&&m.upload&&m.upload.addEventListener("progress",tn(n.onUploadProgress)),(n.cancelToken||n.signal)&&(f=_=>{!m||(i(!_||_.type?new pt(null,t,m):_),m.abort(),m=null)},n.cancelToken&&n.cancelToken.subscribe(f),n.signal&&(n.signal.aborted?f():n.signal.addEventListener("abort",f)));const y=Er(n.url);if(y&&ke.protocols.indexOf(y)===-1){i(new V("Unsupported protocol "+y+":",V.ERR_BAD_REQUEST,t));return}m.send(o||null)})};const jr=(t,e)=>{let s=new AbortController,i;const n=function(f){if(!i){i=!0,a();const d=f instanceof Error?f:this.reason;s.abort(d instanceof V?d:new pt(d instanceof Error?d.message:d))}};let o=e&&setTimeout(()=>{n(new V(`timeout ${e} of ms exceeded`,V.ETIMEDOUT))},e);const a=()=>{t&&(o&&clearTimeout(o),o=null,t.forEach(f=>{f&&(f.removeEventListener?f.removeEventListener("abort",n):f.unsubscribe(n))}),t=null)};t.forEach(f=>f&&f.addEventListener&&f.addEventListener("abort",n));const{signal:l}=s;return l.unsubscribe=a,[l,()=>{o&&clearTimeout(o),o=null}]};var Rr=jr;const Mr=function*(t,e){let s=t.byteLength;if(!e||s<e){yield t;return}let i=0,n;for(;i<s;)n=i+e,yield t.slice(i,n),i=n},Or=async function*(t,e,s){for await(const i of t)yield*Mr(ArrayBuffer.isView(i)?i:await s(String(i)),e)},xs=(t,e,s,i,n)=>{const o=Or(t,e,n);let a=0;return new ReadableStream({type:"bytes",async pull(l){const{done:f,value:d}=await o.next();if(f){l.close(),i();return}let m=d.byteLength;s&&s(a+=m),l.enqueue(new Uint8Array(d))},cancel(l){return i(l),o.return()}},{highWaterMark:2})},Es=(t,e)=>{const s=t!=null;return i=>setTimeout(()=>e({lengthComputable:s,total:t,loaded:i}))},bn=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",Ao=bn&&typeof ReadableStream=="function",Wn=bn&&(typeof TextEncoder=="function"?(t=>e=>t.encode(e))(new TextEncoder):async t=>new Uint8Array(await new Response(t).arrayBuffer())),qr=Ao&&(()=>{let t=!1;const e=new Request(ke.origin,{body:new ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type");return t&&!e})(),Cs=64*1024,Xn=Ao&&!!(()=>{try{return b.isReadableStream(new Response("").body)}catch{}})(),nn={stream:Xn&&(t=>t.body)};bn&&(t=>{["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!nn[e]&&(nn[e]=b.isFunction(t[e])?s=>s[e]():(s,i)=>{throw new V(`Response type '${e}' is not supported`,V.ERR_NOT_SUPPORT,i)})})})(new Response);const Nr=async t=>{if(t==null)return 0;if(b.isBlob(t))return t.size;if(b.isSpecCompliantForm(t))return(await new Request(t).arrayBuffer()).byteLength;if(b.isArrayBufferView(t))return t.byteLength;if(b.isURLSearchParams(t)&&(t=t+""),b.isString(t))return(await Wn(t)).byteLength},Br=async(t,e)=>{const s=b.toFiniteNumber(t.getContentLength());return s==null?Nr(e):s};var Vr=bn&&(async t=>{let{url:e,method:s,data:i,signal:n,cancelToken:o,timeout:a,onDownloadProgress:l,onUploadProgress:f,responseType:d,headers:m,withCredentials:p="same-origin",fetchOptions:y}=ko(t);d=d?(d+"").toLowerCase():"text";let[_,v]=n||o||a?Rr([n,o],a):[],x,j;const q=()=>{!x&&setTimeout(()=>{_&&_.unsubscribe()}),x=!0};let S;try{if(f&&qr&&s!=="get"&&s!=="head"&&(S=await Br(m,i))!==0){let Y=new Request(e,{method:"POST",body:i,duplex:"half"}),K;b.isFormData(i)&&(K=Y.headers.get("content-type"))&&m.setContentType(K),Y.body&&(i=xs(Y.body,Cs,Es(S,tn(f)),null,Wn))}b.isString(p)||(p=p?"cors":"omit"),j=new Request(e,{...y,signal:_,method:s.toUpperCase(),headers:m.normalize().toJSON(),body:i,duplex:"half",withCredentials:p});let k=await fetch(j);const z=Xn&&(d==="stream"||d==="response");if(Xn&&(l||z)){const Y={};["status","statusText","headers"].forEach(Pe=>{Y[Pe]=k[Pe]});const K=b.toFiniteNumber(k.headers.get("content-length"));k=new Response(xs(k.body,Cs,l&&Es(K,tn(l,!0)),z&&q,Wn),Y)}d=d||"text";let le=await nn[b.findKey(nn,d)||"text"](k,t);return!z&&q(),v&&v(),await new Promise((Y,K)=>{To(Y,K,{data:le,headers:Ae.from(k.headers),status:k.status,statusText:k.statusText,config:t,request:j})})}catch(k){throw q(),k&&k.name==="TypeError"&&/fetch/i.test(k.message)?Object.assign(new V("Network Error",V.ERR_NETWORK,t,j),{cause:k.cause||k}):V.from(k,k&&k.code,t,j)}});const Hn={http:er,xhr:Pr,fetch:Vr};b.forEach(Hn,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch{}Object.defineProperty(t,"adapterName",{value:e})}});const Ts=t=>`- ${t}`,Fr=t=>b.isFunction(t)||t===null||t===!1;var So={getAdapter:t=>{t=b.isArray(t)?t:[t];const{length:e}=t;let s,i;const n={};for(let o=0;o<e;o++){s=t[o];let a;if(i=s,!Fr(s)&&(i=Hn[(a=String(s)).toLowerCase()],i===void 0))throw new V(`Unknown adapter '${a}'`);if(i)break;n[a||"#"+o]=i}if(!i){const o=Object.entries(n).map(([l,f])=>`adapter ${l} `+(f===!1?"is not supported by the environment":"is not available in the build"));let a=e?o.length>1?`since :
    44`+o.map(Ts).join(`
    5 `):" "+Ts(o[0]):"as no adapter specified";throw new V("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return i},adapters:Hn};function Sn(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new pt(null,t)}function Is(t){return Sn(t),t.headers=Se.from(t.headers),t.data=kn.call(t,t.transformRequest),["post","put","patch"].indexOf(t.method)!==-1&&t.headers.setContentType("application/x-www-form-urlencoded",!1),Ao.getAdapter(t.adapter||is.adapter)(t).then(function(i){return Sn(t),i.data=kn.call(t,t.transformResponse,i),i.headers=Se.from(i.headers),i},function(i){return Co(i)||(Sn(t),i&&i.response&&(i.response.data=kn.call(t,t.transformResponse,i.response),i.response.headers=Se.from(i.response.headers))),Promise.reject(i)})}const Do="1.7.2",rs={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{rs[t]=function(i){return typeof i===t||"a"+(e<1?"n ":" ")+t}});const ks={};rs.transitional=function(e,s,i){function n(o,a){return"[Axios v"+Do+"] Transitional option '"+o+"'"+a+(i?". "+i:"")}return(o,a,c)=>{if(e===!1)throw new V(n(a," has been removed"+(s?" in "+s:"")),V.ERR_DEPRECATED);return s&&!ks[a]&&(ks[a]=!0,console.warn(n(a," has been deprecated since v"+s+" and will be removed in the near future"))),e?e(o,a,c):!0}};function Fr(t,e,s){if(typeof t!="object")throw new V("options must be an object",V.ERR_BAD_OPTION_VALUE);const i=Object.keys(t);let n=i.length;for(;n-- >0;){const o=i[n],a=e[o];if(a){const c=t[o],f=c===void 0||a(c,o,t);if(f!==!0)throw new V("option "+o+" must be "+f,V.ERR_BAD_OPTION_VALUE);continue}if(s!==!0)throw new V("Unknown option "+o,V.ERR_BAD_OPTION)}}var zn={assertOptions:Fr,validators:rs};const ze=zn.validators;class sn{constructor(e){this.defaults=e,this.interceptors={request:new bs,response:new bs}}async request(e,s){try{return await this._request(e,s)}catch(i){if(i instanceof Error){let n;Error.captureStackTrace?Error.captureStackTrace(n={}):n=new Error;const o=n.stack?n.stack.replace(/^.+\n/,""):"";try{i.stack?o&&!String(i.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(i.stack+=`
    6 `+o):i.stack=o}catch{}}throw i}}_request(e,s){typeof e=="string"?(s=s||{},s.url=e):s=e||{},s=nt(this.defaults,s);const{transitional:i,paramsSerializer:n,headers:o}=s;i!==void 0&&zn.assertOptions(i,{silentJSONParsing:ze.transitional(ze.boolean),forcedJSONParsing:ze.transitional(ze.boolean),clarifyTimeoutError:ze.transitional(ze.boolean)},!1),n!=null&&(b.isFunction(n)?s.paramsSerializer={serialize:n}:zn.assertOptions(n,{encode:ze.function,serialize:ze.function},!0)),s.method=(s.method||this.defaults.method||"get").toLowerCase();let a=o&&b.merge(o.common,o[s.method]);o&&b.forEach(["delete","get","head","post","put","patch","common"],v=>{delete o[v]}),s.headers=Se.concat(a,o);const c=[];let f=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(s)===!1||(f=f&&x.synchronous,c.unshift(x.fulfilled,x.rejected))});const u=[];this.interceptors.response.forEach(function(x){u.push(x.fulfilled,x.rejected)});let l,_=0,p;if(!f){const v=[Is.bind(this),void 0];for(v.unshift.apply(v,c),v.push.apply(v,u),p=v.length,l=Promise.resolve(s);_<p;)l=l.then(v[_++],v[_++]);return l}p=c.length;let y=s;for(_=0;_<p;){const v=c[_++],x=c[_++];try{y=v(y)}catch(R){x.call(this,R);break}}try{l=Is.call(this,y)}catch(v){return Promise.reject(v)}for(_=0,p=u.length;_<p;)l=l.then(u[_++],u[_++]);return l}getUri(e){e=nt(this.defaults,e);const s=Io(e.baseURL,e.url);return wo(s,e.params,e.paramsSerializer)}}b.forEach(["delete","get","head","options"],function(e){sn.prototype[e]=function(s,i){return this.request(nt(i||{},{method:e,url:s,data:(i||{}).data}))}});b.forEach(["post","put","patch"],function(e){function s(i){return function(o,a,c){return this.request(nt(c||{},{method:e,headers:i?{"Content-Type":"multipart/form-data"}:{},url:o,data:a}))}}sn.prototype[e]=s(),sn.prototype[e+"Form"]=s(!0)});var Jt=sn;class as{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let s;this.promise=new Promise(function(o){s=o});const i=this;this.promise.then(n=>{if(!i._listeners)return;let o=i._listeners.length;for(;o-- >0;)i._listeners[o](n);i._listeners=null}),this.promise.then=n=>{let o;const a=new Promise(c=>{i.subscribe(c),o=c}).then(n);return a.cancel=function(){i.unsubscribe(o)},a},e(function(o,a,c){i.reason||(i.reason=new pt(o,a,c),s(i.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const s=this._listeners.indexOf(e);s!==-1&&this._listeners.splice(s,1)}static source(){let e;return{token:new as(function(n){e=n}),cancel:e}}}var Ur=as;function Lr(t){return function(s){return t.apply(null,s)}}function Wr(t){return b.isObject(t)&&t.isAxiosError===!0}const Qn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Qn).forEach(([t,e])=>{Qn[e]=t});var Xr=Qn;function Po(t){const e=new Jt(t),s=lo(Jt.prototype.request,e);return b.extend(s,Jt.prototype,e,{allOwnKeys:!0}),b.extend(s,e,null,{allOwnKeys:!0}),s.create=function(n){return Po(nt(t,n))},s}const re=Po(is);re.Axios=Jt;re.CanceledError=pt;re.CancelToken=Ur;re.isCancel=Co;re.VERSION=Do;re.toFormData=gn;re.AxiosError=V;re.Cancel=re.CanceledError;re.all=function(e){return Promise.all(e)};re.spread=Lr;re.isAxiosError=Wr;re.mergeConfig=nt;re.AxiosHeaders=Se;re.formToJSON=t=>Eo(b.isHTMLForm(t)?new FormData(t):t);re.getAdapter=Ao.getAdapter;re.HttpStatusCode=Xr;re.default=re;var Ss=re;const Hr={data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{formData:{siret:"",company_name:"",siren_number:"",manager_name:"",address:"",city:"",postal_code:"",country:"",phone:"",mobile_phone:"",email:"",website:"",currency_id:"",note:"",user_create:""},fields:{company_name:{label:t.company_name,type:"text",required:!0},manager_name:{label:t.manager_name,type:"text"},address:{label:t.address,type:"text",required:!0},city:{label:t.city,type:"text",required:!0},postal_code:{label:t.postal_code,type:"text"},country:{label:t.country,type:"text"},phone:{label:t.phone,type:"tel",required:!0},mobile_phone:{label:t.mobile,type:"tel"},email:{label:t.email,type:"email",required:!0},website:{label:t.website,type:"url"},currency_id:{label:t.currency,type:"text",required:!0}},options:{currency_options:[],default_currency:"",addon_user_active:!1,addon_siret_active:!1},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},loadingBtn:!1,loadingSiret:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{submitForm(){this.loadingBtn=!0,Ss.post("/wp-json/my-easy-compta/v1/clients/add",this.formData,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>{t.data.success?(this.showToast(t.data.message,"alert-success"),this.loadingBtn=!1,this.resetForm(),this.closeModal(),this.$emit("clientAdded")):(this.showToast(t.data.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Erreur serveur";console.error(t),this.showToast(e,"alert-error"),this.loadingBtn=!1})},closeModal(){document.getElementById("modal_clients").close()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},resetForm(){for(let t in this.formData)this.formData[t]=""},getOptions(t){return t==="currency_id"?this.options.currency_options:[]},fetchOptions(){Ss.get("/wp-json/my-easy-compta/v1/options",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>{this.options.currency_options=t.data.currency_options,this.options.default_currency=t.data.default_currency,this.options.addon_user_active=t.data.addon_user_active,this.options.addon_siret_active=t.data.addon_siret_active}).catch(t=>{console.error("Erreur lors de la r\xE9cup\xE9ration des options",t)})},fetchCompanyInfo(t){t.preventDefault(),this.loadingSiret=!0;const e=this.formData.siret;e?fetch(`/wp-json/my-easy-compta/v1/fetch-company-info/${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>{if(!s.ok)throw new Error("Network response was not ok");return s.json()}).then(s=>{s?(this.formData.company_name=s.company_name,this.formData.manager_name=s.manager_name,this.formData.address=s.address,this.formData.postal_code=s.postal_code,this.formData.city=s.city,this.formData.siren_number=s.siren,this.showToast("Informations charg\xE9es avec succ\xE8s","alert-success"),this.loadingSiret=!1):(this.showToast("Aucune information trouv\xE9e pour ce SIRET","alert-error"),this.loadingSiret=!1)}).catch(s=>{console.error("Error fetching company info:",s),this.showToast("Erreur lors du chargement des informations","alert-error"),this.loadingSiret=!1}):(this.showToast("Veuillez saisir un num\xE9ro SIRET","alert-error"),this.loadingSiret=!1)}},mounted(){this.fetchOptions()}},zr={id:"modal_clients",class:"modal"},Qr={class:"modal-box"},Gr={class:"font-bold text-lg"},Jr={key:0,class:"grid grid-cols-1 gap-4"},Yr={class:"ecwp-group form-group relative join"},Kr={for:"siret",class:"ecwp-label form-label"},Zr=["disabled"],$r={key:0,class:"loading loading-spinner loading-sm"},ea={key:1},ta={class:"grid grid-cols-1 gap-4"},na={class:"ecwp-group form-group relative"},sa={for:"siren",class:"ecwp-label form-label"},oa={class:"grid grid-cols-1 gap-4"},ia={class:"ecwp-group form-group relative"},ra={for:"tax_number",class:"ecwp-label form-label"},aa={class:"grid grid-cols-2 gap-4"},la=["for"],ca=["id","onUpdate:modelValue","required"],da=["value"],ua=["value"],ha=["type","id","onUpdate:modelValue","required"],ma={class:"ecwp-group form-group mt-4 relative"},fa=["for"],pa={key:1,class:"ecwp-group form-group mt-6 w-52 flex justify-between"},_a={class:"form-group mt-4 flex justify-end"},ga=["disabled"],ya={key:0,class:"loading loading-spinner loading-sm"};function ba(t,e,s,i,n,o){return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",zr,[r("div",Qr,[r("h3",Gr,d(o.translations.new_client),1),r("form",{onSubmit:e[7]||(e[7]=K((...a)=>o.submitForm&&o.submitForm(...a),["prevent"]))},[r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=a=>o.closeModal())}," \u2715 "),n.options.addon_siret_active?(h(),m("div",Jr,[r("div",Yr,[r("label",Kr,d(o.translations.siret),1),D(r("input",{type:"number",id:"siret","onUpdate:modelValue":e[1]||(e[1]=a=>n.formData.siret=a),class:"ecwp-input input input-bordered w-full"},null,512),[[W,n.formData.siret]]),r("button",{onClick:e[2]||(e[2]=(...a)=>o.fetchCompanyInfo&&o.fetchCompanyInfo(...a)),class:"btn join-item rounded-r-full mt-5",disabled:n.loadingSiret},[n.loadingSiret?(h(),m("span",$r)):(h(),m("span",ea,d(o.translations.search),1))],8,Zr)])])):g("",!0),r("div",ta,[r("div",na,[r("label",sa,d(o.translations.siren),1),D(r("input",{type:"number",id:"siren","onUpdate:modelValue":e[3]||(e[3]=a=>n.formData.siren_number=a),class:"ecwp-input input input-bordered w-full"},null,512),[[W,n.formData.siren_number]])])]),r("div",oa,[r("div",ia,[r("label",ra,d(o.translations.tax_number),1),D(r("input",{type:"text",id:"tax_number","onUpdate:modelValue":e[4]||(e[4]=a=>n.formData.tax_number=a),class:"ecwp-input input input-bordered w-full"},null,512),[[W,n.formData.tax_number]])])]),r("div",aa,[(h(!0),m(F,null,L(n.fields,(a,c)=>(h(),m("div",{key:c,class:"ecwp-group form-group relative"},[r("label",{for:c,class:"ecwp-label form-label"},d(a.label),9,la),c==="currency_id"?D((h(),m("select",{key:0,id:c,"onUpdate:modelValue":f=>n.formData[c]=f,class:"ecwp-input input input-bordered w-full peer",required:a.required},[r("option",{value:n.options.default_currency},d(o.translations.default_currency),9,da),(h(!0),m(F,null,L(o.getOptions(c),f=>(h(),m("option",{key:f.id,value:f.id},d(f.name)+" - "+d(f.code)+" ("+d(f.symbol)+") ",9,ua))),128))],8,ca)),[[ue,n.formData[c]]]):D((h(),m("input",{key:1,type:a.type,id:c,"onUpdate:modelValue":f=>n.formData[c]=f,class:"ecwp-input input input-bordered w-full peer",placeholder:" ",required:a.required},null,8,ha)),[[ai,n.formData[c]]])]))),128))]),r("div",ma,[r("label",{for:t.key,class:"ecwp-label form-label"},d(o.translations.note),9,fa),D(r("textarea",{id:"note","onUpdate:modelValue":e[5]||(e[5]=a=>n.formData.note=a),class:"ecwp-input textarea textarea-bordered w-full peer",rows:"4",placeholder:" "},null,512),[[W,n.formData.note]])]),n.options.addon_user_active?(h(),m("div",pa,[r("label",null,d(o.translations.create_user),1),D(r("input",{class:"ecwp-switch",type:"checkbox","onUpdate:modelValue":e[6]||(e[6]=a=>n.formData.user_create=a)},null,512),[[ri,n.formData.user_create]])])):g("",!0),r("div",_a,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.add)+" ",1),n.loadingBtn?(h(),m("span",ya)):g("",!0)],8,ga)])],32)])])])}var Ro=ne(Hr,[["render",ba]]);/*!
     5`):" "+Ts(o[0]):"as no adapter specified";throw new V("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return i},adapters:Hn};function An(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new pt(null,t)}function Is(t){return An(t),t.headers=Ae.from(t.headers),t.data=kn.call(t,t.transformRequest),["post","put","patch"].indexOf(t.method)!==-1&&t.headers.setContentType("application/x-www-form-urlencoded",!1),So.getAdapter(t.adapter||is.adapter)(t).then(function(i){return An(t),i.data=kn.call(t,t.transformResponse,i),i.headers=Ae.from(i.headers),i},function(i){return Co(i)||(An(t),i&&i.response&&(i.response.data=kn.call(t,t.transformResponse,i.response),i.response.headers=Ae.from(i.response.headers))),Promise.reject(i)})}const Do="1.7.2",rs={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{rs[t]=function(i){return typeof i===t||"a"+(e<1?"n ":" ")+t}});const ks={};rs.transitional=function(e,s,i){function n(o,a){return"[Axios v"+Do+"] Transitional option '"+o+"'"+a+(i?". "+i:"")}return(o,a,l)=>{if(e===!1)throw new V(n(a," has been removed"+(s?" in "+s:"")),V.ERR_DEPRECATED);return s&&!ks[a]&&(ks[a]=!0,console.warn(n(a," has been deprecated since v"+s+" and will be removed in the near future"))),e?e(o,a,l):!0}};function Ur(t,e,s){if(typeof t!="object")throw new V("options must be an object",V.ERR_BAD_OPTION_VALUE);const i=Object.keys(t);let n=i.length;for(;n-- >0;){const o=i[n],a=e[o];if(a){const l=t[o],f=l===void 0||a(l,o,t);if(f!==!0)throw new V("option "+o+" must be "+f,V.ERR_BAD_OPTION_VALUE);continue}if(s!==!0)throw new V("Unknown option "+o,V.ERR_BAD_OPTION)}}var zn={assertOptions:Ur,validators:rs};const ze=zn.validators;class sn{constructor(e){this.defaults=e,this.interceptors={request:new bs,response:new bs}}async request(e,s){try{return await this._request(e,s)}catch(i){if(i instanceof Error){let n;Error.captureStackTrace?Error.captureStackTrace(n={}):n=new Error;const o=n.stack?n.stack.replace(/^.+\n/,""):"";try{i.stack?o&&!String(i.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(i.stack+=`
     6`+o):i.stack=o}catch{}}throw i}}_request(e,s){typeof e=="string"?(s=s||{},s.url=e):s=e||{},s=nt(this.defaults,s);const{transitional:i,paramsSerializer:n,headers:o}=s;i!==void 0&&zn.assertOptions(i,{silentJSONParsing:ze.transitional(ze.boolean),forcedJSONParsing:ze.transitional(ze.boolean),clarifyTimeoutError:ze.transitional(ze.boolean)},!1),n!=null&&(b.isFunction(n)?s.paramsSerializer={serialize:n}:zn.assertOptions(n,{encode:ze.function,serialize:ze.function},!0)),s.method=(s.method||this.defaults.method||"get").toLowerCase();let a=o&&b.merge(o.common,o[s.method]);o&&b.forEach(["delete","get","head","post","put","patch","common"],v=>{delete o[v]}),s.headers=Ae.concat(a,o);const l=[];let f=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(s)===!1||(f=f&&x.synchronous,l.unshift(x.fulfilled,x.rejected))});const d=[];this.interceptors.response.forEach(function(x){d.push(x.fulfilled,x.rejected)});let m,p=0,y;if(!f){const v=[Is.bind(this),void 0];for(v.unshift.apply(v,l),v.push.apply(v,d),y=v.length,m=Promise.resolve(s);p<y;)m=m.then(v[p++],v[p++]);return m}y=l.length;let _=s;for(p=0;p<y;){const v=l[p++],x=l[p++];try{_=v(_)}catch(j){x.call(this,j);break}}try{m=Is.call(this,_)}catch(v){return Promise.reject(v)}for(p=0,y=d.length;p<y;)m=m.then(d[p++],d[p++]);return m}getUri(e){e=nt(this.defaults,e);const s=Io(e.baseURL,e.url);return wo(s,e.params,e.paramsSerializer)}}b.forEach(["delete","get","head","options"],function(e){sn.prototype[e]=function(s,i){return this.request(nt(i||{},{method:e,url:s,data:(i||{}).data}))}});b.forEach(["post","put","patch"],function(e){function s(i){return function(o,a,l){return this.request(nt(l||{},{method:e,headers:i?{"Content-Type":"multipart/form-data"}:{},url:o,data:a}))}}sn.prototype[e]=s(),sn.prototype[e+"Form"]=s(!0)});var Jt=sn;class as{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let s;this.promise=new Promise(function(o){s=o});const i=this;this.promise.then(n=>{if(!i._listeners)return;let o=i._listeners.length;for(;o-- >0;)i._listeners[o](n);i._listeners=null}),this.promise.then=n=>{let o;const a=new Promise(l=>{i.subscribe(l),o=l}).then(n);return a.cancel=function(){i.unsubscribe(o)},a},e(function(o,a,l){i.reason||(i.reason=new pt(o,a,l),s(i.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const s=this._listeners.indexOf(e);s!==-1&&this._listeners.splice(s,1)}static source(){let e;return{token:new as(function(n){e=n}),cancel:e}}}var Lr=as;function Wr(t){return function(s){return t.apply(null,s)}}function Xr(t){return b.isObject(t)&&t.isAxiosError===!0}const Qn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Qn).forEach(([t,e])=>{Qn[e]=t});var Hr=Qn;function Po(t){const e=new Jt(t),s=lo(Jt.prototype.request,e);return b.extend(s,Jt.prototype,e,{allOwnKeys:!0}),b.extend(s,e,null,{allOwnKeys:!0}),s.create=function(n){return Po(nt(t,n))},s}const re=Po(is);re.Axios=Jt;re.CanceledError=pt;re.CancelToken=Lr;re.isCancel=Co;re.VERSION=Do;re.toFormData=gn;re.AxiosError=V;re.Cancel=re.CanceledError;re.all=function(e){return Promise.all(e)};re.spread=Wr;re.isAxiosError=Xr;re.mergeConfig=nt;re.AxiosHeaders=Ae;re.formToJSON=t=>Eo(b.isHTMLForm(t)?new FormData(t):t);re.getAdapter=So.getAdapter;re.HttpStatusCode=Hr;re.default=re;var As=re;const zr={data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{formData:{siret:"",company_name:"",siren_number:"",manager_name:"",address:"",city:"",postal_code:"",country:"",phone:"",mobile_phone:"",email:"",website:"",currency_id:"",note:"",user_create:""},fields:{company_name:{label:t.company_name,type:"text",required:!0},manager_name:{label:t.manager_name,type:"text"},address:{label:t.address,type:"text",required:!0},city:{label:t.city,type:"text",required:!0},postal_code:{label:t.postal_code,type:"text"},country:{label:t.country,type:"text"},phone:{label:t.phone,type:"tel",required:!0},mobile_phone:{label:t.mobile,type:"tel"},email:{label:t.email,type:"email",required:!0},website:{label:t.website,type:"url"},currency_id:{label:t.currency,type:"text",required:!0}},options:{currency_options:[],default_currency:"",addon_user_active:!1,addon_siret_active:!1},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},loadingBtn:!1,loadingSiret:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{submitForm(){this.loadingBtn=!0,As.post("/wp-json/my-easy-compta/v1/clients/add",this.formData,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>{t.data.success?(this.showToast(t.data.message,"alert-success"),this.loadingBtn=!1,this.resetForm(),this.closeModal(),this.$emit("clientAdded")):(this.showToast(t.data.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Erreur serveur";console.error(t),this.showToast(e,"alert-error"),this.loadingBtn=!1})},closeModal(){document.getElementById("modal_clients").close()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},resetForm(){for(let t in this.formData)this.formData[t]=""},getOptions(t){return t==="currency_id"?this.options.currency_options:[]},fetchOptions(){As.get("/wp-json/my-easy-compta/v1/options",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>{this.options.currency_options=t.data.currency_options,this.options.default_currency=t.data.default_currency,this.options.addon_user_active=t.data.addon_user_active,this.options.addon_siret_active=t.data.addon_siret_active}).catch(t=>{console.error("Erreur lors de la r\xE9cup\xE9ration des options",t)})},fetchCompanyInfo(t){t.preventDefault(),this.loadingSiret=!0;const e=this.formData.siret;e?fetch(`/wp-json/my-easy-compta/v1/fetch-company-info/${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>{if(!s.ok)throw new Error("Network response was not ok");return s.json()}).then(s=>{s?(this.formData.company_name=s.company_name,this.formData.manager_name=s.manager_name,this.formData.address=s.address,this.formData.postal_code=s.postal_code,this.formData.city=s.city,this.formData.siren_number=s.siren,this.showToast("Informations charg\xE9es avec succ\xE8s","alert-success"),this.loadingSiret=!1):(this.showToast("Aucune information trouv\xE9e pour ce SIRET","alert-error"),this.loadingSiret=!1)}).catch(s=>{console.error("Error fetching company info:",s),this.showToast("Erreur lors du chargement des informations","alert-error"),this.loadingSiret=!1}):(this.showToast("Veuillez saisir un num\xE9ro SIRET","alert-error"),this.loadingSiret=!1)}},mounted(){this.fetchOptions()}},Qr={id:"modal_clients",class:"modal"},Gr={class:"modal-box"},Jr={class:"font-bold text-lg"},Yr={key:0,class:"grid grid-cols-1 gap-4"},Kr={class:"ecwp-group form-group relative join"},Zr={for:"siret",class:"ecwp-label form-label"},$r=["disabled"],ea={key:0,class:"loading loading-spinner loading-sm"},ta={key:1},na={class:"grid grid-cols-1 gap-4"},sa={class:"ecwp-group form-group relative"},oa={for:"siren",class:"ecwp-label form-label"},ia={class:"grid grid-cols-1 gap-4"},ra={class:"ecwp-group form-group relative"},aa={for:"tax_number",class:"ecwp-label form-label"},la={class:"grid grid-cols-2 gap-4"},ca=["for"],da=["id","onUpdate:modelValue","required"],ua=["value"],ha=["value"],ma=["type","id","onUpdate:modelValue","required"],fa={class:"ecwp-group form-group mt-4 relative"},pa=["for"],_a={key:1,class:"ecwp-group form-group mt-6 w-52 flex justify-between"},ga={class:"form-group mt-4 flex justify-end"},ya=["disabled"],ba={key:0,class:"loading loading-spinner loading-sm"};function va(t,e,s,i,n,o){return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",Qr,[r("div",Gr,[r("h3",Jr,c(o.translations.new_client),1),r("form",{onSubmit:e[7]||(e[7]=J((...a)=>o.submitForm&&o.submitForm(...a),["prevent"]))},[r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=a=>o.closeModal())}," \u2715 "),n.options.addon_siret_active?(u(),h("div",Yr,[r("div",Kr,[r("label",Zr,c(o.translations.siret),1),D(r("input",{type:"number",id:"siret","onUpdate:modelValue":e[1]||(e[1]=a=>n.formData.siret=a),class:"ecwp-input input input-bordered w-full"},null,512),[[W,n.formData.siret]]),r("button",{onClick:e[2]||(e[2]=(...a)=>o.fetchCompanyInfo&&o.fetchCompanyInfo(...a)),class:"btn join-item rounded-r-full mt-5",disabled:n.loadingSiret},[n.loadingSiret?(u(),h("span",ea)):(u(),h("span",ta,c(o.translations.search),1))],8,$r)])])):g("",!0),r("div",na,[r("div",sa,[r("label",oa,c(o.translations.siren),1),D(r("input",{type:"number",id:"siren","onUpdate:modelValue":e[3]||(e[3]=a=>n.formData.siren_number=a),class:"ecwp-input input input-bordered w-full"},null,512),[[W,n.formData.siren_number]])])]),r("div",ia,[r("div",ra,[r("label",aa,c(o.translations.tax_number),1),D(r("input",{type:"text",id:"tax_number","onUpdate:modelValue":e[4]||(e[4]=a=>n.formData.tax_number=a),class:"ecwp-input input input-bordered w-full"},null,512),[[W,n.formData.tax_number]])])]),r("div",la,[(u(!0),h(F,null,U(n.fields,(a,l)=>(u(),h("div",{key:l,class:"ecwp-group form-group relative"},[r("label",{for:l,class:"ecwp-label form-label"},c(a.label),9,ca),l==="currency_id"?D((u(),h("select",{key:0,id:l,"onUpdate:modelValue":f=>n.formData[l]=f,class:"ecwp-input input input-bordered w-full peer",required:a.required},[r("option",{value:n.options.default_currency},c(o.translations.default_currency),9,ua),(u(!0),h(F,null,U(o.getOptions(l),f=>(u(),h("option",{key:f.id,value:f.id},c(f.name)+" - "+c(f.code)+" ("+c(f.symbol)+") ",9,ha))),128))],8,da)),[[ue,n.formData[l]]]):D((u(),h("input",{key:1,type:a.type,id:l,"onUpdate:modelValue":f=>n.formData[l]=f,class:"ecwp-input input input-bordered w-full peer",placeholder:" ",required:a.required},null,8,ma)),[[li,n.formData[l]]])]))),128))]),r("div",fa,[r("label",{for:t.key,class:"ecwp-label form-label"},c(o.translations.note),9,pa),D(r("textarea",{id:"note","onUpdate:modelValue":e[5]||(e[5]=a=>n.formData.note=a),class:"ecwp-input textarea textarea-bordered w-full peer",rows:"4",placeholder:" "},null,512),[[W,n.formData.note]])]),n.options.addon_user_active?(u(),h("div",_a,[r("label",null,c(o.translations.create_user),1),D(r("input",{class:"ecwp-switch",type:"checkbox","onUpdate:modelValue":e[6]||(e[6]=a=>n.formData.user_create=a)},null,512),[[ai,n.formData.user_create]])])):g("",!0),r("div",ga,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.add)+" ",1),n.loadingBtn?(u(),h("span",ba)):g("",!0)],8,ya)])],32)])])])}var jo=ne(zr,[["render",va]]);/*!
    77  * vue-router v4.4.0
    88  * (c) 2024 Eduardo San Martin Morote
    99  * @license MIT
    10   */const rt=typeof document!="undefined";function va(t){return t.__esModule||t[Symbol.toStringTag]==="Module"}const G=Object.assign;function An(t,e){const s={};for(const i in e){const n=e[i];s[i]=Ae(n)?n.map(t):t(n)}return s}const Tt=()=>{},Ae=Array.isArray,jo=/#/g,wa=/&/g,xa=/\//g,Ea=/=/g,Ca=/\?/g,Oo=/\+/g,Ta=/%5B/g,Ia=/%5D/g,Mo=/%5E/g,ka=/%60/g,qo=/%7B/g,Sa=/%7C/g,No=/%7D/g,Aa=/%20/g;function ls(t){return encodeURI(""+t).replace(Sa,"|").replace(Ta,"[").replace(Ia,"]")}function Da(t){return ls(t).replace(qo,"{").replace(No,"}").replace(Mo,"^")}function Gn(t){return ls(t).replace(Oo,"%2B").replace(Aa,"+").replace(jo,"%23").replace(wa,"%26").replace(ka,"`").replace(qo,"{").replace(No,"}").replace(Mo,"^")}function Pa(t){return Gn(t).replace(Ea,"%3D")}function Ra(t){return ls(t).replace(jo,"%23").replace(Ca,"%3F")}function ja(t){return t==null?"":Ra(t).replace(xa,"%2F")}function Ot(t){try{return decodeURIComponent(""+t)}catch{}return""+t}const Oa=/\/$/,Ma=t=>t.replace(Oa,"");function Dn(t,e,s="/"){let i,n={},o="",a="";const c=e.indexOf("#");let f=e.indexOf("?");return c<f&&c>=0&&(f=-1),f>-1&&(i=e.slice(0,f),o=e.slice(f+1,c>-1?c:e.length),n=t(o)),c>-1&&(i=i||e.slice(0,c),a=e.slice(c,e.length)),i=Va(i!=null?i:e,s),{fullPath:i+(o&&"?")+o+a,path:i,query:n,hash:Ot(a)}}function qa(t,e){const s=e.query?t(e.query):"";return e.path+(s&&"?")+s+(e.hash||"")}function As(t,e){return!e||!t.toLowerCase().startsWith(e.toLowerCase())?t:t.slice(e.length)||"/"}function Na(t,e,s){const i=e.matched.length-1,n=s.matched.length-1;return i>-1&&i===n&&dt(e.matched[i],s.matched[n])&&Bo(e.params,s.params)&&t(e.query)===t(s.query)&&e.hash===s.hash}function dt(t,e){return(t.aliasOf||t)===(e.aliasOf||e)}function Bo(t,e){if(Object.keys(t).length!==Object.keys(e).length)return!1;for(const s in t)if(!Ba(t[s],e[s]))return!1;return!0}function Ba(t,e){return Ae(t)?Ds(t,e):Ae(e)?Ds(e,t):t===e}function Ds(t,e){return Ae(e)?t.length===e.length&&t.every((s,i)=>s===e[i]):t.length===1&&t[0]===e}function Va(t,e){if(t.startsWith("/"))return t;if(!t)return e;const s=e.split("/"),i=t.split("/"),n=i[i.length-1];(n===".."||n===".")&&i.push("");let o=s.length-1,a,c;for(a=0;a<i.length;a++)if(c=i[a],c!==".")if(c==="..")o>1&&o--;else break;return s.slice(0,o).join("/")+"/"+i.slice(a).join("/")}const Qe={path:"/",name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0};var Mt;(function(t){t.pop="pop",t.push="push"})(Mt||(Mt={}));var It;(function(t){t.back="back",t.forward="forward",t.unknown=""})(It||(It={}));function Fa(t){if(!t)if(rt){const e=document.querySelector("base");t=e&&e.getAttribute("href")||"/",t=t.replace(/^\w+:\/\/[^\/]+/,"")}else t="/";return t[0]!=="/"&&t[0]!=="#"&&(t="/"+t),Ma(t)}const Ua=/^[^#]+#/;function La(t,e){return t.replace(Ua,"#")+e}function Wa(t,e){const s=document.documentElement.getBoundingClientRect(),i=t.getBoundingClientRect();return{behavior:e.behavior,left:i.left-s.left-(e.left||0),top:i.top-s.top-(e.top||0)}}const vn=()=>({left:window.scrollX,top:window.scrollY});function Xa(t){let e;if("el"in t){const s=t.el,i=typeof s=="string"&&s.startsWith("#"),n=typeof s=="string"?i?document.getElementById(s.slice(1)):document.querySelector(s):s;if(!n)return;e=Wa(n,t)}else e=t;"scrollBehavior"in document.documentElement.style?window.scrollTo(e):window.scrollTo(e.left!=null?e.left:window.scrollX,e.top!=null?e.top:window.scrollY)}function Ps(t,e){return(history.state?history.state.position-e:-1)+t}const Jn=new Map;function Ha(t,e){Jn.set(t,e)}function za(t){const e=Jn.get(t);return Jn.delete(t),e}let Qa=()=>location.protocol+"//"+location.host;function Vo(t,e){const{pathname:s,search:i,hash:n}=e,o=t.indexOf("#");if(o>-1){let c=n.includes(t.slice(o))?t.slice(o).length:1,f=n.slice(c);return f[0]!=="/"&&(f="/"+f),As(f,"")}return As(s,t)+i+n}function Ga(t,e,s,i){let n=[],o=[],a=null;const c=({state:p})=>{const y=Vo(t,location),v=s.value,x=e.value;let R=0;if(p){if(s.value=y,e.value=p,a&&a===v){a=null;return}R=x?p.position-x.position:0}else i(y);n.forEach(M=>{M(s.value,v,{delta:R,type:Mt.pop,direction:R?R>0?It.forward:It.back:It.unknown})})};function f(){a=s.value}function u(p){n.push(p);const y=()=>{const v=n.indexOf(p);v>-1&&n.splice(v,1)};return o.push(y),y}function l(){const{history:p}=window;!p.state||p.replaceState(G({},p.state,{scroll:vn()}),"")}function _(){for(const p of o)p();o=[],window.removeEventListener("popstate",c),window.removeEventListener("beforeunload",l)}return window.addEventListener("popstate",c),window.addEventListener("beforeunload",l,{passive:!0}),{pauseListeners:f,listen:u,destroy:_}}function Rs(t,e,s,i=!1,n=!1){return{back:t,current:e,forward:s,replaced:i,position:window.history.length,scroll:n?vn():null}}function Ja(t){const{history:e,location:s}=window,i={value:Vo(t,s)},n={value:e.state};n.value||o(i.value,{back:null,current:i.value,forward:null,position:e.length-1,replaced:!0,scroll:null},!0);function o(f,u,l){const _=t.indexOf("#"),p=_>-1?(s.host&&document.querySelector("base")?t:t.slice(_))+f:Qa()+t+f;try{e[l?"replaceState":"pushState"](u,"",p),n.value=u}catch(y){console.error(y),s[l?"replace":"assign"](p)}}function a(f,u){const l=G({},e.state,Rs(n.value.back,f,n.value.forward,!0),u,{position:n.value.position});o(f,l,!0),i.value=f}function c(f,u){const l=G({},n.value,e.state,{forward:f,scroll:vn()});o(l.current,l,!0);const _=G({},Rs(i.value,f,null),{position:l.position+1},u);o(f,_,!1),i.value=f}return{location:i,state:n,push:c,replace:a}}function Ya(t){t=Fa(t);const e=Ja(t),s=Ga(t,e.state,e.location,e.replace);function i(o,a=!0){a||s.pauseListeners(),history.go(o)}const n=G({location:"",base:t,go:i,createHref:La.bind(null,t)},e,s);return Object.defineProperty(n,"location",{enumerable:!0,get:()=>e.location.value}),Object.defineProperty(n,"state",{enumerable:!0,get:()=>e.state.value}),n}function Ka(t){return t=location.host?t||location.pathname+location.search:"",t.includes("#")||(t+="#"),Ya(t)}function Za(t){return typeof t=="string"||t&&typeof t=="object"}function Fo(t){return typeof t=="string"||typeof t=="symbol"}const Uo=Symbol("");var js;(function(t){t[t.aborted=4]="aborted",t[t.cancelled=8]="cancelled",t[t.duplicated=16]="duplicated"})(js||(js={}));function ut(t,e){return G(new Error,{type:t,[Uo]:!0},e)}function Fe(t,e){return t instanceof Error&&Uo in t&&(e==null||!!(t.type&e))}const Os="[^/]+?",$a={sensitive:!1,strict:!1,start:!0,end:!0},el=/[.+*?^${}()[\]/\\]/g;function tl(t,e){const s=G({},$a,e),i=[];let n=s.start?"^":"";const o=[];for(const u of t){const l=u.length?[]:[90];s.strict&&!u.length&&(n+="/");for(let _=0;_<u.length;_++){const p=u[_];let y=40+(s.sensitive?.25:0);if(p.type===0)_||(n+="/"),n+=p.value.replace(el,"\\$&"),y+=40;else if(p.type===1){const{value:v,repeatable:x,optional:R,regexp:M}=p;o.push({name:v,repeatable:x,optional:R});const A=M||Os;if(A!==Os){y+=10;try{new RegExp(`(${A})`)}catch(z){throw new Error(`Invalid custom RegExp for param "${v}" (${A}): `+z.message)}}let k=x?`((?:${A})(?:/(?:${A}))*)`:`(${A})`;_||(k=R&&u.length<2?`(?:/${k})`:"/"+k),R&&(k+="?"),n+=k,y+=20,R&&(y+=-8),x&&(y+=-20),A===".*"&&(y+=-50)}l.push(y)}i.push(l)}if(s.strict&&s.end){const u=i.length-1;i[u][i[u].length-1]+=.7000000000000001}s.strict||(n+="/?"),s.end?n+="$":s.strict&&(n+="(?:/|$)");const a=new RegExp(n,s.sensitive?"":"i");function c(u){const l=u.match(a),_={};if(!l)return null;for(let p=1;p<l.length;p++){const y=l[p]||"",v=o[p-1];_[v.name]=y&&v.repeatable?y.split("/"):y}return _}function f(u){let l="",_=!1;for(const p of t){(!_||!l.endsWith("/"))&&(l+="/"),_=!1;for(const y of p)if(y.type===0)l+=y.value;else if(y.type===1){const{value:v,repeatable:x,optional:R}=y,M=v in u?u[v]:"";if(Ae(M)&&!x)throw new Error(`Provided param "${v}" is an array but it is not repeatable (* or + modifiers)`);const A=Ae(M)?M.join("/"):M;if(!A)if(R)p.length<2&&(l.endsWith("/")?l=l.slice(0,-1):_=!0);else throw new Error(`Missing required param "${v}"`);l+=A}}return l||"/"}return{re:a,score:i,keys:o,parse:c,stringify:f}}function nl(t,e){let s=0;for(;s<t.length&&s<e.length;){const i=e[s]-t[s];if(i)return i;s++}return t.length<e.length?t.length===1&&t[0]===40+40?-1:1:t.length>e.length?e.length===1&&e[0]===40+40?1:-1:0}function Lo(t,e){let s=0;const i=t.score,n=e.score;for(;s<i.length&&s<n.length;){const o=nl(i[s],n[s]);if(o)return o;s++}if(Math.abs(n.length-i.length)===1){if(Ms(i))return 1;if(Ms(n))return-1}return n.length-i.length}function Ms(t){const e=t[t.length-1];return t.length>0&&e[e.length-1]<0}const sl={type:0,value:""},ol=/[a-zA-Z0-9_]/;function il(t){if(!t)return[[]];if(t==="/")return[[sl]];if(!t.startsWith("/"))throw new Error(`Invalid path "${t}"`);function e(y){throw new Error(`ERR (${s})/"${u}": ${y}`)}let s=0,i=s;const n=[];let o;function a(){o&&n.push(o),o=[]}let c=0,f,u="",l="";function _(){!u||(s===0?o.push({type:0,value:u}):s===1||s===2||s===3?(o.length>1&&(f==="*"||f==="+")&&e(`A repeatable param (${u}) must be alone in its segment. eg: '/:ids+.`),o.push({type:1,value:u,regexp:l,repeatable:f==="*"||f==="+",optional:f==="*"||f==="?"})):e("Invalid state to consume buffer"),u="")}function p(){u+=f}for(;c<t.length;){if(f=t[c++],f==="\\"&&s!==2){i=s,s=4;continue}switch(s){case 0:f==="/"?(u&&_(),a()):f===":"?(_(),s=1):p();break;case 4:p(),s=i;break;case 1:f==="("?s=2:ol.test(f)?p():(_(),s=0,f!=="*"&&f!=="?"&&f!=="+"&&c--);break;case 2:f===")"?l[l.length-1]=="\\"?l=l.slice(0,-1)+f:s=3:l+=f;break;case 3:_(),s=0,f!=="*"&&f!=="?"&&f!=="+"&&c--,l="";break;default:e("Unknown state");break}}return s===2&&e(`Unfinished custom RegExp for param "${u}"`),_(),a(),n}function rl(t,e,s){const i=tl(il(t.path),s),n=G(i,{record:t,parent:e,children:[],alias:[]});return e&&!n.record.aliasOf==!e.record.aliasOf&&e.children.push(n),n}function al(t,e){const s=[],i=new Map;e=Bs({strict:!1,end:!0,sensitive:!1},e);function n(_){return i.get(_)}function o(_,p,y){const v=!y,x=ll(_);x.aliasOf=y&&y.record;const R=Bs(e,_),M=[x];if("alias"in _){const z=typeof _.alias=="string"?[_.alias]:_.alias;for(const le of z)M.push(G({},x,{components:y?y.record.components:x.components,path:le,aliasOf:y?y.record:x}))}let A,k;for(const z of M){const{path:le}=z;if(p&&le[0]!=="/"){const J=p.record.path,Y=J[J.length-1]==="/"?"":"/";z.path=p.record.path+(le&&Y+le)}if(A=rl(z,p,R),y?y.alias.push(A):(k=k||A,k!==A&&k.alias.push(A),v&&_.name&&!Ns(A)&&a(_.name)),Wo(A)&&f(A),x.children){const J=x.children;for(let Y=0;Y<J.length;Y++)o(J[Y],A,y&&y.children[Y])}y=y||A}return k?()=>{a(k)}:Tt}function a(_){if(Fo(_)){const p=i.get(_);p&&(i.delete(_),s.splice(s.indexOf(p),1),p.children.forEach(a),p.alias.forEach(a))}else{const p=s.indexOf(_);p>-1&&(s.splice(p,1),_.record.name&&i.delete(_.record.name),_.children.forEach(a),_.alias.forEach(a))}}function c(){return s}function f(_){const p=ul(_,s);s.splice(p,0,_),_.record.name&&!Ns(_)&&i.set(_.record.name,_)}function u(_,p){let y,v={},x,R;if("name"in _&&_.name){if(y=i.get(_.name),!y)throw ut(1,{location:_});R=y.record.name,v=G(qs(p.params,y.keys.filter(k=>!k.optional).concat(y.parent?y.parent.keys.filter(k=>k.optional):[]).map(k=>k.name)),_.params&&qs(_.params,y.keys.map(k=>k.name))),x=y.stringify(v)}else if(_.path!=null)x=_.path,y=s.find(k=>k.re.test(x)),y&&(v=y.parse(x),R=y.record.name);else{if(y=p.name?i.get(p.name):s.find(k=>k.re.test(p.path)),!y)throw ut(1,{location:_,currentLocation:p});R=y.record.name,v=G({},p.params,_.params),x=y.stringify(v)}const M=[];let A=y;for(;A;)M.unshift(A.record),A=A.parent;return{name:R,path:x,params:v,matched:M,meta:dl(M)}}t.forEach(_=>o(_));function l(){s.length=0,i.clear()}return{addRoute:o,resolve:u,removeRoute:a,clearRoutes:l,getRoutes:c,getRecordMatcher:n}}function qs(t,e){const s={};for(const i of e)i in t&&(s[i]=t[i]);return s}function ll(t){return{path:t.path,redirect:t.redirect,name:t.name,meta:t.meta||{},aliasOf:void 0,beforeEnter:t.beforeEnter,props:cl(t),children:t.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},components:"components"in t?t.components||null:t.component&&{default:t.component}}}function cl(t){const e={},s=t.props||!1;if("component"in t)e.default=s;else for(const i in t.components)e[i]=typeof s=="object"?s[i]:s;return e}function Ns(t){for(;t;){if(t.record.aliasOf)return!0;t=t.parent}return!1}function dl(t){return t.reduce((e,s)=>G(e,s.meta),{})}function Bs(t,e){const s={};for(const i in t)s[i]=i in e?e[i]:t[i];return s}function ul(t,e){let s=0,i=e.length;for(;s!==i;){const o=s+i>>1;Lo(t,e[o])<0?i=o:s=o+1}const n=hl(t);return n&&(i=e.lastIndexOf(n,i-1)),i}function hl(t){let e=t;for(;e=e.parent;)if(Wo(e)&&Lo(t,e)===0)return e}function Wo({record:t}){return!!(t.name||t.components&&Object.keys(t.components).length||t.redirect)}function ml(t){const e={};if(t===""||t==="?")return e;const i=(t[0]==="?"?t.slice(1):t).split("&");for(let n=0;n<i.length;++n){const o=i[n].replace(Oo," "),a=o.indexOf("="),c=Ot(a<0?o:o.slice(0,a)),f=a<0?null:Ot(o.slice(a+1));if(c in e){let u=e[c];Ae(u)||(u=e[c]=[u]),u.push(f)}else e[c]=f}return e}function Vs(t){let e="";for(let s in t){const i=t[s];if(s=Pa(s),i==null){i!==void 0&&(e+=(e.length?"&":"")+s);continue}(Ae(i)?i.map(o=>o&&Gn(o)):[i&&Gn(i)]).forEach(o=>{o!==void 0&&(e+=(e.length?"&":"")+s,o!=null&&(e+="="+o))})}return e}function fl(t){const e={};for(const s in t){const i=t[s];i!==void 0&&(e[s]=Ae(i)?i.map(n=>n==null?null:""+n):i==null?i:""+i)}return e}const pl=Symbol(""),Fs=Symbol(""),cs=Symbol(""),Xo=Symbol(""),Yn=Symbol("");function vt(){let t=[];function e(i){return t.push(i),()=>{const n=t.indexOf(i);n>-1&&t.splice(n,1)}}function s(){t=[]}return{add:e,list:()=>t.slice(),reset:s}}function Ge(t,e,s,i,n,o=a=>a()){const a=i&&(i.enterCallbacks[n]=i.enterCallbacks[n]||[]);return()=>new Promise((c,f)=>{const u=p=>{p===!1?f(ut(4,{from:s,to:e})):p instanceof Error?f(p):Za(p)?f(ut(2,{from:e,to:p})):(a&&i.enterCallbacks[n]===a&&typeof p=="function"&&a.push(p),c())},l=o(()=>t.call(i&&i.instances[n],e,s,u));let _=Promise.resolve(l);t.length<3&&(_=_.then(u)),_.catch(p=>f(p))})}function Pn(t,e,s,i,n=o=>o()){const o=[];for(const a of t)for(const c in a.components){let f=a.components[c];if(!(e!=="beforeRouteEnter"&&!a.instances[c]))if(_l(f)){const l=(f.__vccOpts||f)[e];l&&o.push(Ge(l,s,i,a,c,n))}else{let u=f();o.push(()=>u.then(l=>{if(!l)return Promise.reject(new Error(`Couldn't resolve component "${c}" at "${a.path}"`));const _=va(l)?l.default:l;a.components[c]=_;const y=(_.__vccOpts||_)[e];return y&&Ge(y,s,i,a,c,n)()}))}}return o}function _l(t){return typeof t=="object"||"displayName"in t||"props"in t||"__vccOpts"in t}function Us(t){const e=Rt(cs),s=Rt(Xo),i=je(()=>{const f=Ct(t.to);return e.resolve(f)}),n=je(()=>{const{matched:f}=i.value,{length:u}=f,l=f[u-1],_=s.matched;if(!l||!_.length)return-1;const p=_.findIndex(dt.bind(null,l));if(p>-1)return p;const y=Ls(f[u-2]);return u>1&&Ls(l)===y&&_[_.length-1].path!==y?_.findIndex(dt.bind(null,f[u-2])):p}),o=je(()=>n.value>-1&&vl(s.params,i.value.params)),a=je(()=>n.value>-1&&n.value===s.matched.length-1&&Bo(s.params,i.value.params));function c(f={}){return bl(f)?e[Ct(t.replace)?"replace":"push"](Ct(t.to)).catch(Tt):Promise.resolve()}return{route:i,href:je(()=>i.value.href),isActive:o,isExactActive:a,navigate:c}}const gl=eo({name:"RouterLink",compatConfig:{MODE:3},props:{to:{type:[String,Object],required:!0},replace:Boolean,activeClass:String,exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},useLink:Us,setup(t,{slots:e}){const s=ui(Us(t)),{options:i}=Rt(cs),n=je(()=>({[Ws(t.activeClass,i.linkActiveClass,"router-link-active")]:s.isActive,[Ws(t.exactActiveClass,i.linkExactActiveClass,"router-link-exact-active")]:s.isExactActive}));return()=>{const o=e.default&&e.default(s);return t.custom?o:to("a",{"aria-current":s.isExactActive?t.ariaCurrentValue:null,href:s.href,onClick:s.navigate,class:n.value},o)}}}),yl=gl;function bl(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)&&!t.defaultPrevented&&!(t.button!==void 0&&t.button!==0)){if(t.currentTarget&&t.currentTarget.getAttribute){const e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function vl(t,e){for(const s in e){const i=e[s],n=t[s];if(typeof i=="string"){if(i!==n)return!1}else if(!Ae(n)||n.length!==i.length||i.some((o,a)=>o!==n[a]))return!1}return!0}function Ls(t){return t?t.aliasOf?t.aliasOf.path:t.path:""}const Ws=(t,e,s)=>t!=null?t:e!=null?e:s,wl=eo({name:"RouterView",inheritAttrs:!1,props:{name:{type:String,default:"default"},route:Object},compatConfig:{MODE:3},setup(t,{attrs:e,slots:s}){const i=Rt(Yn),n=je(()=>t.route||i.value),o=Rt(Fs,0),a=je(()=>{let u=Ct(o);const{matched:l}=n.value;let _;for(;(_=l[u])&&!_.components;)u++;return u}),c=je(()=>n.value.matched[a.value]);Cn(Fs,je(()=>a.value+1)),Cn(pl,c),Cn(Yn,n);const f=hi();return mi(()=>[f.value,c.value,t.name],([u,l,_],[p,y,v])=>{l&&(l.instances[_]=u,y&&y!==l&&u&&u===p&&(l.leaveGuards.size||(l.leaveGuards=y.leaveGuards),l.updateGuards.size||(l.updateGuards=y.updateGuards))),u&&l&&(!y||!dt(l,y)||!p)&&(l.enterCallbacks[_]||[]).forEach(x=>x(u))},{flush:"post"}),()=>{const u=n.value,l=t.name,_=c.value,p=_&&_.components[l];if(!p)return Xs(s.default,{Component:p,route:u});const y=_.props[l],v=y?y===!0?u.params:typeof y=="function"?y(u):y:null,R=to(p,G({},v,e,{onVnodeUnmounted:M=>{M.component.isUnmounted&&(_.instances[l]=null)},ref:f}));return Xs(s.default,{Component:R,route:u})||R}}});function Xs(t,e){if(!t)return null;const s=t(e);return s.length===1?s[0]:s}const xl=wl;function El(t){const e=al(t.routes,t),s=t.parseQuery||ml,i=t.stringifyQuery||Vs,n=t.history,o=vt(),a=vt(),c=vt(),f=li(Qe);let u=Qe;rt&&t.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const l=An.bind(null,w=>""+w),_=An.bind(null,ja),p=An.bind(null,Ot);function y(w,S){let T,j;return Fo(w)?(T=e.getRecordMatcher(w),j=S):j=w,e.addRoute(j,T)}function v(w){const S=e.getRecordMatcher(w);S&&e.removeRoute(S)}function x(){return e.getRoutes().map(w=>w.record)}function R(w){return!!e.getRecordMatcher(w)}function M(w,S){if(S=G({},S||f.value),typeof w=="string"){const U=Dn(s,w,S.path),ae=e.resolve({path:U.path},S),yt=n.createHref(U.fullPath);return G(U,ae,{params:p(ae.params),hash:Ot(U.hash),redirectedFrom:void 0,href:yt})}let T;if(w.path!=null)T=G({},w,{path:Dn(s,w.path,S.path).path});else{const U=G({},w.params);for(const ae in U)U[ae]==null&&delete U[ae];T=G({},w,{params:_(U)}),S.params=_(S.params)}const j=e.resolve(T,S),Z=w.hash||"";j.params=l(p(j.params));const se=qa(i,G({},w,{hash:Da(Z),path:j.path})),X=n.createHref(se);return G({fullPath:se,hash:Z,query:i===Vs?fl(w.query):w.query||{}},j,{redirectedFrom:void 0,href:X})}function A(w){return typeof w=="string"?Dn(s,w,f.value.path):G({},w)}function k(w,S){if(u!==w)return ut(8,{from:S,to:w})}function z(w){return Y(w)}function le(w){return z(G(A(w),{replace:!0}))}function J(w){const S=w.matched[w.matched.length-1];if(S&&S.redirect){const{redirect:T}=S;let j=typeof T=="function"?T(w):T;return typeof j=="string"&&(j=j.includes("?")||j.includes("#")?j=A(j):{path:j},j.params={}),G({query:w.query,hash:w.hash,params:j.path!=null?{}:w.params},j)}}function Y(w,S){const T=u=M(w),j=f.value,Z=w.state,se=w.force,X=w.replace===!0,U=J(T);if(U)return Y(G(A(U),{state:typeof U=="object"?G({},Z,U.state):Z,force:se,replace:X}),S||T);const ae=T;ae.redirectedFrom=S;let yt;return!se&&Na(i,j,T)&&(yt=ut(16,{to:ae,from:j}),_t(j,j,!0,!1)),(yt?Promise.resolve(yt):Xe(ae,j)).catch(_e=>Fe(_e)?Fe(_e,2)?_e:Ut(_e):Ve(_e,ae,j)).then(_e=>{if(_e){if(Fe(_e,2))return Y(G({replace:X},A(_e.to),{state:typeof _e.to=="object"?G({},Z,_e.to.state):Z,force:se}),S||ae)}else _e=He(ae,j,!0,X,Z);return Ee(ae,j,_e),_e})}function Pe(w,S){const T=k(w,S);return T?Promise.reject(T):Promise.resolve()}function ce(w){const S=Lt.values().next().value;return S&&typeof S.runWithContext=="function"?S.runWithContext(w):w()}function Xe(w,S){let T;const[j,Z,se]=Cl(w,S);T=Pn(j.reverse(),"beforeRouteLeave",w,S);for(const U of j)U.leaveGuards.forEach(ae=>{T.push(Ge(ae,w,S))});const X=Pe.bind(null,w,S);return T.push(X),st(T).then(()=>{T=[];for(const U of o.list())T.push(Ge(U,w,S));return T.push(X),st(T)}).then(()=>{T=Pn(Z,"beforeRouteUpdate",w,S);for(const U of Z)U.updateGuards.forEach(ae=>{T.push(Ge(ae,w,S))});return T.push(X),st(T)}).then(()=>{T=[];for(const U of se)if(U.beforeEnter)if(Ae(U.beforeEnter))for(const ae of U.beforeEnter)T.push(Ge(ae,w,S));else T.push(Ge(U.beforeEnter,w,S));return T.push(X),st(T)}).then(()=>(w.matched.forEach(U=>U.enterCallbacks={}),T=Pn(se,"beforeRouteEnter",w,S,ce),T.push(X),st(T))).then(()=>{T=[];for(const U of a.list())T.push(Ge(U,w,S));return T.push(X),st(T)}).catch(U=>Fe(U,8)?U:Promise.reject(U))}function Ee(w,S,T){c.list().forEach(j=>ce(()=>j(w,S,T)))}function He(w,S,T,j,Z){const se=k(w,S);if(se)return se;const X=S===Qe,U=rt?history.state:{};T&&(j||X?n.replace(w.fullPath,G({scroll:X&&U&&U.scroll},Z)):n.push(w.fullPath,Z)),f.value=w,_t(w,S,T,X),Ut()}let fe;function qe(){fe||(fe=n.listen((w,S,T)=>{if(!fs.listening)return;const j=M(w),Z=J(j);if(Z){Y(G(Z,{replace:!0}),j).catch(Tt);return}u=j;const se=f.value;rt&&Ha(Ps(se.fullPath,T.delta),vn()),Xe(j,se).catch(X=>Fe(X,12)?X:Fe(X,2)?(Y(X.to,j).then(U=>{Fe(U,20)&&!T.delta&&T.type===Mt.pop&&n.go(-1,!1)}).catch(Tt),Promise.reject()):(T.delta&&n.go(-T.delta,!1),Ve(X,j,se))).then(X=>{X=X||He(j,se,!1),X&&(T.delta&&!Fe(X,8)?n.go(-T.delta,!1):T.type===Mt.pop&&Fe(X,20)&&n.go(-1,!1)),Ee(j,se,X)}).catch(Tt)}))}let Ne=vt(),Ce=vt(),Be;function Ve(w,S,T){Ut(w);const j=Ce.list();return j.length?j.forEach(Z=>Z(w,S,T)):console.error(w),Promise.reject(w)}function xn(){return Be&&f.value!==Qe?Promise.resolve():new Promise((w,S)=>{Ne.add([w,S])})}function Ut(w){return Be||(Be=!w,qe(),Ne.list().forEach(([S,T])=>w?T(w):S()),Ne.reset()),w}function _t(w,S,T,j){const{scrollBehavior:Z}=t;if(!rt||!Z)return Promise.resolve();const se=!T&&za(Ps(w.fullPath,0))||(j||!T)&&history.state&&history.state.scroll||null;return di().then(()=>Z(w,S,se)).then(X=>X&&Xa(X)).catch(X=>Ve(X,w,S))}const gt=w=>n.go(w);let En;const Lt=new Set,fs={currentRoute:f,listening:!0,addRoute:y,removeRoute:v,clearRoutes:e.clearRoutes,hasRoute:R,getRoutes:x,resolve:M,options:t,push:z,replace:le,go:gt,back:()=>gt(-1),forward:()=>gt(1),beforeEach:o.add,beforeResolve:a.add,afterEach:c.add,onError:Ce.add,isReady:xn,install(w){const S=this;w.component("RouterLink",yl),w.component("RouterView",xl),w.config.globalProperties.$router=S,Object.defineProperty(w.config.globalProperties,"$route",{enumerable:!0,get:()=>Ct(f)}),rt&&!En&&f.value===Qe&&(En=!0,z(n.location).catch(Z=>{}));const T={};for(const Z in Qe)Object.defineProperty(T,Z,{get:()=>f.value[Z],enumerable:!0});w.provide(cs,S),w.provide(Xo,ci(T)),w.provide(Yn,f);const j=w.unmount;Lt.add(w),w.unmount=function(){Lt.delete(w),Lt.size<1&&(u=Qe,fe&&fe(),fe=null,f.value=Qe,En=!1,Be=!1),j()}}};function st(w){return w.reduce((S,T)=>S.then(()=>ce(T)),Promise.resolve())}return fs}function Cl(t,e){const s=[],i=[],n=[],o=Math.max(e.matched.length,t.matched.length);for(let a=0;a<o;a++){const c=e.matched[a];c&&(t.matched.find(u=>dt(u,c))?i.push(c):s.push(c));const f=t.matched[a];f&&(e.matched.find(u=>dt(u,f))||n.push(f))}return[s,i,n]}const Tl={name:"QuoteEdit",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt},data(){return{quote:{quote_number:"",due_date:"",provisional_start_date:"",client_id:"",client:null,status:""},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchQuoteDetails()},methods:{cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.quote.client_id&&this.setClientById(this.quote.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchQuoteDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?(this.quote=e,this.setClientById(this.quote.client_id)):(console.error("Error fetching quote details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching quote details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.quote.client=this.clients.find(e=>e.id===t)||null,this.quote.client_id=t},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting quote:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Il={class:"pt-2 pr-4"},kl={class:"flex justify-between items-center mb-4"},Sl={class:"card-title"},Al=r("div",{class:"divider mt-2"},null,-1),Dl={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Pl={class:"grid grid-cols-3 gap-4"},Rl={class:"ecwp-group form-group mb-4"},jl={for:"quoteNumber",class:"ecwp-label"},Ol={class:"ecwp-group form-group mb-4"},Ml={for:"quoteDate",class:"ecwp-label"},ql={class:"ecwp-group form-group mb-4"},Nl={for:"quoteProvisanalDate",class:"ecwp-label"},Bl={class:"grid grid-cols-2 gap-4"},Vl={class:"ecwp-group form-group mb-4"},Fl={for:"client",class:"ecwp-label"},Ul={class:"ecwp-group form-group mb-4"},Ll={for:"status",class:"ecwp-label"},Wl={value:"draft"},Xl={value:"pending"},Hl={value:"approved"},zl={value:"rejected"},Ql={class:"flex justify-between"},Gl=["disabled"],Jl={key:0,class:"loading loading-spinner loading-sm"};function Yl(t,e,s,i,n,o){const a=N("VueDatePicker"),c=N("model-select"),f=N("Card");return h(),m("div",Il,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:me(()=>[r("div",kl,[r("h2",Sl,d(o.translations.edit_quote),1)]),Al,n.loading?(h(),m("div",Dl)):g("",!0),r("form",{onSubmit:e[6]||(e[6]=K((...u)=>o.submitQuote&&o.submitQuote(...u),["prevent"]))},[r("div",Pl,[r("div",Rl,[r("label",jl,d(o.translations.quote_number),1),D(r("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=u=>n.quote.quote_number=u),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[W,n.quote.quote_number]])]),r("div",Ol,[r("label",Ml,d(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=u=>n.quote.due_date=u),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])]),r("div",ql,[r("label",Nl,d(o.translations.provisional_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteProvisanalDate",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=u=>n.quote.provisional_start_date=u),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])])]),r("div",Bl,[r("div",Vl,[r("label",Fl,d(o.translations.company_name),1),P(c,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[3]||(e[3]=u=>n.quote.client_id=u),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),r("div",Ul,[r("label",Ll,d(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=u=>n.quote.status=u),required:"",class:I(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[r("option",Wl,d(o.translations.draft),1),r("option",Xl,d(o.translations.pending),1),r("option",Hl,d(o.translations.approved),1),r("option",zl,d(o.translations.rejected),1)],2),[[ue,n.quote.status]])])]),r("div",Ql,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...u)=>o.cancelAction&&o.cancelAction(...u))},d(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.save)+" ",1),n.loadingBtn?(h(),m("span",Jl)):g("",!0)],8,Gl)])],32)]),_:1})])}var Ho=ne(Tl,[["render",Yl]]);const Kl={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm"),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm").close()}}},Zl=["open"],$l={class:"modal-box"},ec={class:"font-bold text-lg"},tc=r("div",{class:"text-center text-red-400 mb-2"},[r("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),nc={class:"text-lg font-semibold text-center"},sc={class:"my-4 text-center text-xl"},oc={class:"flex justify-between space-x-4"};function ic(t,e,s,i,n,o){return h(),m("div",null,[r("dialog",{id:"modal_confirm",class:"modal",open:t.showModal},[r("div",$l,[r("h3",ec,d(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...a)=>o.closeModal&&o.closeModal(...a))}," \u2715 "),tc,r("h2",nc,d(s.title),1),r("p",sc,d(s.message),1),r("div",oc,[r("button",{onClick:e[1]||(e[1]=(...a)=>o.onCancel&&o.onCancel(...a)),class:"btn btn-secondary rounded-full"},d(s.cancelText),1),r("button",{onClick:e[2]||(e[2]=(...a)=>o.onConfirm&&o.onConfirm(...a)),class:"btn rounded-full btn-error text-white"},d(s.confirmText),1)])])],8,Zl)])}var ds=ne(Kl,[["render",ic]]);const rc={name:"QuotesList",components:{Card:Ze,QuoteEditModal:Ho,ConfirmModal:ds,RemoveModal:qt},data(){return{quotes:[],filteredQuotes:[],filters:{quote_number:"",client:"",status:"",total_amount:"",due_date:"",created_at:""},showQuoteDetailsModal:!1,editQuoteModal:!1,selectedQuote:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],clients:[],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchQuotesWithFilters(),this.loadSettings(),this.fetchClients()},methods:{fetchQuotes(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/quotes?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.quotes=s.quotes,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching quotes:",s)}).finally(()=>{this.loading=!1})},fetchQuotesWithFilters(t=1){this.loading=!0;const{perPage:e,filters:s}=this,i=new URLSearchParams({page:t,per_page:e,...s}).toString();fetch(`/wp-json/my-easy-compta/v1/quotes?${i}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(n=>n.json()).then(n=>{this.quotes=n.quotes,this.totalCount=n.total_count,this.totalPages=n.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(n=>{console.error("Error fetching quotes with filters:",n)}).finally(()=>{this.loading=!1})},fetchClients(){fetch("/wp-json/my-easy-compta/v1/clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients}).catch(t=>{console.error("Error fetching clients:",t)})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return so(t,this.default_vat.rate)},calculateWithoutVAT(t){return oo(t)},generatePaginationButtons(){this.paginationButtons=io(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchQuotesWithFilters(t)},perPageChanged(){this.fetchQuotesWithFilters()},formatAmount(t,e){return ro(t,e,this.settings.currency_position)},confirmDuplicateQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},duplicateQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/duplicate/${t}`,{method:"POST",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotesWithFilters(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error duplicate quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},confirmDeleteQuote(t){this.selectedQuote=t,modal_quotes_remove.showModal(),this.showRemoveModal=!0},deleteQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotesWithFilters(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},showToast(t,e){ao(this.toast,t,e)}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},ac={class:"pt-2 pr-4"},lc={class:"flex justify-between items-center"},cc={class:"card-title"},dc={class:"btn btn-primary rounded-full"},uc=r("i",{class:"fas fa-plus-circle"},null,-1),hc={key:0,class:"ms-2"},mc={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab2"},fc=r("i",{class:"fas fa-file-export"},null,-1),pc=["data-tip"],_c={class:"btn btn-outline btn-accent rounded-full",disabled:""},gc=r("i",{class:"fas fa-file-export"},null,-1),yc=r("div",{class:"divider mt-2"},null,-1),bc={class:"flex items-center mb-4"},vc={for:"perPageSelect",class:"mr-2"},wc=["value"],xc={class:"overflow-x-auto"},Ec={class:"table w-full"},Cc={value:""},Tc=["value"],Ic={value:""},kc={value:"draft"},Sc={value:"pending"},Ac={value:"approved"},Dc={value:"rejected"},Pc={class:"flex justify-center"},Rc={key:0},jc={key:0,class:"badge badge-warning badge-outline badge-sm"},Oc={key:1,class:"badge badge-secondary badge-outline badge-sm"},Mc={key:2,class:"badge badge-success badge-outline badge-sm"},qc={key:3,class:"badge badge-error badge-outline badge-sm"},Nc={key:0},Bc={key:0},Vc={key:0},Fc={key:1},Uc={key:1},Lc={key:0},Wc={key:1},Xc={key:1},Hc=r("span",{class:"loading loading-bars loading-sm"},null,-1),zc=[Hc],Qc={key:0},Gc={key:1},Jc=r("span",{class:"loading loading-bars loading-sm"},null,-1),Yc=[Jc],Kc={key:0},Zc={key:1},$c=r("span",{class:"loading loading-bars loading-sm"},null,-1),ed=[$c],td={class:"flex justify-end"},nd=["data-tip"],sd=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"far fa-eye"})],-1),od=["data-tip"],id=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"fas fa-pencil-alt"})],-1),rd=["data-tip"],ad=["onClick"],ld=r("i",{class:"far fa-copy"},null,-1),cd=[ld],dd=["data-tip"],ud=["onClick"],hd=r("i",{class:"far fa-trash-alt"},null,-1),md=[hd],fd={key:0},pd=r("div",{class:"flex gap-4 items-center"},[r("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),r("div",{class:"flex flex-col gap-4 w-full"},[r("div",{class:"skeleton h-4 w-full"}),r("div",{class:"skeleton h-4 w-full"})])],-1),_d=r("div",{class:"divider my-1"},null,-1),gd=[pd,_d],yd={class:"join ecwp_pagination mt-6 pt-4"},bd=["onClick"];function vd(t,e,s,i,n,o){const a=N("confirm-modal"),c=N("remove-modal"),f=N("router-link"),u=N("Card");return h(),m("div",ac,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),P(a,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=l=>this.duplicateQuote(n.selectedQuote)),onCancel:e[1]||(e[1]=l=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(c,{"modal-id":"modal_quotes_remove","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[2]||(e[2]=l=>this.deleteQuote(n.selectedQuote)),onCancel:e[3]||(e[3]=l=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(u,{topMargin:"mt-8"},{default:me(()=>[r("div",lc,[r("h2",cc,d(o.translations.quotes),1),r("div",null,[P(f,{to:{name:"QuoteNew"}},{default:me(()=>[r("button",dc,[C(d(o.translations.add)+" ",1),uc])]),_:1}),n.settings.easy_compta_export_addon_active==1?(h(),m("span",hc,[r("a",mc,[C(d(o.translations.export)+" ",1),fc])])):(h(),m("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[r("button",_c,[C(d(o.translations.export)+" ",1),gc])],8,pc))])]),yc,r("div",bc,[r("label",vc,d(o.translations.display_per_page),1),D(r("select",{id:"perPageSelect","onUpdate:modelValue":e[4]||(e[4]=l=>n.perPage=l),onChange:e[5]||(e[5]=(...l)=>o.perPageChanged&&o.perPageChanged(...l))},[(h(!0),m(F,null,L(n.perPageOptions,l=>(h(),m("option",{key:l,value:l},d(l),9,wc))),128))],544),[[ue,n.perPage]])]),r("div",xc,[r("table",Ec,[r("thead",null,[r("tr",null,[r("th",null,[r("div",null,d(o.translations.quote_number),1),D(r("input",{"onUpdate:modelValue":e[6]||(e[6]=l=>n.filters.quote_number=l),onInput:e[7]||(e[7]=l=>o.fetchQuotesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.quote_number]])]),r("th",null,[r("div",null,d(o.translations.client),1),D(r("select",{"onUpdate:modelValue":e[8]||(e[8]=l=>n.filters.client=l),onChange:e[9]||(e[9]=l=>o.fetchQuotesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",Cc,d(o.translations.all),1),(h(!0),m(F,null,L(n.clients,l=>(h(),m("option",{key:l.id,value:l.company_name},d(l.company_name),9,Tc))),128))],544),[[ue,n.filters.client]])]),r("th",null,[r("div",null,d(o.translations.status),1),D(r("select",{"onUpdate:modelValue":e[10]||(e[10]=l=>n.filters.status=l),onChange:e[11]||(e[11]=l=>o.fetchQuotesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",Ic,d(o.translations.all_statuses),1),r("option",kc,d(o.translations.draft),1),r("option",Sc,d(o.translations.pending),1),r("option",Ac,d(o.translations.approved),1),r("option",Dc,d(o.translations.rejected),1)],544),[[ue,n.filters.status]])]),r("th",null,[r("div",null,d(o.translations.total),1),D(r("input",{"onUpdate:modelValue":e[12]||(e[12]=l=>n.filters.total_amount=l),onInput:e[13]||(e[13]=l=>o.fetchQuotesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.total_amount]])]),r("th",null,[r("div",null,d(o.translations.due_date),1),D(r("input",{"onUpdate:modelValue":e[14]||(e[14]=l=>n.filters.due_date=l),onInput:e[15]||(e[15]=l=>o.fetchQuotesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.due_date]])]),r("th",null,[r("div",null,d(o.translations.created_at),1),D(r("input",{"onUpdate:modelValue":e[16]||(e[16]=l=>n.filters.created_at=l),onInput:e[17]||(e[17]=l=>o.fetchQuotesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.created_at]])]),r("th",Pc,d(o.translations.actions),1)])]),n.loading?g("",!0):(h(),m("tbody",Rc,[(h(!0),m(F,null,L(n.quotes,l=>(h(),m("tr",{key:l.id},[r("td",null,d(l.quote_number),1),r("td",null,d(l.client_name),1),r("td",null,[l.status=="draft"?(h(),m("span",jc,d(o.translations.draft),1)):g("",!0),l.status=="pending"?(h(),m("span",Oc,d(o.translations.pending),1)):g("",!0),l.status=="approved"?(h(),m("span",Mc,d(o.translations.approved),1)):g("",!0),l.status=="rejected"?(h(),m("span",qc,d(o.translations.rejected),1)):g("",!0)]),r("td",null,[n.loadingPrice?(h(),m("div",Xc,zc)):(h(),m("div",Nc,[n.settings.vat_active==1?(h(),m("div",Bc,[n.default_currency_symbol==l.client_currency||l.client_currency==null?(h(),m("span",Vc,d(o.formatAmount(l.total_amount,n.default_currency_symbol)),1)):(h(),m("span",Fc,d(o.formatAmount(l.total_amount,l.client_currency)),1))])):(h(),m("div",Uc,[n.default_currency_symbol==l.client_currency||l.client_currency==null?(h(),m("span",Lc,d(o.formatAmount(l.total_amount,n.default_currency_symbol)),1)):(h(),m("span",Wc,d(o.formatAmount(l.total_amount,l.client_currency)),1))]))]))]),r("td",null,[n.loadingPrice?(h(),m("div",Gc,Yc)):(h(),m("div",Qc,d(l.due_date),1))]),r("td",null,[n.loadingPrice?(h(),m("div",Zc,ed)):(h(),m("div",Kc,d(l.created),1))]),r("td",td,[r("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(f,{to:{name:"QuoteViewDetail",params:{id:l.id}}},{default:me(()=>[sd]),_:2},1032,["to"])],8,nd),r("span",{class:"lg:tooltip","data-tip":o.translations.edit},[P(f,{to:{name:"QuoteEdit",params:{id:l.id}}},{default:me(()=>[id]),_:2},1032,["to"])],8,od),r("span",{class:"lg:tooltip","data-tip":o.translations.duplicate},[r("button",{onClick:_=>o.confirmDuplicateQuote(l.id),class:"btn btn-circle text-purple-600 hover:text-purple-900 mx-1"},cd,8,ad)],8,rd),r("span",{class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:_=>o.confirmDeleteQuote(l.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},md,8,ud)],8,dd)])]))),128))]))]),n.loading?(h(),m("div",fd,[(h(!0),m(F,null,L(n.skeletonRows,l=>(h(),m("div",{key:l,class:"flex flex-col gap-4 w-full"},gd))),128))])):g("",!0)]),r("div",yd,[(h(!0),m(F,null,L(n.paginationButtons,l=>(h(),m("button",{key:l,class:I(["join-item btn",{"btn-disabled":l==="..."||l===n.currentPage}]),onClick:_=>o.goToPage(l)},d(l),11,bd))),128))])]),_:1})])}var wd=ne(rc,[["render",vd]]);const xd={name:"sendQuote",components:{VueEditor:mt.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,quoteId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"quote",id:this.quoteId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Ed=["id","open"],Cd={class:"modal-box"},Td={class:"font-bold text-lg"},Id={key:0},kd={class:"grid grid-cols-1 gap-4"},Sd=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),Ad=r("div",{class:"skeleton h-4 w-full"},null,-1),Dd=[Sd,Ad],Pd={class:"grid grid-cols-1 gap-4"},Rd=["type"],jd=["for"],Od=["id","value","disabled","onInput"],Md={key:1},qd=["for"],Nd={class:"form-group mt-4 flex justify-end"},Bd=["disabled"],Vd={key:0,class:"loading loading-spinner loading-sm"};function Fd(t,e,s,i,n,o){const a=N("vue-editor");return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",Cd,[r("h3",Td,d(o.translations.send_quote),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=c=>o.closeModal())}," \u2715 "),n.loading?(h(),m("div",Id,[r("div",kd,[(h(!0),m(F,null,L(o.skeletonItems,c=>(h(),m("div",{key:c,class:"py-2"},Dd))),128))])])):(h(),m("form",{key:1,onSubmit:e[1]||(e[1]=K((...c)=>o.submitForm&&o.submitForm(...c),["prevent"])),class:"form"},[r("div",Pd,[(h(!0),m(F,null,L(n.fields,(c,f)=>(h(),m("div",{key:f,class:"ecwp-group form-group"},[c.type!=="textarea"?(h(),m("div",{key:0,type:c.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},d(c.label),9,jd),r("input",{id:f,class:I(["ecwp-input input input-bordered",c.class||"w-full"]),value:c.value,disabled:c.disabled,onInput:u=>o.updateFieldValue(f,u.target.value)},null,42,Od)],8,Rd)):(h(),m("div",Md,[r("label",{for:f,class:"form-label"},d(c.label),9,qd),P(a,{modelValue:c.value,"onUpdate:modelValue":u=>c.value=u,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",Nd,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.send)+" ",1),n.loadingBtn?(h(),m("span",Vd)):g("",!0)],8,Bd)])],32))])],8,Ed)])}var Ud=ne(xd,[["render",Fd]]);const Ld={components:{VueDatePicker:Nt},props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},totalAmount:{type:String,required:!0},currency:{type:String,required:!0},advanceSold:{type:String,required:!0},quoteId:{type:Number,required:!0}},data(){return{showError:!1,selectedType:"",inputValue:0,due_date:"",invoiceSolded:!1,establishedAdvances:[],loading:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}},remainingAmount(){this.loading=!0;const t=this.establishedAdvances.reduce((e,s)=>{const i=parseFloat(s.advance_amount);return isNaN(i)?(console.error("Erreur: advance_amount n'est pas un nombre valide",s.advance_amount),e):e+i},0);return this.totalAmount-t},inputValueExceeds(){return this.remainingAmount==0?!0:this.selectedType==="percentage"?this.calculatedAmount>this.remainingAmount:this.selectedType==="fixed"?this.inputValue>this.remainingAmount:!1},calculatedAmount(){return this.selectedType==="percentage"?this.inputValue/100*this.remainingAmount:this.inputValue}},created(){this.fetchEstablishedAdvances(this.quoteId)},methods:{fetchEstablishedAdvances(t){const e=`/wp-json/my-easy-compta/v1/advance/${t}`;fetch(e,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.establishedAdvances=s}).catch(s=>{console.error("Error fetching advances:",s)})},onConfirm(){if(!this.inputValueExceeds){if(this.advanceSold=="no_sold"){if(!this.inputValue||!this.due_date||this.advanceSold=="no_sold"&&!this.selectedType){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:this.selectedType,value:this.inputValue,date:this.due_date})}else{if(!this.due_date){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:"fixed",value:this.remainingAmount,date:this.due_date})}this.closeModal()}},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_advance").close()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Wd=["open"],Xd={class:"modal-box overflow-visible"},Hd={class:"font-bold text-lg"},zd={class:"text-lg font-semibold text-center"},Qd={class:"my-4 text-center text-xl"},Gd={key:0,class:"text-red-500 text-sm"},Jd={class:"grid grid-cols-2 gap-4"},Yd={key:0},Kd={class:"flex ecwp-group form-group mb-4"},Zd=r("label",{for:"advance-type",class:"ecwp-label"},"Type",-1),$d=r("option",{value:"percentage"},"Pourcentage",-1),eu=r("option",{value:"fixed"},"Montant fixe",-1),tu=[$d,eu],nu={key:1},su={class:"flex ecwp-group form-group mb-4"},ou=r("label",{for:"advance-type",class:"ecwp-label"},"Valeur",-1),iu={class:"absolute items-center border rounded-md right-0 top-6"},ru={class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"},au={key:0},lu={key:1},cu={key:1,class:"mt-2"},du={class:"text-sm"},uu={key:2,class:"flex ecwp-group form-group mb-4"},hu={for:"quoteDate",class:"ecwp-label"},mu={key:3},fu={class:"flex justify-between space-x-4 mt-4"},pu=["disabled"];function _u(t,e,s,i,n,o){const a=N("VueDatePicker");return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:"modal_advance",class:"modal",open:s.isVisible},[r("div",Xd,[r("h3",Hd,d(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...c)=>o.closeModal&&o.closeModal(...c))}," \u2715 "),r("h2",zd,d(s.title),1),r("p",Qd," Montant total restant : "+d(o.remainingAmount)+" "+d(s.currency),1),o.inputValueExceeds&&!n.invoiceSolded?(h(),m("p",Gd," Le montant s\xE9lectionn\xE9 d\xE9passe le montant total du devis. ")):g("",!0),r("div",Jd,[s.advanceSold=="no_sold"&&!n.invoiceSolded?(h(),m("div",Yd,[r("div",Kd,[Zd,D(r("select",{"onUpdate:modelValue":e[1]||(e[1]=c=>n.selectedType=c),id:"advance-type",class:I(["ecwp-select ecwp-input input input-bordered w-full",{"input-error":!n.selectedType&&n.showError}])},tu,2),[[ue,n.selectedType]])])])):g("",!0),n.selectedType&&s.advanceSold=="no_sold"&&!n.invoiceSolded?(h(),m("div",nu,[r("div",su,[ou,D(r("input",{"onUpdate:modelValue":e[2]||(e[2]=c=>n.inputValue=c),type:"text",id:"advance-value",class:I([{"input-error":!n.inputValue&&n.showError},"ecwp-input input input-bordered w-full"])},null,2),[[W,n.inputValue]]),r("div",iu,[r("div",ru,[n.selectedType==="percentage"?(h(),m("span",au,"%")):(h(),m("span",lu,d(s.currency),1))])])])])):g("",!0)]),n.selectedType==="percentage"&&!o.inputValueExceeds&!n.invoiceSolded?(h(),m("div",cu,[r("p",du," Montant bas\xE9 sur le pourcentage: "+d(o.calculatedAmount)+" "+d(s.currency),1)])):g("",!0),n.invoiceSolded?g("",!0):(h(),m("div",uu,[r("label",hu,d(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.inputValue&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.due_date,"onUpdate:modelValue":e[3]||(e[3]=c=>n.due_date=c),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr",required:""},null,8,["modelValue","format","min-date","class"])])),n.invoiceSolded?(h(),m("div",mu,"Facture d\xE9j\xE0 sold\xE9")):g("",!0),r("div",fu,[r("button",{onClick:e[4]||(e[4]=(...c)=>o.onCancel&&o.onCancel(...c)),class:"btn btn-secondary rounded-full"},d(s.cancelText),1),r("button",{onClick:e[5]||(e[5]=(...c)=>o.onConfirm&&o.onConfirm(...c)),disabled:o.inputValueExceeds,class:"btn rounded-full btn-error text-white"},d(s.confirmText),9,pu)])])],8,Wd)])}var gu=ne(Ld,[["render",_u]]);const yu={name:"QuoteNavBar",components:{SendQuoteModal:Ud,ConfirmModal:ds,AdvanceModal:gu},props:{quoteInfo:Object,emailActive:Number,advanceActive:Number,currency:String,noItems:Boolean},data(){return{selectedQuote:null,advanceSold:!1,sendQuoteModal:!1,loadingModal:!1,loadingPdf:!1,loading:!1,client_detail:null,subject:"",content:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{async changeQuoteStatus(t){try{const s=await(await fetch("/wp-json/my-easy-compta/v1/quotes/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.quoteInfo.id,status:t})})).json();s.success?(this.quoteInfo.status=t,this.quoteInfo.total_amount=s.total_amount,this.showToast(s.message,"alert-success")):(console.error("Failed to update quote status:",s.message),this.showToast(s.message,"alert-error"))}catch(e){console.error("An error occurred while updating quote status:",e),this.showToast(e,"alert-error")}},convertToInvoice(t){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-quote/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e.success?(this.showToast(e.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:e.id}})):this.showToast(e.message,"alert-error")}).catch(e=>{console.error("Error converting quote:",e),this.showToast(e.message,"alert-error")})},handleAdvanceInvoiceConfirm(t){const{type:e,value:s,date:i}=t;this.convertAdvanceInvoice(this.selectedQuote,e,s,i)},convertAdvanceInvoice(t,e,s,i){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-advance/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({advance_type:e,advance_value:s,advance_date:i})}).then(n=>n.json()).then(n=>{n.success?(this.showToast(n.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:n.id}})):this.showToast(n.message,"alert-error")}).catch(n=>{console.error("Error converting quote:",n),this.showToast(n.message,"alert-error")})},confirmConvertQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},ConvertAdvanceQuote(t,e){this.selectedQuote=t,this.advanceSold=e,modal_advance.showModal(),this.showRemoveModal=!0},exportToPDF(){this.loadingPdf=!0;const t=this.quoteInfo.id;fetch(`/wp-json/my-easy-compta/v1/quotes/pdf/${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return this.loadingPdf=!1,e.blob()}).then(e=>{const s=URL.createObjectURL(e);window.open(s),this.loadingPdf=!1}).catch(e=>{console.error("There was a problem with the fetch operation:",e),this.loadingPdf=!1})},sendQuote(t){this.loadingModal=!0,this.sendQuoteModal=!0,modal_send_quote.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(t.ok){const e=await t.json();this.subject=e.email_quote_subject,this.content=e.email_quote_content,this.loading=!1}else{const e=await t.json();this.showToast(e.message,"alert-error"),this.loading=!1}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},bu={key:0},vu={key:1},wu={key:3,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},xu=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),Eu=[xu],Cu={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},Tu=r("div",{class:"dropdown"},[r("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),r("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[r("li",null,[r("a",null,"Item 1")]),r("li",null,[r("a",null,"Parent"),r("ul",{class:"p-2"},[r("li",null,[r("a",null,"Submenu 1")]),r("li",null,[r("a",null,"Submenu 2")])])]),r("li",null,[r("a",null,"Item 3")])])],-1),Iu={class:"hidden lg:flex gap-2"},ku={class:"btn btn-sm"},Su=r("i",{class:"far fa-edit"},null,-1),Au=r("i",{class:"fa fa-check"},null,-1),Du=["data-tip"],Pu={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Ru=r("i",{class:"fas fa-check"},null,-1),ju=r("i",{class:"fa fa-check"},null,-1),Ou=r("i",{class:"fa fa-times"},null,-1),Mu={key:4},qu={class:"dropdown"},Nu={tabindex:"0",role:"button",class:"btn btn-sm"},Bu=r("i",{class:"fas fa-exchange-alt"},null,-1),Vu={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},Fu={key:0},Uu={key:5},Lu=r("i",{class:"fas fa-exchange-alt"},null,-1),Wu={class:"flex gap-2"},Xu=r("i",{class:"fas fa-paper-plane"},null,-1),Hu={key:0},zu={key:1},Qu={key:2,class:"far fa-envelope"},Gu=["data-tip"],Ju={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Yu=r("i",{class:"fas fa-paper-plane"},null,-1),Ku=["data-tip"],Zu={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},$u=r("i",{class:"fas fa-paper-plane"},null,-1),eh=["disabled"],th=r("i",{class:"far fa-file-pdf"},null,-1),nh={key:0,class:"loading loading-spinner loading-sm"};function sh(t,e,s,i,n,o){const a=N("send-quote-modal"),c=N("confirm-modal"),f=N("advance-modal"),u=N("router-link");return h(),m("div",null,[s.emailActive==1?(h(),m("div",bu,[P(a,{loading:n.loadingModal,"show-modal":n.sendQuoteModal,"modal-id":"modal_send_quote",client:n.client_detail,"quote-id":s.quoteInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=l=>n.sendQuoteModal=!1)},null,8,["loading","show-modal","client","quote-id","subject","content"])])):g("",!0),P(c,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[1]||(e[1]=l=>this.convertToInvoice(n.selectedQuote)),onCancel:e[2]||(e[2]=l=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),s.advanceActive==1?(h(),m("div",vu,[P(f,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,"total-amount":s.quoteInfo.total_amount,currency:s.currency,quoteId:s.quoteInfo.id,"advance-sold":n.advanceSold,onConfirm:o.handleAdvanceInvoiceConfirm,onCancel:e[3]||(e[3]=l=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","total-amount","currency","quoteId","advance-sold","onConfirm"])])):g("",!0),n.toast.visible?(h(),m("div",{key:2,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),n.loading?(h(),m("div",wu,Eu)):g("",!0),r("div",Cu,[r("div",null,[Tu,r("div",Iu,[P(u,{to:{name:"QuoteEdit",params:{id:s.quoteInfo.id}}},{default:me(()=>[r("button",ku,[Su,C(d(o.translations.edit_quote),1)])]),_:1},8,["to"]),s.quoteInfo.status=="draft"&&!s.noItems?(h(),m("button",{key:0,class:"btn btn-outline btn-success btn-sm",onClick:e[4]||(e[4]=l=>o.changeQuoteStatus("pending"))},[Au,C(" "+d(o.translations.validate_quote),1)])):g("",!0),s.quoteInfo.status=="draft"&&s.noItems?(h(),m("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.min_article},[r("button",Pu,[Ru,C(" "+d(o.translations.validate_quote),1)])],8,Du)):g("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="rejected")&&!s.noItems?(h(),m("button",{key:2,class:"btn btn-outline btn-success btn-sm",onClick:e[5]||(e[5]=l=>o.changeQuoteStatus("approved"))},[ju,C(" "+d(o.translations.mark_as_accepted),1)])):g("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="approved")&&!s.noItems?(h(),m("button",{key:3,class:"btn btn-outline btn-error btn-sm",onClick:e[6]||(e[6]=l=>o.changeQuoteStatus("rejected"))},[Ou,C(" "+d(o.translations.mark_as_rejected),1)])):g("",!0),s.advanceActive==1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(h(),m("div",Mu,[r("div",qu,[r("div",Nu,[Bu,C(" "+d(o.translations.convertToInvoice),1)]),r("ul",Vu,[s.quoteInfo.advance!=1?(h(),m("li",Fu,[r("a",{href:"#",onClick:e[7]||(e[7]=K(l=>o.confirmConvertQuote(s.quoteInfo.id),["prevent"]))}," Facture global ")])):g("",!0),r("li",null,[r("a",{href:"#",onClick:e[8]||(e[8]=K(l=>o.ConvertAdvanceQuote(s.quoteInfo.id,"no_sold"),["prevent"]))}," Facture d'acompte "),s.quoteInfo.advance!=0?(h(),m("a",{key:0,href:"#",onClick:e[9]||(e[9]=K(l=>o.ConvertAdvanceQuote(s.quoteInfo.id,"sold"),["prevent"]))}," Facture du solde ")):g("",!0)])])])])):g("",!0),s.advanceActive!=1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(h(),m("div",Uu,[r("button",{onClick:e[10]||(e[10]=l=>o.confirmConvertQuote(s.quoteInfo.id)),class:"btn btn-sm"},[Lu,C(" "+d(o.translations.convertToInvoice),1)])])):g("",!0)])]),r("div",Wu,[s.emailActive==1&&s.quoteInfo.status!="draft"?(h(),m("button",{key:0,onClick:e[11]||(e[11]=K(l=>o.sendQuote(s.quoteInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[Xu,s.quoteInfo.sent==1?(h(),m("span",Hu,d(o.translations.resend_quote),1)):(h(),m("span",zu,d(o.translations.send_quote),1)),s.quoteInfo.sent==1?(h(),m("i",Qu)):g("",!0)])):s.emailActive==1&&s.quoteInfo.status=="draft"?(h(),m("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.quote_draft_cannot_send},[r("button",Ju,[Yu,C(" "+d(o.translations.send_quote),1)])],8,Gu)):(h(),m("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[r("button",Zu,[$u,C(" "+d(o.translations.send_quote),1)])],8,Ku)),r("button",{onClick:e[12]||(e[12]=(...l)=>o.exportToPDF&&o.exportToPDF(...l)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[th,C(" "+d(o.translations.exportToPDF)+" ",1),n.loadingPdf?(h(),m("span",nh)):g("",!0)],8,eh)])])])}var oh=ne(yu,[["render",sh]]);const ih={components:{VueEditor:mt.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:t.item_name},item_description:{label:t.description,type:"textarea"},quantity:{label:t.quantity,type:"number"},vat_rate:{label:"Taux de TVA",type:"number"},unit_price:{label:t.unit_price,type:"number"},discount:{label:t.discount,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/quotes/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},rh=["id","open"],ah={class:"modal-box"},lh={class:"font-bold text-lg"},ch={key:0},dh={class:"grid grid-cols-1 gap-4"},uh=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),hh=r("div",{class:"skeleton h-4 w-full"},null,-1),mh=[uh,hh],fh={class:"grid grid-cols-1 gap-4"},ph=["type"],_h=["for"],gh=["id","onUpdate:modelValue"],yh={key:1},bh=["for"],vh={class:"form-group mt-4 flex justify-end"},wh=["disabled"],xh={key:0,class:"loading loading-spinner loading-sm"};function Eh(t,e,s,i,n,o){const a=N("vue-editor");return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",ah,[r("h3",lh,d(s.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=c=>o.closeModal())}," \u2715 "),n.loading?(h(),m("div",ch,[r("div",dh,[(h(!0),m(F,null,L(o.skeletonItems,c=>(h(),m("div",{key:c,class:"py-2"},mh))),128))])])):(h(),m("form",{key:1,onSubmit:e[1]||(e[1]=K((...c)=>o.submitForm&&o.submitForm(...c),["prevent"])),class:"form"},[r("div",fh,[(h(!0),m(F,null,L(n.fields,(c,f)=>(h(),m("div",{key:f,class:"ecwp-group form-group"},[c.type!=="textarea"?(h(),m("div",{key:0,type:c.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},d(c.label),9,_h),D(r("input",{id:f,"onUpdate:modelValue":u=>n.editedItem[f]=u,class:I(["ecwp-input input input-bordered",c.class||"w-full"])},null,10,gh),[[W,n.editedItem[f]]])],8,ph)):(h(),m("div",yh,[r("label",{for:f,class:"form-label"},d(c.label),9,bh),P(a,{id:f,modelValue:n.editedItem[f],"onUpdate:modelValue":u=>n.editedItem[f]=u,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",vh,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.save)+" ",1),n.loadingBtn?(h(),m("span",xh)):g("",!0)],8,wh)])],32))])],8,rh)])}var Ch=ne(ih,[["render",Eh]]);/**!
     10  */const rt=typeof document!="undefined";function wa(t){return t.__esModule||t[Symbol.toStringTag]==="Module"}const G=Object.assign;function Sn(t,e){const s={};for(const i in e){const n=e[i];s[i]=Se(n)?n.map(t):t(n)}return s}const Tt=()=>{},Se=Array.isArray,Ro=/#/g,xa=/&/g,Ea=/\//g,Ca=/=/g,Ta=/\?/g,Mo=/\+/g,Ia=/%5B/g,ka=/%5D/g,Oo=/%5E/g,Aa=/%60/g,qo=/%7B/g,Sa=/%7C/g,No=/%7D/g,Da=/%20/g;function ls(t){return encodeURI(""+t).replace(Sa,"|").replace(Ia,"[").replace(ka,"]")}function Pa(t){return ls(t).replace(qo,"{").replace(No,"}").replace(Oo,"^")}function Gn(t){return ls(t).replace(Mo,"%2B").replace(Da,"+").replace(Ro,"%23").replace(xa,"%26").replace(Aa,"`").replace(qo,"{").replace(No,"}").replace(Oo,"^")}function ja(t){return Gn(t).replace(Ca,"%3D")}function Ra(t){return ls(t).replace(Ro,"%23").replace(Ta,"%3F")}function Ma(t){return t==null?"":Ra(t).replace(Ea,"%2F")}function Mt(t){try{return decodeURIComponent(""+t)}catch{}return""+t}const Oa=/\/$/,qa=t=>t.replace(Oa,"");function Dn(t,e,s="/"){let i,n={},o="",a="";const l=e.indexOf("#");let f=e.indexOf("?");return l<f&&l>=0&&(f=-1),f>-1&&(i=e.slice(0,f),o=e.slice(f+1,l>-1?l:e.length),n=t(o)),l>-1&&(i=i||e.slice(0,l),a=e.slice(l,e.length)),i=Fa(i!=null?i:e,s),{fullPath:i+(o&&"?")+o+a,path:i,query:n,hash:Mt(a)}}function Na(t,e){const s=e.query?t(e.query):"";return e.path+(s&&"?")+s+(e.hash||"")}function Ss(t,e){return!e||!t.toLowerCase().startsWith(e.toLowerCase())?t:t.slice(e.length)||"/"}function Ba(t,e,s){const i=e.matched.length-1,n=s.matched.length-1;return i>-1&&i===n&&dt(e.matched[i],s.matched[n])&&Bo(e.params,s.params)&&t(e.query)===t(s.query)&&e.hash===s.hash}function dt(t,e){return(t.aliasOf||t)===(e.aliasOf||e)}function Bo(t,e){if(Object.keys(t).length!==Object.keys(e).length)return!1;for(const s in t)if(!Va(t[s],e[s]))return!1;return!0}function Va(t,e){return Se(t)?Ds(t,e):Se(e)?Ds(e,t):t===e}function Ds(t,e){return Se(e)?t.length===e.length&&t.every((s,i)=>s===e[i]):t.length===1&&t[0]===e}function Fa(t,e){if(t.startsWith("/"))return t;if(!t)return e;const s=e.split("/"),i=t.split("/"),n=i[i.length-1];(n===".."||n===".")&&i.push("");let o=s.length-1,a,l;for(a=0;a<i.length;a++)if(l=i[a],l!==".")if(l==="..")o>1&&o--;else break;return s.slice(0,o).join("/")+"/"+i.slice(a).join("/")}const Qe={path:"/",name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0};var Ot;(function(t){t.pop="pop",t.push="push"})(Ot||(Ot={}));var It;(function(t){t.back="back",t.forward="forward",t.unknown=""})(It||(It={}));function Ua(t){if(!t)if(rt){const e=document.querySelector("base");t=e&&e.getAttribute("href")||"/",t=t.replace(/^\w+:\/\/[^\/]+/,"")}else t="/";return t[0]!=="/"&&t[0]!=="#"&&(t="/"+t),qa(t)}const La=/^[^#]+#/;function Wa(t,e){return t.replace(La,"#")+e}function Xa(t,e){const s=document.documentElement.getBoundingClientRect(),i=t.getBoundingClientRect();return{behavior:e.behavior,left:i.left-s.left-(e.left||0),top:i.top-s.top-(e.top||0)}}const vn=()=>({left:window.scrollX,top:window.scrollY});function Ha(t){let e;if("el"in t){const s=t.el,i=typeof s=="string"&&s.startsWith("#"),n=typeof s=="string"?i?document.getElementById(s.slice(1)):document.querySelector(s):s;if(!n)return;e=Xa(n,t)}else e=t;"scrollBehavior"in document.documentElement.style?window.scrollTo(e):window.scrollTo(e.left!=null?e.left:window.scrollX,e.top!=null?e.top:window.scrollY)}function Ps(t,e){return(history.state?history.state.position-e:-1)+t}const Jn=new Map;function za(t,e){Jn.set(t,e)}function Qa(t){const e=Jn.get(t);return Jn.delete(t),e}let Ga=()=>location.protocol+"//"+location.host;function Vo(t,e){const{pathname:s,search:i,hash:n}=e,o=t.indexOf("#");if(o>-1){let l=n.includes(t.slice(o))?t.slice(o).length:1,f=n.slice(l);return f[0]!=="/"&&(f="/"+f),Ss(f,"")}return Ss(s,t)+i+n}function Ja(t,e,s,i){let n=[],o=[],a=null;const l=({state:y})=>{const _=Vo(t,location),v=s.value,x=e.value;let j=0;if(y){if(s.value=_,e.value=y,a&&a===v){a=null;return}j=x?y.position-x.position:0}else i(_);n.forEach(q=>{q(s.value,v,{delta:j,type:Ot.pop,direction:j?j>0?It.forward:It.back:It.unknown})})};function f(){a=s.value}function d(y){n.push(y);const _=()=>{const v=n.indexOf(y);v>-1&&n.splice(v,1)};return o.push(_),_}function m(){const{history:y}=window;!y.state||y.replaceState(G({},y.state,{scroll:vn()}),"")}function p(){for(const y of o)y();o=[],window.removeEventListener("popstate",l),window.removeEventListener("beforeunload",m)}return window.addEventListener("popstate",l),window.addEventListener("beforeunload",m,{passive:!0}),{pauseListeners:f,listen:d,destroy:p}}function js(t,e,s,i=!1,n=!1){return{back:t,current:e,forward:s,replaced:i,position:window.history.length,scroll:n?vn():null}}function Ya(t){const{history:e,location:s}=window,i={value:Vo(t,s)},n={value:e.state};n.value||o(i.value,{back:null,current:i.value,forward:null,position:e.length-1,replaced:!0,scroll:null},!0);function o(f,d,m){const p=t.indexOf("#"),y=p>-1?(s.host&&document.querySelector("base")?t:t.slice(p))+f:Ga()+t+f;try{e[m?"replaceState":"pushState"](d,"",y),n.value=d}catch(_){console.error(_),s[m?"replace":"assign"](y)}}function a(f,d){const m=G({},e.state,js(n.value.back,f,n.value.forward,!0),d,{position:n.value.position});o(f,m,!0),i.value=f}function l(f,d){const m=G({},n.value,e.state,{forward:f,scroll:vn()});o(m.current,m,!0);const p=G({},js(i.value,f,null),{position:m.position+1},d);o(f,p,!1),i.value=f}return{location:i,state:n,push:l,replace:a}}function Ka(t){t=Ua(t);const e=Ya(t),s=Ja(t,e.state,e.location,e.replace);function i(o,a=!0){a||s.pauseListeners(),history.go(o)}const n=G({location:"",base:t,go:i,createHref:Wa.bind(null,t)},e,s);return Object.defineProperty(n,"location",{enumerable:!0,get:()=>e.location.value}),Object.defineProperty(n,"state",{enumerable:!0,get:()=>e.state.value}),n}function Za(t){return t=location.host?t||location.pathname+location.search:"",t.includes("#")||(t+="#"),Ka(t)}function $a(t){return typeof t=="string"||t&&typeof t=="object"}function Fo(t){return typeof t=="string"||typeof t=="symbol"}const Uo=Symbol("");var Rs;(function(t){t[t.aborted=4]="aborted",t[t.cancelled=8]="cancelled",t[t.duplicated=16]="duplicated"})(Rs||(Rs={}));function ut(t,e){return G(new Error,{type:t,[Uo]:!0},e)}function Fe(t,e){return t instanceof Error&&Uo in t&&(e==null||!!(t.type&e))}const Ms="[^/]+?",el={sensitive:!1,strict:!1,start:!0,end:!0},tl=/[.+*?^${}()[\]/\\]/g;function nl(t,e){const s=G({},el,e),i=[];let n=s.start?"^":"";const o=[];for(const d of t){const m=d.length?[]:[90];s.strict&&!d.length&&(n+="/");for(let p=0;p<d.length;p++){const y=d[p];let _=40+(s.sensitive?.25:0);if(y.type===0)p||(n+="/"),n+=y.value.replace(tl,"\\$&"),_+=40;else if(y.type===1){const{value:v,repeatable:x,optional:j,regexp:q}=y;o.push({name:v,repeatable:x,optional:j});const S=q||Ms;if(S!==Ms){_+=10;try{new RegExp(`(${S})`)}catch(z){throw new Error(`Invalid custom RegExp for param "${v}" (${S}): `+z.message)}}let k=x?`((?:${S})(?:/(?:${S}))*)`:`(${S})`;p||(k=j&&d.length<2?`(?:/${k})`:"/"+k),j&&(k+="?"),n+=k,_+=20,j&&(_+=-8),x&&(_+=-20),S===".*"&&(_+=-50)}m.push(_)}i.push(m)}if(s.strict&&s.end){const d=i.length-1;i[d][i[d].length-1]+=.7000000000000001}s.strict||(n+="/?"),s.end?n+="$":s.strict&&(n+="(?:/|$)");const a=new RegExp(n,s.sensitive?"":"i");function l(d){const m=d.match(a),p={};if(!m)return null;for(let y=1;y<m.length;y++){const _=m[y]||"",v=o[y-1];p[v.name]=_&&v.repeatable?_.split("/"):_}return p}function f(d){let m="",p=!1;for(const y of t){(!p||!m.endsWith("/"))&&(m+="/"),p=!1;for(const _ of y)if(_.type===0)m+=_.value;else if(_.type===1){const{value:v,repeatable:x,optional:j}=_,q=v in d?d[v]:"";if(Se(q)&&!x)throw new Error(`Provided param "${v}" is an array but it is not repeatable (* or + modifiers)`);const S=Se(q)?q.join("/"):q;if(!S)if(j)y.length<2&&(m.endsWith("/")?m=m.slice(0,-1):p=!0);else throw new Error(`Missing required param "${v}"`);m+=S}}return m||"/"}return{re:a,score:i,keys:o,parse:l,stringify:f}}function sl(t,e){let s=0;for(;s<t.length&&s<e.length;){const i=e[s]-t[s];if(i)return i;s++}return t.length<e.length?t.length===1&&t[0]===40+40?-1:1:t.length>e.length?e.length===1&&e[0]===40+40?1:-1:0}function Lo(t,e){let s=0;const i=t.score,n=e.score;for(;s<i.length&&s<n.length;){const o=sl(i[s],n[s]);if(o)return o;s++}if(Math.abs(n.length-i.length)===1){if(Os(i))return 1;if(Os(n))return-1}return n.length-i.length}function Os(t){const e=t[t.length-1];return t.length>0&&e[e.length-1]<0}const ol={type:0,value:""},il=/[a-zA-Z0-9_]/;function rl(t){if(!t)return[[]];if(t==="/")return[[ol]];if(!t.startsWith("/"))throw new Error(`Invalid path "${t}"`);function e(_){throw new Error(`ERR (${s})/"${d}": ${_}`)}let s=0,i=s;const n=[];let o;function a(){o&&n.push(o),o=[]}let l=0,f,d="",m="";function p(){!d||(s===0?o.push({type:0,value:d}):s===1||s===2||s===3?(o.length>1&&(f==="*"||f==="+")&&e(`A repeatable param (${d}) must be alone in its segment. eg: '/:ids+.`),o.push({type:1,value:d,regexp:m,repeatable:f==="*"||f==="+",optional:f==="*"||f==="?"})):e("Invalid state to consume buffer"),d="")}function y(){d+=f}for(;l<t.length;){if(f=t[l++],f==="\\"&&s!==2){i=s,s=4;continue}switch(s){case 0:f==="/"?(d&&p(),a()):f===":"?(p(),s=1):y();break;case 4:y(),s=i;break;case 1:f==="("?s=2:il.test(f)?y():(p(),s=0,f!=="*"&&f!=="?"&&f!=="+"&&l--);break;case 2:f===")"?m[m.length-1]=="\\"?m=m.slice(0,-1)+f:s=3:m+=f;break;case 3:p(),s=0,f!=="*"&&f!=="?"&&f!=="+"&&l--,m="";break;default:e("Unknown state");break}}return s===2&&e(`Unfinished custom RegExp for param "${d}"`),p(),a(),n}function al(t,e,s){const i=nl(rl(t.path),s),n=G(i,{record:t,parent:e,children:[],alias:[]});return e&&!n.record.aliasOf==!e.record.aliasOf&&e.children.push(n),n}function ll(t,e){const s=[],i=new Map;e=Bs({strict:!1,end:!0,sensitive:!1},e);function n(p){return i.get(p)}function o(p,y,_){const v=!_,x=cl(p);x.aliasOf=_&&_.record;const j=Bs(e,p),q=[x];if("alias"in p){const z=typeof p.alias=="string"?[p.alias]:p.alias;for(const le of z)q.push(G({},x,{components:_?_.record.components:x.components,path:le,aliasOf:_?_.record:x}))}let S,k;for(const z of q){const{path:le}=z;if(y&&le[0]!=="/"){const Y=y.record.path,K=Y[Y.length-1]==="/"?"":"/";z.path=y.record.path+(le&&K+le)}if(S=al(z,y,j),_?_.alias.push(S):(k=k||S,k!==S&&k.alias.push(S),v&&p.name&&!Ns(S)&&a(p.name)),Wo(S)&&f(S),x.children){const Y=x.children;for(let K=0;K<Y.length;K++)o(Y[K],S,_&&_.children[K])}_=_||S}return k?()=>{a(k)}:Tt}function a(p){if(Fo(p)){const y=i.get(p);y&&(i.delete(p),s.splice(s.indexOf(y),1),y.children.forEach(a),y.alias.forEach(a))}else{const y=s.indexOf(p);y>-1&&(s.splice(y,1),p.record.name&&i.delete(p.record.name),p.children.forEach(a),p.alias.forEach(a))}}function l(){return s}function f(p){const y=hl(p,s);s.splice(y,0,p),p.record.name&&!Ns(p)&&i.set(p.record.name,p)}function d(p,y){let _,v={},x,j;if("name"in p&&p.name){if(_=i.get(p.name),!_)throw ut(1,{location:p});j=_.record.name,v=G(qs(y.params,_.keys.filter(k=>!k.optional).concat(_.parent?_.parent.keys.filter(k=>k.optional):[]).map(k=>k.name)),p.params&&qs(p.params,_.keys.map(k=>k.name))),x=_.stringify(v)}else if(p.path!=null)x=p.path,_=s.find(k=>k.re.test(x)),_&&(v=_.parse(x),j=_.record.name);else{if(_=y.name?i.get(y.name):s.find(k=>k.re.test(y.path)),!_)throw ut(1,{location:p,currentLocation:y});j=_.record.name,v=G({},y.params,p.params),x=_.stringify(v)}const q=[];let S=_;for(;S;)q.unshift(S.record),S=S.parent;return{name:j,path:x,params:v,matched:q,meta:ul(q)}}t.forEach(p=>o(p));function m(){s.length=0,i.clear()}return{addRoute:o,resolve:d,removeRoute:a,clearRoutes:m,getRoutes:l,getRecordMatcher:n}}function qs(t,e){const s={};for(const i of e)i in t&&(s[i]=t[i]);return s}function cl(t){return{path:t.path,redirect:t.redirect,name:t.name,meta:t.meta||{},aliasOf:void 0,beforeEnter:t.beforeEnter,props:dl(t),children:t.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},components:"components"in t?t.components||null:t.component&&{default:t.component}}}function dl(t){const e={},s=t.props||!1;if("component"in t)e.default=s;else for(const i in t.components)e[i]=typeof s=="object"?s[i]:s;return e}function Ns(t){for(;t;){if(t.record.aliasOf)return!0;t=t.parent}return!1}function ul(t){return t.reduce((e,s)=>G(e,s.meta),{})}function Bs(t,e){const s={};for(const i in t)s[i]=i in e?e[i]:t[i];return s}function hl(t,e){let s=0,i=e.length;for(;s!==i;){const o=s+i>>1;Lo(t,e[o])<0?i=o:s=o+1}const n=ml(t);return n&&(i=e.lastIndexOf(n,i-1)),i}function ml(t){let e=t;for(;e=e.parent;)if(Wo(e)&&Lo(t,e)===0)return e}function Wo({record:t}){return!!(t.name||t.components&&Object.keys(t.components).length||t.redirect)}function fl(t){const e={};if(t===""||t==="?")return e;const i=(t[0]==="?"?t.slice(1):t).split("&");for(let n=0;n<i.length;++n){const o=i[n].replace(Mo," "),a=o.indexOf("="),l=Mt(a<0?o:o.slice(0,a)),f=a<0?null:Mt(o.slice(a+1));if(l in e){let d=e[l];Se(d)||(d=e[l]=[d]),d.push(f)}else e[l]=f}return e}function Vs(t){let e="";for(let s in t){const i=t[s];if(s=ja(s),i==null){i!==void 0&&(e+=(e.length?"&":"")+s);continue}(Se(i)?i.map(o=>o&&Gn(o)):[i&&Gn(i)]).forEach(o=>{o!==void 0&&(e+=(e.length?"&":"")+s,o!=null&&(e+="="+o))})}return e}function pl(t){const e={};for(const s in t){const i=t[s];i!==void 0&&(e[s]=Se(i)?i.map(n=>n==null?null:""+n):i==null?i:""+i)}return e}const _l=Symbol(""),Fs=Symbol(""),cs=Symbol(""),Xo=Symbol(""),Yn=Symbol("");function vt(){let t=[];function e(i){return t.push(i),()=>{const n=t.indexOf(i);n>-1&&t.splice(n,1)}}function s(){t=[]}return{add:e,list:()=>t.slice(),reset:s}}function Ge(t,e,s,i,n,o=a=>a()){const a=i&&(i.enterCallbacks[n]=i.enterCallbacks[n]||[]);return()=>new Promise((l,f)=>{const d=y=>{y===!1?f(ut(4,{from:s,to:e})):y instanceof Error?f(y):$a(y)?f(ut(2,{from:e,to:y})):(a&&i.enterCallbacks[n]===a&&typeof y=="function"&&a.push(y),l())},m=o(()=>t.call(i&&i.instances[n],e,s,d));let p=Promise.resolve(m);t.length<3&&(p=p.then(d)),p.catch(y=>f(y))})}function Pn(t,e,s,i,n=o=>o()){const o=[];for(const a of t)for(const l in a.components){let f=a.components[l];if(!(e!=="beforeRouteEnter"&&!a.instances[l]))if(gl(f)){const m=(f.__vccOpts||f)[e];m&&o.push(Ge(m,s,i,a,l,n))}else{let d=f();o.push(()=>d.then(m=>{if(!m)return Promise.reject(new Error(`Couldn't resolve component "${l}" at "${a.path}"`));const p=wa(m)?m.default:m;a.components[l]=p;const _=(p.__vccOpts||p)[e];return _&&Ge(_,s,i,a,l,n)()}))}}return o}function gl(t){return typeof t=="object"||"displayName"in t||"props"in t||"__vccOpts"in t}function Us(t){const e=jt(cs),s=jt(Xo),i=Re(()=>{const f=Ct(t.to);return e.resolve(f)}),n=Re(()=>{const{matched:f}=i.value,{length:d}=f,m=f[d-1],p=s.matched;if(!m||!p.length)return-1;const y=p.findIndex(dt.bind(null,m));if(y>-1)return y;const _=Ls(f[d-2]);return d>1&&Ls(m)===_&&p[p.length-1].path!==_?p.findIndex(dt.bind(null,f[d-2])):y}),o=Re(()=>n.value>-1&&wl(s.params,i.value.params)),a=Re(()=>n.value>-1&&n.value===s.matched.length-1&&Bo(s.params,i.value.params));function l(f={}){return vl(f)?e[Ct(t.replace)?"replace":"push"](Ct(t.to)).catch(Tt):Promise.resolve()}return{route:i,href:Re(()=>i.value.href),isActive:o,isExactActive:a,navigate:l}}const yl=eo({name:"RouterLink",compatConfig:{MODE:3},props:{to:{type:[String,Object],required:!0},replace:Boolean,activeClass:String,exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},useLink:Us,setup(t,{slots:e}){const s=hi(Us(t)),{options:i}=jt(cs),n=Re(()=>({[Ws(t.activeClass,i.linkActiveClass,"router-link-active")]:s.isActive,[Ws(t.exactActiveClass,i.linkExactActiveClass,"router-link-exact-active")]:s.isExactActive}));return()=>{const o=e.default&&e.default(s);return t.custom?o:to("a",{"aria-current":s.isExactActive?t.ariaCurrentValue:null,href:s.href,onClick:s.navigate,class:n.value},o)}}}),bl=yl;function vl(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)&&!t.defaultPrevented&&!(t.button!==void 0&&t.button!==0)){if(t.currentTarget&&t.currentTarget.getAttribute){const e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function wl(t,e){for(const s in e){const i=e[s],n=t[s];if(typeof i=="string"){if(i!==n)return!1}else if(!Se(n)||n.length!==i.length||i.some((o,a)=>o!==n[a]))return!1}return!0}function Ls(t){return t?t.aliasOf?t.aliasOf.path:t.path:""}const Ws=(t,e,s)=>t!=null?t:e!=null?e:s,xl=eo({name:"RouterView",inheritAttrs:!1,props:{name:{type:String,default:"default"},route:Object},compatConfig:{MODE:3},setup(t,{attrs:e,slots:s}){const i=jt(Yn),n=Re(()=>t.route||i.value),o=jt(Fs,0),a=Re(()=>{let d=Ct(o);const{matched:m}=n.value;let p;for(;(p=m[d])&&!p.components;)d++;return d}),l=Re(()=>n.value.matched[a.value]);Cn(Fs,Re(()=>a.value+1)),Cn(_l,l),Cn(Yn,n);const f=mi();return fi(()=>[f.value,l.value,t.name],([d,m,p],[y,_,v])=>{m&&(m.instances[p]=d,_&&_!==m&&d&&d===y&&(m.leaveGuards.size||(m.leaveGuards=_.leaveGuards),m.updateGuards.size||(m.updateGuards=_.updateGuards))),d&&m&&(!_||!dt(m,_)||!y)&&(m.enterCallbacks[p]||[]).forEach(x=>x(d))},{flush:"post"}),()=>{const d=n.value,m=t.name,p=l.value,y=p&&p.components[m];if(!y)return Xs(s.default,{Component:y,route:d});const _=p.props[m],v=_?_===!0?d.params:typeof _=="function"?_(d):_:null,j=to(y,G({},v,e,{onVnodeUnmounted:q=>{q.component.isUnmounted&&(p.instances[m]=null)},ref:f}));return Xs(s.default,{Component:j,route:d})||j}}});function Xs(t,e){if(!t)return null;const s=t(e);return s.length===1?s[0]:s}const El=xl;function Cl(t){const e=ll(t.routes,t),s=t.parseQuery||fl,i=t.stringifyQuery||Vs,n=t.history,o=vt(),a=vt(),l=vt(),f=ci(Qe);let d=Qe;rt&&t.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const m=Sn.bind(null,w=>""+w),p=Sn.bind(null,Ma),y=Sn.bind(null,Mt);function _(w,A){let T,R;return Fo(w)?(T=e.getRecordMatcher(w),R=A):R=w,e.addRoute(R,T)}function v(w){const A=e.getRecordMatcher(w);A&&e.removeRoute(A)}function x(){return e.getRoutes().map(w=>w.record)}function j(w){return!!e.getRecordMatcher(w)}function q(w,A){if(A=G({},A||f.value),typeof w=="string"){const L=Dn(s,w,A.path),ae=e.resolve({path:L.path},A),yt=n.createHref(L.fullPath);return G(L,ae,{params:y(ae.params),hash:Mt(L.hash),redirectedFrom:void 0,href:yt})}let T;if(w.path!=null)T=G({},w,{path:Dn(s,w.path,A.path).path});else{const L=G({},w.params);for(const ae in L)L[ae]==null&&delete L[ae];T=G({},w,{params:p(L)}),A.params=p(A.params)}const R=e.resolve(T,A),Z=w.hash||"";R.params=m(y(R.params));const se=Na(i,G({},w,{hash:Pa(Z),path:R.path})),X=n.createHref(se);return G({fullPath:se,hash:Z,query:i===Vs?pl(w.query):w.query||{}},R,{redirectedFrom:void 0,href:X})}function S(w){return typeof w=="string"?Dn(s,w,f.value.path):G({},w)}function k(w,A){if(d!==w)return ut(8,{from:A,to:w})}function z(w){return K(w)}function le(w){return z(G(S(w),{replace:!0}))}function Y(w){const A=w.matched[w.matched.length-1];if(A&&A.redirect){const{redirect:T}=A;let R=typeof T=="function"?T(w):T;return typeof R=="string"&&(R=R.includes("?")||R.includes("#")?R=S(R):{path:R},R.params={}),G({query:w.query,hash:w.hash,params:R.path!=null?{}:w.params},R)}}function K(w,A){const T=d=q(w),R=f.value,Z=w.state,se=w.force,X=w.replace===!0,L=Y(T);if(L)return K(G(S(L),{state:typeof L=="object"?G({},Z,L.state):Z,force:se,replace:X}),A||T);const ae=T;ae.redirectedFrom=A;let yt;return!se&&Ba(i,R,T)&&(yt=ut(16,{to:ae,from:R}),_t(R,R,!0,!1)),(yt?Promise.resolve(yt):Xe(ae,R)).catch(_e=>Fe(_e)?Fe(_e,2)?_e:Ut(_e):Ve(_e,ae,R)).then(_e=>{if(_e){if(Fe(_e,2))return K(G({replace:X},S(_e.to),{state:typeof _e.to=="object"?G({},Z,_e.to.state):Z,force:se}),A||ae)}else _e=He(ae,R,!0,X,Z);return Ee(ae,R,_e),_e})}function Pe(w,A){const T=k(w,A);return T?Promise.reject(T):Promise.resolve()}function ce(w){const A=Lt.values().next().value;return A&&typeof A.runWithContext=="function"?A.runWithContext(w):w()}function Xe(w,A){let T;const[R,Z,se]=Tl(w,A);T=Pn(R.reverse(),"beforeRouteLeave",w,A);for(const L of R)L.leaveGuards.forEach(ae=>{T.push(Ge(ae,w,A))});const X=Pe.bind(null,w,A);return T.push(X),st(T).then(()=>{T=[];for(const L of o.list())T.push(Ge(L,w,A));return T.push(X),st(T)}).then(()=>{T=Pn(Z,"beforeRouteUpdate",w,A);for(const L of Z)L.updateGuards.forEach(ae=>{T.push(Ge(ae,w,A))});return T.push(X),st(T)}).then(()=>{T=[];for(const L of se)if(L.beforeEnter)if(Se(L.beforeEnter))for(const ae of L.beforeEnter)T.push(Ge(ae,w,A));else T.push(Ge(L.beforeEnter,w,A));return T.push(X),st(T)}).then(()=>(w.matched.forEach(L=>L.enterCallbacks={}),T=Pn(se,"beforeRouteEnter",w,A,ce),T.push(X),st(T))).then(()=>{T=[];for(const L of a.list())T.push(Ge(L,w,A));return T.push(X),st(T)}).catch(L=>Fe(L,8)?L:Promise.reject(L))}function Ee(w,A,T){l.list().forEach(R=>ce(()=>R(w,A,T)))}function He(w,A,T,R,Z){const se=k(w,A);if(se)return se;const X=A===Qe,L=rt?history.state:{};T&&(R||X?n.replace(w.fullPath,G({scroll:X&&L&&L.scroll},Z)):n.push(w.fullPath,Z)),f.value=w,_t(w,A,T,X),Ut()}let fe;function qe(){fe||(fe=n.listen((w,A,T)=>{if(!fs.listening)return;const R=q(w),Z=Y(R);if(Z){K(G(Z,{replace:!0}),R).catch(Tt);return}d=R;const se=f.value;rt&&za(Ps(se.fullPath,T.delta),vn()),Xe(R,se).catch(X=>Fe(X,12)?X:Fe(X,2)?(K(X.to,R).then(L=>{Fe(L,20)&&!T.delta&&T.type===Ot.pop&&n.go(-1,!1)}).catch(Tt),Promise.reject()):(T.delta&&n.go(-T.delta,!1),Ve(X,R,se))).then(X=>{X=X||He(R,se,!1),X&&(T.delta&&!Fe(X,8)?n.go(-T.delta,!1):T.type===Ot.pop&&Fe(X,20)&&n.go(-1,!1)),Ee(R,se,X)}).catch(Tt)}))}let Ne=vt(),Ce=vt(),Be;function Ve(w,A,T){Ut(w);const R=Ce.list();return R.length?R.forEach(Z=>Z(w,A,T)):console.error(w),Promise.reject(w)}function xn(){return Be&&f.value!==Qe?Promise.resolve():new Promise((w,A)=>{Ne.add([w,A])})}function Ut(w){return Be||(Be=!w,qe(),Ne.list().forEach(([A,T])=>w?T(w):A()),Ne.reset()),w}function _t(w,A,T,R){const{scrollBehavior:Z}=t;if(!rt||!Z)return Promise.resolve();const se=!T&&Qa(Ps(w.fullPath,0))||(R||!T)&&history.state&&history.state.scroll||null;return ui().then(()=>Z(w,A,se)).then(X=>X&&Ha(X)).catch(X=>Ve(X,w,A))}const gt=w=>n.go(w);let En;const Lt=new Set,fs={currentRoute:f,listening:!0,addRoute:_,removeRoute:v,clearRoutes:e.clearRoutes,hasRoute:j,getRoutes:x,resolve:q,options:t,push:z,replace:le,go:gt,back:()=>gt(-1),forward:()=>gt(1),beforeEach:o.add,beforeResolve:a.add,afterEach:l.add,onError:Ce.add,isReady:xn,install(w){const A=this;w.component("RouterLink",bl),w.component("RouterView",El),w.config.globalProperties.$router=A,Object.defineProperty(w.config.globalProperties,"$route",{enumerable:!0,get:()=>Ct(f)}),rt&&!En&&f.value===Qe&&(En=!0,z(n.location).catch(Z=>{}));const T={};for(const Z in Qe)Object.defineProperty(T,Z,{get:()=>f.value[Z],enumerable:!0});w.provide(cs,A),w.provide(Xo,di(T)),w.provide(Yn,f);const R=w.unmount;Lt.add(w),w.unmount=function(){Lt.delete(w),Lt.size<1&&(d=Qe,fe&&fe(),fe=null,f.value=Qe,En=!1,Be=!1),R()}}};function st(w){return w.reduce((A,T)=>A.then(()=>ce(T)),Promise.resolve())}return fs}function Tl(t,e){const s=[],i=[],n=[],o=Math.max(e.matched.length,t.matched.length);for(let a=0;a<o;a++){const l=e.matched[a];l&&(t.matched.find(d=>dt(d,l))?i.push(l):s.push(l));const f=t.matched[a];f&&(e.matched.find(d=>dt(d,f))||n.push(f))}return[s,i,n]}const Il={name:"QuoteEdit",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt},data(){return{quote:{quote_number:"",due_date:"",provisional_start_date:"",client_id:"",client:null,status:""},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchQuoteDetails()},methods:{cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.quote.client_id&&this.setClientById(this.quote.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchQuoteDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?(this.quote=e,this.setClientById(this.quote.client_id)):(console.error("Error fetching quote details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching quote details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.quote.client=this.clients.find(e=>e.id===t)||null,this.quote.client_id=t},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting quote:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},kl={class:"pt-2 pr-4"},Al={class:"flex justify-between items-center mb-4"},Sl={class:"card-title"},Dl=r("div",{class:"divider mt-2"},null,-1),Pl={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},jl={class:"grid grid-cols-3 gap-4"},Rl={class:"ecwp-group form-group mb-4"},Ml={for:"quoteNumber",class:"ecwp-label"},Ol={class:"ecwp-group form-group mb-4"},ql={for:"quoteDate",class:"ecwp-label"},Nl={class:"ecwp-group form-group mb-4"},Bl={for:"quoteProvisanalDate",class:"ecwp-label"},Vl={class:"grid grid-cols-2 gap-4"},Fl={class:"ecwp-group form-group mb-4"},Ul={for:"client",class:"ecwp-label"},Ll={class:"ecwp-group form-group mb-4"},Wl={for:"status",class:"ecwp-label"},Xl={value:"draft"},Hl={value:"pending"},zl={value:"approved"},Ql={value:"rejected"},Gl={class:"flex justify-between"},Jl=["disabled"],Yl={key:0,class:"loading loading-spinner loading-sm"};function Kl(t,e,s,i,n,o){const a=O("VueDatePicker"),l=O("model-select"),f=O("Card");return u(),h("div",kl,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:me(()=>[r("div",Al,[r("h2",Sl,c(o.translations.edit_quote),1)]),Dl,n.loading?(u(),h("div",Pl)):g("",!0),r("form",{onSubmit:e[6]||(e[6]=J((...d)=>o.submitQuote&&o.submitQuote(...d),["prevent"]))},[r("div",jl,[r("div",Rl,[r("label",Ml,c(o.translations.quote_number),1),D(r("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=d=>n.quote.quote_number=d),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[W,n.quote.quote_number]])]),r("div",Ol,[r("label",ql,c(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=d=>n.quote.due_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])]),r("div",Nl,[r("label",Bl,c(o.translations.provisional_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteProvisanalDate",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=d=>n.quote.provisional_start_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date},null,8,["class","modelValue","format","min-date"])])]),r("div",Vl,[r("div",Fl,[r("label",Ul,c(o.translations.company_name),1),P(l,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[3]||(e[3]=d=>n.quote.client_id=d),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),r("div",Ll,[r("label",Wl,c(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=d=>n.quote.status=d),required:"",class:I(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[r("option",Xl,c(o.translations.draft),1),r("option",Hl,c(o.translations.pending),1),r("option",zl,c(o.translations.approved),1),r("option",Ql,c(o.translations.rejected),1)],2),[[ue,n.quote.status]])])]),r("div",Gl,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...d)=>o.cancelAction&&o.cancelAction(...d))},c(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.save)+" ",1),n.loadingBtn?(u(),h("span",Yl)):g("",!0)],8,Jl)])],32)]),_:1})])}var Ho=ne(Il,[["render",Kl]]);const Zl={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm"),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm").close()}}},$l=["open"],ec={class:"modal-box"},tc={class:"font-bold text-lg"},nc=r("div",{class:"text-center text-red-400 mb-2"},[r("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),sc={class:"text-lg font-semibold text-center"},oc={class:"my-4 text-center text-xl"},ic={class:"flex justify-between space-x-4"};function rc(t,e,s,i,n,o){return u(),h("div",null,[r("dialog",{id:"modal_confirm",class:"modal",open:t.showModal},[r("div",ec,[r("h3",tc,c(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...a)=>o.closeModal&&o.closeModal(...a))}," \u2715 "),nc,r("h2",sc,c(s.title),1),r("p",oc,c(s.message),1),r("div",ic,[r("button",{onClick:e[1]||(e[1]=(...a)=>o.onCancel&&o.onCancel(...a)),class:"btn btn-secondary rounded-full"},c(s.cancelText),1),r("button",{onClick:e[2]||(e[2]=(...a)=>o.onConfirm&&o.onConfirm(...a)),class:"btn rounded-full btn-error text-white"},c(s.confirmText),1)])])],8,$l)])}var ds=ne(Zl,[["render",rc]]);const ac={name:"QuotesList",components:{Card:Ze,QuoteEditModal:Ho,ConfirmModal:ds,RemoveModal:qt},data(){return{quotes:[],filteredQuotes:[],filters:{quote_number:"",client:"",status:"",total_amount:"",due_date:"",created_at:""},showQuoteDetailsModal:!1,editQuoteModal:!1,selectedQuote:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],clients:[],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchQuotesWithFilters(),this.loadSettings(),this.fetchClients()},methods:{fetchQuotes(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/quotes?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.quotes=s.quotes,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching quotes:",s)}).finally(()=>{this.loading=!1})},fetchQuotesWithFilters(t=1){this.loading=!0;const{perPage:e,filters:s}=this,i=new URLSearchParams({page:t,per_page:e,...s}).toString();fetch(`/wp-json/my-easy-compta/v1/quotes?${i}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(n=>n.json()).then(n=>{this.quotes=n.quotes,this.totalCount=n.total_count,this.totalPages=n.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(n=>{console.error("Error fetching quotes with filters:",n)}).finally(()=>{this.loading=!1})},fetchClients(){fetch("/wp-json/my-easy-compta/v1/clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients}).catch(t=>{console.error("Error fetching clients:",t)})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return so(t,this.default_vat.rate)},calculateWithoutVAT(t){return oo(t)},generatePaginationButtons(){this.paginationButtons=io(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchQuotesWithFilters(t)},perPageChanged(){this.fetchQuotesWithFilters()},formatAmount(t,e){return ro(t,e,this.settings.currency_position)},confirmDuplicateQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},duplicateQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/duplicate/${t}`,{method:"POST",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotesWithFilters(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error duplicate quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},confirmDeleteQuote(t){this.selectedQuote=t,modal_quotes_remove.showModal(),this.showRemoveModal=!0},deleteQuote(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchQuotesWithFilters(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting quote:",e.statusText))}).catch(e=>{console.log(e.message),this.showToast(e.message,"alert-error")})},showToast(t,e){ao(this.toast,t,e)}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},lc={class:"pt-2 pr-4"},cc={class:"flex justify-between items-center"},dc={class:"card-title"},uc={class:"btn btn-primary rounded-full"},hc=r("i",{class:"fas fa-plus-circle"},null,-1),mc={key:0,class:"ms-2"},fc={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab2"},pc=r("i",{class:"fas fa-file-export"},null,-1),_c=["data-tip"],gc={class:"btn btn-outline btn-accent rounded-full",disabled:""},yc=r("i",{class:"fas fa-file-export"},null,-1),bc=r("div",{class:"divider mt-2"},null,-1),vc={class:"flex items-center mb-4"},wc={for:"perPageSelect",class:"mr-2"},xc=["value"],Ec={class:"overflow-x-auto"},Cc={class:"table w-full"},Tc={value:""},Ic=["value"],kc={value:""},Ac={value:"draft"},Sc={value:"pending"},Dc={value:"approved"},Pc={value:"rejected"},jc={class:"flex justify-center"},Rc={key:0},Mc={key:0,class:"badge badge-warning badge-outline badge-sm"},Oc={key:1,class:"badge badge-secondary badge-outline badge-sm"},qc={key:2,class:"badge badge-success badge-outline badge-sm"},Nc={key:3,class:"badge badge-error badge-outline badge-sm"},Bc={key:0},Vc={key:0},Fc={key:0},Uc={key:1},Lc={key:1},Wc={key:0},Xc={key:1},Hc={key:1},zc=r("span",{class:"loading loading-bars loading-sm"},null,-1),Qc=[zc],Gc={key:0},Jc={key:1},Yc=r("span",{class:"loading loading-bars loading-sm"},null,-1),Kc=[Yc],Zc={key:0},$c={key:1},ed=r("span",{class:"loading loading-bars loading-sm"},null,-1),td=[ed],nd={class:"flex justify-end"},sd=["data-tip"],od=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"far fa-eye"})],-1),id=["data-tip"],rd=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"fas fa-pencil-alt"})],-1),ad=["data-tip"],ld=["onClick"],cd=r("i",{class:"far fa-copy"},null,-1),dd=[cd],ud=["data-tip"],hd=["onClick"],md=r("i",{class:"far fa-trash-alt"},null,-1),fd=[md],pd={key:0},_d=r("div",{class:"flex gap-4 items-center"},[r("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),r("div",{class:"flex flex-col gap-4 w-full"},[r("div",{class:"skeleton h-4 w-full"}),r("div",{class:"skeleton h-4 w-full"})])],-1),gd=r("div",{class:"divider my-1"},null,-1),yd=[_d,gd],bd={class:"join ecwp_pagination mt-6 pt-4"},vd=["onClick"];function wd(t,e,s,i,n,o){const a=O("confirm-modal"),l=O("remove-modal"),f=O("router-link"),d=O("Card");return u(),h("div",lc,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),P(a,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=m=>this.duplicateQuote(n.selectedQuote)),onCancel:e[1]||(e[1]=m=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(l,{"modal-id":"modal_quotes_remove","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[2]||(e[2]=m=>this.deleteQuote(n.selectedQuote)),onCancel:e[3]||(e[3]=m=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(d,{topMargin:"mt-8"},{default:me(()=>[r("div",cc,[r("h2",dc,c(o.translations.quotes),1),r("div",null,[P(f,{to:{name:"QuoteNew"}},{default:me(()=>[r("button",uc,[C(c(o.translations.add)+" ",1),hc])]),_:1}),n.settings.easy_compta_export_addon_active==1?(u(),h("span",mc,[r("a",fc,[C(c(o.translations.export)+" ",1),pc])])):(u(),h("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[r("button",gc,[C(c(o.translations.export)+" ",1),yc])],8,_c))])]),bc,r("div",vc,[r("label",wc,c(o.translations.display_per_page),1),D(r("select",{id:"perPageSelect","onUpdate:modelValue":e[4]||(e[4]=m=>n.perPage=m),onChange:e[5]||(e[5]=(...m)=>o.perPageChanged&&o.perPageChanged(...m))},[(u(!0),h(F,null,U(n.perPageOptions,m=>(u(),h("option",{key:m,value:m},c(m),9,xc))),128))],544),[[ue,n.perPage]])]),r("div",Ec,[r("table",Cc,[r("thead",null,[r("tr",null,[r("th",null,[r("div",null,c(o.translations.quote_number),1),D(r("input",{"onUpdate:modelValue":e[6]||(e[6]=m=>n.filters.quote_number=m),onInput:e[7]||(e[7]=m=>o.fetchQuotesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.quote_number]])]),r("th",null,[r("div",null,c(o.translations.client),1),D(r("select",{"onUpdate:modelValue":e[8]||(e[8]=m=>n.filters.client=m),onChange:e[9]||(e[9]=m=>o.fetchQuotesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",Tc,c(o.translations.all),1),(u(!0),h(F,null,U(n.clients,m=>(u(),h("option",{key:m.id,value:m.company_name},c(m.company_name),9,Ic))),128))],544),[[ue,n.filters.client]])]),r("th",null,[r("div",null,c(o.translations.status),1),D(r("select",{"onUpdate:modelValue":e[10]||(e[10]=m=>n.filters.status=m),onChange:e[11]||(e[11]=m=>o.fetchQuotesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",kc,c(o.translations.all_statuses),1),r("option",Ac,c(o.translations.draft),1),r("option",Sc,c(o.translations.pending),1),r("option",Dc,c(o.translations.approved),1),r("option",Pc,c(o.translations.rejected),1)],544),[[ue,n.filters.status]])]),r("th",null,[r("div",null,c(o.translations.total),1),D(r("input",{"onUpdate:modelValue":e[12]||(e[12]=m=>n.filters.total_amount=m),onInput:e[13]||(e[13]=m=>o.fetchQuotesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.total_amount]])]),r("th",null,[r("div",null,c(o.translations.due_date),1),D(r("input",{"onUpdate:modelValue":e[14]||(e[14]=m=>n.filters.due_date=m),onInput:e[15]||(e[15]=m=>o.fetchQuotesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.due_date]])]),r("th",null,[r("div",null,c(o.translations.created_at),1),D(r("input",{"onUpdate:modelValue":e[16]||(e[16]=m=>n.filters.created_at=m),onInput:e[17]||(e[17]=m=>o.fetchQuotesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.created_at]])]),r("th",jc,c(o.translations.actions),1)])]),n.loading?g("",!0):(u(),h("tbody",Rc,[(u(!0),h(F,null,U(n.quotes,m=>(u(),h("tr",{key:m.id},[r("td",null,c(m.quote_number),1),r("td",null,c(m.client_name),1),r("td",null,[m.status=="draft"?(u(),h("span",Mc,c(o.translations.draft),1)):g("",!0),m.status=="pending"?(u(),h("span",Oc,c(o.translations.pending),1)):g("",!0),m.status=="approved"?(u(),h("span",qc,c(o.translations.approved),1)):g("",!0),m.status=="rejected"?(u(),h("span",Nc,c(o.translations.rejected),1)):g("",!0)]),r("td",null,[n.loadingPrice?(u(),h("div",Hc,Qc)):(u(),h("div",Bc,[n.settings.vat_active==1?(u(),h("div",Vc,[n.default_currency_symbol==m.client_currency||m.client_currency==null?(u(),h("span",Fc,c(o.formatAmount(m.total_amount,n.default_currency_symbol)),1)):(u(),h("span",Uc,c(o.formatAmount(m.total_amount,m.client_currency)),1))])):(u(),h("div",Lc,[n.default_currency_symbol==m.client_currency||m.client_currency==null?(u(),h("span",Wc,c(o.formatAmount(m.total_amount,n.default_currency_symbol)),1)):(u(),h("span",Xc,c(o.formatAmount(m.total_amount,m.client_currency)),1))]))]))]),r("td",null,[n.loadingPrice?(u(),h("div",Jc,Kc)):(u(),h("div",Gc,c(m.due_date),1))]),r("td",null,[n.loadingPrice?(u(),h("div",$c,td)):(u(),h("div",Zc,c(m.created),1))]),r("td",nd,[r("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(f,{to:{name:"QuoteViewDetail",params:{id:m.id}}},{default:me(()=>[od]),_:2},1032,["to"])],8,sd),r("span",{class:"lg:tooltip","data-tip":o.translations.edit},[P(f,{to:{name:"QuoteEdit",params:{id:m.id}}},{default:me(()=>[rd]),_:2},1032,["to"])],8,id),r("span",{class:"lg:tooltip","data-tip":o.translations.duplicate},[r("button",{onClick:p=>o.confirmDuplicateQuote(m.id),class:"btn btn-circle text-purple-600 hover:text-purple-900 mx-1"},dd,8,ld)],8,ad),r("span",{class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:p=>o.confirmDeleteQuote(m.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},fd,8,hd)],8,ud)])]))),128))]))]),n.loading?(u(),h("div",pd,[(u(!0),h(F,null,U(n.skeletonRows,m=>(u(),h("div",{key:m,class:"flex flex-col gap-4 w-full"},yd))),128))])):g("",!0)]),r("div",bd,[(u(!0),h(F,null,U(n.paginationButtons,m=>(u(),h("button",{key:m,class:I(["join-item btn",{"btn-disabled":m==="..."||m===n.currentPage}]),onClick:p=>o.goToPage(m)},c(m),11,vd))),128))])]),_:1})])}var xd=ne(ac,[["render",wd]]);const Ed={name:"sendQuote",components:{VueEditor:mt.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,quoteId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"quote",id:this.quoteId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Cd=["id","open"],Td={class:"modal-box"},Id={class:"font-bold text-lg"},kd={key:0},Ad={class:"grid grid-cols-1 gap-4"},Sd=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),Dd=r("div",{class:"skeleton h-4 w-full"},null,-1),Pd=[Sd,Dd],jd={class:"grid grid-cols-1 gap-4"},Rd=["type"],Md=["for"],Od=["id","value","disabled","onInput"],qd={key:1},Nd=["for"],Bd={class:"form-group mt-4 flex justify-end"},Vd=["disabled"],Fd={key:0,class:"loading loading-spinner loading-sm"};function Ud(t,e,s,i,n,o){const a=O("vue-editor");return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",Td,[r("h3",Id,c(o.translations.send_quote),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=l=>o.closeModal())}," \u2715 "),n.loading?(u(),h("div",kd,[r("div",Ad,[(u(!0),h(F,null,U(o.skeletonItems,l=>(u(),h("div",{key:l,class:"py-2"},Pd))),128))])])):(u(),h("form",{key:1,onSubmit:e[1]||(e[1]=J((...l)=>o.submitForm&&o.submitForm(...l),["prevent"])),class:"form"},[r("div",jd,[(u(!0),h(F,null,U(n.fields,(l,f)=>(u(),h("div",{key:f,class:"ecwp-group form-group"},[l.type!=="textarea"?(u(),h("div",{key:0,type:l.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},c(l.label),9,Md),r("input",{id:f,class:I(["ecwp-input input input-bordered",l.class||"w-full"]),value:l.value,disabled:l.disabled,onInput:d=>o.updateFieldValue(f,d.target.value)},null,42,Od)],8,Rd)):(u(),h("div",qd,[r("label",{for:f,class:"form-label"},c(l.label),9,Nd),P(a,{modelValue:l.value,"onUpdate:modelValue":d=>l.value=d,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",Bd,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.send)+" ",1),n.loadingBtn?(u(),h("span",Fd)):g("",!0)],8,Vd)])],32))])],8,Cd)])}var Ld=ne(Ed,[["render",Ud]]);const Wd={components:{VueDatePicker:Nt},props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},totalAmount:{type:String,required:!0},currency:{type:String,required:!0},advanceSold:{type:String,required:!0},quoteId:{type:Number,required:!0}},data(){return{showError:!1,selectedType:"",inputValue:0,due_date:"",invoiceSolded:!1,establishedAdvances:[],loading:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}},remainingAmount(){this.loading=!0;const t=this.establishedAdvances.reduce((e,s)=>{const i=parseFloat(s.advance_amount);return isNaN(i)?(console.error("Erreur: advance_amount n'est pas un nombre valide",s.advance_amount),e):e+i},0);return this.totalAmount-t},inputValueExceeds(){return this.remainingAmount==0?!0:this.selectedType==="percentage"?this.calculatedAmount>this.remainingAmount:this.selectedType==="fixed"?this.inputValue>this.remainingAmount:!1},calculatedAmount(){return this.selectedType==="percentage"?this.inputValue/100*this.remainingAmount:this.inputValue}},created(){this.fetchEstablishedAdvances(this.quoteId)},methods:{fetchEstablishedAdvances(t){const e=`/wp-json/my-easy-compta/v1/advance/${t}`;fetch(e,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.establishedAdvances=s}).catch(s=>{console.error("Error fetching advances:",s)})},onConfirm(){if(!this.inputValueExceeds){if(this.advanceSold=="no_sold"){if(!this.inputValue||!this.due_date||this.advanceSold=="no_sold"&&!this.selectedType){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:this.selectedType,value:this.inputValue,date:this.due_date})}else{if(!this.due_date){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.$emit("confirm",{type:"fixed",value:this.remainingAmount,date:this.due_date})}this.closeModal()}},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_advance").close()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Xd=["open"],Hd={class:"modal-box overflow-visible"},zd={class:"font-bold text-lg"},Qd={class:"text-lg font-semibold text-center"},Gd={class:"my-4 text-center text-xl"},Jd={key:0,class:"text-red-500 text-sm"},Yd={class:"grid grid-cols-2 gap-4"},Kd={key:0},Zd={class:"flex ecwp-group form-group mb-4"},$d=r("label",{for:"advance-type",class:"ecwp-label"},"Type",-1),eu=r("option",{value:"percentage"},"Pourcentage",-1),tu=r("option",{value:"fixed"},"Montant fixe",-1),nu=[eu,tu],su={key:1},ou={class:"flex ecwp-group form-group mb-4"},iu=r("label",{for:"advance-type",class:"ecwp-label"},"Valeur",-1),ru={class:"absolute items-center border rounded-md right-0 top-6"},au={class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"},lu={key:0},cu={key:1},du={key:1,class:"mt-2"},uu={class:"text-sm"},hu={key:2,class:"flex ecwp-group form-group mb-4"},mu={for:"quoteDate",class:"ecwp-label"},fu={key:3},pu={class:"flex justify-between space-x-4 mt-4"},_u=["disabled"];function gu(t,e,s,i,n,o){const a=O("VueDatePicker");return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:"modal_advance",class:"modal",open:s.isVisible},[r("div",Hd,[r("h3",zd,c(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...l)=>o.closeModal&&o.closeModal(...l))}," \u2715 "),r("h2",Qd,c(s.title),1),r("p",Gd," Montant total restant : "+c(o.remainingAmount)+" "+c(s.currency),1),o.inputValueExceeds&&!n.invoiceSolded?(u(),h("p",Jd," Le montant s\xE9lectionn\xE9 d\xE9passe le montant total du devis. ")):g("",!0),r("div",Yd,[s.advanceSold=="no_sold"&&!n.invoiceSolded?(u(),h("div",Kd,[r("div",Zd,[$d,D(r("select",{"onUpdate:modelValue":e[1]||(e[1]=l=>n.selectedType=l),id:"advance-type",class:I(["ecwp-select ecwp-input input input-bordered w-full",{"input-error":!n.selectedType&&n.showError}])},nu,2),[[ue,n.selectedType]])])])):g("",!0),n.selectedType&&s.advanceSold=="no_sold"&&!n.invoiceSolded?(u(),h("div",su,[r("div",ou,[iu,D(r("input",{"onUpdate:modelValue":e[2]||(e[2]=l=>n.inputValue=l),type:"text",id:"advance-value",class:I([{"input-error":!n.inputValue&&n.showError},"ecwp-input input input-bordered w-full"])},null,2),[[W,n.inputValue]]),r("div",ru,[r("div",au,[n.selectedType==="percentage"?(u(),h("span",lu,"%")):(u(),h("span",cu,c(s.currency),1))])])])])):g("",!0)]),n.selectedType==="percentage"&&!o.inputValueExceeds&!n.invoiceSolded?(u(),h("div",du,[r("p",uu," Montant bas\xE9 sur le pourcentage: "+c(o.calculatedAmount)+" "+c(s.currency),1)])):g("",!0),n.invoiceSolded?g("",!0):(u(),h("div",hu,[r("label",mu,c(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.inputValue&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.due_date,"onUpdate:modelValue":e[3]||(e[3]=l=>n.due_date=l),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr",required:""},null,8,["modelValue","format","min-date","class"])])),n.invoiceSolded?(u(),h("div",fu,"Facture d\xE9j\xE0 sold\xE9")):g("",!0),r("div",pu,[r("button",{onClick:e[4]||(e[4]=(...l)=>o.onCancel&&o.onCancel(...l)),class:"btn btn-secondary rounded-full"},c(s.cancelText),1),r("button",{onClick:e[5]||(e[5]=(...l)=>o.onConfirm&&o.onConfirm(...l)),disabled:o.inputValueExceeds,class:"btn rounded-full btn-error text-white"},c(s.confirmText),9,_u)])])],8,Xd)])}var yu=ne(Wd,[["render",gu]]);const bu={name:"QuoteNavBar",components:{SendQuoteModal:Ld,ConfirmModal:ds,AdvanceModal:yu},props:{quoteInfo:Object,emailActive:Number,advanceActive:Number,currency:String,noItems:Boolean},data(){return{selectedQuote:null,advanceSold:!1,sendQuoteModal:!1,loadingModal:!1,loadingPdf:!1,loading:!1,client_detail:null,subject:"",content:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{async changeQuoteStatus(t){try{const s=await(await fetch("/wp-json/my-easy-compta/v1/quotes/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.quoteInfo.id,status:t})})).json();s.success?(this.quoteInfo.status=t,this.quoteInfo.total_amount=s.total_amount,this.showToast(s.message,"alert-success")):(console.error("Failed to update quote status:",s.message),this.showToast(s.message,"alert-error"))}catch(e){console.error("An error occurred while updating quote status:",e),this.showToast(e,"alert-error")}},convertToInvoice(t){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-quote/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e.success?(this.showToast(e.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:e.id}})):this.showToast(e.message,"alert-error")}).catch(e=>{console.error("Error converting quote:",e),this.showToast(e.message,"alert-error")})},handleAdvanceInvoiceConfirm(t){const{type:e,value:s,date:i}=t;this.convertAdvanceInvoice(this.selectedQuote,e,s,i)},convertAdvanceInvoice(t,e,s,i){fetch(`/wp-json/my-easy-compta/v1/quotes/convert-advance/${t}`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({advance_type:e,advance_value:s,advance_date:i})}).then(n=>n.json()).then(n=>{n.success?(this.showToast(n.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:n.id}})):this.showToast(n.message,"alert-error")}).catch(n=>{console.error("Error converting quote:",n),this.showToast(n.message,"alert-error")})},confirmConvertQuote(t){this.selectedQuote=t,modal_confirm.showModal(),this.showRemoveModal=!0},ConvertAdvanceQuote(t,e){this.selectedQuote=t,this.advanceSold=e,modal_advance.showModal(),this.showRemoveModal=!0},exportToPDF(){this.loadingPdf=!0;const t=this.quoteInfo.id;fetch(`/wp-json/my-easy-compta/v1/quotes/pdf/${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return this.loadingPdf=!1,e.blob()}).then(e=>{const s=URL.createObjectURL(e);window.open(s),this.loadingPdf=!1}).catch(e=>{console.error("There was a problem with the fetch operation:",e),this.loadingPdf=!1})},sendQuote(t){this.loadingModal=!0,this.sendQuoteModal=!0,modal_send_quote.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(t.ok){const e=await t.json();this.subject=e.email_quote_subject,this.content=e.email_quote_content,this.loading=!1}else{const e=await t.json();this.showToast(e.message,"alert-error"),this.loading=!1}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},vu={key:0},wu={key:1},xu={key:3,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Eu=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),Cu=[Eu],Tu={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},Iu=r("div",{class:"dropdown"},[r("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),r("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[r("li",null,[r("a",null,"Item 1")]),r("li",null,[r("a",null,"Parent"),r("ul",{class:"p-2"},[r("li",null,[r("a",null,"Submenu 1")]),r("li",null,[r("a",null,"Submenu 2")])])]),r("li",null,[r("a",null,"Item 3")])])],-1),ku={class:"hidden lg:flex gap-2"},Au={class:"btn btn-sm"},Su=r("i",{class:"far fa-edit"},null,-1),Du=r("i",{class:"fa fa-check"},null,-1),Pu=["data-tip"],ju={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Ru=r("i",{class:"fas fa-check"},null,-1),Mu=r("i",{class:"fa fa-check"},null,-1),Ou=r("i",{class:"fa fa-times"},null,-1),qu={key:4},Nu={class:"dropdown"},Bu={tabindex:"0",role:"button",class:"btn btn-sm"},Vu=r("i",{class:"fas fa-exchange-alt"},null,-1),Fu={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},Uu={key:0},Lu={key:5},Wu=r("i",{class:"fas fa-exchange-alt"},null,-1),Xu={class:"flex gap-2"},Hu=r("i",{class:"fas fa-paper-plane"},null,-1),zu={key:0},Qu={key:1},Gu={key:2,class:"far fa-envelope"},Ju=["data-tip"],Yu={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Ku=r("i",{class:"fas fa-paper-plane"},null,-1),Zu=["data-tip"],$u={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},eh=r("i",{class:"fas fa-paper-plane"},null,-1),th=["disabled"],nh=r("i",{class:"far fa-file-pdf"},null,-1),sh={key:0,class:"loading loading-spinner loading-sm"};function oh(t,e,s,i,n,o){const a=O("send-quote-modal"),l=O("confirm-modal"),f=O("advance-modal"),d=O("router-link");return u(),h("div",null,[s.emailActive==1?(u(),h("div",vu,[P(a,{loading:n.loadingModal,"show-modal":n.sendQuoteModal,"modal-id":"modal_send_quote",client:n.client_detail,"quote-id":s.quoteInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=m=>n.sendQuoteModal=!1)},null,8,["loading","show-modal","client","quote-id","subject","content"])])):g("",!0),P(l,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[1]||(e[1]=m=>this.convertToInvoice(n.selectedQuote)),onCancel:e[2]||(e[2]=m=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),s.advanceActive==1?(u(),h("div",wu,[P(f,{"show-modal":t.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,"total-amount":s.quoteInfo.total_amount,currency:s.currency,quoteId:s.quoteInfo.id,"advance-sold":n.advanceSold,onConfirm:o.handleAdvanceInvoiceConfirm,onCancel:e[3]||(e[3]=m=>t.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","total-amount","currency","quoteId","advance-sold","onConfirm"])])):g("",!0),n.toast.visible?(u(),h("div",{key:2,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),n.loading?(u(),h("div",xu,Cu)):g("",!0),r("div",Tu,[r("div",null,[Iu,r("div",ku,[P(d,{to:{name:"QuoteEdit",params:{id:s.quoteInfo.id}}},{default:me(()=>[r("button",Au,[Su,C(c(o.translations.edit_quote),1)])]),_:1},8,["to"]),s.quoteInfo.status=="draft"&&!s.noItems?(u(),h("button",{key:0,class:"btn btn-outline btn-success btn-sm",onClick:e[4]||(e[4]=m=>o.changeQuoteStatus("pending"))},[Du,C(" "+c(o.translations.validate_quote),1)])):g("",!0),s.quoteInfo.status=="draft"&&s.noItems?(u(),h("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.min_article},[r("button",ju,[Ru,C(" "+c(o.translations.validate_quote),1)])],8,Pu)):g("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="rejected")&&!s.noItems?(u(),h("button",{key:2,class:"btn btn-outline btn-success btn-sm",onClick:e[5]||(e[5]=m=>o.changeQuoteStatus("approved"))},[Mu,C(" "+c(o.translations.mark_as_accepted),1)])):g("",!0),(s.quoteInfo.status=="pending"||s.quoteInfo.status=="approved")&&!s.noItems?(u(),h("button",{key:3,class:"btn btn-outline btn-error btn-sm",onClick:e[6]||(e[6]=m=>o.changeQuoteStatus("rejected"))},[Ou,C(" "+c(o.translations.mark_as_rejected),1)])):g("",!0),s.advanceActive==1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(u(),h("div",qu,[r("div",Nu,[r("div",Bu,[Vu,C(" "+c(o.translations.convertToInvoice),1)]),r("ul",Fu,[s.quoteInfo.advance!=1?(u(),h("li",Uu,[r("a",{href:"#",onClick:e[7]||(e[7]=J(m=>o.confirmConvertQuote(s.quoteInfo.id),["prevent"]))}," Facture global ")])):g("",!0),r("li",null,[r("a",{href:"#",onClick:e[8]||(e[8]=J(m=>o.ConvertAdvanceQuote(s.quoteInfo.id,"no_sold"),["prevent"]))}," Facture d'acompte "),s.quoteInfo.advance!=0?(u(),h("a",{key:0,href:"#",onClick:e[9]||(e[9]=J(m=>o.ConvertAdvanceQuote(s.quoteInfo.id,"sold"),["prevent"]))}," Facture du solde ")):g("",!0)])])])])):g("",!0),s.advanceActive!=1&&s.quoteInfo.converted!=1&&s.quoteInfo.status=="approved"&&!s.noItems?(u(),h("div",Lu,[r("button",{onClick:e[10]||(e[10]=m=>o.confirmConvertQuote(s.quoteInfo.id)),class:"btn btn-sm"},[Wu,C(" "+c(o.translations.convertToInvoice),1)])])):g("",!0)])]),r("div",Xu,[s.emailActive==1&&s.quoteInfo.status!="draft"?(u(),h("button",{key:0,onClick:e[11]||(e[11]=J(m=>o.sendQuote(s.quoteInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[Hu,s.quoteInfo.sent==1?(u(),h("span",zu,c(o.translations.resend_quote),1)):(u(),h("span",Qu,c(o.translations.send_quote),1)),s.quoteInfo.sent==1?(u(),h("i",Gu)):g("",!0)])):s.emailActive==1&&s.quoteInfo.status=="draft"?(u(),h("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.quote_draft_cannot_send},[r("button",Yu,[Ku,C(" "+c(o.translations.send_quote),1)])],8,Ju)):(u(),h("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[r("button",$u,[eh,C(" "+c(o.translations.send_quote),1)])],8,Zu)),r("button",{onClick:e[12]||(e[12]=(...m)=>o.exportToPDF&&o.exportToPDF(...m)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[nh,C(" "+c(o.translations.exportToPDF)+" ",1),n.loadingPdf?(u(),h("span",sh)):g("",!0)],8,th)])])])}var ih=ne(bu,[["render",oh]]);const rh={components:{VueEditor:mt.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:t.item_name},item_description:{label:t.description,type:"textarea"},quantity:{label:t.quantity,type:"number"},vat_rate:{label:t.vat,type:"number"},unit_price:{label:t.unit_price,type:"number"},discount:{label:t.discount,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/quotes/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},ah=["id","open"],lh={class:"modal-box"},ch={class:"font-bold text-lg"},dh={key:0},uh={class:"grid grid-cols-1 gap-4"},hh=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),mh=r("div",{class:"skeleton h-4 w-full"},null,-1),fh=[hh,mh],ph={class:"grid grid-cols-1 gap-4"},_h=["type"],gh=["for"],yh=["id","onUpdate:modelValue"],bh={key:1},vh=["for"],wh={class:"form-group mt-4 flex justify-end"},xh=["disabled"],Eh={key:0,class:"loading loading-spinner loading-sm"};function Ch(t,e,s,i,n,o){const a=O("vue-editor");return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",lh,[r("h3",ch,c(s.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=l=>o.closeModal())}," \u2715 "),n.loading?(u(),h("div",dh,[r("div",uh,[(u(!0),h(F,null,U(o.skeletonItems,l=>(u(),h("div",{key:l,class:"py-2"},fh))),128))])])):(u(),h("form",{key:1,onSubmit:e[1]||(e[1]=J((...l)=>o.submitForm&&o.submitForm(...l),["prevent"])),class:"form"},[r("div",ph,[(u(!0),h(F,null,U(n.fields,(l,f)=>(u(),h("div",{key:f,class:"ecwp-group form-group"},[l.type!=="textarea"?(u(),h("div",{key:0,type:l.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},c(l.label),9,gh),D(r("input",{id:f,"onUpdate:modelValue":d=>n.editedItem[f]=d,class:I(["ecwp-input input input-bordered",l.class||"w-full"])},null,10,yh),[[W,n.editedItem[f]]])],8,_h)):(u(),h("div",bh,[r("label",{for:f,class:"form-label"},c(l.label),9,vh),P(a,{id:f,modelValue:n.editedItem[f],"onUpdate:modelValue":d=>n.editedItem[f]=d,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",wh,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.save)+" ",1),n.loadingBtn?(u(),h("span",Eh)):g("",!0)],8,xh)])],32))])],8,ah)])}var Th=ne(rh,[["render",Ch]]);const Ih={props:{showModal:Boolean,modalId:String,modalTitle:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{articles:[],translations:t}},computed:{skeletonItems(){return Array.from({length:7},(t,e)=>e)}},mounted(){this.fetchArticlesList()},methods:{closeModal(){const t=document.getElementById(this.modalId);t&&(t.close(),this.$emit("close"))},selectItem(t){this.$emit("select-article",t),this.closeModal()},fetchArticlesList(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/articles",{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.articles=t,this.loading=!1}).catch(t=>{console.error("Erreur lors du chargement des articles :",t),this.loading=!1})}}},kh=["id","open"],Ah={class:"modal-box"},Sh={class:"font-bold text-lg"},Dh={key:0},Ph={key:0,class:""},jh=["onClick"],Rh={key:1},Mh={class:"grid grid-cols-2 gap-4"},Oh=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),qh=r("div",{class:"skeleton h-4 w-full"},null,-1),Nh=[Oh,qh];function Bh(t,e,s,i,n,o){return u(),h("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",Ah,[r("h3",Sh,c(s.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=a=>o.closeModal())}," \u2715 "),n.articles?(u(),h("div",Dh,[n.articles.length?(u(),h("ul",Ph,[(u(!0),h(F,null,U(n.articles,a=>(u(),h("li",{key:a.name,onClick:l=>o.selectItem(a),class:"flex justify-between autocomplete-item hover:bg-base-200"},[r("span",null,[r("strong",null,c(a.ref),1),C(" - "+c(a.name),1)]),r("span",null,[r("strong",null,c(a.unit_price),1)])],8,jh))),128))])):g("",!0)])):(u(),h("div",Rh,[r("div",Mh,[(u(!0),h(F,null,U(o.skeletonItems,a=>(u(),h("div",{key:a,class:"py-2"},Nh))),128))])]))])],8,kh)}var zo=ne(Ih,[["render",Bh]]);/**!
    1111 * Sortable 1.15.2
    1212 * @author  RubaXa   <trash@rubaxa.org>
    1313 * @author  owenm    <owen23355@gmail.com>
    1414 * @license MIT
    15  */function Hs(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),s.push.apply(s,i)}return s}function Me(t){for(var e=1;e<arguments.length;e++){var s=arguments[e]!=null?arguments[e]:{};e%2?Hs(Object(s),!0).forEach(function(i){Th(t,i,s[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):Hs(Object(s)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(s,i))})}return t}function Yt(t){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Yt=function(e){return typeof e}:Yt=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Yt(t)}function Th(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function Le(){return Le=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},Le.apply(this,arguments)}function Ih(t,e){if(t==null)return{};var s={},i=Object.keys(t),n,o;for(o=0;o<i.length;o++)n=i[o],!(e.indexOf(n)>=0)&&(s[n]=t[n]);return s}function kh(t,e){if(t==null)return{};var s=Ih(t,e),i,n;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)i=o[n],!(e.indexOf(i)>=0)&&(!Object.prototype.propertyIsEnumerable.call(t,i)||(s[i]=t[i]))}return s}var Sh="1.15.2";function Ue(t){if(typeof window!="undefined"&&window.navigator)return!!navigator.userAgent.match(t)}var We=Ue(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),Vt=Ue(/Edge/i),zs=Ue(/firefox/i),kt=Ue(/safari/i)&&!Ue(/chrome/i)&&!Ue(/android/i),zo=Ue(/iP(ad|od|hone)/i),Qo=Ue(/chrome/i)&&Ue(/android/i),Go={capture:!1,passive:!1};function Q(t,e,s){t.addEventListener(e,s,!We&&Go)}function H(t,e,s){t.removeEventListener(e,s,!We&&Go)}function on(t,e){if(!!e){if(e[0]===">"&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch{return!1}return!1}}function Ah(t){return t.host&&t!==document&&t.host.nodeType?t.host:t.parentNode}function Ie(t,e,s,i){if(t){s=s||document;do{if(e!=null&&(e[0]===">"?t.parentNode===s&&on(t,e):on(t,e))||i&&t===s)return t;if(t===s)break}while(t=Ah(t))}return null}var Qs=/\s+/g;function ye(t,e,s){if(t&&e)if(t.classList)t.classList[s?"add":"remove"](e);else{var i=(" "+t.className+" ").replace(Qs," ").replace(" "+e+" "," ");t.className=(i+(s?" "+e:"")).replace(Qs," ")}}function q(t,e,s){var i=t&&t.style;if(i){if(s===void 0)return document.defaultView&&document.defaultView.getComputedStyle?s=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(s=t.currentStyle),e===void 0?s:s[e];!(e in i)&&e.indexOf("webkit")===-1&&(e="-webkit-"+e),i[e]=s+(typeof s=="string"?"":"px")}}function ct(t,e){var s="";if(typeof t=="string")s=t;else do{var i=q(t,"transform");i&&i!=="none"&&(s=i+" "+s)}while(!e&&(t=t.parentNode));var n=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return n&&new n(s)}function Jo(t,e,s){if(t){var i=t.getElementsByTagName(e),n=0,o=i.length;if(s)for(;n<o;n++)s(i[n],n);return i}return[]}function Oe(){var t=document.scrollingElement;return t||document.documentElement}function ie(t,e,s,i,n){if(!(!t.getBoundingClientRect&&t!==window)){var o,a,c,f,u,l,_;if(t!==window&&t.parentNode&&t!==Oe()?(o=t.getBoundingClientRect(),a=o.top,c=o.left,f=o.bottom,u=o.right,l=o.height,_=o.width):(a=0,c=0,f=window.innerHeight,u=window.innerWidth,l=window.innerHeight,_=window.innerWidth),(e||s)&&t!==window&&(n=n||t.parentNode,!We))do if(n&&n.getBoundingClientRect&&(q(n,"transform")!=="none"||s&&q(n,"position")!=="static")){var p=n.getBoundingClientRect();a-=p.top+parseInt(q(n,"border-top-width")),c-=p.left+parseInt(q(n,"border-left-width")),f=a+o.height,u=c+o.width;break}while(n=n.parentNode);if(i&&t!==window){var y=ct(n||t),v=y&&y.a,x=y&&y.d;y&&(a/=x,c/=v,_/=v,l/=x,f=a+l,u=c+_)}return{top:a,left:c,bottom:f,right:u,width:_,height:l}}}function Gs(t,e,s){for(var i=Ke(t,!0),n=ie(t)[e];i;){var o=ie(i)[s],a=void 0;if(s==="top"||s==="left"?a=n>=o:a=n<=o,!a)return i;if(i===Oe())break;i=Ke(i,!1)}return!1}function ht(t,e,s,i){for(var n=0,o=0,a=t.children;o<a.length;){if(a[o].style.display!=="none"&&a[o]!==O.ghost&&(i||a[o]!==O.dragged)&&Ie(a[o],s.draggable,t,!1)){if(n===e)return a[o];n++}o++}return null}function us(t,e){for(var s=t.lastElementChild;s&&(s===O.ghost||q(s,"display")==="none"||e&&!on(s,e));)s=s.previousElementSibling;return s||null}function we(t,e){var s=0;if(!t||!t.parentNode)return-1;for(;t=t.previousElementSibling;)t.nodeName.toUpperCase()!=="TEMPLATE"&&t!==O.clone&&(!e||on(t,e))&&s++;return s}function Js(t){var e=0,s=0,i=Oe();if(t)do{var n=ct(t),o=n.a,a=n.d;e+=t.scrollLeft*o,s+=t.scrollTop*a}while(t!==i&&(t=t.parentNode));return[e,s]}function Dh(t,e){for(var s in t)if(!!t.hasOwnProperty(s)){for(var i in e)if(e.hasOwnProperty(i)&&e[i]===t[s][i])return Number(s)}return-1}function Ke(t,e){if(!t||!t.getBoundingClientRect)return Oe();var s=t,i=!1;do if(s.clientWidth<s.scrollWidth||s.clientHeight<s.scrollHeight){var n=q(s);if(s.clientWidth<s.scrollWidth&&(n.overflowX=="auto"||n.overflowX=="scroll")||s.clientHeight<s.scrollHeight&&(n.overflowY=="auto"||n.overflowY=="scroll")){if(!s.getBoundingClientRect||s===document.body)return Oe();if(i||e)return s;i=!0}}while(s=s.parentNode);return Oe()}function Ph(t,e){if(t&&e)for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t}function Rn(t,e){return Math.round(t.top)===Math.round(e.top)&&Math.round(t.left)===Math.round(e.left)&&Math.round(t.height)===Math.round(e.height)&&Math.round(t.width)===Math.round(e.width)}var St;function Yo(t,e){return function(){if(!St){var s=arguments,i=this;s.length===1?t.call(i,s[0]):t.apply(i,s),St=setTimeout(function(){St=void 0},e)}}}function Rh(){clearTimeout(St),St=void 0}function Ko(t,e,s){t.scrollLeft+=e,t.scrollTop+=s}function Zo(t){var e=window.Polymer,s=window.jQuery||window.Zepto;return e&&e.dom?e.dom(t).cloneNode(!0):s?s(t).clone(!0)[0]:t.cloneNode(!0)}function $o(t,e,s){var i={};return Array.from(t.children).forEach(function(n){var o,a,c,f;if(!(!Ie(n,e.draggable,t,!1)||n.animated||n===s)){var u=ie(n);i.left=Math.min((o=i.left)!==null&&o!==void 0?o:1/0,u.left),i.top=Math.min((a=i.top)!==null&&a!==void 0?a:1/0,u.top),i.right=Math.max((c=i.right)!==null&&c!==void 0?c:-1/0,u.right),i.bottom=Math.max((f=i.bottom)!==null&&f!==void 0?f:-1/0,u.bottom)}}),i.width=i.right-i.left,i.height=i.bottom-i.top,i.x=i.left,i.y=i.top,i}var ve="Sortable"+new Date().getTime();function jh(){var t=[],e;return{captureAnimationState:function(){if(t=[],!!this.options.animation){var i=[].slice.call(this.el.children);i.forEach(function(n){if(!(q(n,"display")==="none"||n===O.ghost)){t.push({target:n,rect:ie(n)});var o=Me({},t[t.length-1].rect);if(n.thisAnimationDuration){var a=ct(n,!0);a&&(o.top-=a.f,o.left-=a.e)}n.fromRect=o}})}},addAnimationState:function(i){t.push(i)},removeAnimationState:function(i){t.splice(Dh(t,{target:i}),1)},animateAll:function(i){var n=this;if(!this.options.animation){clearTimeout(e),typeof i=="function"&&i();return}var o=!1,a=0;t.forEach(function(c){var f=0,u=c.target,l=u.fromRect,_=ie(u),p=u.prevFromRect,y=u.prevToRect,v=c.rect,x=ct(u,!0);x&&(_.top-=x.f,_.left-=x.e),u.toRect=_,u.thisAnimationDuration&&Rn(p,_)&&!Rn(l,_)&&(v.top-_.top)/(v.left-_.left)===(l.top-_.top)/(l.left-_.left)&&(f=Mh(v,p,y,n.options)),Rn(_,l)||(u.prevFromRect=l,u.prevToRect=_,f||(f=n.options.animation),n.animate(u,v,_,f)),f&&(o=!0,a=Math.max(a,f),clearTimeout(u.animationResetTimer),u.animationResetTimer=setTimeout(function(){u.animationTime=0,u.prevFromRect=null,u.fromRect=null,u.prevToRect=null,u.thisAnimationDuration=null},f),u.thisAnimationDuration=f)}),clearTimeout(e),o?e=setTimeout(function(){typeof i=="function"&&i()},a):typeof i=="function"&&i(),t=[]},animate:function(i,n,o,a){if(a){q(i,"transition",""),q(i,"transform","");var c=ct(this.el),f=c&&c.a,u=c&&c.d,l=(n.left-o.left)/(f||1),_=(n.top-o.top)/(u||1);i.animatingX=!!l,i.animatingY=!!_,q(i,"transform","translate3d("+l+"px,"+_+"px,0)"),this.forRepaintDummy=Oh(i),q(i,"transition","transform "+a+"ms"+(this.options.easing?" "+this.options.easing:"")),q(i,"transform","translate3d(0,0,0)"),typeof i.animated=="number"&&clearTimeout(i.animated),i.animated=setTimeout(function(){q(i,"transition",""),q(i,"transform",""),i.animated=!1,i.animatingX=!1,i.animatingY=!1},a)}}}}function Oh(t){return t.offsetWidth}function Mh(t,e,s,i){return Math.sqrt(Math.pow(e.top-t.top,2)+Math.pow(e.left-t.left,2))/Math.sqrt(Math.pow(e.top-s.top,2)+Math.pow(e.left-s.left,2))*i.animation}var ot=[],jn={initializeByDefault:!0},Ft={mount:function(e){for(var s in jn)jn.hasOwnProperty(s)&&!(s in e)&&(e[s]=jn[s]);ot.forEach(function(i){if(i.pluginName===e.pluginName)throw"Sortable: Cannot mount plugin ".concat(e.pluginName," more than once")}),ot.push(e)},pluginEvent:function(e,s,i){var n=this;this.eventCanceled=!1,i.cancel=function(){n.eventCanceled=!0};var o=e+"Global";ot.forEach(function(a){!s[a.pluginName]||(s[a.pluginName][o]&&s[a.pluginName][o](Me({sortable:s},i)),s.options[a.pluginName]&&s[a.pluginName][e]&&s[a.pluginName][e](Me({sortable:s},i)))})},initializePlugins:function(e,s,i,n){ot.forEach(function(c){var f=c.pluginName;if(!(!e.options[f]&&!c.initializeByDefault)){var u=new c(e,s,e.options);u.sortable=e,u.options=e.options,e[f]=u,Le(i,u.defaults)}});for(var o in e.options)if(!!e.options.hasOwnProperty(o)){var a=this.modifyOption(e,o,e.options[o]);typeof a!="undefined"&&(e.options[o]=a)}},getEventProperties:function(e,s){var i={};return ot.forEach(function(n){typeof n.eventProperties=="function"&&Le(i,n.eventProperties.call(s[n.pluginName],e))}),i},modifyOption:function(e,s,i){var n;return ot.forEach(function(o){!e[o.pluginName]||o.optionListeners&&typeof o.optionListeners[s]=="function"&&(n=o.optionListeners[s].call(e[o.pluginName],i))}),n}};function qh(t){var e=t.sortable,s=t.rootEl,i=t.name,n=t.targetEl,o=t.cloneEl,a=t.toEl,c=t.fromEl,f=t.oldIndex,u=t.newIndex,l=t.oldDraggableIndex,_=t.newDraggableIndex,p=t.originalEvent,y=t.putSortable,v=t.extraEventProperties;if(e=e||s&&s[ve],!!e){var x,R=e.options,M="on"+i.charAt(0).toUpperCase()+i.substr(1);window.CustomEvent&&!We&&!Vt?x=new CustomEvent(i,{bubbles:!0,cancelable:!0}):(x=document.createEvent("Event"),x.initEvent(i,!0,!0)),x.to=a||s,x.from=c||s,x.item=n||s,x.clone=o,x.oldIndex=f,x.newIndex=u,x.oldDraggableIndex=l,x.newDraggableIndex=_,x.originalEvent=p,x.pullMode=y?y.lastPutMode:void 0;var A=Me(Me({},v),Ft.getEventProperties(i,e));for(var k in A)x[k]=A[k];s&&s.dispatchEvent(x),R[M]&&R[M].call(e,x)}}var Nh=["evt"],ge=function(e,s){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},n=i.evt,o=kh(i,Nh);Ft.pluginEvent.bind(O)(e,s,Me({dragEl:E,parentEl:te,ghostEl:B,rootEl:$,nextEl:tt,lastDownEl:Kt,cloneEl:ee,cloneHidden:Ye,dragStarted:wt,putSortable:de,activeSortable:O.active,originalEvent:n,oldIndex:lt,oldDraggableIndex:At,newIndex:be,newDraggableIndex:Je,hideGhostForTarget:si,unhideGhostForTarget:oi,cloneNowHidden:function(){Ye=!0},cloneNowShown:function(){Ye=!1},dispatchSortableEvent:function(c){pe({sortable:s,name:c,originalEvent:n})}},o))};function pe(t){qh(Me({putSortable:de,cloneEl:ee,targetEl:E,rootEl:$,oldIndex:lt,oldDraggableIndex:At,newIndex:be,newDraggableIndex:Je},t))}var E,te,B,$,tt,Kt,ee,Ye,lt,be,At,Je,Wt,de,at=!1,rn=!1,an=[],$e,Te,On,Mn,Ys,Ks,wt,it,Dt,Pt=!1,Xt=!1,Zt,he,qn=[],Kn=!1,ln=[],wn=typeof document!="undefined",Ht=zo,Zs=Vt||We?"cssFloat":"float",Bh=wn&&!Qo&&!zo&&"draggable"in document.createElement("div"),ei=function(){if(!!wn){if(We)return!1;var t=document.createElement("x");return t.style.cssText="pointer-events:auto",t.style.pointerEvents==="auto"}}(),ti=function(e,s){var i=q(e),n=parseInt(i.width)-parseInt(i.paddingLeft)-parseInt(i.paddingRight)-parseInt(i.borderLeftWidth)-parseInt(i.borderRightWidth),o=ht(e,0,s),a=ht(e,1,s),c=o&&q(o),f=a&&q(a),u=c&&parseInt(c.marginLeft)+parseInt(c.marginRight)+ie(o).width,l=f&&parseInt(f.marginLeft)+parseInt(f.marginRight)+ie(a).width;if(i.display==="flex")return i.flexDirection==="column"||i.flexDirection==="column-reverse"?"vertical":"horizontal";if(i.display==="grid")return i.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(o&&c.float&&c.float!=="none"){var _=c.float==="left"?"left":"right";return a&&(f.clear==="both"||f.clear===_)?"vertical":"horizontal"}return o&&(c.display==="block"||c.display==="flex"||c.display==="table"||c.display==="grid"||u>=n&&i[Zs]==="none"||a&&i[Zs]==="none"&&u+l>n)?"vertical":"horizontal"},Vh=function(e,s,i){var n=i?e.left:e.top,o=i?e.right:e.bottom,a=i?e.width:e.height,c=i?s.left:s.top,f=i?s.right:s.bottom,u=i?s.width:s.height;return n===c||o===f||n+a/2===c+u/2},Fh=function(e,s){var i;return an.some(function(n){var o=n[ve].options.emptyInsertThreshold;if(!(!o||us(n))){var a=ie(n),c=e>=a.left-o&&e<=a.right+o,f=s>=a.top-o&&s<=a.bottom+o;if(c&&f)return i=n}}),i},ni=function(e){function s(o,a){return function(c,f,u,l){var _=c.options.group.name&&f.options.group.name&&c.options.group.name===f.options.group.name;if(o==null&&(a||_))return!0;if(o==null||o===!1)return!1;if(a&&o==="clone")return o;if(typeof o=="function")return s(o(c,f,u,l),a)(c,f,u,l);var p=(a?c:f).options.group.name;return o===!0||typeof o=="string"&&o===p||o.join&&o.indexOf(p)>-1}}var i={},n=e.group;(!n||Yt(n)!="object")&&(n={name:n}),i.name=n.name,i.checkPull=s(n.pull,!0),i.checkPut=s(n.put),i.revertClone=n.revertClone,e.group=i},si=function(){!ei&&B&&q(B,"display","none")},oi=function(){!ei&&B&&q(B,"display","")};wn&&!Qo&&document.addEventListener("click",function(t){if(rn)return t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation(),rn=!1,!1},!0);var et=function(e){if(E){e=e.touches?e.touches[0]:e;var s=Fh(e.clientX,e.clientY);if(s){var i={};for(var n in e)e.hasOwnProperty(n)&&(i[n]=e[n]);i.target=i.rootEl=s,i.preventDefault=void 0,i.stopPropagation=void 0,s[ve]._onDragOver(i)}}},Uh=function(e){E&&E.parentNode[ve]._isOutsideThisEl(e.target)};function O(t,e){if(!(t&&t.nodeType&&t.nodeType===1))throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=Le({},e),t[ve]=this;var s={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return ti(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(a,c){a.setData("Text",c.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:O.supportPointer!==!1&&"PointerEvent"in window&&!kt,emptyInsertThreshold:5};Ft.initializePlugins(this,t,s);for(var i in s)!(i in e)&&(e[i]=s[i]);ni(e);for(var n in this)n.charAt(0)==="_"&&typeof this[n]=="function"&&(this[n]=this[n].bind(this));this.nativeDraggable=e.forceFallback?!1:Bh,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?Q(t,"pointerdown",this._onTapStart):(Q(t,"mousedown",this._onTapStart),Q(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(Q(t,"dragover",this),Q(t,"dragenter",this)),an.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),Le(this,jh())}O.prototype={constructor:O,_isOutsideThisEl:function(e){!this.el.contains(e)&&e!==this.el&&(it=null)},_getDirection:function(e,s){return typeof this.options.direction=="function"?this.options.direction.call(this,e,s,E):this.options.direction},_onTapStart:function(e){if(!!e.cancelable){var s=this,i=this.el,n=this.options,o=n.preventOnFilter,a=e.type,c=e.touches&&e.touches[0]||e.pointerType&&e.pointerType==="touch"&&e,f=(c||e).target,u=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||f,l=n.filter;if(Jh(i),!E&&!(/mousedown|pointerdown/.test(a)&&e.button!==0||n.disabled)&&!u.isContentEditable&&!(!this.nativeDraggable&&kt&&f&&f.tagName.toUpperCase()==="SELECT")&&(f=Ie(f,n.draggable,i,!1),!(f&&f.animated)&&Kt!==f)){if(lt=we(f),At=we(f,n.draggable),typeof l=="function"){if(l.call(this,e,f,this)){pe({sortable:s,rootEl:u,name:"filter",targetEl:f,toEl:i,fromEl:i}),ge("filter",s,{evt:e}),o&&e.cancelable&&e.preventDefault();return}}else if(l&&(l=l.split(",").some(function(_){if(_=Ie(u,_.trim(),i,!1),_)return pe({sortable:s,rootEl:_,name:"filter",targetEl:f,fromEl:i,toEl:i}),ge("filter",s,{evt:e}),!0}),l)){o&&e.cancelable&&e.preventDefault();return}n.handle&&!Ie(u,n.handle,i,!1)||this._prepareDragStart(e,c,f)}}},_prepareDragStart:function(e,s,i){var n=this,o=n.el,a=n.options,c=o.ownerDocument,f;if(i&&!E&&i.parentNode===o){var u=ie(i);if($=o,E=i,te=E.parentNode,tt=E.nextSibling,Kt=i,Wt=a.group,O.dragged=E,$e={target:E,clientX:(s||e).clientX,clientY:(s||e).clientY},Ys=$e.clientX-u.left,Ks=$e.clientY-u.top,this._lastX=(s||e).clientX,this._lastY=(s||e).clientY,E.style["will-change"]="all",f=function(){if(ge("delayEnded",n,{evt:e}),O.eventCanceled){n._onDrop();return}n._disableDelayedDragEvents(),!zs&&n.nativeDraggable&&(E.draggable=!0),n._triggerDragStart(e,s),pe({sortable:n,name:"choose",originalEvent:e}),ye(E,a.chosenClass,!0)},a.ignore.split(",").forEach(function(l){Jo(E,l.trim(),Nn)}),Q(c,"dragover",et),Q(c,"mousemove",et),Q(c,"touchmove",et),Q(c,"mouseup",n._onDrop),Q(c,"touchend",n._onDrop),Q(c,"touchcancel",n._onDrop),zs&&this.nativeDraggable&&(this.options.touchStartThreshold=4,E.draggable=!0),ge("delayStart",this,{evt:e}),a.delay&&(!a.delayOnTouchOnly||s)&&(!this.nativeDraggable||!(Vt||We))){if(O.eventCanceled){this._onDrop();return}Q(c,"mouseup",n._disableDelayedDrag),Q(c,"touchend",n._disableDelayedDrag),Q(c,"touchcancel",n._disableDelayedDrag),Q(c,"mousemove",n._delayedDragTouchMoveHandler),Q(c,"touchmove",n._delayedDragTouchMoveHandler),a.supportPointer&&Q(c,"pointermove",n._delayedDragTouchMoveHandler),n._dragStartTimer=setTimeout(f,a.delay)}else f()}},_delayedDragTouchMoveHandler:function(e){var s=e.touches?e.touches[0]:e;Math.max(Math.abs(s.clientX-this._lastX),Math.abs(s.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){E&&Nn(E),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;H(e,"mouseup",this._disableDelayedDrag),H(e,"touchend",this._disableDelayedDrag),H(e,"touchcancel",this._disableDelayedDrag),H(e,"mousemove",this._delayedDragTouchMoveHandler),H(e,"touchmove",this._delayedDragTouchMoveHandler),H(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,s){s=s||e.pointerType=="touch"&&e,!this.nativeDraggable||s?this.options.supportPointer?Q(document,"pointermove",this._onTouchMove):s?Q(document,"touchmove",this._onTouchMove):Q(document,"mousemove",this._onTouchMove):(Q(E,"dragend",this),Q($,"dragstart",this._onDragStart));try{document.selection?$t(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch{}},_dragStarted:function(e,s){if(at=!1,$&&E){ge("dragStarted",this,{evt:s}),this.nativeDraggable&&Q(document,"dragover",Uh);var i=this.options;!e&&ye(E,i.dragClass,!1),ye(E,i.ghostClass,!0),O.active=this,e&&this._appendGhost(),pe({sortable:this,name:"start",originalEvent:s})}else this._nulling()},_emulateDragOver:function(){if(Te){this._lastX=Te.clientX,this._lastY=Te.clientY,si();for(var e=document.elementFromPoint(Te.clientX,Te.clientY),s=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(Te.clientX,Te.clientY),e!==s);)s=e;if(E.parentNode[ve]._isOutsideThisEl(e),s)do{if(s[ve]){var i=void 0;if(i=s[ve]._onDragOver({clientX:Te.clientX,clientY:Te.clientY,target:e,rootEl:s}),i&&!this.options.dragoverBubble)break}e=s}while(s=s.parentNode);oi()}},_onTouchMove:function(e){if($e){var s=this.options,i=s.fallbackTolerance,n=s.fallbackOffset,o=e.touches?e.touches[0]:e,a=B&&ct(B,!0),c=B&&a&&a.a,f=B&&a&&a.d,u=Ht&&he&&Js(he),l=(o.clientX-$e.clientX+n.x)/(c||1)+(u?u[0]-qn[0]:0)/(c||1),_=(o.clientY-$e.clientY+n.y)/(f||1)+(u?u[1]-qn[1]:0)/(f||1);if(!O.active&&!at){if(i&&Math.max(Math.abs(o.clientX-this._lastX),Math.abs(o.clientY-this._lastY))<i)return;this._onDragStart(e,!0)}if(B){a?(a.e+=l-(On||0),a.f+=_-(Mn||0)):a={a:1,b:0,c:0,d:1,e:l,f:_};var p="matrix(".concat(a.a,",").concat(a.b,",").concat(a.c,",").concat(a.d,",").concat(a.e,",").concat(a.f,")");q(B,"webkitTransform",p),q(B,"mozTransform",p),q(B,"msTransform",p),q(B,"transform",p),On=l,Mn=_,Te=o}e.cancelable&&e.preventDefault()}},_appendGhost:function(){if(!B){var e=this.options.fallbackOnBody?document.body:$,s=ie(E,!0,Ht,!0,e),i=this.options;if(Ht){for(he=e;q(he,"position")==="static"&&q(he,"transform")==="none"&&he!==document;)he=he.parentNode;he!==document.body&&he!==document.documentElement?(he===document&&(he=Oe()),s.top+=he.scrollTop,s.left+=he.scrollLeft):he=Oe(),qn=Js(he)}B=E.cloneNode(!0),ye(B,i.ghostClass,!1),ye(B,i.fallbackClass,!0),ye(B,i.dragClass,!0),q(B,"transition",""),q(B,"transform",""),q(B,"box-sizing","border-box"),q(B,"margin",0),q(B,"top",s.top),q(B,"left",s.left),q(B,"width",s.width),q(B,"height",s.height),q(B,"opacity","0.8"),q(B,"position",Ht?"absolute":"fixed"),q(B,"zIndex","100000"),q(B,"pointerEvents","none"),O.ghost=B,e.appendChild(B),q(B,"transform-origin",Ys/parseInt(B.style.width)*100+"% "+Ks/parseInt(B.style.height)*100+"%")}},_onDragStart:function(e,s){var i=this,n=e.dataTransfer,o=i.options;if(ge("dragStart",this,{evt:e}),O.eventCanceled){this._onDrop();return}ge("setupClone",this),O.eventCanceled||(ee=Zo(E),ee.removeAttribute("id"),ee.draggable=!1,ee.style["will-change"]="",this._hideClone(),ye(ee,this.options.chosenClass,!1),O.clone=ee),i.cloneId=$t(function(){ge("clone",i),!O.eventCanceled&&(i.options.removeCloneOnHide||$.insertBefore(ee,E),i._hideClone(),pe({sortable:i,name:"clone"}))}),!s&&ye(E,o.dragClass,!0),s?(rn=!0,i._loopId=setInterval(i._emulateDragOver,50)):(H(document,"mouseup",i._onDrop),H(document,"touchend",i._onDrop),H(document,"touchcancel",i._onDrop),n&&(n.effectAllowed="move",o.setData&&o.setData.call(i,n,E)),Q(document,"drop",i),q(E,"transform","translateZ(0)")),at=!0,i._dragStartId=$t(i._dragStarted.bind(i,s,e)),Q(document,"selectstart",i),wt=!0,kt&&q(document.body,"user-select","none")},_onDragOver:function(e){var s=this.el,i=e.target,n,o,a,c=this.options,f=c.group,u=O.active,l=Wt===f,_=c.sort,p=de||u,y,v=this,x=!1;if(Kn)return;function R(Ve,xn){ge(Ve,v,Me({evt:e,isOwner:l,axis:y?"vertical":"horizontal",revert:a,dragRect:n,targetRect:o,canSort:_,fromSortable:p,target:i,completed:A,onMove:function(_t,gt){return zt($,s,E,n,_t,ie(_t),e,gt)},changed:k},xn))}function M(){R("dragOverAnimationCapture"),v.captureAnimationState(),v!==p&&p.captureAnimationState()}function A(Ve){return R("dragOverCompleted",{insertion:Ve}),Ve&&(l?u._hideClone():u._showClone(v),v!==p&&(ye(E,de?de.options.ghostClass:u.options.ghostClass,!1),ye(E,c.ghostClass,!0)),de!==v&&v!==O.active?de=v:v===O.active&&de&&(de=null),p===v&&(v._ignoreWhileAnimating=i),v.animateAll(function(){R("dragOverAnimationComplete"),v._ignoreWhileAnimating=null}),v!==p&&(p.animateAll(),p._ignoreWhileAnimating=null)),(i===E&&!E.animated||i===s&&!i.animated)&&(it=null),!c.dragoverBubble&&!e.rootEl&&i!==document&&(E.parentNode[ve]._isOutsideThisEl(e.target),!Ve&&et(e)),!c.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),x=!0}function k(){be=we(E),Je=we(E,c.draggable),pe({sortable:v,name:"change",toEl:s,newIndex:be,newDraggableIndex:Je,originalEvent:e})}if(e.preventDefault!==void 0&&e.cancelable&&e.preventDefault(),i=Ie(i,c.draggable,s,!0),R("dragOver"),O.eventCanceled)return x;if(E.contains(e.target)||i.animated&&i.animatingX&&i.animatingY||v._ignoreWhileAnimating===i)return A(!1);if(rn=!1,u&&!c.disabled&&(l?_||(a=te!==$):de===this||(this.lastPutMode=Wt.checkPull(this,u,E,e))&&f.checkPut(this,u,E,e))){if(y=this._getDirection(e,i)==="vertical",n=ie(E),R("dragOverValid"),O.eventCanceled)return x;if(a)return te=$,M(),this._hideClone(),R("revert"),O.eventCanceled||(tt?$.insertBefore(E,tt):$.appendChild(E)),A(!0);var z=us(s,c.draggable);if(!z||Hh(e,y,this)&&!z.animated){if(z===E)return A(!1);if(z&&s===e.target&&(i=z),i&&(o=ie(i)),zt($,s,E,n,i,o,e,!!i)!==!1)return M(),z&&z.nextSibling?s.insertBefore(E,z.nextSibling):s.appendChild(E),te=s,k(),A(!0)}else if(z&&Xh(e,y,this)){var le=ht(s,0,c,!0);if(le===E)return A(!1);if(i=le,o=ie(i),zt($,s,E,n,i,o,e,!1)!==!1)return M(),s.insertBefore(E,le),te=s,k(),A(!0)}else if(i.parentNode===s){o=ie(i);var J=0,Y,Pe=E.parentNode!==s,ce=!Vh(E.animated&&E.toRect||n,i.animated&&i.toRect||o,y),Xe=y?"top":"left",Ee=Gs(i,"top","top")||Gs(E,"top","top"),He=Ee?Ee.scrollTop:void 0;it!==i&&(Y=o[Xe],Pt=!1,Xt=!ce&&c.invertSwap||Pe),J=zh(e,i,o,y,ce?1:c.swapThreshold,c.invertedSwapThreshold==null?c.swapThreshold:c.invertedSwapThreshold,Xt,it===i);var fe;if(J!==0){var qe=we(E);do qe-=J,fe=te.children[qe];while(fe&&(q(fe,"display")==="none"||fe===B))}if(J===0||fe===i)return A(!1);it=i,Dt=J;var Ne=i.nextElementSibling,Ce=!1;Ce=J===1;var Be=zt($,s,E,n,i,o,e,Ce);if(Be!==!1)return(Be===1||Be===-1)&&(Ce=Be===1),Kn=!0,setTimeout(Wh,30),M(),Ce&&!Ne?s.appendChild(E):i.parentNode.insertBefore(E,Ce?Ne:i),Ee&&Ko(Ee,0,He-Ee.scrollTop),te=E.parentNode,Y!==void 0&&!Xt&&(Zt=Math.abs(Y-ie(i)[Xe])),k(),A(!0)}if(s.contains(E))return A(!1)}return!1},_ignoreWhileAnimating:null,_offMoveEvents:function(){H(document,"mousemove",this._onTouchMove),H(document,"touchmove",this._onTouchMove),H(document,"pointermove",this._onTouchMove),H(document,"dragover",et),H(document,"mousemove",et),H(document,"touchmove",et)},_offUpEvents:function(){var e=this.el.ownerDocument;H(e,"mouseup",this._onDrop),H(e,"touchend",this._onDrop),H(e,"pointerup",this._onDrop),H(e,"touchcancel",this._onDrop),H(document,"selectstart",this)},_onDrop:function(e){var s=this.el,i=this.options;if(be=we(E),Je=we(E,i.draggable),ge("drop",this,{evt:e}),te=E&&E.parentNode,be=we(E),Je=we(E,i.draggable),O.eventCanceled){this._nulling();return}at=!1,Xt=!1,Pt=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),Zn(this.cloneId),Zn(this._dragStartId),this.nativeDraggable&&(H(document,"drop",this),H(s,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),kt&&q(document.body,"user-select",""),q(E,"transform",""),e&&(wt&&(e.cancelable&&e.preventDefault(),!i.dropBubble&&e.stopPropagation()),B&&B.parentNode&&B.parentNode.removeChild(B),($===te||de&&de.lastPutMode!=="clone")&&ee&&ee.parentNode&&ee.parentNode.removeChild(ee),E&&(this.nativeDraggable&&H(E,"dragend",this),Nn(E),E.style["will-change"]="",wt&&!at&&ye(E,de?de.options.ghostClass:this.options.ghostClass,!1),ye(E,this.options.chosenClass,!1),pe({sortable:this,name:"unchoose",toEl:te,newIndex:null,newDraggableIndex:null,originalEvent:e}),$!==te?(be>=0&&(pe({rootEl:te,name:"add",toEl:te,fromEl:$,originalEvent:e}),pe({sortable:this,name:"remove",toEl:te,originalEvent:e}),pe({rootEl:te,name:"sort",toEl:te,fromEl:$,originalEvent:e}),pe({sortable:this,name:"sort",toEl:te,originalEvent:e})),de&&de.save()):be!==lt&&be>=0&&(pe({sortable:this,name:"update",toEl:te,originalEvent:e}),pe({sortable:this,name:"sort",toEl:te,originalEvent:e})),O.active&&((be==null||be===-1)&&(be=lt,Je=At),pe({sortable:this,name:"end",toEl:te,originalEvent:e}),this.save()))),this._nulling()},_nulling:function(){ge("nulling",this),$=E=te=B=tt=ee=Kt=Ye=$e=Te=wt=be=Je=lt=At=it=Dt=de=Wt=O.dragged=O.ghost=O.clone=O.active=null,ln.forEach(function(e){e.checked=!0}),ln.length=On=Mn=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":E&&(this._onDragOver(e),Lh(e));break;case"selectstart":e.preventDefault();break}},toArray:function(){for(var e=[],s,i=this.el.children,n=0,o=i.length,a=this.options;n<o;n++)s=i[n],Ie(s,a.draggable,this.el,!1)&&e.push(s.getAttribute(a.dataIdAttr)||Gh(s));return e},sort:function(e,s){var i={},n=this.el;this.toArray().forEach(function(o,a){var c=n.children[a];Ie(c,this.options.draggable,n,!1)&&(i[o]=c)},this),s&&this.captureAnimationState(),e.forEach(function(o){i[o]&&(n.removeChild(i[o]),n.appendChild(i[o]))}),s&&this.animateAll()},save:function(){var e=this.options.store;e&&e.set&&e.set(this)},closest:function(e,s){return Ie(e,s||this.options.draggable,this.el,!1)},option:function(e,s){var i=this.options;if(s===void 0)return i[e];var n=Ft.modifyOption(this,e,s);typeof n!="undefined"?i[e]=n:i[e]=s,e==="group"&&ni(i)},destroy:function(){ge("destroy",this);var e=this.el;e[ve]=null,H(e,"mousedown",this._onTapStart),H(e,"touchstart",this._onTapStart),H(e,"pointerdown",this._onTapStart),this.nativeDraggable&&(H(e,"dragover",this),H(e,"dragenter",this)),Array.prototype.forEach.call(e.querySelectorAll("[draggable]"),function(s){s.removeAttribute("draggable")}),this._onDrop(),this._disableDelayedDragEvents(),an.splice(an.indexOf(this.el),1),this.el=e=null},_hideClone:function(){if(!Ye){if(ge("hideClone",this),O.eventCanceled)return;q(ee,"display","none"),this.options.removeCloneOnHide&&ee.parentNode&&ee.parentNode.removeChild(ee),Ye=!0}},_showClone:function(e){if(e.lastPutMode!=="clone"){this._hideClone();return}if(Ye){if(ge("showClone",this),O.eventCanceled)return;E.parentNode==$&&!this.options.group.revertClone?$.insertBefore(ee,E):tt?$.insertBefore(ee,tt):$.appendChild(ee),this.options.group.revertClone&&this.animate(E,ee),q(ee,"display",""),Ye=!1}}};function Lh(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move"),t.cancelable&&t.preventDefault()}function zt(t,e,s,i,n,o,a,c){var f,u=t[ve],l=u.options.onMove,_;return window.CustomEvent&&!We&&!Vt?f=new CustomEvent("move",{bubbles:!0,cancelable:!0}):(f=document.createEvent("Event"),f.initEvent("move",!0,!0)),f.to=e,f.from=t,f.dragged=s,f.draggedRect=i,f.related=n||e,f.relatedRect=o||ie(e),f.willInsertAfter=c,f.originalEvent=a,t.dispatchEvent(f),l&&(_=l.call(u,f,a)),_}function Nn(t){t.draggable=!1}function Wh(){Kn=!1}function Xh(t,e,s){var i=ie(ht(s.el,0,s.options,!0)),n=$o(s.el,s.options,B),o=10;return e?t.clientX<n.left-o||t.clientY<i.top&&t.clientX<i.right:t.clientY<n.top-o||t.clientY<i.bottom&&t.clientX<i.left}function Hh(t,e,s){var i=ie(us(s.el,s.options.draggable)),n=$o(s.el,s.options,B),o=10;return e?t.clientX>n.right+o||t.clientY>i.bottom&&t.clientX>i.left:t.clientY>n.bottom+o||t.clientX>i.right&&t.clientY>i.top}function zh(t,e,s,i,n,o,a,c){var f=i?t.clientY:t.clientX,u=i?s.height:s.width,l=i?s.top:s.left,_=i?s.bottom:s.right,p=!1;if(!a){if(c&&Zt<u*n){if(!Pt&&(Dt===1?f>l+u*o/2:f<_-u*o/2)&&(Pt=!0),Pt)p=!0;else if(Dt===1?f<l+Zt:f>_-Zt)return-Dt}else if(f>l+u*(1-n)/2&&f<_-u*(1-n)/2)return Qh(e)}return p=p||a,p&&(f<l+u*o/2||f>_-u*o/2)?f>l+u/2?1:-1:0}function Qh(t){return we(E)<we(t)?1:-1}function Gh(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,s=e.length,i=0;s--;)i+=e.charCodeAt(s);return i.toString(36)}function Jh(t){ln.length=0;for(var e=t.getElementsByTagName("input"),s=e.length;s--;){var i=e[s];i.checked&&ln.push(i)}}function $t(t){return setTimeout(t,0)}function Zn(t){return clearTimeout(t)}wn&&Q(document,"touchmove",function(t){(O.active||at)&&t.cancelable&&t.preventDefault()});O.utils={on:Q,off:H,css:q,find:Jo,is:function(e,s){return!!Ie(e,s,e,!1)},extend:Ph,throttle:Yo,closest:Ie,toggleClass:ye,clone:Zo,index:we,nextTick:$t,cancelNextTick:Zn,detectDirection:ti,getChild:ht};O.get=function(t){return t[ve]};O.mount=function(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];e[0].constructor===Array&&(e=e[0]),e.forEach(function(i){if(!i.prototype||!i.prototype.constructor)throw"Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(i));i.utils&&(O.utils=Me(Me({},O.utils),i.utils)),Ft.mount(i)})};O.create=function(t,e){return new O(t,e)};O.version=Sh;var oe=[],xt,$n,es=!1,Bn,Vn,cn,Et;function Yh(){function t(){this.defaults={scroll:!0,forceAutoScrollFallback:!1,scrollSensitivity:30,scrollSpeed:10,bubbleScroll:!0};for(var e in this)e.charAt(0)==="_"&&typeof this[e]=="function"&&(this[e]=this[e].bind(this))}return t.prototype={dragStarted:function(s){var i=s.originalEvent;this.sortable.nativeDraggable?Q(document,"dragover",this._handleAutoScroll):this.options.supportPointer?Q(document,"pointermove",this._handleFallbackAutoScroll):i.touches?Q(document,"touchmove",this._handleFallbackAutoScroll):Q(document,"mousemove",this._handleFallbackAutoScroll)},dragOverCompleted:function(s){var i=s.originalEvent;!this.options.dragOverBubble&&!i.rootEl&&this._handleAutoScroll(i)},drop:function(){this.sortable.nativeDraggable?H(document,"dragover",this._handleAutoScroll):(H(document,"pointermove",this._handleFallbackAutoScroll),H(document,"touchmove",this._handleFallbackAutoScroll),H(document,"mousemove",this._handleFallbackAutoScroll)),$s(),en(),Rh()},nulling:function(){cn=$n=xt=es=Et=Bn=Vn=null,oe.length=0},_handleFallbackAutoScroll:function(s){this._handleAutoScroll(s,!0)},_handleAutoScroll:function(s,i){var n=this,o=(s.touches?s.touches[0]:s).clientX,a=(s.touches?s.touches[0]:s).clientY,c=document.elementFromPoint(o,a);if(cn=s,i||this.options.forceAutoScrollFallback||Vt||We||kt){Fn(s,this.options,c,i);var f=Ke(c,!0);es&&(!Et||o!==Bn||a!==Vn)&&(Et&&$s(),Et=setInterval(function(){var u=Ke(document.elementFromPoint(o,a),!0);u!==f&&(f=u,en()),Fn(s,n.options,u,i)},10),Bn=o,Vn=a)}else{if(!this.options.bubbleScroll||Ke(c,!0)===Oe()){en();return}Fn(s,this.options,Ke(c,!1),!1)}}},Le(t,{pluginName:"scroll",initializeByDefault:!0})}function en(){oe.forEach(function(t){clearInterval(t.pid)}),oe=[]}function $s(){clearInterval(Et)}var Fn=Yo(function(t,e,s,i){if(!!e.scroll){var n=(t.touches?t.touches[0]:t).clientX,o=(t.touches?t.touches[0]:t).clientY,a=e.scrollSensitivity,c=e.scrollSpeed,f=Oe(),u=!1,l;$n!==s&&($n=s,en(),xt=e.scroll,l=e.scrollFn,xt===!0&&(xt=Ke(s,!0)));var _=0,p=xt;do{var y=p,v=ie(y),x=v.top,R=v.bottom,M=v.left,A=v.right,k=v.width,z=v.height,le=void 0,J=void 0,Y=y.scrollWidth,Pe=y.scrollHeight,ce=q(y),Xe=y.scrollLeft,Ee=y.scrollTop;y===f?(le=k<Y&&(ce.overflowX==="auto"||ce.overflowX==="scroll"||ce.overflowX==="visible"),J=z<Pe&&(ce.overflowY==="auto"||ce.overflowY==="scroll"||ce.overflowY==="visible")):(le=k<Y&&(ce.overflowX==="auto"||ce.overflowX==="scroll"),J=z<Pe&&(ce.overflowY==="auto"||ce.overflowY==="scroll"));var He=le&&(Math.abs(A-n)<=a&&Xe+k<Y)-(Math.abs(M-n)<=a&&!!Xe),fe=J&&(Math.abs(R-o)<=a&&Ee+z<Pe)-(Math.abs(x-o)<=a&&!!Ee);if(!oe[_])for(var qe=0;qe<=_;qe++)oe[qe]||(oe[qe]={});(oe[_].vx!=He||oe[_].vy!=fe||oe[_].el!==y)&&(oe[_].el=y,oe[_].vx=He,oe[_].vy=fe,clearInterval(oe[_].pid),(He!=0||fe!=0)&&(u=!0,oe[_].pid=setInterval(function(){i&&this.layer===0&&O.active._onTouchMove(cn);var Ne=oe[this.layer].vy?oe[this.layer].vy*c:0,Ce=oe[this.layer].vx?oe[this.layer].vx*c:0;typeof l=="function"&&l.call(O.dragged.parentNode[ve],Ce,Ne,t,cn,oe[this.layer].el)!=="continue"||Ko(oe[this.layer].el,Ce,Ne)}.bind({layer:_}),24))),_++}while(e.bubbleScroll&&p!==f&&(p=Ke(p,!1)));es=u}},30),ii=function(e){var s=e.originalEvent,i=e.putSortable,n=e.dragEl,o=e.activeSortable,a=e.dispatchSortableEvent,c=e.hideGhostForTarget,f=e.unhideGhostForTarget;if(!!s){var u=i||o;c();var l=s.changedTouches&&s.changedTouches.length?s.changedTouches[0]:s,_=document.elementFromPoint(l.clientX,l.clientY);f(),u&&!u.el.contains(_)&&(a("spill"),this.onSpill({dragEl:n,putSortable:i}))}};function hs(){}hs.prototype={startIndex:null,dragStart:function(e){var s=e.oldDraggableIndex;this.startIndex=s},onSpill:function(e){var s=e.dragEl,i=e.putSortable;this.sortable.captureAnimationState(),i&&i.captureAnimationState();var n=ht(this.sortable.el,this.startIndex,this.options);n?this.sortable.el.insertBefore(s,n):this.sortable.el.appendChild(s),this.sortable.animateAll(),i&&i.animateAll()},drop:ii};Le(hs,{pluginName:"revertOnSpill"});function ms(){}ms.prototype={onSpill:function(e){var s=e.dragEl,i=e.putSortable,n=i||this.sortable;n.captureAnimationState(),s.parentNode&&s.parentNode.removeChild(s),n.animateAll()},drop:ii};Le(ms,{pluginName:"removeOnSpill"});O.mount(new Yh);O.mount(ms,hs);const Kh={name:"QuoteViewDetail",components:{Card:Ze,QuoteNavBar:oh,EditItemModal:Ch,RemoveModal:qt},data(){return{selectedItem:null,selectedInvoiceId:null,editItemsModal:!1,no_items:!0,loading:!0,loading_add:!1,quote:[],quoteItems:[],newItem:{loading_del:!1,item_ref:"",item_name:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},vatRate:0,settings:[],list_vats:[],client_detail:[],client_email:null,client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},articles:[],categories:[],showDropdown:!1,refs:[],showDropdownRef:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isQuoteExpired(){const t=new Date().getTime(),e=this.quote.due_date?new Date(this.quote.due_date).getTime():null;return e&&e<t},totalAmountWithoutDiscount(){const t=this.quoteItems.reduce((e,s)=>{const i=s.quantity*s.unit_price;return e+i},0);return this.formatCurrency(t)},totalAmount(){const t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.quoteItems.reduce((i,n)=>i+parseFloat(n.total_amount),0)*this.quote.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)},signatureImageUrl(){const t="/wp-json/my-easy-compta/v1/signature-image/",e=myEasyComptaAdmin.nonce;return`${t}${this.quote.file_sign}?_wpnonce=${e}`}},methods:{getUniqueVATRates(){const t=new Set;return this.quoteItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.quoteItems.forEach(s=>{if(s.vat_rate===t){const i=s.quantity*s.unit_price,n=i*s.discount/100;e+=(i-n)*t/100}}),this.formatCurrency(e)},calculateTotalAmountWithVAT(){let t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.formatCurrency(t)},fetchQuote(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.quote=t,this.fetchClientInfo(t.client_id)):console.error("Quote not found")}).catch(t=>{console.error("Error fetching quote:",t),this.loading=!1})},fetchClientInfo(t){fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.client_email=e.email;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.quoteItems=[],this.loading=!1,this.no_items=!0):(this.quoteItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var i=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;i=s+n}else i=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(i)},calculateTotalWithVat(t,e,s,i){const n=t*e,o=n*i/100,a=n-o,c=a*s/100,f=a+c;return this.formatCurrency(f)},calculateTotal(t,e,s){const i=t*e,n=i*s/100,a=i-n;return this.formatCurrency(a)},submitItems(){this.updateTotal();const t={...this.newItem,quote_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/quotes/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.selectedInvoiceId=e,modal_item_remove.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.quoteItems.find(i=>i.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({quote_id:e})}).then(i=>i.json()).then(i=>{i.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(i.message,"alert-error"),console.error("Error removing item:",i.message),s.loading_del=!1)}).catch(i=>{this.showToast(i.message,"alert-error"),console.error("Error removing item:",i),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/quotes/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,i){const o=t*e*i/100,a=o*s/100,c=o+a;return this.formatCurrency(c)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.quoteItems[t.oldIndex];this.quoteItems.splice(t.oldIndex,1),this.quoteItems.splice(t.newIndex,0,e);const s=this.quoteItems.map(i=>i.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/quotes/update-quote-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}const t=document.getElementById("loader_articles");t.classList.remove("hidden"),fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.articles=e}).catch(e=>console.error("Error fetching articles:",e)).finally(()=>{t.classList.add("hidden")})},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loading=!0,this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:i}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=i,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1,this.loading=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1,this.loading=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchQuote(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");O.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},Zh={class:"pt-2 pr-4"},$h={key:1,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},em=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),tm=[em],nm={key:2},sm={role:"alert",class:"alert alert-warning"},om=r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),im={key:0,class:"relative"},rm={class:"ecwp-watermark"},am={class:"grid grid-cols-2"},lm={class:"md:col-span-1"},cm=["src"],dm={class:"md:col-span-1 text-right"},um={class:"text-lg font-semibold"},hm={key:0,class:"badge badge-warning text-white"},mm={key:1,class:"badge badge-secondary text-white"},fm={key:2,class:"badge badge-success text-white"},pm={key:3,class:"badge badge-error text-white"},_m={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},gm=r("br",null,null,-1),ym=r("br",null,null,-1),bm=r("br",null,null,-1),vm=["href"],wm=r("br",null,null,-1),xm=r("br",null,null,-1),Em=r("br",null,null,-1),Cm=["href"],Tm=r("br",null,null,-1),Im=["href"],km={class:"table mt-8"},Sm=r("th",null,null,-1),Am={width:"5%"},Dm={width:"19%"},Pm={width:"21%"},Rm={width:"10%",class:"text-center"},jm={width:"8%",class:"text-center"},Om={key:0,width:"5%",class:"text-center"},Mm={key:1,width:"5%"},qm={width:"10%",class:"text-center"},Nm={width:"10%",class:"text-right"},Bm=r("th",{width:"18%",class:"text-right inv-actions"},null,-1),Vm=r("td",{class:"draggable-item drag-handle px-2"},[r("i",{class:"fas fa-bars"})],-1),Fm={key:0,class:"badge badge-ghost badge-xs"},Um=["innerHTML"],Lm={class:"text-center"},Wm={class:"text-center"},Xm={key:0},Hm={key:1},zm={key:0,class:"text-center"},Qm={key:1},Gm={key:2,class:"text-center"},Jm=r("br",null,null,-1),Ym={key:3,class:"text-center"},Km=r("br",null,null,-1),Zm={class:"text-right"},$m={key:0},ef={key:1},tf=["data-tip"],nf=["onClick"],sf=r("i",{class:"far fa-edit"},null,-1),of=[sf],rf=["data-tip"],af=["onClick"],lf={key:0,class:"far fa-trash-alt"},cf={key:1,class:"loading loading-spinner loading-xs"},df={key:0},uf=r("td",{class:"px-2"},null,-1),hf={class:"align-top px-2"},mf={class:"flex items-center border rounded-md relative"},ff=["placeholder"],pf={key:0,class:"autocomplete-dropdown bg-base-300"},_f=["onClick","innerHTML"],gf={class:"align-top px-2"},yf=r("option",{disabled:"",selected:""},"Type",-1),bf=["value"],vf={class:"flex items-center border rounded-md relative"},wf=r("span",{id:"loader_articles",class:"loading loading-spinner loading-xs absolute right-2 hidden"},null,-1),xf=["placeholder"],Ef={key:0,class:"autocomplete-dropdown bg-base-300"},Cf=["onClick","innerHTML"],Tf={class:"align-top"},If={class:"flex items-center rounded-md"},kf=["placeholder"],Sf={class:"align-top"},Af={class:"flex items-center border rounded-lg"},Df={class:"inline-flex"},Pf=["placeholder"],Rf={class:"align-top"},jf={class:"flex items-center border rounded-md"},Of=["placeholder"],Mf={key:0,class:"align-top"},qf=["value"],Nf={key:1,class:"align-top"},Bf={class:"align-top"},Vf={class:"flex items-center border rounded-md"},Ff=["placeholder"],Uf=r("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),Lf={key:2,class:"text-right"},Wf={key:3,class:"text-right"},Xf=["data-tip"],Hf={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},zf={key:0,class:"fa fa-plus"},Qf={key:1,class:"loading loading-spinner loading-xs"},Gf={colspan:"8",class:"text-right no-border"},Jf={class:"text-right"},Yf={key:0,class:"line-through"},Kf=r("td",null,null,-1),Zf={colspan:"8",class:"text-right no-border"},$f={class:"text-right"},ep=r("td",null,null,-1),tp={colspan:"8",class:"text-right no-border font-bold text-xl"},np={class:"text-right no-border font-bold text-xl"},sp=r("td",null,null,-1),op={key:2},ip={colspan:"8",class:"text-right no-border"},rp={class:"text-right no-border"},ap={key:3},lp={colspan:"8",class:"text-right no-border"},cp={class:"text-right no-border font-bold text-xl"},dp={key:1,class:"relative"},up={class:"flex justify-end mt-4"},hp={class:"border-2 border-slate-300 max-w-md"},mp=["src"];function fp(t,e,s,i,n,o){const a=N("QuoteNavBar"),c=N("remove-modal"),f=N("edit-item-modal"),u=N("Card");return h(),m("div",Zh,[P(a,{quoteInfo:n.quote,emailActive:n.settings.easy_compta_email_addon_active,advanceActive:n.settings.easy_compta_advance_addon_active,currency:n.default_currency_symbol,noItems:n.no_items},null,8,["quoteInfo","emailActive","advanceActive","currency","noItems"]),n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),P(c,{"modal-id":"modal_item_remove","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=l=>this.removeItem(n.selectedItem,n.selectedInvoiceId)),onCancel:e[1]||(e[1]=l=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.loading?(h(),m("div",$h,tm)):g("",!0),o.isQuoteExpired&&n.quote.status=="pending"?(h(),m("div",nm,[r("div",sm,[om,r("span",null,d(o.translations.quote_expired),1)])])):g("",!0),P(u,{topMargin:"mt-8",id:"quote-content"},{default:me(()=>[n.settings.easy_compta_signature_addon_active&&n.quote.signed==1?(h(),m("div",im,[r("span",rm,d(o.translations.signed),1)])):g("",!0),r("div",am,[r("div",lm,[r("div",null,[r("img",{src:n.settings.logo_url,style:no({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,cm)])]),r("div",dm,[r("p",um,d(n.quote.quote_number),1),r("div",null,[C(d(o.translations.created_at)+": ",1),r("strong",null,d(n.quote.created_at),1)]),r("div",null,[C(d(o.translations.due_date)+": ",1),r("strong",null,d(n.quote.due_date),1)]),r("div",null,[C(d(o.translations.provisional_date)+": ",1),r("strong",null,d(n.quote.provisional_start_date),1)]),r("div",null,[C(d(o.translations.status)+": ",1),n.quote.status=="draft"?(h(),m("span",hm,d(o.translations.draft),1)):g("",!0),n.quote.status=="pending"?(h(),m("span",mm,d(o.translations.pending),1)):g("",!0),n.quote.status=="approved"?(h(),m("span",fm,d(o.translations.approved),1)):g("",!0),n.quote.status=="rejected"?(h(),m("span",pm,d(o.translations.rejected),1)):g("",!0)])])]),r("div",_m,[r("div",null,[r("strong",null,d(o.translations.bill_to)+":",1),r("h4",null,[r("strong",null,d(n.client_detail.company_name),1)]),r("p",null,[C(d(n.client_detail.address),1),gm,C(" "+d(n.client_detail.postal_code)+", "+d(n.client_detail.city)+" ",1),ym,C(" "+d(n.client_detail.country),1),bm,n.client_detail.phone?(h(),m("a",{key:0,href:"tel:"+n.client_detail.phone},d(n.client_detail.phone),9,vm)):g("",!0)])]),r("div",null,[r("strong",null,d(o.translations.received_from)+":",1),r("h4",null,[r("strong",null,d(n.settings.company_name),1)]),r("p",null,[C(d(n.settings.company_address),1),wm,C(" "+d(n.settings.postal_code)+", "+d(n.settings.city)+" ",1),xm,C(" "+d(n.settings.country),1),Em,n.settings.company_phone?(h(),m("a",{key:0,href:"tel:"+n.settings.company_phone},d(n.settings.company_phone),9,Cm)):g("",!0),Tm,n.settings.mobile_phone?(h(),m("a",{key:1,href:"tel:"+n.settings.mobile_phone},d(n.settings.mobile_phone),9,Im)):g("",!0)])])]),P(f,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[2]||(e[2]=l=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),r("form",{onSubmit:e[22]||(e[22]=K((...l)=>o.submitItems&&o.submitItems(...l),["prevent"]))},[r("table",km,[r("thead",null,[r("tr",null,[Sm,r("th",Am,d(o.translations.item_ref),1),r("th",Dm,d(o.translations.item_name),1),r("th",Pm,d(o.translations.description),1),r("th",Rm,d(o.translations.quantity),1),r("th",jm,d(o.translations.unit_price),1),n.settings.vat_active==1?(h(),m("th",Om,d(o.translations.vat),1)):(h(),m("th",Mm)),r("th",qm,d(o.translations.discount),1),r("th",Nm,d(o.translations.total),1),Bm])]),r("tbody",null,[(h(!0),m(F,null,L(n.quoteItems,(l,_)=>(h(),m("tr",{key:l.id||_},[Vm,r("td",null,d(l.item_ref),1),r("td",null,[l.category_name?(h(),m("div",Fm,d(l.category_name),1)):g("",!0),r("div",null,d(l.item_name),1)]),r("td",{innerHTML:o.nl2br(l.item_description)},null,8,Um),r("td",Lm,d(l.quantity),1),r("td",Wm,[C(d(l.unit_price),1),n.default_currency_symbol==n.client_currency?(h(),m("span",Xm,d(n.default_currency_symbol),1)):(h(),m("span",Hm,d(n.client_currency),1))]),n.settings.vat_active==1?(h(),m("td",zm,d(l.vat_rate)+"% ",1)):(h(),m("td",Qm)),n.settings.vat_active==1?(h(),m("td",Gm,[C(d(l.discount)+"% ",1),Jm,C(" "+d(o.calculateDiscountAmountWithVAT(l.quantity,l.unit_price,l.vat_rate,l.discount)),1)])):(h(),m("td",Ym,[C(d(l.discount)+"% ",1),Km,C(" "+d(o.calculateDiscountAmount(l.quantity,l.unit_price,l.discount)),1)])),r("td",Zm,[C(d(l.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(h(),m("span",$m,d(n.default_currency_symbol),1)):(h(),m("span",ef,d(n.client_currency),1))]),r("td",null,[n.quote.status=="draft"||n.quote.status=="pending"?(h(),m("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[r("button",{onClick:K(p=>o.editItem(l.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},of,8,nf)],8,tf)):g("",!0),n.quote.status=="draft"||n.quote.status=="pending"?(h(),m("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:K(p=>o.confirmremoveItem(l.id,n.quote.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[l.loading_del?g("",!0):(h(),m("i",lf)),l.loading_del?(h(),m("span",cf)):g("",!0)],8,af)],8,rf)):g("",!0)])]))),128)),n.quote.status=="draft"||n.quote.status=="pending"?(h(),m("tr",df,[uf,r("td",hf,[r("div",mf,[D(r("input",{type:"text","onUpdate:modelValue":e[3]||(e[3]=l=>n.newItem.item_ref=l),onInput:e[4]||(e[4]=(...l)=>o.fetchRefs&&o.fetchRefs(...l)),onFocus:e[5]||(e[5]=l=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,ff),[[W,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(h(),m("ul",pf,[(h(!0),m(F,null,L(n.refs,l=>(h(),m("li",{key:l.ref,onClick:_=>o.selectItem(l),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(l.ref)},null,8,_f))),128))])):g("",!0)])]),r("td",gf,[D(r("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[6]||(e[6]=l=>n.newItem.item_category=l)},[yf,(h(!0),m(F,null,L(n.categories,l=>(h(),m("option",{key:l.id,value:l.id},d(l.name),9,bf))),128))],512),[[ue,n.newItem.item_category]]),r("div",vf,[wf,D(r("input",{type:"text","onUpdate:modelValue":e[7]||(e[7]=l=>n.newItem.item_name=l),onInput:e[8]||(e[8]=(...l)=>o.fetchArticles&&o.fetchArticles(...l)),onFocus:e[9]||(e[9]=l=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,xf),[[W,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(h(),m("ul",Ef,[(h(!0),m(F,null,L(n.articles,l=>(h(),m("li",{key:l.name,onClick:_=>o.selectItem(l),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(l.name)},null,8,Cf))),128))])):g("",!0)])]),r("td",Tf,[r("div",If,[D(r("textarea",{"onUpdate:modelValue":e[10]||(e[10]=l=>n.newItem.item_description=l),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[11]||(e[11]=l=>o.resize()),ref:"textarea"},null,40,kf),[[W,n.newItem.item_description]])])]),r("td",Sf,[r("div",Af,[r("div",Df,[r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[12]||(e[12]=(...l)=>o.decrease&&o.decrease(...l))}," - "),D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[13]||(e[13]=l=>n.newItem.quantity=l),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[14]||(e[14]=(...l)=>o.updateTotal&&o.updateTotal(...l))},null,40,Pf),[[W,n.newItem.quantity]]),r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[15]||(e[15]=(...l)=>o.increase&&o.increase(...l))}," + ")])])]),r("td",Rf,[r("div",jf,[D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[16]||(e[16]=l=>n.newItem.unit_price=l),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[17]||(e[17]=(...l)=>o.updateTotal&&o.updateTotal(...l))},null,40,Of),[[W,n.newItem.unit_price]])])]),n.settings.vat_active==1?(h(),m("td",Mf,[D(r("select",{"onUpdate:modelValue":e[18]||(e[18]=l=>n.newItem.vat_rate=l),onChange:e[19]||(e[19]=(...l)=>o.updateTotal&&o.updateTotal(...l)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(h(!0),m(F,null,L(n.list_vats,l=>(h(),m("option",{key:l,value:l.rate},d(l.rate)+"% ",9,qf))),128))],544),[[ue,n.newItem.vat_rate]])])):(h(),m("td",Nf)),r("td",Bf,[r("div",Vf,[D(r("input",{type:"number",min:"0",max:"100","onUpdate:modelValue":e[20]||(e[20]=l=>n.newItem.discount=l),placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[21]||(e[21]=(...l)=>o.updateTotal&&o.updateTotal(...l))},null,40,Ff),[[W,n.newItem.discount]]),Uf])]),n.settings.vat_active==1?(h(),m("td",Lf,d(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(h(),m("td",Wf,d(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),r("td",null,[r("span",{class:"lg:tooltip","data-tip":o.translations.add},[r("button",Hf,[n.loading_add?g("",!0):(h(),m("i",zf)),n.loading_add?(h(),m("span",Qf)):g("",!0)])],8,Xf)])])):g("",!0),r("tr",null,[r("td",Gf,[r("strong",null,d(o.translations.subtotal),1)]),r("td",Jf,[o.totalAmount!==o.totalAmountWithoutDiscount?(h(),m("span",Yf,d(o.totalAmountWithoutDiscount),1)):g("",!0),C(" "+d(o.totalAmount),1)]),Kf]),n.settings.vat_active==1?(h(!0),m(F,{key:1},L(o.getUniqueVATRates(),(l,_)=>(h(),m("tr",{key:_},[r("td",Zf,[r("strong",null,d(o.translations.tax)+" ("+d(l)+"%) ",1)]),r("td",$f,d(o.calculateVATForRate(l)),1),ep]))),128)):g("",!0),r("tr",null,[r("td",tp,[r("strong",null,d(o.translations.total),1)]),r("td",np,d(o.calculateTotalAmountWithVAT()),1),sp]),n.client_currency!=n.default_currency_symbol?(h(),m("tr",op,[r("td",ip,[r("strong",null,d(o.translations.exchange_rate),1)]),r("td",rp,d(n.quote.exchange_rate),1)])):g("",!0),n.client_currency!=n.default_currency_symbol?(h(),m("tr",ap,[r("td",lp,[r("strong",null,d(o.translations.total)+" "+d(n.default_currency_symbol),1)]),r("td",cp,d(o.totalAmountDefaultCurrency)+d(n.default_currency_symbol),1)])):g("",!0)])])],32),n.settings.easy_compta_signature_addon_active&&n.quote.signed==1&&n.quote.file_sign?(h(),m("div",dp,[r("div",up,[r("span",hp,[r("img",{src:o.signatureImageUrl,alt:"Signature"},null,8,mp)])])])):g("",!0)]),_:1})])}var pp=ne(Kh,[["render",fp]]);const _p={name:"QuoteNew",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt,AddClientModal:Ro},data(){return{clientOptions:[],clients:[],quote:{number:"",due_date:"",provisional_start_date:"",client_id:"",status:""},showError:!1,loading:!1,loadingBtn:!1,settings:[],last_quote_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{AddNew(){modal_clients.showModal()},cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},customLabel(t){return t.text},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.quote_prefix}_${String(this.settings.last_quote_id).padStart(4,"0")}`;this.quote.number=s}else{const e=await t.json()}}catch{this.loading=!1}},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/quotes",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting quote:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},gp={class:"pt-2 pr-4"},yp={class:"flex justify-between items-center mb-4"},bp={class:"card-title"},vp=r("div",{class:"divider mt-2"},null,-1),wp={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},xp={class:"grid grid-cols-3 gap-4"},Ep={class:"ecwp-group form-group mb-4"},Cp={for:"quoteNumber",class:"ecwp-label"},Tp={class:"ecwp-group form-group mb-4"},Ip={for:"quoteDate",class:"ecwp-label"},kp={class:"ecwp-group form-group mb-4"},Sp={for:"quoteDatePr",class:"ecwp-label"},Ap={class:"grid grid-cols-2 gap-4"},Dp={class:"mb-4"},Pp={class:"flex gap-2 items-end"},Rp=r("i",{class:"fas fa-plus"},null,-1),jp=[Rp],Op={class:"ecwp-group form-group w-full"},Mp={for:"client",class:"ecwp-label"},qp={class:"ecwp-group form-group mb-4"},Np={for:"status",class:"ecwp-label"},Bp={value:"draft",selected:""},Vp={value:"pending"},Fp={value:"approved"},Up={value:"rejected"},Lp={class:"flex justify-between"},Wp=["disabled"],Xp={key:0,class:"loading loading-spinner loading-sm"};function Hp(t,e,s,i,n,o){const a=N("VueDatePicker"),c=N("model-select"),f=N("Card"),u=N("AddClientModal");return h(),m("div",gp,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:me(()=>[r("div",yp,[r("h2",bp,d(o.translations.new_quote),1)]),vp,n.loading?(h(),m("div",wp)):g("",!0),r("form",{onSubmit:e[7]||(e[7]=K((...l)=>o.submitQuote&&o.submitQuote(...l),["prevent"]))},[r("div",xp,[r("div",Ep,[r("label",Cp,d(o.translations.quote_number),1),D(r("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=l=>n.quote.number=l),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[W,n.quote.number]])]),r("div",Tp,[r("label",Ip,d(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=l=>n.quote.due_date=l),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),r("div",kp,[r("label",Sp,d(o.translations.provisional_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteDatePr",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=l=>n.quote.provisional_start_date=l),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])])]),r("div",Ap,[r("div",Dp,[r("div",Pp,[r("button",{type:"button",class:"btn btn-primary",onClick:e[3]||(e[3]=(...l)=>o.AddNew&&o.AddNew(...l))},jp),r("div",Op,[r("label",Mp,d(o.translations.company_name),1),P(c,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[4]||(e[4]=l=>n.quote.client_id=l),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])])])]),r("div",qp,[r("label",Np,d(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[5]||(e[5]=l=>n.quote.status=l),class:I(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[r("option",Bp,d(o.translations.draft),1),r("option",Vp,d(o.translations.pending),1),r("option",Fp,d(o.translations.approved),1),r("option",Up,d(o.translations.rejected),1)],2),[[ue,n.quote.status]])])]),r("div",Lp,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[6]||(e[6]=(...l)=>o.cancelAction&&o.cancelAction(...l))},d(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.submit)+" ",1),n.loadingBtn?(h(),m("span",Xp)):g("",!0)],8,Wp)])],32)]),_:1}),P(u,{onClientAdded:o.fetchClients},null,8,["onClientAdded"])])}var zp=ne(_p,[["render",Hp]]);const Qp={name:"InvoicesList",components:{Card:Ze,RemoveModal:qt},data(){return{invoices:[],filteredInvoices:[],filters:{invoice_number:"",client:"",status:"",total_amount:"",due_date:"",created_at:""},showInvoiceDetailsModal:!1,editInvoiceModal:!1,selectedInvoice:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchInvoices(),this.fetchClients(),this.loadSettings()},methods:{fetchInvoices(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/invoices?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.invoices=s.invoices,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching invoices:",s)}).finally(()=>{this.loading=!1})},fetchInvoicesWithFilters(t=1){this.loading=!0;const{perPage:e,filters:s}=this,i=new URLSearchParams({page:t,per_page:e,...s}).toString();fetch(`/wp-json/my-easy-compta/v1/invoices?${i}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(n=>n.json()).then(n=>{this.invoices=n.invoices,this.totalCount=n.total_count,this.totalPages=n.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(n=>{console.error("Error fetching invoices with filters:",n)}).finally(()=>{this.loading=!1})},fetchClients(){fetch("/wp-json/my-easy-compta/v1/clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients}).catch(t=>{console.error("Error fetching clients:",t)})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return so(t,this.default_vat.rate)},calculateWithoutVAT(t){return oo(t)},generatePaginationButtons(){this.paginationButtons=io(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchInvoicesWithFilters(t)},perPageChanged(){this.fetchInvoicesWithFilters()},formatAmount(t,e){return ro(t,e,this.settings.currency_position)},showToast(t,e){ao(this.toast,t,e)},confirmDeleteInvoice(t){this.selectedInvoice=t,modal_invoice_remove.showModal(),this.showRemoveModal=!0},deleteInvoice(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchInvoices(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting invoice:",e.statusText))}).catch(e=>{console.log(e.message);const s=e&&e.message?e.message:"Error deleting client";s==="This client cannot be deleted because it has associated data."?this.showToast(s,"alert-error"):console.error("Error deleting client:",e)})}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},Gp={class:"pt-2 pr-4"},Jp={class:"flex justify-between items-center"},Yp={class:"card-title"},Kp={class:"btn btn-primary rounded-full"},Zp=r("i",{class:"fas fa-plus-circle"},null,-1),$p={key:0,class:"ms-2"},e_={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab3"},t_=r("i",{class:"fas fa-file-export"},null,-1),n_=["data-tip"],s_={class:"btn btn-outline btn-accent rounded-full",disabled:""},o_=r("i",{class:"fas fa-file-export"},null,-1),i_=r("div",{class:"divider mt-2"},null,-1),r_={class:"flex items-center mb-4"},a_={for:"perPageSelect",class:"mr-2"},l_=["value"],c_={class:"overflow-x-auto"},d_={class:"table w-full"},u_={value:""},h_=["value"],m_={value:""},f_={value:"draft"},p_={value:"unpaid"},__={value:"paid"},g_={class:"flex justify-center"},y_={key:0},b_={key:0,class:"badge badge-primary badge-outline badge-sm mr-2"},v_={key:0,class:"badge badge-scondary badge-outline badge-sm"},w_={key:1,class:"badge badge-warning badge-outline badge-sm"},x_={key:2,class:"badge badge-success badge-outline badge-sm"},E_={key:3,class:"badge badge-error badge-outline badge-sm ms-2"},C_={key:0},T_={key:0},I_={key:0},k_={key:1},S_={key:0},A_={key:1},D_={key:1},P_=r("span",{class:"loading loading-bars loading-sm"},null,-1),R_=[P_],j_={key:0},O_={key:1},M_=r("span",{class:"loading loading-bars loading-sm"},null,-1),q_=[M_],N_={key:0},B_={key:1},V_=r("span",{class:"loading loading-bars loading-sm"},null,-1),F_=[V_],U_={class:"flex justify-end"},L_=["data-tip"],W_=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"far fa-eye"})],-1),X_=["data-tip"],H_=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"fas fa-pencil-alt"})],-1),z_=["data-tip"],Q_=["onClick"],G_=r("i",{class:"far fa-trash-alt"},null,-1),J_=[G_],Y_={key:0},K_=r("div",{class:"flex gap-4 items-center"},[r("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),r("div",{class:"flex flex-col gap-4 w-full"},[r("div",{class:"skeleton h-4 w-full"}),r("div",{class:"skeleton h-4 w-full"})])],-1),Z_=r("div",{class:"divider my-1"},null,-1),$_=[K_,Z_],eg={class:"join ecwp_pagination mt-6 pt-4"},tg=["onClick"];function ng(t,e,s,i,n,o){const a=N("remove-modal"),c=N("router-link"),f=N("Card");return h(),m("div",Gp,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),P(a,{"modal-id":"modal_invoice_remove","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=u=>this.deleteInvoice(n.selectedInvoice)),onCancel:e[1]||(e[1]=u=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(f,{topMargin:"mt-8"},{default:me(()=>[r("div",Jp,[r("h2",Yp,d(o.translations.invoices),1),r("div",null,[P(c,{to:{name:"InvoiceNew"}},{default:me(()=>[r("button",Kp,[C(d(o.translations.add)+" ",1),Zp])]),_:1}),n.settings.easy_compta_export_addon_active==1?(h(),m("span",$p,[r("a",e_,[C(d(o.translations.export)+" ",1),t_])])):(h(),m("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[r("button",s_,[C(d(o.translations.export)+" ",1),o_])],8,n_))])]),i_,r("div",r_,[r("label",a_,d(o.translations.display_per_page),1),D(r("select",{id:"perPageSelect","onUpdate:modelValue":e[2]||(e[2]=u=>n.perPage=u),onChange:e[3]||(e[3]=(...u)=>o.perPageChanged&&o.perPageChanged(...u))},[(h(!0),m(F,null,L(n.perPageOptions,u=>(h(),m("option",{key:u,value:u},d(u),9,l_))),128))],544),[[ue,n.perPage]])]),r("div",c_,[r("table",d_,[r("thead",null,[r("tr",null,[r("th",null,[r("div",null,d(o.translations.invoice_number),1),D(r("input",{"onUpdate:modelValue":e[4]||(e[4]=u=>n.filters.invoice_number=u),onInput:e[5]||(e[5]=u=>o.fetchInvoicesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.invoice_number]])]),r("th",null,[r("div",null,d(o.translations.client),1),D(r("select",{"onUpdate:modelValue":e[6]||(e[6]=u=>n.filters.client=u),onChange:e[7]||(e[7]=u=>o.fetchInvoicesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",u_,d(o.translations.all),1),(h(!0),m(F,null,L(t.clients,u=>(h(),m("option",{key:u.id,value:u.company_name},d(u.company_name),9,h_))),128))],544),[[ue,n.filters.client]])]),r("th",null,[r("div",null,d(o.translations.status),1),D(r("select",{"onUpdate:modelValue":e[8]||(e[8]=u=>n.filters.status=u),onChange:e[9]||(e[9]=u=>o.fetchInvoicesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",m_,d(o.translations.all_statuses),1),r("option",f_,d(o.translations.draft),1),r("option",p_,d(o.translations.unpaid),1),r("option",__,d(o.translations.paid),1)],544),[[ue,n.filters.status]])]),r("th",null,[r("div",null,d(o.translations.total),1),D(r("input",{"onUpdate:modelValue":e[10]||(e[10]=u=>n.filters.total_amount=u),onInput:e[11]||(e[11]=u=>o.fetchInvoicesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.total_amount]])]),r("th",null,[r("div",null,d(o.translations.due_date),1),D(r("input",{"onUpdate:modelValue":e[12]||(e[12]=u=>n.filters.due_date=u),onInput:e[13]||(e[13]=u=>o.fetchInvoicesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.due_date]])]),r("th",null,[r("div",null,d(o.translations.created_at),1),D(r("input",{"onUpdate:modelValue":e[14]||(e[14]=u=>n.filters.created_at=u),onInput:e[15]||(e[15]=u=>o.fetchInvoicesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.created_at]])]),r("th",g_,d(o.translations.actions),1)])]),n.loading?g("",!0):(h(),m("tbody",y_,[(h(!0),m(F,null,L(n.invoices,u=>(h(),m("tr",{key:u.id},[r("td",null,[u.advance==1?(h(),m("span",b_,d(o.translations.advance),1)):g("",!0),C(d(u.invoice_number),1)]),r("td",null,d(u.client_name),1),r("td",null,[u.status=="draft"?(h(),m("span",v_,d(o.translations.draft),1)):g("",!0),u.status=="unpaid"?(h(),m("span",w_,d(o.translations.unpaid),1)):g("",!0),u.status=="paid"?(h(),m("span",x_,d(o.translations.paid),1)):g("",!0),u.credit=="1"?(h(),m("span",E_,d(o.translations.credit),1)):g("",!0)]),r("td",null,[n.loadingPrice?(h(),m("div",D_,R_)):(h(),m("div",C_,[n.settings.easy_compta_advance_addon_active&&u.advance==1?(h(),m("div",T_,d(o.formatAmount(u.advance_amount,u.client_currency||n.default_currency_symbol)),1)):g("",!0),n.settings.vat_active==1?(h(),m("div",{key:1,class:I({"text-xs":u.advance==1})},[n.default_currency_symbol==u.client_currency||u.client_currency==null?(h(),m("span",I_,d(o.formatAmount(u.total_amount,n.default_currency_symbol)),1)):(h(),m("span",k_,d(o.formatAmount(u.total_amount,u.client_currency)),1))],2)):(h(),m("div",{key:2,class:I({"text-xs":u.advance==1})},[n.default_currency_symbol==u.client_currency||u.client_currency==null?(h(),m("span",S_,d(o.formatAmount(u.total_amount,n.default_currency_symbol)),1)):(h(),m("span",A_,d(o.formatAmount(u.total_amount,u.client_currency)),1))],2))]))]),r("td",null,[n.loadingPrice?(h(),m("div",O_,q_)):(h(),m("div",j_,d(u.due_date),1))]),r("td",null,[n.loadingPrice?(h(),m("div",B_,F_)):(h(),m("div",N_,d(u.created),1))]),r("td",U_,[r("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(c,{to:{name:"InvoiceViewDetail",params:{id:u.id}}},{default:me(()=>[W_]),_:2},1032,["to"])],8,L_),u.status=="draft"?(h(),m("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[P(c,{to:{name:"InvoiceEdit",params:{id:u.id}}},{default:me(()=>[H_]),_:2},1032,["to"])],8,X_)):g("",!0),u.status=="draft"?(h(),m("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:l=>o.confirmDeleteInvoice(u.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},J_,8,Q_)],8,z_)):g("",!0)])]))),128))]))]),n.loading?(h(),m("div",Y_,[(h(!0),m(F,null,L(n.skeletonRows,u=>(h(),m("div",{key:u,class:"flex flex-col gap-4 w-full"},$_))),128))])):g("",!0)]),r("div",eg,[(h(!0),m(F,null,L(n.paginationButtons,u=>(h(),m("button",{key:u,class:I(["join-item btn",{"btn-disabled":u==="..."||u===n.currentPage}]),onClick:l=>o.goToPage(u)},d(u),11,tg))),128))])]),_:1})])}var sg=ne(Qp,[["render",ng]]);const og={name:"sendInvoice",components:{VueEditor:mt.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"invoice",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},ig=["id","open"],rg={class:"modal-box"},ag={class:"font-bold text-lg"},lg={key:0},cg={class:"grid grid-cols-1 gap-4"},dg=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),ug=r("div",{class:"skeleton h-4 w-full"},null,-1),hg=[dg,ug],mg={class:"grid grid-cols-1 gap-4"},fg=["type"],pg=["for"],_g=["id","value","disabled","onInput"],gg={key:1},yg=["for"],bg={class:"form-group mt-4 flex justify-end"},vg=["disabled"],wg={key:0,class:"loading loading-spinner loading-sm"};function xg(t,e,s,i,n,o){const a=N("vue-editor");return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",rg,[r("h3",ag,d(o.translations.send_invoice),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=c=>o.closeModal())}," \u2715 "),n.loading?(h(),m("div",lg,[r("div",cg,[(h(!0),m(F,null,L(o.skeletonItems,c=>(h(),m("div",{key:c,class:"py-2"},hg))),128))])])):(h(),m("form",{key:1,onSubmit:e[1]||(e[1]=K((...c)=>o.submitForm&&o.submitForm(...c),["prevent"])),class:"form"},[r("div",mg,[(h(!0),m(F,null,L(n.fields,(c,f)=>(h(),m("div",{key:f,class:"ecwp-group form-group"},[c.type!=="textarea"?(h(),m("div",{key:0,type:c.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},d(c.label),9,pg),r("input",{id:f,class:I(["ecwp-input input input-bordered",c.class||"w-full"]),value:c.value,disabled:c.disabled,onInput:u=>o.updateFieldValue(f,u.target.value)},null,42,_g)],8,fg)):(h(),m("div",gg,[r("label",{for:f,class:"form-label"},d(c.label),9,yg),P(a,{modelValue:c.value,"onUpdate:modelValue":u=>c.value=u,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",bg,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.send)+" ",1),n.loadingBtn?(h(),m("span",wg)):g("",!0)],8,vg)])],32))])],8,ig)])}var Eg=ne(og,[["render",xg]]);const Cg={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:"",paymentMethods:[],hasPaymentMethodError:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},mounted(){this.fetchPaymentMethods()},methods:{async fetchPaymentMethods(){try{const t=await fetch("/wp-json/my-easy-compta/v1/payments/methods",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(!t.ok)throw new Error(`Erreur : ${t.status}`);const e=await t.json();this.paymentMethods=e}catch(t){console.error("Erreur lors de la r\xE9cup\xE9ration des m\xE9thodes de paiement :",t)}},onConfirm(){if(!this.selectedPaymentMethod){this.hasPaymentMethodError=!0;return}this.hasPaymentMethodError=!1,this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm_paid").close()}}},Tg=["open"],Ig={class:"modal-box"},kg={class:"font-bold text-lg"},Sg=r("div",{class:"text-center text-red-400 mb-2"},[r("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),Ag={class:"text-lg font-semibold text-center"},Dg={class:"my-4 text-center text-xl"},Pg={key:0,class:"mt-4 mb-4"},Rg={class:"ecwp-group form-group"},jg={for:"payment_method",class:"ecwp-label form-label"},Og={value:""},Mg=["value"],qg={class:"flex justify-between space-x-4"};function Ng(t,e,s,i,n,o){return h(),m("div",null,[r("dialog",{id:"modal_confirm_paid",class:"modal",open:t.showModal},[r("div",Ig,[r("h3",kg,d(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...a)=>o.closeModal&&o.closeModal(...a))}," \u2715 "),Sg,r("h2",Ag,d(s.title),1),r("p",Dg,d(s.message),1),s.status==="paid"?(h(),m("div",Pg,[r("div",Rg,[r("label",jg,d(o.translations.payment_method),1),D(r("select",{id:"payment_method","onUpdate:modelValue":e[1]||(e[1]=a=>n.selectedPaymentMethod=a),class:I([{"input-error":n.hasPaymentMethodError},"ecwp-input input input-bordered w-full"])},[r("option",Og,d(o.translations.select),1),(h(!0),m(F,null,L(n.paymentMethods,a=>(h(),m("option",{key:a.id,value:a.id},d(a.method_name),9,Mg))),128))],2),[[ue,n.selectedPaymentMethod]])])])):g("",!0),r("div",qg,[r("button",{onClick:e[2]||(e[2]=(...a)=>o.onCancel&&o.onCancel(...a)),class:"btn btn-secondary rounded-full"},d(s.cancelText),1),r("button",{onClick:e[3]||(e[3]=(...a)=>o.onConfirm&&o.onConfirm(...a)),class:"btn rounded-full btn-error text-white"},d(s.confirmText),1)])])],8,Tg)])}var Bg=ne(Cg,[["render",Ng]]);const Vg={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm_credit").close()}}},Fg=["open"],Ug={class:"modal-box"},Lg={class:"font-bold text-lg"},Wg=r("div",{class:"text-center text-red-400 mb-2"},[r("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),Xg={class:"text-lg font-semibold text-center"},Hg={class:"my-4 text-center text-xl"},zg={class:"flex justify-between space-x-4"};function Qg(t,e,s,i,n,o){return h(),m("div",null,[r("dialog",{id:"modal_confirm_credit",class:"modal",open:t.showModal},[r("div",Ug,[r("h3",Lg,d(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...a)=>o.closeModal&&o.closeModal(...a))}," \u2715 "),Wg,r("h2",Xg,d(s.title),1),r("p",Hg,d(s.message),1),r("div",zg,[r("button",{onClick:e[1]||(e[1]=(...a)=>o.onCancel&&o.onCancel(...a)),class:"btn btn-secondary rounded-full"},d(s.cancelText),1),r("button",{onClick:e[2]||(e[2]=(...a)=>o.onConfirm&&o.onConfirm(...a)),class:"btn rounded-full btn-error text-white"},d(s.confirmText),1)])])],8,Fg)])}var Gg=ne(Vg,[["render",Qg]]);const Jg={name:"InvoiceNavBar",components:{SendInvoiceModal:Eg,RemoveModal:qt,ConfirmModal:ds,ConfirmModalPaid:Bg,ConfirmModalCredit:Gg},props:{invoiceInfo:Object,currencyDefault:Object,currencyClient:Object,emailActive:String,qrCodeActive:String,totalAmount:String,noItems:Boolean},data(){return{showConfirmModal:!1,showConfirmCreditModal:!1,loading:!1,sendInvoiceModal:!1,loadingModal:!1,loadingPdf:!1,client_detail:null,selectedStatus:null,subject:"",content:"",showQrCodeModal:!1,qrCodeSrc:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{changeInvoiceStatusWithPaymentMethod(t){const e=this.selectedStatus;this.changeInvoiceStatus(e,t),this.showConfirmModal=!1},async changeInvoiceStatus(t,e){this.loading=!0;try{const i=await(await fetch("/wp-json/my-easy-compta/v1/invoices/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id,status:t,method:e})})).json();i.success?(this.invoiceInfo.status=t,this.loading=!1):(console.error("Failed to update invoice status:",i.message),this.loading=!1)}catch(s){console.error("An error occurred while updating invoice status:",s)}},async addCreditInvoice(){this.loading=!0;try{const e=await(await fetch("/wp-json/my-easy-compta/v1/invoices/credit",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id})})).json();e.success?(this.invoiceInfo.credit=1,this.loading=!1):(console.error("Failed to update invoice status:",e.message),this.loading=!1)}catch(t){console.error("An error occurred while updating invoice status:",t)}},exportToPDF(t){this.loadingPdf=!0;let s=`/wp-json/my-easy-compta/v1/invoices/pdf/${this.invoiceInfo.id}?currency_id=${t}`;fetch(s,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(i=>{if(!i.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return i.blob()}).then(i=>{const n=URL.createObjectURL(i);window.open(n),this.loadingPdf=!1}).catch(i=>{console.error("There was a problem with the fetch operation:",i),this.loadingPdf=!1})},sendInvoice(t){this.loadingModal=!0,this.sendInvoiceModal=!0,modal_send_invoice.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.subject=e.email_invoice_subject,this.content=e.email_invoice_content}else{const e=await t.json();this.showToast(e.message,"alert-error")}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},confirmValidateInvoice(t){this.selectedStatus=t,t=="unpaid"?modal_confirm.showModal():t=="paid"&&modal_confirm_paid.showModal(),this.showConfirmModal=!0},confirmCreditInvoice(){modal_confirm_credit.showModal(),this.showConfirmCreditModal=!0},async generateQRCode(){this.loading=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/generate-qrcode",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_ref:this.invoiceInfo.invoice_number||`Facture #${this.invoiceInfo.number}`,price:parseFloat(this.invoiceInfo.total_amount)})}),e=await t.json();t.ok&&e.qr_code?(this.qrCodeSrc=e.qr_code,this.showQrCodeModal=!0):console.error("Erreur lors de la g\xE9n\xE9ration du QR Code :",e.message)}catch(t){console.error("Erreur lors de l'appel \xE0 l'API pour g\xE9n\xE9rer le QR code :",t)}finally{this.loading=!1}},closeQrCodeModal(){this.showQrCodeModal=!1},downloadQRCode(){const t=document.createElement("a");t.href=this.qrCodeSrc,t.download=`qr_code_${this.invoiceInfo.invoice_number||this.invoiceInfo.number}.png`,t.click()}}},Yg={key:0},Kg={key:1,class:"modal modal-open"},Zg={class:"modal-box"},$g={class:"font-bold text-lg"},ey={class:"mb-4"},ty=["src"],ny={class:"flex justify-end space-x-4"},sy={key:2,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},oy=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),iy=[oy],ry={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},ay=r("div",{class:"dropdown"},[r("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),r("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[r("li",null,[r("a",null,"Item")]),r("li",null,[r("a",null,"Parent"),r("ul",{class:"p-2"},[r("li",null,[r("a",null,"Submenu")]),r("li",null,[r("a",null,"Submenu")])])]),r("li",null,[r("a",null,"Item")])])],-1),ly={class:"hidden lg:flex gap-2"},cy={class:"btn btn-sm"},dy=r("i",{class:"far fa-edit"},null,-1),uy={key:1},hy={class:"btn btn-sm",disabled:""},my=r("i",{class:"far fa-edit"},null,-1),fy={key:2},py=r("i",{class:"fa fa-check"},null,-1),_y={class:"btn btn-outline btn-success btn-sm hover:text-white",disabled:""},gy=r("i",{class:"fa fa-check"},null,-1),yy={key:0},by={class:"btn btn-sm ms-2",disabled:""},vy=r("i",{class:"fas fa-undo"},null,-1),wy={key:1},xy=r("i",{class:"fas fa-undo"},null,-1),Ey=["disabled"],Cy=r("i",{class:"far fa-file-pdf"},null,-1),Ty={key:0,class:"loading loading-spinner loading-sm"},Iy={class:"flex gap-2"},ky=r("i",{class:"fas fa-paper-plane"},null,-1),Sy={key:0},Ay={key:1},Dy={key:2,class:"far fa-envelope"},Py=["data-tip"],Ry={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},jy=r("i",{class:"fas fa-paper-plane"},null,-1),Oy=["data-tip"],My={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},qy=r("i",{class:"fas fa-paper-plane"},null,-1),Ny={key:3},By=r("i",{class:"fas fa-qrcode"},null,-1),Vy={key:1,click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Fy=r("i",{class:"fas fa-qrcode"},null,-1),Uy=["data-tip"],Ly={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Wy=r("i",{class:"fas fa-qrcode"},null,-1),Xy={key:5},Hy={key:0,class:"dropdown dropdown-end"},zy={tabindex:"0",role:"button",class:"btn btn-outline btn-success btn-sm"},Qy=r("i",{class:"far fa-file-pdf"},null,-1),Gy={key:0,class:"loading loading-spinner loading-sm"},Jy={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},Yy=["disabled"],Ky=["disabled"],Zy={key:6},$y=["disabled"],eb=r("i",{class:"far fa-file-pdf"},null,-1),tb={key:0},nb={key:1},sb={key:2,class:"loading loading-spinner loading-sm"},ob=r("i",{class:"fas fa-check"},null,-1),ib=["data-tip"],rb={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},ab=r("i",{class:"fas fa-check"},null,-1);function lb(t,e,s,i,n,o){const a=N("send-invoice-modal"),c=N("confirm-modal"),f=N("confirm-modal-paid"),u=N("confirm-modal-credit"),l=N("router-link");return h(),m("div",null,[s.emailActive==1?(h(),m("div",Yg,[P(a,{loading:n.loadingModal,"show-modal":n.sendInvoiceModal,"modal-id":"modal_send_invoice",client:n.client_detail,"invoice-id":s.invoiceInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=_=>n.sendInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):g("",!0),P(c,{"show-modal":n.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,status:n.selectedStatus,onConfirm:e[1]||(e[1]=_=>o.changeInvoiceStatus("unpaid")),onCancel:e[2]||(e[2]=_=>n.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","status"]),P(f,{"show-modal":n.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,status:n.selectedStatus,onConfirm:o.changeInvoiceStatusWithPaymentMethod,onCancel:e[3]||(e[3]=_=>n.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","status","onConfirm"]),P(u,{"show-modal":n.showConfirmCreditModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[4]||(e[4]=_=>this.addCreditInvoice()),onCancel:e[5]||(e[5]=_=>n.showConfirmCreditModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),s.qrCodeActive==1&&n.showQrCodeModal?(h(),m("div",Kg,[r("div",Zg,[r("h3",$g,d(o.translations.download_qr_code),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[6]||(e[6]=_=>o.closeQrCodeModal())}," \u2715 "),r("div",ey,[r("img",{src:n.qrCodeSrc,alt:"QR Code",class:"max-w-full h-auto mx-auto"},null,8,ty)]),r("div",ny,[r("button",{onClick:e[7]||(e[7]=(..._)=>o.downloadQRCode&&o.downloadQRCode(..._)),class:"btn btn-primary"},d(o.translations.download_qr_code),1)])])])):g("",!0),n.loading?(h(),m("div",sy,iy)):g("",!0),r("div",ry,[r("div",null,[ay,r("div",ly,[s.invoiceInfo.status=="draft"?(h(),fi(l,{key:0,to:{name:"InvoiceEdit",params:{id:s.invoiceInfo.id}}},{default:me(()=>[r("button",cy,[dy,C(" "+d(o.translations.edit_invoice),1)])]),_:1},8,["to"])):(h(),m("div",uy,[r("button",hy,[my,C(" "+d(o.translations.edit_invoice),1)])])),s.invoiceInfo.status=="unpaid"&&!s.noItems?(h(),m("div",fy,[r("button",{class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[8]||(e[8]=_=>o.confirmValidateInvoice("paid"))},[py,C(" "+d(o.translations.mark_as_paid),1)])])):(h(),m(F,{key:3},[r("div",null,[r("button",_y,[gy,C(" "+d(o.translations.mark_as_paid),1)])]),s.invoiceInfo.credit!=0&&s.invoiceInfo.status=="paid"&&!s.noItems?(h(),m("div",yy,[r("button",by,[vy,C(" "+d(o.translations.credit_invoice),1)])])):g("",!0),s.invoiceInfo.credit==0&&s.invoiceInfo.status=="paid"&&!s.noItems?(h(),m("div",wy,[r("button",{class:"btn btn-sm ms-2",onClick:e[9]||(e[9]=_=>o.confirmCreditInvoice())},[xy,C(" "+d(o.translations.credit_invoice),1)])])):g("",!0)],64))])]),s.invoiceInfo.status=="draft"?(h(),m("button",{key:0,onClick:e[10]||(e[10]=_=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-secondary btn-sm",disabled:n.loadingPdf},[Cy,r("span",null,d(o.translations.previewPDF),1),n.loadingPdf?(h(),m("span",Ty)):g("",!0)],8,Ey)):g("",!0),r("div",Iy,[s.emailActive==1&&s.invoiceInfo.status!="draft"?(h(),m("button",{key:0,onClick:e[11]||(e[11]=K(_=>o.sendInvoice(s.invoiceInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[ky,s.invoiceInfo.sent==1?(h(),m("span",Sy,d(o.translations.resend_invoice),1)):(h(),m("span",Ay,d(o.translations.send_invoice),1)),s.invoiceInfo.sent==1?(h(),m("i",Dy)):g("",!0)])):s.emailActive==1&&s.invoiceInfo.status=="draft"?(h(),m("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.draft_cannot_send},[r("button",Ry,[jy,C(" "+d(o.translations.send_invoice),1)])],8,Py)):(h(),m("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[r("button",My,[qy,C(" "+d(o.translations.send_invoice),1)])],8,Oy)),s.qrCodeActive==1?(h(),m("div",Ny,[s.invoiceInfo.status=="unpaid"?(h(),m("button",{key:0,class:"btn btn-outline btn-accent btn-sm",onClick:e[12]||(e[12]=(..._)=>o.generateQRCode&&o.generateQRCode(..._))},[By,C(" "+d(o.translations.generate_qrcode),1)])):(h(),m("button",Vy,[Fy,C(" "+d(o.translations.generate_qrcode),1)]))])):(h(),m("div",{key:4,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_qrcode_addon},[r("button",Ly,[Wy,C(" "+d(o.translations.generate_qrcode),1)])],8,Uy)),s.currencyDefault.currency_id!==s.currencyClient.currency_id?(h(),m("div",Xy,[s.invoiceInfo.status!="draft"?(h(),m("div",Hy,[r("div",zy,[Qy,C(" "+d(o.translations.exportToPDF)+" ",1),n.loadingPdf?(h(),m("span",Gy)):g("",!0)]),r("ul",Jy,[r("li",null,[r("a",{onClick:e[13]||(e[13]=_=>o.exportToPDF(s.currencyDefault.currency_id)),disabled:n.loadingPdf},d(o.translations.invoice_in)+" "+d(s.currencyDefault.currency_symbol),9,Yy)]),r("li",null,[r("a",{onClick:e[14]||(e[14]=_=>o.exportToPDF(s.currencyClient.currency_id)),disabled:n.loadingPdf},d(o.translations.invoice_in)+" "+d(s.currencyClient.currency_symbol),9,Ky)])])])):g("",!0)])):(h(),m("div",Zy,[s.invoiceInfo.status!="draft"?(h(),m("button",{key:0,onClick:e[15]||(e[15]=_=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[eb,s.invoiceInfo.status!="draft"?(h(),m("span",tb,d(o.translations.exportToPDF),1)):(h(),m("span",nb,d(o.translations.previewPDF),1)),n.loadingPdf?(h(),m("span",sb)):g("",!0)],8,$y)):g("",!0)])),s.invoiceInfo.status=="draft"&&!s.noItems?(h(),m("button",{key:7,class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[16]||(e[16]=_=>o.confirmValidateInvoice("unpaid"))},[ob,C(" "+d(o.translations.validateInvoice),1)])):g("",!0),s.invoiceInfo.status=="draft"&&s.noItems?(h(),m("div",{key:8,class:"tooltip tooltip-left tooltip-warning","data-tip":o.translations.min_article},[r("button",rb,[ab,C(" "+d(o.translations.validateInvoice),1)])],8,ib)):g("",!0)])])])}var cb=ne(Jg,[["render",lb]]);const db={components:{VueEditor:mt.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:t.item_name},item_description:{label:t.item_description,type:"textarea"},quantity:{label:t.quantity,type:"number"},vat_rate:{label:t.vat,type:"number"},unit_price:{label:t.unit_price,type:"number"},discount:{label:t.discount,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/invoices/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},ub=["id","open"],hb={class:"modal-box"},mb={class:"font-bold text-lg"},fb={key:0},pb={class:"grid grid-cols-1 gap-4"},_b=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),gb=r("div",{class:"skeleton h-4 w-full"},null,-1),yb=[_b,gb],bb={class:"grid grid-cols-1 gap-4"},vb=["type"],wb=["for"],xb=["id","onUpdate:modelValue"],Eb={key:1},Cb=["for"],Tb={class:"form-group mt-4 flex justify-end"},Ib=["disabled"],kb={key:0,class:"loading loading-spinner loading-sm"};function Sb(t,e,s,i,n,o){const a=N("vue-editor");return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",hb,[r("h3",mb,d(s.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=c=>o.closeModal())}," \u2715 "),n.loading?(h(),m("div",fb,[r("div",pb,[(h(!0),m(F,null,L(o.skeletonItems,c=>(h(),m("div",{key:c,class:"py-2"},yb))),128))])])):(h(),m("form",{key:1,onSubmit:e[1]||(e[1]=K((...c)=>o.submitForm&&o.submitForm(...c),["prevent"])),class:"form"},[r("div",bb,[(h(!0),m(F,null,L(n.fields,(c,f)=>(h(),m("div",{key:f,class:"ecwp-group form-group"},[c.type!=="textarea"?(h(),m("div",{key:0,type:c.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},d(c.label),9,wb),D(r("input",{id:f,"onUpdate:modelValue":u=>n.editedItem[f]=u,class:I(["ecwp-input input input-bordered",c.class||"w-full"])},null,10,xb),[[W,n.editedItem[f]]])],8,vb)):(h(),m("div",Eb,[r("label",{for:f,class:"form-label"},d(c.label),9,Cb),P(a,{id:f,modelValue:n.editedItem[f],"onUpdate:modelValue":u=>n.editedItem[f]=u,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",Tb,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.save)+" ",1),n.loadingBtn?(h(),m("span",kb)):g("",!0)],8,Ib)])],32))])],8,ub)])}var Ab=ne(db,[["render",Sb]]);const Db={components:{VueEditor:mt.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,disb:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedDisb:{...this.disb},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{title:{label:t.item_name},description:{label:t.item_description,type:"textarea"},unit_price:{label:t.unit_price,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/invoices/edit-disb/${this.editedDisb.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedDisb)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("disbEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{disb:{handler(t){this.editedDisb={...t}},immediate:!0}}},Pb=["id","open"],Rb={class:"modal-box"},jb={class:"font-bold text-lg"},Ob={key:0},Mb={class:"grid grid-cols-1 gap-4"},qb=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),Nb=r("div",{class:"skeleton h-4 w-full"},null,-1),Bb=[qb,Nb],Vb={class:"grid grid-cols-1 gap-4"},Fb=["type"],Ub=["for"],Lb=["id","onUpdate:modelValue"],Wb={key:1},Xb=["for"],Hb={class:"form-group mt-4 flex justify-end"},zb=["disabled"],Qb={key:0,class:"loading loading-spinner loading-sm"};function Gb(t,e,s,i,n,o){const a=N("vue-editor");return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",Rb,[r("h3",jb,d(s.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=c=>o.closeModal())}," \u2715 "),n.loading?(h(),m("div",Ob,[r("div",Mb,[(h(!0),m(F,null,L(o.skeletonItems,c=>(h(),m("div",{key:c,class:"py-2"},Bb))),128))])])):(h(),m("form",{key:1,onSubmit:e[1]||(e[1]=K((...c)=>o.submitForm&&o.submitForm(...c),["prevent"])),class:"form"},[r("div",Vb,[(h(!0),m(F,null,L(n.fields,(c,f)=>(h(),m("div",{key:f,class:"ecwp-group form-group"},[c.type!=="textarea"?(h(),m("div",{key:0,type:c.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},d(c.label),9,Ub),D(r("input",{id:f,"onUpdate:modelValue":u=>n.editedDisb[f]=u,class:I(["ecwp-input input input-bordered",c.class||"w-full"])},null,10,Lb),[[W,n.editedDisb[f]]])],8,Fb)):(h(),m("div",Wb,[r("label",{for:f,class:"form-label"},d(c.label),9,Xb),P(a,{id:f,modelValue:n.editedDisb[f],"onUpdate:modelValue":u=>n.editedDisb[f]=u,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",Hb,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.save)+" ",1),n.loadingBtn?(h(),m("span",Qb)):g("",!0)],8,zb)])],32))])],8,Pb)])}var Jb=ne(Db,[["render",Gb]]);const Yb={name:"sendRemind",components:{VueEditor:mt.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"remind",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Kb=["id","open"],Zb={class:"modal-box"},$b={class:"font-bold text-lg"},ev={key:0},tv={class:"grid grid-cols-1 gap-4"},nv=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),sv=r("div",{class:"skeleton h-4 w-full"},null,-1),ov=[nv,sv],iv={class:"grid grid-cols-1 gap-4"},rv=["type"],av=["for"],lv=["id","value","disabled","onInput"],cv={key:1},dv=["for"],uv={class:"form-group mt-4 flex justify-end"},hv=["disabled"],mv={key:0,class:"loading loading-spinner loading-sm"};function fv(t,e,s,i,n,o){const a=N("vue-editor");return h(),m("div",null,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",Zb,[r("h3",$b,d(o.translations.remind_invoice),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=c=>o.closeModal())}," \u2715 "),n.loading?(h(),m("div",ev,[r("div",tv,[(h(!0),m(F,null,L(o.skeletonItems,c=>(h(),m("div",{key:c,class:"py-2"},ov))),128))])])):(h(),m("form",{key:1,onSubmit:e[1]||(e[1]=K((...c)=>o.submitForm&&o.submitForm(...c),["prevent"])),class:"form"},[r("div",iv,[(h(!0),m(F,null,L(n.fields,(c,f)=>(h(),m("div",{key:f,class:"ecwp-group form-group"},[c.type!=="textarea"?(h(),m("div",{key:0,type:c.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},d(c.label),9,av),r("input",{id:f,class:I(["ecwp-input input input-bordered",c.class||"w-full"]),value:c.value,disabled:c.disabled,onInput:u=>o.updateFieldValue(f,u.target.value)},null,42,lv)],8,rv)):(h(),m("div",cv,[r("label",{for:f,class:"form-label"},d(c.label),9,dv),P(a,{modelValue:c.value,"onUpdate:modelValue":u=>c.value=u,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",uv,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.send)+" ",1),n.loadingBtn?(h(),m("span",mv)):g("",!0)],8,hv)])],32))])],8,Kb)])}var pv=ne(Yb,[["render",fv]]);const _v={name:"InvoiceViewDetail",components:{Card:Ze,InvoiceNavBar:cb,EditItemModal:Ab,EditDisbModal:Jb,RemoveModal:qt,RemindInvoiceModal:pv},data(){return{selectedItem:null,selectedDisb:null,SelectedInvoiceId:null,editItemsModal:!1,editDisbModal:!1,RemindInvoiceModal:!1,no_items:!0,loading:!1,loading_add:!1,invoice:[],invoiceItems:[],newItem:{loading_del:!1,item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},settings:[],client_detail:[],list_vats:[],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",articles:[],categories:[],refs:[],showDropdown:!1,showDropdownRef:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},showDisbursements:!1,disbursementsExist:!1,disbursementsItem:{title:"",description:"",unit_price:""},loading_add_disbursements:!1,disbursementsList:[]}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isInvoiceOverdue(){const t=new Date().getTime(),e=this.invoice.due_date?new Date(this.invoice.due_date).getTime():null;return e&&e<t},defaultCurrency(){return{currency_id:this.settings.default_currency,currency_symbol:this.default_currency_symbol}},clientCurrency(){return{currency_id:this.client_detail.currency_id,currency_symbol:this.client_currency}},totalAmountWithoutDiscount(){const t=this.invoiceItems.reduce((e,s)=>{const i=s.quantity*s.unit_price;return e+i},0);return this.formatCurrency(t)},totalAmount(){const t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.invoiceItems.reduce((i,n)=>i+parseFloat(n.total_amount),0)*this.invoice.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)}},methods:{getUniqueVATRates(){const t=new Set;return this.invoiceItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.invoiceItems.forEach(s=>{if(s.vat_rate===t){const i=s.quantity*s.unit_price,n=i*s.discount/100;e+=(i-n)*t/100}}),this.formatCurrency(e)},totalDisbursements(){let t=0;return this.disbursementsList&&this.disbursementsList.length>0&&(t+=this.disbursementsList.reduce((e,s)=>e+parseFloat(s.unit_price||0),0)),this.formatCurrency(t)},calculateTotalAmountWithVAT(){let t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.disbursementsList&&this.disbursementsList.length>0&&(t+=this.disbursementsList.reduce((e,s)=>e+parseFloat(s.unit_price||0),0)),this.settings.easy_compta_woo_addon_active==1&&(t+=parseFloat(this.invoice.shipping_amount||0)),this.formatCurrency(t)},formatShippingAmout(t){return this.formatShippingCurrency(t)},formatShippingCurrency(t){const s=(parseFloat(t)||0).toFixed(2),i=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${s}${i}`},fetchInvoice(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.invoice=t,this.fetchClientInfo(t.client_id)):console.error("Invoice not found")}).catch(t=>{console.error("Error fetching invoice:",t),this.loading=!1})},fetchClientInfo(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.invoiceItems=[],this.loading=!1,this.no_items=!0):(this.invoiceItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchDisbursements(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/disbursements/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code==="no_disbursements"?(console.error("No disbursements found"),this.disbursementsList=[],this.disbursementsExist=!1):(this.disbursementsList=t,this.disbursementsExist=!0),this.loading=!1}).catch(t=>{console.error("Error fetching disbursements:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loading=!1,new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var i=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;i=s+n}else i=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(i)},calculateTotalWithVat(t,e,s,i){const n=t*e,o=n*i/100,a=n-o,c=a*s/100,f=a+c;return this.formatCurrency(f)},calculateTotal(t,e,s){const i=t*e,n=i*s/100,a=i-n;return this.formatCurrency(a)},submitItems(){this.updateTotal();const t={...this.newItem,invoice_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/invoices/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.SelectedInvoiceId=e,modal_remove_item.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.invoiceItems.find(i=>i.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:e})}).then(i=>i.json()).then(i=>{i.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(i.message,"alert-error"),console.error("Error removing item:",i.message),s.loading_del=!1)}).catch(i=>{this.showToast(i.message,"alert-error"),console.error("Error removing item:",i),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/invoices/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},editDisb(t){this.loadingModal=!0,this.editDisbModal=!0,modal_edit_disb.showModal(),this.fetchDisbDetails(t)},fetchDisbDetails(t){fetch(`/wp-json/my-easy-compta/v1/invoices/disb-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedDisb=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},confirmremoveDisb(t,e){this.selectedDisb=t,this.SelectedInvoiceId=e,modal_remove_disb.showModal(),this.showRemoveModalDisb=!0},removeDisb(t,e){const s=this.disbursementsList.find(i=>i.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/disb-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:e})}).then(i=>i.json()).then(i=>{i.success?(s.loading_del=!1,this.fetchDisbursements()):(this.showToast(i.message,"alert-error"),console.error("Error removing item:",i.message),s.loading_del=!1)}).catch(i=>{this.showToast(i.message,"alert-error"),console.error("Error removing item:",i),s.loading_del=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,i){const o=t*e*i/100,a=o*s/100,c=o+a;return this.formatCurrency(c)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.invoiceItems[t.oldIndex];this.invoiceItems.splice(t.oldIndex,1),this.invoiceItems.splice(t.newIndex,0,e);const s=this.invoiceItems.map(i=>i.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/invoices/update-invoice-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}const t=document.getElementById("loader_articles");t.classList.remove("hidden"),fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.articles=e}).catch(e=>console.error("Error fetching articles:",e)).finally(()=>{t.classList.add("hidden")})},toggleDisbursements(){this.showDisbursements=!this.showDisbursements},addDisbursements(){this.loading_add_disbursements=!0,fetch("/wp-json/my-easy-compta/v1/invoices/disbursements",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:this.invoice.id,title:this.disbursementsItem.title,description:this.disbursementsItem.description,unit_price:parseFloat(this.disbursementsItem.unit_price)})}).then(t=>{if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}).then(t=>{this.disbursementsItem={title:"",description:"",unit_price:""},this.disbursementsList.push(t),this.disbursementsExist=!0}).catch(t=>{console.error("Erreur lors de l'ajout du d\xE9bours :",t)}).finally(()=>{this.loading_add_disbursements=!1})},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:i}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=i,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)},sendRemind(t){this.loadingModal=!0,this.RemindInvoiceModal=!0,modal_send_remind.showModal(),this.fetchClientInfo(t),this.loadSettings()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchInvoice(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),this.fetchDisbursements(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");O.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},gv={class:"pt-2 pr-4"},yv={key:0},bv={key:2,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},vv=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),wv=[vv],xv={key:3},Ev={role:"alert",class:"alert alert-warning"},Cv=r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),Tv={key:0},Iv=["data-tip"],kv={class:"btn btn-sm btn-primary",disabled:""},Sv={class:"grid grid-cols-2"},Av={class:"md:col-span-1"},Dv=["src"],Pv={class:"md:col-span-1 text-right"},Rv={class:"text-lg font-semibold"},jv={key:0,class:"badge badge-error text-white"},Ov={key:1,class:"badge badge-error text-white"},Mv={key:2,class:"badge badge-success text-white"},qv={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},Nv=r("br",null,null,-1),Bv=r("br",null,null,-1),Vv=r("br",null,null,-1),Fv=["href"],Uv=r("br",null,null,-1),Lv=r("br",null,null,-1),Wv=r("br",null,null,-1),Xv=["href"],Hv=r("br",null,null,-1),zv=["href"],Qv={class:"table mt-8"},Gv=r("th",null,null,-1),Jv={width:"5%"},Yv={width:"19%"},Kv={width:"21%"},Zv={width:"10%",class:"text-center"},$v={width:"8%",class:"text-center"},e1={key:0,width:"5%",class:"text-center"},t1={key:1,width:"5%"},n1={width:"10%",class:"text-center"},s1={width:"10%",class:"text-right"},o1=r("th",{width:"18%",class:"text-right inv-actions"},null,-1),i1=r("td",{class:"draggable-item drag-handle px-2"},[r("i",{class:"fas fa-bars"})],-1),r1={key:0,class:"badge badge-ghost badge-xs"},a1=["innerHTML"],l1={class:"text-center"},c1={class:"text-center"},d1={key:0},u1={key:1},h1={key:0,class:"text-center"},m1={key:1},f1={key:2,class:"text-center"},p1=r("br",null,null,-1),_1={key:3,class:"text-center"},g1=r("br",null,null,-1),y1={class:"text-right"},b1={key:0},v1={key:1},w1={key:0},x1=["data-tip"],E1=["onClick"],C1=r("i",{class:"far fa-edit"},null,-1),T1=[C1],I1=["data-tip"],k1=["onClick"],S1={key:0,class:"far fa-trash-alt"},A1={key:1,class:"loading loading-spinner loading-xs"},D1={key:0},P1=r("td",{class:"px-2"},null,-1),R1={class:"align-top px-2"},j1={class:"flex items-center border rounded-md relative"},O1=["placeholder"],M1={key:0,class:"autocomplete-dropdown bg-base-100"},q1=["onClick","innerHTML"],N1={class:"align-top px-2"},B1=r("option",{disabled:"",selected:""},"Type",-1),V1=["value"],F1={class:"flex items-center border rounded-md relative"},U1=r("span",{id:"loader_articles",class:"loading loading-spinner loading-xs absolute right-2 hidden"},null,-1),L1=["placeholder"],W1={key:0,class:"autocomplete-dropdown bg-base-100"},X1=["onClick","innerHTML"],H1={class:"align-top"},z1={class:"flex items-center rounded-md"},Q1=["placeholder"],G1={class:"align-top"},J1={class:"flex items-center border rounded-lg"},Y1={class:"inline-flex"},K1=["placeholder"],Z1={class:"align-top"},$1={class:"flex items-center border rounded-md"},ew=["placeholder"],tw={key:0,class:"align-top"},nw=["value"],sw={key:1,class:"align-top"},ow={class:"align-top"},iw={class:"flex items-center border rounded-md"},rw=["placeholder"],aw=r("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),lw={key:2,class:"text-right"},cw={key:3,class:"text-right"},dw={key:0},uw=["data-tip"],hw={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},mw={key:0,class:"fa fa-plus"},fw={key:1,class:"loading loading-spinner loading-xs"},pw={key:1},_w={colspan:"12",class:"font-bold text-lg pl-0 pt-10"},gw={key:1,class:"ml-2"},yw={key:2},bw={class:"p-2",colspan:"3"},vw={class:"p-2"},ww={class:"p-2",colspan:"1"},xw={class:"p-2",colspan:"3"},Ew=["innerHTML"],Cw={class:"p-2"},Tw={class:"p-2",colspan:"2"},Iw=["data-tip"],kw=["onClick"],Sw=r("i",{class:"far fa-edit"},null,-1),Aw=[Sw],Dw=["data-tip"],Pw=["onClick"],Rw={key:0,class:"far fa-trash-alt"},jw={key:1,class:"loading loading-spinner loading-xs"},Ow={key:3},Mw={class:"align-top px-2",colspan:"3"},qw={class:"flex items-center border rounded-md"},Nw=["placeholder"],Bw={class:"align-top px-2"},Vw={class:"flex items-center rounded-md"},Fw=["placeholder"],Uw={class:"align-top"},Lw={class:"flex items-center border rounded-md"},Ww=["placeholder"],Xw=r("td",{class:"align-top",colspan:"3"},null,-1),Hw={class:"text-right"},zw=["data-tip"],Qw={key:0,class:"fa fa-plus"},Gw={key:1,class:"loading loading-spinner loading-xs"},Jw={class:"border-t-4"},Yw={colspan:"8",class:"text-right no-border"},Kw={class:"text-right"},Zw={key:0,class:"line-through"},$w=r("td",null,null,-1),e0={colspan:"8",class:"text-right no-border"},t0={class:"text-right"},n0=r("td",null,null,-1),s0={key:5},o0={colspan:"8",class:"text-right no-border"},i0={class:"text-right no-border"},r0={key:6},a0={colspan:"8",class:"text-right no-border"},l0={class:"text-right no-border"},c0=r("td",null,null,-1),d0={colspan:"8",class:"text-right no-border font-bold text-xl"},u0={class:"text-right no-border font-bold text-xl"},h0=r("td",null,null,-1),m0={key:7},f0={colspan:"8",class:"text-right no-border"},p0={class:"text-right no-border"},_0={key:8},g0={colspan:"8",class:"text-right no-border"},y0={class:"text-right no-border font-bold text-xl"};function b0(t,e,s,i,n,o){const a=N("InvoiceNavBar"),c=N("remove-modal"),f=N("remind-invoice-modal"),u=N("edit-item-modal"),l=N("edit-disb-modal"),_=N("Card");return h(),m("div",gv,[P(a,{invoiceInfo:n.invoice,currencyDefault:o.defaultCurrency,currencyClient:o.clientCurrency,emailActive:n.settings.easy_compta_email_addon_active,qrCodeActive:n.settings.easy_compta_qrcode_addon_active,noItems:n.no_items},null,8,["invoiceInfo","currencyDefault","currencyClient","emailActive","qrCodeActive","noItems"]),P(c,{"modal-id":"modal_remove_item","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=p=>this.removeItem(n.selectedItem,n.SelectedInvoiceId)),onCancel:e[1]||(e[1]=p=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(c,{"modal-id":"modal_remove_disb","show-modal":t.showRemoveModalDisb,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[2]||(e[2]=p=>this.removeDisb(n.selectedDisb,n.SelectedInvoiceId)),onCancel:e[3]||(e[3]=p=>t.showRemoveModalDisb=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),n.settings.easy_compta_email_addon_active==1?(h(),m("div",yv,[P(f,{loading:t.loadingModal,"show-modal":n.RemindInvoiceModal,"modal-id":"modal_send_remind",client:n.client_detail,"invoice-id":n.invoice.id,subject:n.settings.remind_invoice_subject,content:n.settings.remind_invoice_content,onClose:e[4]||(e[4]=p=>n.RemindInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):g("",!0),n.toast.visible?(h(),m("div",{key:1,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),n.loading?(h(),m("div",bv,wv)):g("",!0),o.isInvoiceOverdue&&n.invoice.status=="unpaid"?(h(),m("div",xv,[r("div",Ev,[Cv,r("span",null,d(o.translations.invoice_overdue),1),n.settings.easy_compta_email_addon_active==1?(h(),m("div",Tv,[r("button",{onClick:e[5]||(e[5]=K(p=>o.sendRemind(n.invoice.client_id),["prevent"])),class:"btn btn-sm btn-primary"},d(o.translations.remind_invoice),1)])):(h(),m("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[r("button",kv,d(o.translations.remind_invoice),1)],8,Iv))])])):g("",!0),P(_,{topMargin:"mt-8",id:"invoice-content"},{default:me(()=>[r("div",Sv,[r("div",Av,[r("div",null,[r("img",{src:n.settings.logo_url,style:no({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,Dv)])]),r("div",Pv,[r("p",Rv,d(n.invoice.invoice_number),1),r("div",null,[C(d(o.translations.created_at)+": ",1),r("strong",null,d(n.invoice.created_at),1)]),r("div",null,[C(d(o.translations.due_date)+": ",1),r("strong",null,d(n.invoice.due_date),1)]),r("div",null,[C(d(o.translations.status)+": ",1),n.invoice.status=="draft"?(h(),m("span",jv,d(o.translations.draft),1)):g("",!0),n.invoice.status=="unpaid"?(h(),m("span",Ov,d(o.translations.unpaid),1)):g("",!0),n.invoice.status=="paid"?(h(),m("span",Mv,d(o.translations.paid),1)):g("",!0)])])]),r("div",qv,[r("div",null,[r("strong",null,d(o.translations.bill_to)+":",1),r("h4",null,[r("strong",null,d(n.client_detail.company_name),1)]),r("p",null,[C(d(n.client_detail.address),1),Nv,C(" "+d(n.client_detail.postal_code)+", "+d(n.client_detail.city)+" ",1),Bv,C(" "+d(n.client_detail.country),1),Vv,n.client_detail.phone?(h(),m("a",{key:0,href:"tel:"+n.client_detail.phone},d(n.client_detail.phone),9,Fv)):g("",!0)])]),r("div",null,[r("strong",null,d(o.translations.received_from)+":",1),r("h4",null,[r("strong",null,d(n.settings.company_name),1)]),r("p",null,[C(d(n.settings.company_address),1),Uv,C(" "+d(n.settings.postal_code)+", "+d(n.settings.city)+" ",1),Lv,C(" "+d(n.settings.country),1),Wv,n.settings.company_phone?(h(),m("a",{key:0,href:"tel:"+n.settings.company_phone},d(n.settings.company_phone),9,Xv)):g("",!0),Hv,n.settings.mobile_phone?(h(),m("a",{key:1,href:"tel:"+n.settings.mobile_phone},d(n.settings.mobile_phone),9,zv)):g("",!0)])])]),P(u,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[6]||(e[6]=p=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),P(l,{loading:t.loadingModal,"show-modal":n.editDisbModal,"modal-id":"modal_edit_disb","modal-title":o.translations.edit_item,disb:n.selectedDisb,onClose:e[7]||(e[7]=p=>n.editDisbModal=!1),onDisbEdited:o.fetchDisbursements},null,8,["loading","show-modal","modal-title","disb","onDisbEdited"]),r("form",{onSubmit:e[32]||(e[32]=K((...p)=>o.submitItems&&o.submitItems(...p),["prevent"]))},[r("table",Qv,[r("thead",null,[r("tr",null,[Gv,r("th",Jv,d(o.translations.item_ref),1),r("th",Yv,d(o.translations.item_name),1),r("th",Kv,d(o.translations.description),1),r("th",Zv,d(o.translations.quantity),1),r("th",$v,d(o.translations.unit_price),1),n.settings.vat_active==1?(h(),m("th",e1,d(o.translations.vat),1)):(h(),m("th",t1)),r("th",n1,d(o.translations.discount),1),r("th",s1,d(o.translations.total),1),o1])]),r("tbody",null,[(h(!0),m(F,null,L(n.invoiceItems,(p,y)=>(h(),m("tr",{key:p.id||y},[i1,r("td",null,d(p.item_ref),1),r("td",null,[p.category_name?(h(),m("div",r1,d(p.category_name),1)):g("",!0),r("div",null,d(p.item_name),1)]),r("td",{innerHTML:o.nl2br(p.item_description)},null,8,a1),r("td",l1,d(p.quantity),1),r("td",c1,[C(d(p.unit_price),1),n.default_currency_symbol==n.client_currency?(h(),m("span",d1,d(n.default_currency_symbol),1)):(h(),m("span",u1,d(n.client_currency),1))]),n.settings.vat_active==1?(h(),m("td",h1,d(p.vat_rate)+"% ",1)):(h(),m("td",m1)),n.settings.vat_active==1?(h(),m("td",f1,[C(d(p.discount)+"% ",1),p1,C(" "+d(o.calculateDiscountAmountWithVAT(p.quantity,p.unit_price,p.vat_rate,p.discount)),1)])):(h(),m("td",_1,[C(d(p.discount)+"% ",1),g1,C(" "+d(o.calculateDiscountAmount(p.quantity,p.unit_price,p.discount)),1)])),r("td",y1,[C(d(p.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(h(),m("span",b1,d(n.default_currency_symbol),1)):(h(),m("span",v1,d(n.client_currency),1))]),r("td",null,[n.invoice.status=="draft"?(h(),m("div",w1,[r("span",{class:"lg:tooltip","data-tip":o.translations.edit},[r("button",{onClick:K(v=>o.editItem(p.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},T1,8,E1)],8,x1),r("span",{class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:K(v=>o.confirmremoveItem(p.id,n.invoice.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[p.loading_del?g("",!0):(h(),m("i",S1)),p.loading_del?(h(),m("span",A1)):g("",!0)],8,k1)],8,I1)])):g("",!0)])]))),128)),n.invoice.status=="draft"?(h(),m("tr",D1,[P1,r("td",R1,[r("div",j1,[D(r("input",{type:"text","onUpdate:modelValue":e[8]||(e[8]=p=>n.newItem.item_ref=p),onInput:e[9]||(e[9]=(...p)=>o.fetchRefs&&o.fetchRefs(...p)),onFocus:e[10]||(e[10]=p=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 input-xs outline-none"},null,40,O1),[[W,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(h(),m("ul",M1,[(h(!0),m(F,null,L(n.refs,p=>(h(),m("li",{key:p.ref,onClick:y=>o.selectItem(p),class:"autocomplete-item",innerHTML:o.highlightMatch(p.ref)},null,8,q1))),128))])):g("",!0)])]),r("td",N1,[D(r("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[11]||(e[11]=p=>n.newItem.item_category=p)},[B1,(h(!0),m(F,null,L(n.categories,p=>(h(),m("option",{key:p.id,value:p.id},d(p.name),9,V1))),128))],512),[[ue,n.newItem.item_category]]),r("div",F1,[U1,D(r("input",{type:"text","onUpdate:modelValue":e[12]||(e[12]=p=>n.newItem.item_name=p),onInput:e[13]||(e[13]=(...p)=>o.fetchArticles&&o.fetchArticles(...p)),onFocus:e[14]||(e[14]=p=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,L1),[[W,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(h(),m("ul",W1,[(h(!0),m(F,null,L(n.articles,p=>(h(),m("li",{key:p.name,onClick:y=>o.selectItem(p),class:"autocomplete-item bt-primary",innerHTML:o.highlightMatch(p.name)},null,8,X1))),128))])):g("",!0)])]),r("td",H1,[r("div",z1,[D(r("textarea",{"onUpdate:modelValue":e[15]||(e[15]=p=>n.newItem.item_description=p),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[16]||(e[16]=p=>o.resize()),ref:"textarea"},null,40,Q1),[[W,n.newItem.item_description]])])]),r("td",G1,[r("div",J1,[r("div",Y1,[r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[17]||(e[17]=(...p)=>o.decrease&&o.decrease(...p))}," - "),D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[18]||(e[18]=p=>n.newItem.quantity=p),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[19]||(e[19]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,K1),[[W,n.newItem.quantity]]),r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[20]||(e[20]=(...p)=>o.increase&&o.increase(...p))}," + ")])])]),r("td",Z1,[r("div",$1,[D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[21]||(e[21]=p=>n.newItem.unit_price=p),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[22]||(e[22]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,ew),[[W,n.newItem.unit_price]])])]),n.settings.vat_active==1?(h(),m("td",tw,[D(r("select",{"onUpdate:modelValue":e[23]||(e[23]=p=>n.newItem.vat_rate=p),onChange:e[24]||(e[24]=(...p)=>o.updateTotal&&o.updateTotal(...p)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(h(!0),m(F,null,L(n.list_vats,p=>(h(),m("option",{key:p,value:p.rate},d(p.rate)+"% ",9,nw))),128))],544),[[ue,n.newItem.vat_rate]])])):(h(),m("td",sw)),r("td",ow,[r("div",iw,[D(r("input",{type:"number","onUpdate:modelValue":e[25]||(e[25]=p=>n.newItem.discount=p),min:"0",max:"100",placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[26]||(e[26]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,rw),[[W,n.newItem.discount]]),aw])]),n.settings.vat_active==1?(h(),m("td",lw,d(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(h(),m("td",cw,d(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),r("td",null,[n.invoice.status=="draft"?(h(),m("div",dw,[r("span",{class:"lg:tooltip","data-tip":o.translations.add},[r("button",hw,[n.loading_add?g("",!0):(h(),m("i",mw)),n.loading_add?(h(),m("span",fw)):g("",!0)])],8,uw)])):g("",!0)])])):g("",!0),n.settings.active_disbursements==1?(h(),m("tr",pw,[r("td",_w,[n.invoice.status=="draft"?(h(),m("button",{key:0,onClick:e[27]||(e[27]=K((...p)=>o.toggleDisbursements&&o.toggleDisbursements(...p),["prevent"])),class:"btn btn-primary py-2 px-4 rounded text-white"},[r("i",{class:I({"fas fa-plus":!n.showDisbursements,"fas fa-minus":n.showDisbursements})},null,2)])):g("",!0),n.invoice.status=="draft"||n.disbursementsExist?(h(),m("span",gw,d(o.translations.disbursements),1)):g("",!0)])])):g("",!0),n.settings.active_disbursements==1&&n.disbursementsList&&n.disbursementsList.length>0?(h(),m("tr",yw,[r("th",bw,d(o.translations.item_name),1),r("th",vw,d(o.translations.description),1),r("th",ww,d(o.translations.unit_price),1)])):g("",!0),(h(!0),m(F,null,L(n.disbursementsList,p=>(h(),m("tr",{key:p.id},[r("td",xw,d(p.title),1),r("td",{class:"p-2",innerHTML:o.nl2br(p.description)},null,8,Ew),r("td",Cw,d(o.calculateTotal(1,p.unit_price,0)),1),r("td",Tw,[r("span",{class:"lg:tooltip","data-tip":o.translations.edit},[r("button",{onClick:K(y=>o.editDisb(p.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},Aw,8,kw)],8,Iw),r("span",{class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:K(y=>o.confirmremoveDisb(p.id,n.invoice.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[p.loading_del?g("",!0):(h(),m("i",Rw)),p.loading_del?(h(),m("span",jw)):g("",!0)],8,Pw)],8,Dw)])]))),128)),n.settings.active_disbursements==1&&n.showDisbursements&&n.invoice.status=="draft"?(h(),m("tr",Ow,[r("td",Mw,[r("div",qw,[D(r("input",{type:"text","onUpdate:modelValue":e[28]||(e[28]=p=>n.disbursementsItem.title=p),placeholder:o.translations.title,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,8,Nw),[[W,n.disbursementsItem.title]])])]),r("td",Bw,[r("div",Vw,[D(r("textarea",{"onUpdate:modelValue":e[29]||(e[29]=p=>n.disbursementsItem.description=p),placeholder:o.translations.description,class:"textarea textarea-bordered input-xs w-full"},null,8,Fw),[[W,n.disbursementsItem.description]])])]),r("td",Uw,[r("div",Lw,[D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[30]||(e[30]=p=>n.disbursementsItem.unit_price=p),placeholder:o.translations.price,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,8,Ww),[[W,n.disbursementsItem.unit_price]])])]),Xw,r("td",Hw,d(o.calculateTotal(1,n.disbursementsItem.unit_price,0)),1),r("td",null,[r("span",{class:"lg:tooltip","data-tip":o.translations.add_disbursements},[r("button",{type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded",onClick:e[31]||(e[31]=K((...p)=>o.addDisbursements&&o.addDisbursements(...p),["prevent"]))},[n.loading_add_disbursements?g("",!0):(h(),m("i",Qw)),n.loading_add_disbursements?(h(),m("span",Gw)):g("",!0)])],8,zw)])])):g("",!0),r("tr",Jw,[r("td",Yw,[r("strong",null,d(o.translations.subtotal),1)]),r("td",Kw,[o.totalAmount!==o.totalAmountWithoutDiscount?(h(),m("span",Zw,d(o.totalAmountWithoutDiscount),1)):g("",!0),C(" "+d(o.totalAmount),1)]),$w]),n.settings.vat_active==1?(h(!0),m(F,{key:4},L(o.getUniqueVATRates(),(p,y)=>(h(),m("tr",{key:y},[r("td",e0,[r("strong",null,d(o.translations.tax)+" ("+d(p)+"%) ",1)]),r("td",t0,d(o.calculateVATForRate(p)),1),n0]))),128)):g("",!0),n.invoice.shipping_amount?(h(),m("tr",s0,[r("td",o0,[r("strong",null,d(o.translations.shipping_fees),1)]),r("td",i0,d(o.formatShippingAmout(n.invoice.shipping_amount)),1)])):g("",!0),n.settings.active_disbursements==1&&n.disbursementsExist?(h(),m("tr",r0,[r("td",a0,[r("strong",null,d(o.translations.total_disbursements),1)]),r("td",l0,d(o.totalDisbursements()),1),c0])):g("",!0),r("tr",null,[r("td",d0,[r("strong",null,d(o.translations.total),1)]),r("td",u0,d(o.calculateTotalAmountWithVAT()),1),h0]),n.client_currency!=n.default_currency_symbol?(h(),m("tr",m0,[r("td",f0,[r("strong",null,d(o.translations.exchange_rate),1)]),r("td",p0,d(n.invoice.exchange_rate),1)])):g("",!0),n.client_currency!=n.default_currency_symbol?(h(),m("tr",_0,[r("td",g0,[r("strong",null,d(o.translations.total)+" "+d(n.default_currency_symbol),1)]),r("td",y0,d(o.totalAmountDefaultCurrency)+d(n.default_currency_symbol),1)])):g("",!0)])])],32)]),_:1})])}var v0=ne(_v,[["render",b0]]);const w0={name:"InvoiceNew",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt,AddClientModal:Ro},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],last_invoice_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{AddNew(){modal_clients.showModal()},cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.invoice_prefix}_${String(this.settings.last_invoice_id).padStart(4,"0")}`;this.invoice.number=s}else{const e=await t.json()}}catch{this.loading=!1}},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/invoices",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting invoice:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},x0={class:"pt-2 pr-4"},E0={class:"flex justify-between items-center mb-4"},C0={class:"card-title"},T0=r("div",{class:"divider mt-2"},null,-1),I0={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},k0={class:"grid grid-cols-2 gap-4"},S0={class:"ecwp-group form-group mb-4"},A0={for:"invoiceNumber",class:"ecwp-label"},D0={class:"ecwp-group form-group mb-4"},P0={for:"invoiceDate",class:"ecwp-label"},R0={class:"mb-4"},j0={class:"flex gap-2 items-end"},O0=r("i",{class:"fas fa-plus"},null,-1),M0=[O0],q0={class:"ecwp-group form-group w-full"},N0={for:"client",class:"ecwp-label"},B0={class:"ecwp-group form-group mb-4"},V0={for:"status",class:"ecwp-label"},F0={value:"draft"},U0={key:0,class:"ecwp-group form-group mb-4"},L0={for:"exchangeRate",class:"ecwp-label"},W0={class:"flex justify-between"},X0=["disabled"],H0={key:0,class:"loading loading-spinner loading-sm"};function z0(t,e,s,i,n,o){const a=N("VueDatePicker"),c=N("model-select"),f=N("Card"),u=N("AddClientModal");return h(),m("div",x0,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:me(()=>[r("div",E0,[r("h2",C0,d(o.translations.new_invoice),1)]),T0,n.loading?(h(),m("div",I0)):g("",!0),r("form",{onSubmit:e[7]||(e[7]=K((...l)=>o.submitInvoice&&o.submitInvoice(...l),["prevent"]))},[r("div",k0,[r("div",S0,[r("label",A0,d(o.translations.invoice_number),1),D(r("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=l=>n.invoice.number=l),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[W,n.invoice.number]])]),r("div",D0,[r("label",P0,d(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=l=>n.invoice.due_date=l),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),r("div",R0,[r("div",j0,[r("button",{type:"button",class:"btn btn-primary",onClick:e[2]||(e[2]=(...l)=>o.AddNew&&o.AddNew(...l))},M0),r("div",q0,[r("label",N0,d(o.translations.company_name),1),P(c,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[3]||(e[3]=l=>n.invoice.client_id=l),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])])])]),r("div",B0,[r("label",V0,d(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=l=>n.invoice.status=l),class:I(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[r("option",F0,d(o.translations.draft),1)],2),[[ue,n.invoice.status]])]),o.currencyMismatch?(h(),m("div",U0,[r("label",L0,d(o.translations.exchange_rate),1),D(r("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[5]||(e[5]=l=>n.invoice.exchange_rate=l),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[W,n.invoice.exchange_rate]])])):g("",!0)]),r("div",W0,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[6]||(e[6]=(...l)=>o.cancelAction&&o.cancelAction(...l))},d(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.submit)+" ",1),n.loadingBtn?(h(),m("span",H0)):g("",!0)],8,X0)])],32)]),_:1}),P(u,{onClientAdded:o.fetchClients},null,8,["onClientAdded"])])}var Q0=ne(w0,[["render",z0]]);const G0={name:"invoiceEdit",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"paid",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchInvoiceDetails()},methods:{cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.invoice.client_id&&this.setClientById(this.invoice.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchInvoiceDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?this.invoice=e:(console.error("Error fetching invoice details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching invoice details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.invoice.client=this.clients.find(e=>e.id===t)||null},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting invoice:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},J0={class:"pt-2 pr-4"},Y0={class:"flex justify-between items-center mb-4"},K0={class:"card-title"},Z0=r("div",{class:"divider mt-2"},null,-1),$0={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},ex={class:"grid grid-cols-2 gap-4"},tx={class:"ecwp-group form-group mb-4"},nx={for:"invoiceNumber",class:"ecwp-label"},sx={class:"ecwp-group form-group mb-4"},ox={for:"invoiceDate",class:"ecwp-label"},ix={class:"ecwp-group form-group mb-4"},rx={for:"client",class:"ecwp-label"},ax={class:"ecwp-group form-group mb-4"},lx={for:"status",class:"ecwp-label"},cx={value:"draft",selected:""},dx={value:"unpaid"},ux={value:"paid"},hx={key:0,class:"ecwp-group form-group mb-4"},mx={for:"exchangeRate",class:"ecwp-label"},fx={class:"flex justify-between"},px=["disabled"],_x={key:0,class:"loading loading-spinner loading-sm"};function gx(t,e,s,i,n,o){const a=N("VueDatePicker"),c=N("model-select"),f=N("Card");return h(),m("div",J0,[n.toast.visible?(h(),m("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,d(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:me(()=>[r("div",Y0,[r("h2",K0,d(o.translations.edit_invoice),1)]),Z0,n.loading?(h(),m("div",$0)):g("",!0),r("form",{onSubmit:e[6]||(e[6]=K((...u)=>o.submitInvoice&&o.submitInvoice(...u),["prevent"]))},[r("div",ex,[r("div",tx,[r("label",nx,d(o.translations.invoice_number),1),D(r("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=u=>n.invoice.invoice_number=u),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[W,n.invoice.invoice_number]])]),r("div",sx,[r("label",ox,d(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=u=>n.invoice.due_date=u),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),r("div",ix,[r("label",rx,d(o.translations.company_name),1),P(c,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[2]||(e[2]=u=>n.invoice.client_id=u),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),r("div",ax,[r("label",lx,d(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[3]||(e[3]=u=>n.invoice.status=u),class:I(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[r("option",cx,d(o.translations.draft),1),r("option",dx,d(o.translations.unpaid),1),r("option",ux,d(o.translations.paid),1)],2),[[ue,n.invoice.status]])]),o.currencyMismatch?(h(),m("div",hx,[r("label",mx,d(o.translations.exchange_rate),1),D(r("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[4]||(e[4]=u=>n.invoice.exchange_rate=u),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[W,n.invoice.exchange_rate]])])):g("",!0)]),r("div",fx,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...u)=>o.cancelAction&&o.cancelAction(...u))},d(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(d(o.translations.save)+" ",1),n.loadingBtn?(h(),m("span",_x)):g("",!0)],8,px)])],32)]),_:1})])}var yx=ne(G0,[["render",gx]]);const Re=un;(function(t,e){const s=un,i=t();for(;[];)try{if(-parseInt(s(388))/1+-parseInt(s(399))/2+parseInt(s(402))/3*(parseInt(s(395))/4)+parseInt(s(391))/5*(parseInt(s(390))/6)+parseInt(s(384))/7*(parseInt(s(398))/8)+parseInt(s(396))/9*(-parseInt(s(381))/10)+-parseInt(s(383))/11*(-parseInt(s(392))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(dn,780643);function dn(){const t=["24qXimAf","/invoice/new","/quotes","549964dluHzw","443367uwdKlU","InvoiceNew","15256xYralW","1560954OjeLLN","InvoiceViewDetail","/quote/new","9lEwjuS","190YMLdNZ","/quote/edit/:id","3000305yGGYhw","3913VkmcCa","/invoices","Invoice","/invoice/detail/:id","128860zarLXn","QuoteViewDetail","6jCBQZu","3009905JNrxkz"];return dn=function(){return t},dn()}function un(t,e){const s=dn();return un=function(i,n){return i=i-381,s[i]},un(t,e)}const bx=[{path:Re(394),name:"Quote",component:wd},{path:"/quote/detail/:id",name:Re(389),component:pp},{path:Re(401),name:"QuoteNew",component:zp},{path:Re(382),name:"QuoteEdit",component:Ho},{path:Re(385),name:Re(386),component:sg},{path:Re(387),name:Re(400),component:v0},{path:"/invoice/edit/:id",name:"InvoiceEdit",component:yx},{path:Re(393),name:Re(397),component:Q0}],Ix=El({history:Ka(),routes:bx});export{Ro as A,Ix as r};
     15 */function Hs(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),s.push.apply(s,i)}return s}function Oe(t){for(var e=1;e<arguments.length;e++){var s=arguments[e]!=null?arguments[e]:{};e%2?Hs(Object(s),!0).forEach(function(i){Vh(t,i,s[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):Hs(Object(s)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(s,i))})}return t}function Yt(t){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Yt=function(e){return typeof e}:Yt=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Yt(t)}function Vh(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function Le(){return Le=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},Le.apply(this,arguments)}function Fh(t,e){if(t==null)return{};var s={},i=Object.keys(t),n,o;for(o=0;o<i.length;o++)n=i[o],!(e.indexOf(n)>=0)&&(s[n]=t[n]);return s}function Uh(t,e){if(t==null)return{};var s=Fh(t,e),i,n;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)i=o[n],!(e.indexOf(i)>=0)&&(!Object.prototype.propertyIsEnumerable.call(t,i)||(s[i]=t[i]))}return s}var Lh="1.15.2";function Ue(t){if(typeof window!="undefined"&&window.navigator)return!!navigator.userAgent.match(t)}var We=Ue(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),Vt=Ue(/Edge/i),zs=Ue(/firefox/i),kt=Ue(/safari/i)&&!Ue(/chrome/i)&&!Ue(/android/i),Qo=Ue(/iP(ad|od|hone)/i),Go=Ue(/chrome/i)&&Ue(/android/i),Jo={capture:!1,passive:!1};function Q(t,e,s){t.addEventListener(e,s,!We&&Jo)}function H(t,e,s){t.removeEventListener(e,s,!We&&Jo)}function on(t,e){if(!!e){if(e[0]===">"&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch{return!1}return!1}}function Wh(t){return t.host&&t!==document&&t.host.nodeType?t.host:t.parentNode}function Ie(t,e,s,i){if(t){s=s||document;do{if(e!=null&&(e[0]===">"?t.parentNode===s&&on(t,e):on(t,e))||i&&t===s)return t;if(t===s)break}while(t=Wh(t))}return null}var Qs=/\s+/g;function ye(t,e,s){if(t&&e)if(t.classList)t.classList[s?"add":"remove"](e);else{var i=(" "+t.className+" ").replace(Qs," ").replace(" "+e+" "," ");t.className=(i+(s?" "+e:"")).replace(Qs," ")}}function N(t,e,s){var i=t&&t.style;if(i){if(s===void 0)return document.defaultView&&document.defaultView.getComputedStyle?s=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(s=t.currentStyle),e===void 0?s:s[e];!(e in i)&&e.indexOf("webkit")===-1&&(e="-webkit-"+e),i[e]=s+(typeof s=="string"?"":"px")}}function ct(t,e){var s="";if(typeof t=="string")s=t;else do{var i=N(t,"transform");i&&i!=="none"&&(s=i+" "+s)}while(!e&&(t=t.parentNode));var n=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return n&&new n(s)}function Yo(t,e,s){if(t){var i=t.getElementsByTagName(e),n=0,o=i.length;if(s)for(;n<o;n++)s(i[n],n);return i}return[]}function Me(){var t=document.scrollingElement;return t||document.documentElement}function ie(t,e,s,i,n){if(!(!t.getBoundingClientRect&&t!==window)){var o,a,l,f,d,m,p;if(t!==window&&t.parentNode&&t!==Me()?(o=t.getBoundingClientRect(),a=o.top,l=o.left,f=o.bottom,d=o.right,m=o.height,p=o.width):(a=0,l=0,f=window.innerHeight,d=window.innerWidth,m=window.innerHeight,p=window.innerWidth),(e||s)&&t!==window&&(n=n||t.parentNode,!We))do if(n&&n.getBoundingClientRect&&(N(n,"transform")!=="none"||s&&N(n,"position")!=="static")){var y=n.getBoundingClientRect();a-=y.top+parseInt(N(n,"border-top-width")),l-=y.left+parseInt(N(n,"border-left-width")),f=a+o.height,d=l+o.width;break}while(n=n.parentNode);if(i&&t!==window){var _=ct(n||t),v=_&&_.a,x=_&&_.d;_&&(a/=x,l/=v,p/=v,m/=x,f=a+m,d=l+p)}return{top:a,left:l,bottom:f,right:d,width:p,height:m}}}function Gs(t,e,s){for(var i=Ke(t,!0),n=ie(t)[e];i;){var o=ie(i)[s],a=void 0;if(s==="top"||s==="left"?a=n>=o:a=n<=o,!a)return i;if(i===Me())break;i=Ke(i,!1)}return!1}function ht(t,e,s,i){for(var n=0,o=0,a=t.children;o<a.length;){if(a[o].style.display!=="none"&&a[o]!==M.ghost&&(i||a[o]!==M.dragged)&&Ie(a[o],s.draggable,t,!1)){if(n===e)return a[o];n++}o++}return null}function us(t,e){for(var s=t.lastElementChild;s&&(s===M.ghost||N(s,"display")==="none"||e&&!on(s,e));)s=s.previousElementSibling;return s||null}function we(t,e){var s=0;if(!t||!t.parentNode)return-1;for(;t=t.previousElementSibling;)t.nodeName.toUpperCase()!=="TEMPLATE"&&t!==M.clone&&(!e||on(t,e))&&s++;return s}function Js(t){var e=0,s=0,i=Me();if(t)do{var n=ct(t),o=n.a,a=n.d;e+=t.scrollLeft*o,s+=t.scrollTop*a}while(t!==i&&(t=t.parentNode));return[e,s]}function Xh(t,e){for(var s in t)if(!!t.hasOwnProperty(s)){for(var i in e)if(e.hasOwnProperty(i)&&e[i]===t[s][i])return Number(s)}return-1}function Ke(t,e){if(!t||!t.getBoundingClientRect)return Me();var s=t,i=!1;do if(s.clientWidth<s.scrollWidth||s.clientHeight<s.scrollHeight){var n=N(s);if(s.clientWidth<s.scrollWidth&&(n.overflowX=="auto"||n.overflowX=="scroll")||s.clientHeight<s.scrollHeight&&(n.overflowY=="auto"||n.overflowY=="scroll")){if(!s.getBoundingClientRect||s===document.body)return Me();if(i||e)return s;i=!0}}while(s=s.parentNode);return Me()}function Hh(t,e){if(t&&e)for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t}function jn(t,e){return Math.round(t.top)===Math.round(e.top)&&Math.round(t.left)===Math.round(e.left)&&Math.round(t.height)===Math.round(e.height)&&Math.round(t.width)===Math.round(e.width)}var At;function Ko(t,e){return function(){if(!At){var s=arguments,i=this;s.length===1?t.call(i,s[0]):t.apply(i,s),At=setTimeout(function(){At=void 0},e)}}}function zh(){clearTimeout(At),At=void 0}function Zo(t,e,s){t.scrollLeft+=e,t.scrollTop+=s}function $o(t){var e=window.Polymer,s=window.jQuery||window.Zepto;return e&&e.dom?e.dom(t).cloneNode(!0):s?s(t).clone(!0)[0]:t.cloneNode(!0)}function ei(t,e,s){var i={};return Array.from(t.children).forEach(function(n){var o,a,l,f;if(!(!Ie(n,e.draggable,t,!1)||n.animated||n===s)){var d=ie(n);i.left=Math.min((o=i.left)!==null&&o!==void 0?o:1/0,d.left),i.top=Math.min((a=i.top)!==null&&a!==void 0?a:1/0,d.top),i.right=Math.max((l=i.right)!==null&&l!==void 0?l:-1/0,d.right),i.bottom=Math.max((f=i.bottom)!==null&&f!==void 0?f:-1/0,d.bottom)}}),i.width=i.right-i.left,i.height=i.bottom-i.top,i.x=i.left,i.y=i.top,i}var ve="Sortable"+new Date().getTime();function Qh(){var t=[],e;return{captureAnimationState:function(){if(t=[],!!this.options.animation){var i=[].slice.call(this.el.children);i.forEach(function(n){if(!(N(n,"display")==="none"||n===M.ghost)){t.push({target:n,rect:ie(n)});var o=Oe({},t[t.length-1].rect);if(n.thisAnimationDuration){var a=ct(n,!0);a&&(o.top-=a.f,o.left-=a.e)}n.fromRect=o}})}},addAnimationState:function(i){t.push(i)},removeAnimationState:function(i){t.splice(Xh(t,{target:i}),1)},animateAll:function(i){var n=this;if(!this.options.animation){clearTimeout(e),typeof i=="function"&&i();return}var o=!1,a=0;t.forEach(function(l){var f=0,d=l.target,m=d.fromRect,p=ie(d),y=d.prevFromRect,_=d.prevToRect,v=l.rect,x=ct(d,!0);x&&(p.top-=x.f,p.left-=x.e),d.toRect=p,d.thisAnimationDuration&&jn(y,p)&&!jn(m,p)&&(v.top-p.top)/(v.left-p.left)===(m.top-p.top)/(m.left-p.left)&&(f=Jh(v,y,_,n.options)),jn(p,m)||(d.prevFromRect=m,d.prevToRect=p,f||(f=n.options.animation),n.animate(d,v,p,f)),f&&(o=!0,a=Math.max(a,f),clearTimeout(d.animationResetTimer),d.animationResetTimer=setTimeout(function(){d.animationTime=0,d.prevFromRect=null,d.fromRect=null,d.prevToRect=null,d.thisAnimationDuration=null},f),d.thisAnimationDuration=f)}),clearTimeout(e),o?e=setTimeout(function(){typeof i=="function"&&i()},a):typeof i=="function"&&i(),t=[]},animate:function(i,n,o,a){if(a){N(i,"transition",""),N(i,"transform","");var l=ct(this.el),f=l&&l.a,d=l&&l.d,m=(n.left-o.left)/(f||1),p=(n.top-o.top)/(d||1);i.animatingX=!!m,i.animatingY=!!p,N(i,"transform","translate3d("+m+"px,"+p+"px,0)"),this.forRepaintDummy=Gh(i),N(i,"transition","transform "+a+"ms"+(this.options.easing?" "+this.options.easing:"")),N(i,"transform","translate3d(0,0,0)"),typeof i.animated=="number"&&clearTimeout(i.animated),i.animated=setTimeout(function(){N(i,"transition",""),N(i,"transform",""),i.animated=!1,i.animatingX=!1,i.animatingY=!1},a)}}}}function Gh(t){return t.offsetWidth}function Jh(t,e,s,i){return Math.sqrt(Math.pow(e.top-t.top,2)+Math.pow(e.left-t.left,2))/Math.sqrt(Math.pow(e.top-s.top,2)+Math.pow(e.left-s.left,2))*i.animation}var ot=[],Rn={initializeByDefault:!0},Ft={mount:function(e){for(var s in Rn)Rn.hasOwnProperty(s)&&!(s in e)&&(e[s]=Rn[s]);ot.forEach(function(i){if(i.pluginName===e.pluginName)throw"Sortable: Cannot mount plugin ".concat(e.pluginName," more than once")}),ot.push(e)},pluginEvent:function(e,s,i){var n=this;this.eventCanceled=!1,i.cancel=function(){n.eventCanceled=!0};var o=e+"Global";ot.forEach(function(a){!s[a.pluginName]||(s[a.pluginName][o]&&s[a.pluginName][o](Oe({sortable:s},i)),s.options[a.pluginName]&&s[a.pluginName][e]&&s[a.pluginName][e](Oe({sortable:s},i)))})},initializePlugins:function(e,s,i,n){ot.forEach(function(l){var f=l.pluginName;if(!(!e.options[f]&&!l.initializeByDefault)){var d=new l(e,s,e.options);d.sortable=e,d.options=e.options,e[f]=d,Le(i,d.defaults)}});for(var o in e.options)if(!!e.options.hasOwnProperty(o)){var a=this.modifyOption(e,o,e.options[o]);typeof a!="undefined"&&(e.options[o]=a)}},getEventProperties:function(e,s){var i={};return ot.forEach(function(n){typeof n.eventProperties=="function"&&Le(i,n.eventProperties.call(s[n.pluginName],e))}),i},modifyOption:function(e,s,i){var n;return ot.forEach(function(o){!e[o.pluginName]||o.optionListeners&&typeof o.optionListeners[s]=="function"&&(n=o.optionListeners[s].call(e[o.pluginName],i))}),n}};function Yh(t){var e=t.sortable,s=t.rootEl,i=t.name,n=t.targetEl,o=t.cloneEl,a=t.toEl,l=t.fromEl,f=t.oldIndex,d=t.newIndex,m=t.oldDraggableIndex,p=t.newDraggableIndex,y=t.originalEvent,_=t.putSortable,v=t.extraEventProperties;if(e=e||s&&s[ve],!!e){var x,j=e.options,q="on"+i.charAt(0).toUpperCase()+i.substr(1);window.CustomEvent&&!We&&!Vt?x=new CustomEvent(i,{bubbles:!0,cancelable:!0}):(x=document.createEvent("Event"),x.initEvent(i,!0,!0)),x.to=a||s,x.from=l||s,x.item=n||s,x.clone=o,x.oldIndex=f,x.newIndex=d,x.oldDraggableIndex=m,x.newDraggableIndex=p,x.originalEvent=y,x.pullMode=_?_.lastPutMode:void 0;var S=Oe(Oe({},v),Ft.getEventProperties(i,e));for(var k in S)x[k]=S[k];s&&s.dispatchEvent(x),j[q]&&j[q].call(e,x)}}var Kh=["evt"],ge=function(e,s){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},n=i.evt,o=Uh(i,Kh);Ft.pluginEvent.bind(M)(e,s,Oe({dragEl:E,parentEl:te,ghostEl:B,rootEl:$,nextEl:tt,lastDownEl:Kt,cloneEl:ee,cloneHidden:Ye,dragStarted:wt,putSortable:de,activeSortable:M.active,originalEvent:n,oldIndex:lt,oldDraggableIndex:St,newIndex:be,newDraggableIndex:Je,hideGhostForTarget:oi,unhideGhostForTarget:ii,cloneNowHidden:function(){Ye=!0},cloneNowShown:function(){Ye=!1},dispatchSortableEvent:function(l){pe({sortable:s,name:l,originalEvent:n})}},o))};function pe(t){Yh(Oe({putSortable:de,cloneEl:ee,targetEl:E,rootEl:$,oldIndex:lt,oldDraggableIndex:St,newIndex:be,newDraggableIndex:Je},t))}var E,te,B,$,tt,Kt,ee,Ye,lt,be,St,Je,Wt,de,at=!1,rn=!1,an=[],$e,Te,Mn,On,Ys,Ks,wt,it,Dt,Pt=!1,Xt=!1,Zt,he,qn=[],Kn=!1,ln=[],wn=typeof document!="undefined",Ht=Qo,Zs=Vt||We?"cssFloat":"float",Zh=wn&&!Go&&!Qo&&"draggable"in document.createElement("div"),ti=function(){if(!!wn){if(We)return!1;var t=document.createElement("x");return t.style.cssText="pointer-events:auto",t.style.pointerEvents==="auto"}}(),ni=function(e,s){var i=N(e),n=parseInt(i.width)-parseInt(i.paddingLeft)-parseInt(i.paddingRight)-parseInt(i.borderLeftWidth)-parseInt(i.borderRightWidth),o=ht(e,0,s),a=ht(e,1,s),l=o&&N(o),f=a&&N(a),d=l&&parseInt(l.marginLeft)+parseInt(l.marginRight)+ie(o).width,m=f&&parseInt(f.marginLeft)+parseInt(f.marginRight)+ie(a).width;if(i.display==="flex")return i.flexDirection==="column"||i.flexDirection==="column-reverse"?"vertical":"horizontal";if(i.display==="grid")return i.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(o&&l.float&&l.float!=="none"){var p=l.float==="left"?"left":"right";return a&&(f.clear==="both"||f.clear===p)?"vertical":"horizontal"}return o&&(l.display==="block"||l.display==="flex"||l.display==="table"||l.display==="grid"||d>=n&&i[Zs]==="none"||a&&i[Zs]==="none"&&d+m>n)?"vertical":"horizontal"},$h=function(e,s,i){var n=i?e.left:e.top,o=i?e.right:e.bottom,a=i?e.width:e.height,l=i?s.left:s.top,f=i?s.right:s.bottom,d=i?s.width:s.height;return n===l||o===f||n+a/2===l+d/2},em=function(e,s){var i;return an.some(function(n){var o=n[ve].options.emptyInsertThreshold;if(!(!o||us(n))){var a=ie(n),l=e>=a.left-o&&e<=a.right+o,f=s>=a.top-o&&s<=a.bottom+o;if(l&&f)return i=n}}),i},si=function(e){function s(o,a){return function(l,f,d,m){var p=l.options.group.name&&f.options.group.name&&l.options.group.name===f.options.group.name;if(o==null&&(a||p))return!0;if(o==null||o===!1)return!1;if(a&&o==="clone")return o;if(typeof o=="function")return s(o(l,f,d,m),a)(l,f,d,m);var y=(a?l:f).options.group.name;return o===!0||typeof o=="string"&&o===y||o.join&&o.indexOf(y)>-1}}var i={},n=e.group;(!n||Yt(n)!="object")&&(n={name:n}),i.name=n.name,i.checkPull=s(n.pull,!0),i.checkPut=s(n.put),i.revertClone=n.revertClone,e.group=i},oi=function(){!ti&&B&&N(B,"display","none")},ii=function(){!ti&&B&&N(B,"display","")};wn&&!Go&&document.addEventListener("click",function(t){if(rn)return t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation(),rn=!1,!1},!0);var et=function(e){if(E){e=e.touches?e.touches[0]:e;var s=em(e.clientX,e.clientY);if(s){var i={};for(var n in e)e.hasOwnProperty(n)&&(i[n]=e[n]);i.target=i.rootEl=s,i.preventDefault=void 0,i.stopPropagation=void 0,s[ve]._onDragOver(i)}}},tm=function(e){E&&E.parentNode[ve]._isOutsideThisEl(e.target)};function M(t,e){if(!(t&&t.nodeType&&t.nodeType===1))throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=Le({},e),t[ve]=this;var s={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return ni(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(a,l){a.setData("Text",l.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:M.supportPointer!==!1&&"PointerEvent"in window&&!kt,emptyInsertThreshold:5};Ft.initializePlugins(this,t,s);for(var i in s)!(i in e)&&(e[i]=s[i]);si(e);for(var n in this)n.charAt(0)==="_"&&typeof this[n]=="function"&&(this[n]=this[n].bind(this));this.nativeDraggable=e.forceFallback?!1:Zh,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?Q(t,"pointerdown",this._onTapStart):(Q(t,"mousedown",this._onTapStart),Q(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(Q(t,"dragover",this),Q(t,"dragenter",this)),an.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),Le(this,Qh())}M.prototype={constructor:M,_isOutsideThisEl:function(e){!this.el.contains(e)&&e!==this.el&&(it=null)},_getDirection:function(e,s){return typeof this.options.direction=="function"?this.options.direction.call(this,e,s,E):this.options.direction},_onTapStart:function(e){if(!!e.cancelable){var s=this,i=this.el,n=this.options,o=n.preventOnFilter,a=e.type,l=e.touches&&e.touches[0]||e.pointerType&&e.pointerType==="touch"&&e,f=(l||e).target,d=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||f,m=n.filter;if(cm(i),!E&&!(/mousedown|pointerdown/.test(a)&&e.button!==0||n.disabled)&&!d.isContentEditable&&!(!this.nativeDraggable&&kt&&f&&f.tagName.toUpperCase()==="SELECT")&&(f=Ie(f,n.draggable,i,!1),!(f&&f.animated)&&Kt!==f)){if(lt=we(f),St=we(f,n.draggable),typeof m=="function"){if(m.call(this,e,f,this)){pe({sortable:s,rootEl:d,name:"filter",targetEl:f,toEl:i,fromEl:i}),ge("filter",s,{evt:e}),o&&e.cancelable&&e.preventDefault();return}}else if(m&&(m=m.split(",").some(function(p){if(p=Ie(d,p.trim(),i,!1),p)return pe({sortable:s,rootEl:p,name:"filter",targetEl:f,fromEl:i,toEl:i}),ge("filter",s,{evt:e}),!0}),m)){o&&e.cancelable&&e.preventDefault();return}n.handle&&!Ie(d,n.handle,i,!1)||this._prepareDragStart(e,l,f)}}},_prepareDragStart:function(e,s,i){var n=this,o=n.el,a=n.options,l=o.ownerDocument,f;if(i&&!E&&i.parentNode===o){var d=ie(i);if($=o,E=i,te=E.parentNode,tt=E.nextSibling,Kt=i,Wt=a.group,M.dragged=E,$e={target:E,clientX:(s||e).clientX,clientY:(s||e).clientY},Ys=$e.clientX-d.left,Ks=$e.clientY-d.top,this._lastX=(s||e).clientX,this._lastY=(s||e).clientY,E.style["will-change"]="all",f=function(){if(ge("delayEnded",n,{evt:e}),M.eventCanceled){n._onDrop();return}n._disableDelayedDragEvents(),!zs&&n.nativeDraggable&&(E.draggable=!0),n._triggerDragStart(e,s),pe({sortable:n,name:"choose",originalEvent:e}),ye(E,a.chosenClass,!0)},a.ignore.split(",").forEach(function(m){Yo(E,m.trim(),Nn)}),Q(l,"dragover",et),Q(l,"mousemove",et),Q(l,"touchmove",et),Q(l,"mouseup",n._onDrop),Q(l,"touchend",n._onDrop),Q(l,"touchcancel",n._onDrop),zs&&this.nativeDraggable&&(this.options.touchStartThreshold=4,E.draggable=!0),ge("delayStart",this,{evt:e}),a.delay&&(!a.delayOnTouchOnly||s)&&(!this.nativeDraggable||!(Vt||We))){if(M.eventCanceled){this._onDrop();return}Q(l,"mouseup",n._disableDelayedDrag),Q(l,"touchend",n._disableDelayedDrag),Q(l,"touchcancel",n._disableDelayedDrag),Q(l,"mousemove",n._delayedDragTouchMoveHandler),Q(l,"touchmove",n._delayedDragTouchMoveHandler),a.supportPointer&&Q(l,"pointermove",n._delayedDragTouchMoveHandler),n._dragStartTimer=setTimeout(f,a.delay)}else f()}},_delayedDragTouchMoveHandler:function(e){var s=e.touches?e.touches[0]:e;Math.max(Math.abs(s.clientX-this._lastX),Math.abs(s.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){E&&Nn(E),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;H(e,"mouseup",this._disableDelayedDrag),H(e,"touchend",this._disableDelayedDrag),H(e,"touchcancel",this._disableDelayedDrag),H(e,"mousemove",this._delayedDragTouchMoveHandler),H(e,"touchmove",this._delayedDragTouchMoveHandler),H(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,s){s=s||e.pointerType=="touch"&&e,!this.nativeDraggable||s?this.options.supportPointer?Q(document,"pointermove",this._onTouchMove):s?Q(document,"touchmove",this._onTouchMove):Q(document,"mousemove",this._onTouchMove):(Q(E,"dragend",this),Q($,"dragstart",this._onDragStart));try{document.selection?$t(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch{}},_dragStarted:function(e,s){if(at=!1,$&&E){ge("dragStarted",this,{evt:s}),this.nativeDraggable&&Q(document,"dragover",tm);var i=this.options;!e&&ye(E,i.dragClass,!1),ye(E,i.ghostClass,!0),M.active=this,e&&this._appendGhost(),pe({sortable:this,name:"start",originalEvent:s})}else this._nulling()},_emulateDragOver:function(){if(Te){this._lastX=Te.clientX,this._lastY=Te.clientY,oi();for(var e=document.elementFromPoint(Te.clientX,Te.clientY),s=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(Te.clientX,Te.clientY),e!==s);)s=e;if(E.parentNode[ve]._isOutsideThisEl(e),s)do{if(s[ve]){var i=void 0;if(i=s[ve]._onDragOver({clientX:Te.clientX,clientY:Te.clientY,target:e,rootEl:s}),i&&!this.options.dragoverBubble)break}e=s}while(s=s.parentNode);ii()}},_onTouchMove:function(e){if($e){var s=this.options,i=s.fallbackTolerance,n=s.fallbackOffset,o=e.touches?e.touches[0]:e,a=B&&ct(B,!0),l=B&&a&&a.a,f=B&&a&&a.d,d=Ht&&he&&Js(he),m=(o.clientX-$e.clientX+n.x)/(l||1)+(d?d[0]-qn[0]:0)/(l||1),p=(o.clientY-$e.clientY+n.y)/(f||1)+(d?d[1]-qn[1]:0)/(f||1);if(!M.active&&!at){if(i&&Math.max(Math.abs(o.clientX-this._lastX),Math.abs(o.clientY-this._lastY))<i)return;this._onDragStart(e,!0)}if(B){a?(a.e+=m-(Mn||0),a.f+=p-(On||0)):a={a:1,b:0,c:0,d:1,e:m,f:p};var y="matrix(".concat(a.a,",").concat(a.b,",").concat(a.c,",").concat(a.d,",").concat(a.e,",").concat(a.f,")");N(B,"webkitTransform",y),N(B,"mozTransform",y),N(B,"msTransform",y),N(B,"transform",y),Mn=m,On=p,Te=o}e.cancelable&&e.preventDefault()}},_appendGhost:function(){if(!B){var e=this.options.fallbackOnBody?document.body:$,s=ie(E,!0,Ht,!0,e),i=this.options;if(Ht){for(he=e;N(he,"position")==="static"&&N(he,"transform")==="none"&&he!==document;)he=he.parentNode;he!==document.body&&he!==document.documentElement?(he===document&&(he=Me()),s.top+=he.scrollTop,s.left+=he.scrollLeft):he=Me(),qn=Js(he)}B=E.cloneNode(!0),ye(B,i.ghostClass,!1),ye(B,i.fallbackClass,!0),ye(B,i.dragClass,!0),N(B,"transition",""),N(B,"transform",""),N(B,"box-sizing","border-box"),N(B,"margin",0),N(B,"top",s.top),N(B,"left",s.left),N(B,"width",s.width),N(B,"height",s.height),N(B,"opacity","0.8"),N(B,"position",Ht?"absolute":"fixed"),N(B,"zIndex","100000"),N(B,"pointerEvents","none"),M.ghost=B,e.appendChild(B),N(B,"transform-origin",Ys/parseInt(B.style.width)*100+"% "+Ks/parseInt(B.style.height)*100+"%")}},_onDragStart:function(e,s){var i=this,n=e.dataTransfer,o=i.options;if(ge("dragStart",this,{evt:e}),M.eventCanceled){this._onDrop();return}ge("setupClone",this),M.eventCanceled||(ee=$o(E),ee.removeAttribute("id"),ee.draggable=!1,ee.style["will-change"]="",this._hideClone(),ye(ee,this.options.chosenClass,!1),M.clone=ee),i.cloneId=$t(function(){ge("clone",i),!M.eventCanceled&&(i.options.removeCloneOnHide||$.insertBefore(ee,E),i._hideClone(),pe({sortable:i,name:"clone"}))}),!s&&ye(E,o.dragClass,!0),s?(rn=!0,i._loopId=setInterval(i._emulateDragOver,50)):(H(document,"mouseup",i._onDrop),H(document,"touchend",i._onDrop),H(document,"touchcancel",i._onDrop),n&&(n.effectAllowed="move",o.setData&&o.setData.call(i,n,E)),Q(document,"drop",i),N(E,"transform","translateZ(0)")),at=!0,i._dragStartId=$t(i._dragStarted.bind(i,s,e)),Q(document,"selectstart",i),wt=!0,kt&&N(document.body,"user-select","none")},_onDragOver:function(e){var s=this.el,i=e.target,n,o,a,l=this.options,f=l.group,d=M.active,m=Wt===f,p=l.sort,y=de||d,_,v=this,x=!1;if(Kn)return;function j(Ve,xn){ge(Ve,v,Oe({evt:e,isOwner:m,axis:_?"vertical":"horizontal",revert:a,dragRect:n,targetRect:o,canSort:p,fromSortable:y,target:i,completed:S,onMove:function(_t,gt){return zt($,s,E,n,_t,ie(_t),e,gt)},changed:k},xn))}function q(){j("dragOverAnimationCapture"),v.captureAnimationState(),v!==y&&y.captureAnimationState()}function S(Ve){return j("dragOverCompleted",{insertion:Ve}),Ve&&(m?d._hideClone():d._showClone(v),v!==y&&(ye(E,de?de.options.ghostClass:d.options.ghostClass,!1),ye(E,l.ghostClass,!0)),de!==v&&v!==M.active?de=v:v===M.active&&de&&(de=null),y===v&&(v._ignoreWhileAnimating=i),v.animateAll(function(){j("dragOverAnimationComplete"),v._ignoreWhileAnimating=null}),v!==y&&(y.animateAll(),y._ignoreWhileAnimating=null)),(i===E&&!E.animated||i===s&&!i.animated)&&(it=null),!l.dragoverBubble&&!e.rootEl&&i!==document&&(E.parentNode[ve]._isOutsideThisEl(e.target),!Ve&&et(e)),!l.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),x=!0}function k(){be=we(E),Je=we(E,l.draggable),pe({sortable:v,name:"change",toEl:s,newIndex:be,newDraggableIndex:Je,originalEvent:e})}if(e.preventDefault!==void 0&&e.cancelable&&e.preventDefault(),i=Ie(i,l.draggable,s,!0),j("dragOver"),M.eventCanceled)return x;if(E.contains(e.target)||i.animated&&i.animatingX&&i.animatingY||v._ignoreWhileAnimating===i)return S(!1);if(rn=!1,d&&!l.disabled&&(m?p||(a=te!==$):de===this||(this.lastPutMode=Wt.checkPull(this,d,E,e))&&f.checkPut(this,d,E,e))){if(_=this._getDirection(e,i)==="vertical",n=ie(E),j("dragOverValid"),M.eventCanceled)return x;if(a)return te=$,q(),this._hideClone(),j("revert"),M.eventCanceled||(tt?$.insertBefore(E,tt):$.appendChild(E)),S(!0);var z=us(s,l.draggable);if(!z||im(e,_,this)&&!z.animated){if(z===E)return S(!1);if(z&&s===e.target&&(i=z),i&&(o=ie(i)),zt($,s,E,n,i,o,e,!!i)!==!1)return q(),z&&z.nextSibling?s.insertBefore(E,z.nextSibling):s.appendChild(E),te=s,k(),S(!0)}else if(z&&om(e,_,this)){var le=ht(s,0,l,!0);if(le===E)return S(!1);if(i=le,o=ie(i),zt($,s,E,n,i,o,e,!1)!==!1)return q(),s.insertBefore(E,le),te=s,k(),S(!0)}else if(i.parentNode===s){o=ie(i);var Y=0,K,Pe=E.parentNode!==s,ce=!$h(E.animated&&E.toRect||n,i.animated&&i.toRect||o,_),Xe=_?"top":"left",Ee=Gs(i,"top","top")||Gs(E,"top","top"),He=Ee?Ee.scrollTop:void 0;it!==i&&(K=o[Xe],Pt=!1,Xt=!ce&&l.invertSwap||Pe),Y=rm(e,i,o,_,ce?1:l.swapThreshold,l.invertedSwapThreshold==null?l.swapThreshold:l.invertedSwapThreshold,Xt,it===i);var fe;if(Y!==0){var qe=we(E);do qe-=Y,fe=te.children[qe];while(fe&&(N(fe,"display")==="none"||fe===B))}if(Y===0||fe===i)return S(!1);it=i,Dt=Y;var Ne=i.nextElementSibling,Ce=!1;Ce=Y===1;var Be=zt($,s,E,n,i,o,e,Ce);if(Be!==!1)return(Be===1||Be===-1)&&(Ce=Be===1),Kn=!0,setTimeout(sm,30),q(),Ce&&!Ne?s.appendChild(E):i.parentNode.insertBefore(E,Ce?Ne:i),Ee&&Zo(Ee,0,He-Ee.scrollTop),te=E.parentNode,K!==void 0&&!Xt&&(Zt=Math.abs(K-ie(i)[Xe])),k(),S(!0)}if(s.contains(E))return S(!1)}return!1},_ignoreWhileAnimating:null,_offMoveEvents:function(){H(document,"mousemove",this._onTouchMove),H(document,"touchmove",this._onTouchMove),H(document,"pointermove",this._onTouchMove),H(document,"dragover",et),H(document,"mousemove",et),H(document,"touchmove",et)},_offUpEvents:function(){var e=this.el.ownerDocument;H(e,"mouseup",this._onDrop),H(e,"touchend",this._onDrop),H(e,"pointerup",this._onDrop),H(e,"touchcancel",this._onDrop),H(document,"selectstart",this)},_onDrop:function(e){var s=this.el,i=this.options;if(be=we(E),Je=we(E,i.draggable),ge("drop",this,{evt:e}),te=E&&E.parentNode,be=we(E),Je=we(E,i.draggable),M.eventCanceled){this._nulling();return}at=!1,Xt=!1,Pt=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),Zn(this.cloneId),Zn(this._dragStartId),this.nativeDraggable&&(H(document,"drop",this),H(s,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),kt&&N(document.body,"user-select",""),N(E,"transform",""),e&&(wt&&(e.cancelable&&e.preventDefault(),!i.dropBubble&&e.stopPropagation()),B&&B.parentNode&&B.parentNode.removeChild(B),($===te||de&&de.lastPutMode!=="clone")&&ee&&ee.parentNode&&ee.parentNode.removeChild(ee),E&&(this.nativeDraggable&&H(E,"dragend",this),Nn(E),E.style["will-change"]="",wt&&!at&&ye(E,de?de.options.ghostClass:this.options.ghostClass,!1),ye(E,this.options.chosenClass,!1),pe({sortable:this,name:"unchoose",toEl:te,newIndex:null,newDraggableIndex:null,originalEvent:e}),$!==te?(be>=0&&(pe({rootEl:te,name:"add",toEl:te,fromEl:$,originalEvent:e}),pe({sortable:this,name:"remove",toEl:te,originalEvent:e}),pe({rootEl:te,name:"sort",toEl:te,fromEl:$,originalEvent:e}),pe({sortable:this,name:"sort",toEl:te,originalEvent:e})),de&&de.save()):be!==lt&&be>=0&&(pe({sortable:this,name:"update",toEl:te,originalEvent:e}),pe({sortable:this,name:"sort",toEl:te,originalEvent:e})),M.active&&((be==null||be===-1)&&(be=lt,Je=St),pe({sortable:this,name:"end",toEl:te,originalEvent:e}),this.save()))),this._nulling()},_nulling:function(){ge("nulling",this),$=E=te=B=tt=ee=Kt=Ye=$e=Te=wt=be=Je=lt=St=it=Dt=de=Wt=M.dragged=M.ghost=M.clone=M.active=null,ln.forEach(function(e){e.checked=!0}),ln.length=Mn=On=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":E&&(this._onDragOver(e),nm(e));break;case"selectstart":e.preventDefault();break}},toArray:function(){for(var e=[],s,i=this.el.children,n=0,o=i.length,a=this.options;n<o;n++)s=i[n],Ie(s,a.draggable,this.el,!1)&&e.push(s.getAttribute(a.dataIdAttr)||lm(s));return e},sort:function(e,s){var i={},n=this.el;this.toArray().forEach(function(o,a){var l=n.children[a];Ie(l,this.options.draggable,n,!1)&&(i[o]=l)},this),s&&this.captureAnimationState(),e.forEach(function(o){i[o]&&(n.removeChild(i[o]),n.appendChild(i[o]))}),s&&this.animateAll()},save:function(){var e=this.options.store;e&&e.set&&e.set(this)},closest:function(e,s){return Ie(e,s||this.options.draggable,this.el,!1)},option:function(e,s){var i=this.options;if(s===void 0)return i[e];var n=Ft.modifyOption(this,e,s);typeof n!="undefined"?i[e]=n:i[e]=s,e==="group"&&si(i)},destroy:function(){ge("destroy",this);var e=this.el;e[ve]=null,H(e,"mousedown",this._onTapStart),H(e,"touchstart",this._onTapStart),H(e,"pointerdown",this._onTapStart),this.nativeDraggable&&(H(e,"dragover",this),H(e,"dragenter",this)),Array.prototype.forEach.call(e.querySelectorAll("[draggable]"),function(s){s.removeAttribute("draggable")}),this._onDrop(),this._disableDelayedDragEvents(),an.splice(an.indexOf(this.el),1),this.el=e=null},_hideClone:function(){if(!Ye){if(ge("hideClone",this),M.eventCanceled)return;N(ee,"display","none"),this.options.removeCloneOnHide&&ee.parentNode&&ee.parentNode.removeChild(ee),Ye=!0}},_showClone:function(e){if(e.lastPutMode!=="clone"){this._hideClone();return}if(Ye){if(ge("showClone",this),M.eventCanceled)return;E.parentNode==$&&!this.options.group.revertClone?$.insertBefore(ee,E):tt?$.insertBefore(ee,tt):$.appendChild(ee),this.options.group.revertClone&&this.animate(E,ee),N(ee,"display",""),Ye=!1}}};function nm(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move"),t.cancelable&&t.preventDefault()}function zt(t,e,s,i,n,o,a,l){var f,d=t[ve],m=d.options.onMove,p;return window.CustomEvent&&!We&&!Vt?f=new CustomEvent("move",{bubbles:!0,cancelable:!0}):(f=document.createEvent("Event"),f.initEvent("move",!0,!0)),f.to=e,f.from=t,f.dragged=s,f.draggedRect=i,f.related=n||e,f.relatedRect=o||ie(e),f.willInsertAfter=l,f.originalEvent=a,t.dispatchEvent(f),m&&(p=m.call(d,f,a)),p}function Nn(t){t.draggable=!1}function sm(){Kn=!1}function om(t,e,s){var i=ie(ht(s.el,0,s.options,!0)),n=ei(s.el,s.options,B),o=10;return e?t.clientX<n.left-o||t.clientY<i.top&&t.clientX<i.right:t.clientY<n.top-o||t.clientY<i.bottom&&t.clientX<i.left}function im(t,e,s){var i=ie(us(s.el,s.options.draggable)),n=ei(s.el,s.options,B),o=10;return e?t.clientX>n.right+o||t.clientY>i.bottom&&t.clientX>i.left:t.clientY>n.bottom+o||t.clientX>i.right&&t.clientY>i.top}function rm(t,e,s,i,n,o,a,l){var f=i?t.clientY:t.clientX,d=i?s.height:s.width,m=i?s.top:s.left,p=i?s.bottom:s.right,y=!1;if(!a){if(l&&Zt<d*n){if(!Pt&&(Dt===1?f>m+d*o/2:f<p-d*o/2)&&(Pt=!0),Pt)y=!0;else if(Dt===1?f<m+Zt:f>p-Zt)return-Dt}else if(f>m+d*(1-n)/2&&f<p-d*(1-n)/2)return am(e)}return y=y||a,y&&(f<m+d*o/2||f>p-d*o/2)?f>m+d/2?1:-1:0}function am(t){return we(E)<we(t)?1:-1}function lm(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,s=e.length,i=0;s--;)i+=e.charCodeAt(s);return i.toString(36)}function cm(t){ln.length=0;for(var e=t.getElementsByTagName("input"),s=e.length;s--;){var i=e[s];i.checked&&ln.push(i)}}function $t(t){return setTimeout(t,0)}function Zn(t){return clearTimeout(t)}wn&&Q(document,"touchmove",function(t){(M.active||at)&&t.cancelable&&t.preventDefault()});M.utils={on:Q,off:H,css:N,find:Yo,is:function(e,s){return!!Ie(e,s,e,!1)},extend:Hh,throttle:Ko,closest:Ie,toggleClass:ye,clone:$o,index:we,nextTick:$t,cancelNextTick:Zn,detectDirection:ni,getChild:ht};M.get=function(t){return t[ve]};M.mount=function(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];e[0].constructor===Array&&(e=e[0]),e.forEach(function(i){if(!i.prototype||!i.prototype.constructor)throw"Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(i));i.utils&&(M.utils=Oe(Oe({},M.utils),i.utils)),Ft.mount(i)})};M.create=function(t,e){return new M(t,e)};M.version=Lh;var oe=[],xt,$n,es=!1,Bn,Vn,cn,Et;function dm(){function t(){this.defaults={scroll:!0,forceAutoScrollFallback:!1,scrollSensitivity:30,scrollSpeed:10,bubbleScroll:!0};for(var e in this)e.charAt(0)==="_"&&typeof this[e]=="function"&&(this[e]=this[e].bind(this))}return t.prototype={dragStarted:function(s){var i=s.originalEvent;this.sortable.nativeDraggable?Q(document,"dragover",this._handleAutoScroll):this.options.supportPointer?Q(document,"pointermove",this._handleFallbackAutoScroll):i.touches?Q(document,"touchmove",this._handleFallbackAutoScroll):Q(document,"mousemove",this._handleFallbackAutoScroll)},dragOverCompleted:function(s){var i=s.originalEvent;!this.options.dragOverBubble&&!i.rootEl&&this._handleAutoScroll(i)},drop:function(){this.sortable.nativeDraggable?H(document,"dragover",this._handleAutoScroll):(H(document,"pointermove",this._handleFallbackAutoScroll),H(document,"touchmove",this._handleFallbackAutoScroll),H(document,"mousemove",this._handleFallbackAutoScroll)),$s(),en(),zh()},nulling:function(){cn=$n=xt=es=Et=Bn=Vn=null,oe.length=0},_handleFallbackAutoScroll:function(s){this._handleAutoScroll(s,!0)},_handleAutoScroll:function(s,i){var n=this,o=(s.touches?s.touches[0]:s).clientX,a=(s.touches?s.touches[0]:s).clientY,l=document.elementFromPoint(o,a);if(cn=s,i||this.options.forceAutoScrollFallback||Vt||We||kt){Fn(s,this.options,l,i);var f=Ke(l,!0);es&&(!Et||o!==Bn||a!==Vn)&&(Et&&$s(),Et=setInterval(function(){var d=Ke(document.elementFromPoint(o,a),!0);d!==f&&(f=d,en()),Fn(s,n.options,d,i)},10),Bn=o,Vn=a)}else{if(!this.options.bubbleScroll||Ke(l,!0)===Me()){en();return}Fn(s,this.options,Ke(l,!1),!1)}}},Le(t,{pluginName:"scroll",initializeByDefault:!0})}function en(){oe.forEach(function(t){clearInterval(t.pid)}),oe=[]}function $s(){clearInterval(Et)}var Fn=Ko(function(t,e,s,i){if(!!e.scroll){var n=(t.touches?t.touches[0]:t).clientX,o=(t.touches?t.touches[0]:t).clientY,a=e.scrollSensitivity,l=e.scrollSpeed,f=Me(),d=!1,m;$n!==s&&($n=s,en(),xt=e.scroll,m=e.scrollFn,xt===!0&&(xt=Ke(s,!0)));var p=0,y=xt;do{var _=y,v=ie(_),x=v.top,j=v.bottom,q=v.left,S=v.right,k=v.width,z=v.height,le=void 0,Y=void 0,K=_.scrollWidth,Pe=_.scrollHeight,ce=N(_),Xe=_.scrollLeft,Ee=_.scrollTop;_===f?(le=k<K&&(ce.overflowX==="auto"||ce.overflowX==="scroll"||ce.overflowX==="visible"),Y=z<Pe&&(ce.overflowY==="auto"||ce.overflowY==="scroll"||ce.overflowY==="visible")):(le=k<K&&(ce.overflowX==="auto"||ce.overflowX==="scroll"),Y=z<Pe&&(ce.overflowY==="auto"||ce.overflowY==="scroll"));var He=le&&(Math.abs(S-n)<=a&&Xe+k<K)-(Math.abs(q-n)<=a&&!!Xe),fe=Y&&(Math.abs(j-o)<=a&&Ee+z<Pe)-(Math.abs(x-o)<=a&&!!Ee);if(!oe[p])for(var qe=0;qe<=p;qe++)oe[qe]||(oe[qe]={});(oe[p].vx!=He||oe[p].vy!=fe||oe[p].el!==_)&&(oe[p].el=_,oe[p].vx=He,oe[p].vy=fe,clearInterval(oe[p].pid),(He!=0||fe!=0)&&(d=!0,oe[p].pid=setInterval(function(){i&&this.layer===0&&M.active._onTouchMove(cn);var Ne=oe[this.layer].vy?oe[this.layer].vy*l:0,Ce=oe[this.layer].vx?oe[this.layer].vx*l:0;typeof m=="function"&&m.call(M.dragged.parentNode[ve],Ce,Ne,t,cn,oe[this.layer].el)!=="continue"||Zo(oe[this.layer].el,Ce,Ne)}.bind({layer:p}),24))),p++}while(e.bubbleScroll&&y!==f&&(y=Ke(y,!1)));es=d}},30),ri=function(e){var s=e.originalEvent,i=e.putSortable,n=e.dragEl,o=e.activeSortable,a=e.dispatchSortableEvent,l=e.hideGhostForTarget,f=e.unhideGhostForTarget;if(!!s){var d=i||o;l();var m=s.changedTouches&&s.changedTouches.length?s.changedTouches[0]:s,p=document.elementFromPoint(m.clientX,m.clientY);f(),d&&!d.el.contains(p)&&(a("spill"),this.onSpill({dragEl:n,putSortable:i}))}};function hs(){}hs.prototype={startIndex:null,dragStart:function(e){var s=e.oldDraggableIndex;this.startIndex=s},onSpill:function(e){var s=e.dragEl,i=e.putSortable;this.sortable.captureAnimationState(),i&&i.captureAnimationState();var n=ht(this.sortable.el,this.startIndex,this.options);n?this.sortable.el.insertBefore(s,n):this.sortable.el.appendChild(s),this.sortable.animateAll(),i&&i.animateAll()},drop:ri};Le(hs,{pluginName:"revertOnSpill"});function ms(){}ms.prototype={onSpill:function(e){var s=e.dragEl,i=e.putSortable,n=i||this.sortable;n.captureAnimationState(),s.parentNode&&s.parentNode.removeChild(s),n.animateAll()},drop:ri};Le(ms,{pluginName:"removeOnSpill"});M.mount(new dm);M.mount(ms,hs);const um={name:"QuoteViewDetail",components:{Card:Ze,QuoteNavBar:ih,EditItemModal:Th,RemoveModal:qt,ArticleModal:zo},data(){return{selectedItem:null,selectedInvoiceId:null,editItemsModal:!1,no_items:!0,loading:!0,loading_add:!1,quote:[],quoteItems:[],newItem:{loading_del:!1,item_ref:"",item_name:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},vatRate:0,settings:[],list_vats:[],client_detail:[],client_email:null,client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},showArticlesModal:!1,articles:[],categories:[],showDropdown:!1,refs:[],showDropdownRef:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isQuoteExpired(){const t=new Date().getTime(),e=this.quote.due_date?new Date(this.quote.due_date).getTime():null;return e&&e<t},totalAmountWithoutDiscount(){const t=this.quoteItems.reduce((e,s)=>{const i=s.quantity*s.unit_price;return e+i},0);return this.formatCurrency(t)},totalAmount(){const t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.quoteItems.reduce((i,n)=>i+parseFloat(n.total_amount),0)*this.quote.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)},signatureImageUrl(){const t="/wp-json/my-easy-compta/v1/signature-image/",e=myEasyComptaAdmin.nonce;return`${t}${this.quote.file_sign}?_wpnonce=${e}`}},methods:{getUniqueVATRates(){const t=new Set;return this.quoteItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.quoteItems.forEach(s=>{if(s.vat_rate===t){const i=s.quantity*s.unit_price,n=i*s.discount/100;e+=(i-n)*t/100}}),this.formatCurrency(e)},calculateTotalAmountWithVAT(){let t=this.quoteItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.formatCurrency(t)},fetchQuote(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.quote=t,this.fetchClientInfo(t.client_id)):console.error("Quote not found")}).catch(t=>{console.error("Error fetching quote:",t),this.loading=!1})},fetchClientInfo(t){fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.client_email=e.email;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.quoteItems=[],this.loading=!1,this.no_items=!0):(this.quoteItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var i=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;i=s+n}else i=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(i)},calculateTotalWithVat(t,e,s,i){const n=t*e,o=n*i/100,a=n-o,l=a*s/100,f=a+l;return this.formatCurrency(f)},calculateTotal(t,e,s){const i=t*e,n=i*s/100,a=i-n;return this.formatCurrency(a)},submitItems(){this.updateTotal();const t={...this.newItem,quote_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/quotes/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.selectedInvoiceId=e,modal_item_remove.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.quoteItems.find(i=>i.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/quotes/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({quote_id:e})}).then(i=>i.json()).then(i=>{i.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(i.message,"alert-error"),console.error("Error removing item:",i.message),s.loading_del=!1)}).catch(i=>{this.showToast(i.message,"alert-error"),console.error("Error removing item:",i),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/quotes/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,i){const o=t*e*i/100,a=o*s/100,l=o+a;return this.formatCurrency(l)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.quoteItems[t.oldIndex];this.quoteItems.splice(t.oldIndex,1),this.quoteItems.splice(t.newIndex,0,e);const s=this.quoteItems.map(i=>i.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/quotes/update-quote-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},ShowModalArticles(){this.showArticlesModal=!0,modal_articles.showModal()},applySelectedArticle(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description||"",this.newItem.unit_price=t.unit_price||0},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}const t=document.getElementById("loader_articles");t.classList.remove("hidden"),fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.articles=e}).catch(e=>console.error("Error fetching articles:",e)).finally(()=>{t.classList.add("hidden")})},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loading=!0,this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:i}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=i,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1,this.loading=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1,this.loading=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchQuote(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");M.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},hm={class:"pt-2 pr-4"},mm={key:1,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},fm=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),pm=[fm],_m={key:2},gm={role:"alert",class:"alert alert-warning"},ym=r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),bm={key:0,class:"relative"},vm={class:"ecwp-watermark"},wm={class:"grid grid-cols-2"},xm={class:"md:col-span-1"},Em=["src"],Cm={class:"md:col-span-1 text-right"},Tm={class:"text-lg font-semibold"},Im={key:0,class:"badge badge-warning text-white"},km={key:1,class:"badge badge-secondary text-white"},Am={key:2,class:"badge badge-success text-white"},Sm={key:3,class:"badge badge-error text-white"},Dm={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},Pm=r("br",null,null,-1),jm=r("br",null,null,-1),Rm=r("br",null,null,-1),Mm=["href"],Om=r("br",null,null,-1),qm=r("br",null,null,-1),Nm=r("br",null,null,-1),Bm=["href"],Vm=r("br",null,null,-1),Fm=["href"],Um={class:"table mt-8"},Lm=r("th",null,null,-1),Wm={width:"5%"},Xm={width:"19%"},Hm={width:"21%"},zm={width:"10%",class:"text-center"},Qm={width:"8%",class:"text-center"},Gm={key:0,width:"5%",class:"text-center"},Jm={key:1,width:"5%"},Ym={width:"10%",class:"text-center"},Km={width:"10%",class:"text-right"},Zm=r("th",{width:"18%",class:"text-right inv-actions"},null,-1),$m=r("td",{class:"draggable-item drag-handle px-2"},[r("i",{class:"fas fa-sort"})],-1),ef={key:0,class:"badge badge-ghost badge-xs"},tf=["innerHTML"],nf={class:"text-center"},sf={class:"text-center"},of={key:0},rf={key:1},af={key:0,class:"text-center"},lf={key:1},cf={key:2,class:"text-center"},df=r("br",null,null,-1),uf={key:3,class:"text-center"},hf=r("br",null,null,-1),mf={class:"text-right"},ff={key:0},pf={key:1},_f=["data-tip"],gf=["onClick"],yf=r("i",{class:"far fa-edit"},null,-1),bf=[yf],vf=["data-tip"],wf=["onClick"],xf={key:0,class:"far fa-trash-alt"},Ef={key:1,class:"loading loading-spinner loading-xs"},Cf={key:0},Tf={class:"align-top px-2"},If=r("i",{class:"fas fa-list-ul"},null,-1),kf=[If],Af={class:"align-top px-2"},Sf={class:"flex items-center border rounded-md relative"},Df=["placeholder"],Pf={key:0,class:"autocomplete-dropdown bg-base-300"},jf=["onClick","innerHTML"],Rf={class:"align-top px-2"},Mf=r("option",{disabled:"",selected:""},"Type",-1),Of=["value"],qf={class:"flex items-center border rounded-md relative"},Nf=r("span",{id:"loader_articles",class:"loading loading-spinner loading-xs absolute right-2 hidden"},null,-1),Bf=["placeholder"],Vf={key:0,class:"autocomplete-dropdown bg-base-300"},Ff=["onClick","innerHTML"],Uf={class:"align-top"},Lf={class:"flex items-center rounded-md"},Wf=["placeholder"],Xf={class:"align-top"},Hf={class:"flex items-center border rounded-lg"},zf={class:"inline-flex"},Qf=["placeholder"],Gf={class:"align-top"},Jf={class:"flex items-center border rounded-md"},Yf=["placeholder"],Kf={key:0,class:"align-top"},Zf=["value"],$f={key:1,class:"align-top"},ep={class:"align-top"},tp={class:"flex items-center border rounded-md"},np=["placeholder"],sp=r("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),op={key:2,class:"text-right"},ip={key:3,class:"text-right"},rp=["data-tip"],ap={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},lp={key:0,class:"fa fa-plus"},cp={key:1,class:"loading loading-spinner loading-xs"},dp={colspan:"8",class:"text-right no-border"},up={class:"text-right"},hp={key:0,class:"line-through"},mp=r("td",null,null,-1),fp={colspan:"8",class:"text-right no-border"},pp={class:"text-right"},_p=r("td",null,null,-1),gp={colspan:"8",class:"text-right no-border font-bold text-xl"},yp={class:"text-right no-border font-bold text-xl"},bp=r("td",null,null,-1),vp={key:2},wp={colspan:"8",class:"text-right no-border"},xp={class:"text-right no-border"},Ep={key:3},Cp={colspan:"8",class:"text-right no-border"},Tp={class:"text-right no-border font-bold text-xl"},Ip={key:1,class:"relative"},kp={class:"flex justify-end mt-4"},Ap={class:"border-2 border-slate-300 max-w-md"},Sp=["src"];function Dp(t,e,s,i,n,o){const a=O("QuoteNavBar"),l=O("remove-modal"),f=O("article-modal"),d=O("edit-item-modal"),m=O("Card");return u(),h("div",hm,[P(a,{quoteInfo:n.quote,emailActive:n.settings.easy_compta_email_addon_active,advanceActive:n.settings.easy_compta_advance_addon_active,currency:n.default_currency_symbol,noItems:n.no_items},null,8,["quoteInfo","emailActive","advanceActive","currency","noItems"]),n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),P(l,{"modal-id":"modal_item_remove","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=p=>this.removeItem(n.selectedItem,n.selectedInvoiceId)),onCancel:e[1]||(e[1]=p=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(f,{"show-modal":n.showArticlesModal,"modal-id":"modal_articles","modal-title":o.translations.select,onSelectArticle:o.applySelectedArticle,onClose:e[2]||(e[2]=p=>n.showArticlesModal=!1)},null,8,["show-modal","modal-title","onSelectArticle"]),n.loading?(u(),h("div",mm,pm)):g("",!0),o.isQuoteExpired&&n.quote.status=="pending"?(u(),h("div",_m,[r("div",gm,[ym,r("span",null,c(o.translations.quote_expired),1)])])):g("",!0),P(m,{topMargin:"mt-8",id:"quote-content"},{default:me(()=>[n.settings.easy_compta_signature_addon_active&&n.quote.signed==1?(u(),h("div",bm,[r("span",vm,c(o.translations.signed),1)])):g("",!0),r("div",wm,[r("div",xm,[r("div",null,[r("img",{src:n.settings.logo_url,style:no({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,Em)])]),r("div",Cm,[r("p",Tm,c(n.quote.quote_number),1),r("div",null,[C(c(o.translations.created_at)+": ",1),r("strong",null,c(n.quote.created_at),1)]),r("div",null,[C(c(o.translations.due_date)+": ",1),r("strong",null,c(n.quote.due_date),1)]),r("div",null,[C(c(o.translations.provisional_date)+": ",1),r("strong",null,c(n.quote.provisional_start_date),1)]),r("div",null,[C(c(o.translations.status)+": ",1),n.quote.status=="draft"?(u(),h("span",Im,c(o.translations.draft),1)):g("",!0),n.quote.status=="pending"?(u(),h("span",km,c(o.translations.pending),1)):g("",!0),n.quote.status=="approved"?(u(),h("span",Am,c(o.translations.approved),1)):g("",!0),n.quote.status=="rejected"?(u(),h("span",Sm,c(o.translations.rejected),1)):g("",!0)])])]),r("div",Dm,[r("div",null,[r("strong",null,c(o.translations.bill_to)+":",1),r("h4",null,[r("strong",null,c(n.client_detail.company_name),1)]),r("p",null,[C(c(n.client_detail.address),1),Pm,C(" "+c(n.client_detail.postal_code)+", "+c(n.client_detail.city)+" ",1),jm,C(" "+c(n.client_detail.country),1),Rm,n.client_detail.phone?(u(),h("a",{key:0,href:"tel:"+n.client_detail.phone},c(n.client_detail.phone),9,Mm)):g("",!0)])]),r("div",null,[r("strong",null,c(o.translations.received_from)+":",1),r("h4",null,[r("strong",null,c(n.settings.company_name),1)]),r("p",null,[C(c(n.settings.company_address),1),Om,C(" "+c(n.settings.postal_code)+", "+c(n.settings.city)+" ",1),qm,C(" "+c(n.settings.country),1),Nm,n.settings.company_phone?(u(),h("a",{key:0,href:"tel:"+n.settings.company_phone},c(n.settings.company_phone),9,Bm)):g("",!0),Vm,n.settings.mobile_phone?(u(),h("a",{key:1,href:"tel:"+n.settings.mobile_phone},c(n.settings.mobile_phone),9,Fm)):g("",!0)])])]),P(d,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[3]||(e[3]=p=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),r("form",{onSubmit:e[24]||(e[24]=J((...p)=>o.submitItems&&o.submitItems(...p),["prevent"]))},[r("table",Um,[r("thead",null,[r("tr",null,[Lm,r("th",Wm,c(o.translations.item_ref),1),r("th",Xm,c(o.translations.item_name),1),r("th",Hm,c(o.translations.description),1),r("th",zm,c(o.translations.quantity),1),r("th",Qm,c(o.translations.unit_price),1),n.settings.vat_active==1?(u(),h("th",Gm,c(o.translations.vat),1)):(u(),h("th",Jm)),r("th",Ym,c(o.translations.discount),1),r("th",Km,c(o.translations.total),1),Zm])]),r("tbody",null,[(u(!0),h(F,null,U(n.quoteItems,(p,y)=>(u(),h("tr",{key:p.id||y},[$m,r("td",null,c(p.item_ref),1),r("td",null,[p.category_name?(u(),h("div",ef,c(p.category_name),1)):g("",!0),r("div",null,c(p.item_name),1)]),r("td",{innerHTML:o.nl2br(p.item_description)},null,8,tf),r("td",nf,c(p.quantity),1),r("td",sf,[C(c(p.unit_price),1),n.default_currency_symbol==n.client_currency?(u(),h("span",of,c(n.default_currency_symbol),1)):(u(),h("span",rf,c(n.client_currency),1))]),n.settings.vat_active==1?(u(),h("td",af,c(p.vat_rate)+"% ",1)):(u(),h("td",lf)),n.settings.vat_active==1?(u(),h("td",cf,[C(c(p.discount)+"% ",1),df,C(" "+c(o.calculateDiscountAmountWithVAT(p.quantity,p.unit_price,p.vat_rate,p.discount)),1)])):(u(),h("td",uf,[C(c(p.discount)+"% ",1),hf,C(" "+c(o.calculateDiscountAmount(p.quantity,p.unit_price,p.discount)),1)])),r("td",mf,[C(c(p.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(u(),h("span",ff,c(n.default_currency_symbol),1)):(u(),h("span",pf,c(n.client_currency),1))]),r("td",null,[n.quote.status=="draft"||n.quote.status=="pending"?(u(),h("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[r("button",{onClick:J(_=>o.editItem(p.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},bf,8,gf)],8,_f)):g("",!0),n.quote.status=="draft"||n.quote.status=="pending"?(u(),h("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:J(_=>o.confirmremoveItem(p.id,n.quote.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[p.loading_del?g("",!0):(u(),h("i",xf)),p.loading_del?(u(),h("span",Ef)):g("",!0)],8,wf)],8,vf)):g("",!0)])]))),128)),n.quote.status=="draft"||n.quote.status=="pending"?(u(),h("tr",Cf,[r("td",Tf,[r("span",{class:"cursor-pointer",onClick:e[4]||(e[4]=J((...p)=>o.ShowModalArticles&&o.ShowModalArticles(...p),["prevent"]))},kf)]),r("td",Af,[r("div",Sf,[D(r("input",{type:"text","onUpdate:modelValue":e[5]||(e[5]=p=>n.newItem.item_ref=p),onInput:e[6]||(e[6]=(...p)=>o.fetchRefs&&o.fetchRefs(...p)),onFocus:e[7]||(e[7]=p=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,Df),[[W,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(u(),h("ul",Pf,[(u(!0),h(F,null,U(n.refs,p=>(u(),h("li",{key:p.ref,onClick:y=>o.selectItem(p),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(p.ref)},null,8,jf))),128))])):g("",!0)])]),r("td",Rf,[D(r("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[8]||(e[8]=p=>n.newItem.item_category=p)},[Mf,(u(!0),h(F,null,U(n.categories,p=>(u(),h("option",{key:p.id,value:p.id},c(p.name),9,Of))),128))],512),[[ue,n.newItem.item_category]]),r("div",qf,[Nf,D(r("input",{type:"text","onUpdate:modelValue":e[9]||(e[9]=p=>n.newItem.item_name=p),onInput:e[10]||(e[10]=(...p)=>o.fetchArticles&&o.fetchArticles(...p)),onFocus:e[11]||(e[11]=p=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,Bf),[[W,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(u(),h("ul",Vf,[(u(!0),h(F,null,U(n.articles,p=>(u(),h("li",{key:p.name,onClick:y=>o.selectItem(p),class:"autocomplete-item hover:bg-base-200",innerHTML:o.highlightMatch(p.name)},null,8,Ff))),128))])):g("",!0)])]),r("td",Uf,[r("div",Lf,[D(r("textarea",{"onUpdate:modelValue":e[12]||(e[12]=p=>n.newItem.item_description=p),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[13]||(e[13]=p=>o.resize()),ref:"textarea"},null,40,Wf),[[W,n.newItem.item_description]])])]),r("td",Xf,[r("div",Hf,[r("div",zf,[r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[14]||(e[14]=(...p)=>o.decrease&&o.decrease(...p))}," - "),D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[15]||(e[15]=p=>n.newItem.quantity=p),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[16]||(e[16]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,Qf),[[W,n.newItem.quantity]]),r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[17]||(e[17]=(...p)=>o.increase&&o.increase(...p))}," + ")])])]),r("td",Gf,[r("div",Jf,[D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[18]||(e[18]=p=>n.newItem.unit_price=p),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[19]||(e[19]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,Yf),[[W,n.newItem.unit_price]])])]),n.settings.vat_active==1?(u(),h("td",Kf,[D(r("select",{"onUpdate:modelValue":e[20]||(e[20]=p=>n.newItem.vat_rate=p),onChange:e[21]||(e[21]=(...p)=>o.updateTotal&&o.updateTotal(...p)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(u(!0),h(F,null,U(n.list_vats,p=>(u(),h("option",{key:p,value:p.rate},c(p.rate)+"% ",9,Zf))),128))],544),[[ue,n.newItem.vat_rate]])])):(u(),h("td",$f)),r("td",ep,[r("div",tp,[D(r("input",{type:"number",min:"0",max:"100","onUpdate:modelValue":e[22]||(e[22]=p=>n.newItem.discount=p),placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[23]||(e[23]=(...p)=>o.updateTotal&&o.updateTotal(...p))},null,40,np),[[W,n.newItem.discount]]),sp])]),n.settings.vat_active==1?(u(),h("td",op,c(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(u(),h("td",ip,c(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),r("td",null,[r("span",{class:"lg:tooltip","data-tip":o.translations.add},[r("button",ap,[n.loading_add?g("",!0):(u(),h("i",lp)),n.loading_add?(u(),h("span",cp)):g("",!0)])],8,rp)])])):g("",!0),r("tr",null,[r("td",dp,[r("strong",null,c(o.translations.subtotal),1)]),r("td",up,[o.totalAmount!==o.totalAmountWithoutDiscount?(u(),h("span",hp,c(o.totalAmountWithoutDiscount),1)):g("",!0),C(" "+c(o.totalAmount),1)]),mp]),n.settings.vat_active==1?(u(!0),h(F,{key:1},U(o.getUniqueVATRates(),(p,y)=>(u(),h("tr",{key:y},[r("td",fp,[r("strong",null,c(o.translations.tax)+" ("+c(p)+"%) ",1)]),r("td",pp,c(o.calculateVATForRate(p)),1),_p]))),128)):g("",!0),r("tr",null,[r("td",gp,[r("strong",null,c(o.translations.total),1)]),r("td",yp,c(o.calculateTotalAmountWithVAT()),1),bp]),n.client_currency!=n.default_currency_symbol?(u(),h("tr",vp,[r("td",wp,[r("strong",null,c(o.translations.exchange_rate),1)]),r("td",xp,c(n.quote.exchange_rate),1)])):g("",!0),n.client_currency!=n.default_currency_symbol?(u(),h("tr",Ep,[r("td",Cp,[r("strong",null,c(o.translations.total)+" "+c(n.default_currency_symbol),1)]),r("td",Tp,c(o.totalAmountDefaultCurrency)+c(n.default_currency_symbol),1)])):g("",!0)])])],32),n.settings.easy_compta_signature_addon_active&&n.quote.signed==1&&n.quote.file_sign?(u(),h("div",Ip,[r("div",kp,[r("span",Ap,[r("img",{src:o.signatureImageUrl,alt:"Signature"},null,8,Sp)])])])):g("",!0)]),_:1})])}var Pp=ne(um,[["render",Dp]]);const jp={name:"QuoteNew",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt,AddClientModal:jo},data(){return{clientOptions:[],clients:[],quote:{number:"",due_date:"",provisional_start_date:"",client_id:"",status:""},showError:!1,loading:!1,loadingBtn:!1,settings:[],last_quote_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{AddNew(){modal_clients.showModal()},cancelAction(){this.$router.push("/quotes")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},customLabel(t){return t.text},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.quote_prefix}_${String(this.settings.last_quote_id).padStart(4,"0")}`;this.quote.number=s}else{const e=await t.json()}}catch{this.loading=!1}},submitQuote(){if(!this.quote.due_date||!this.quote.provisional_start_date||!this.quote.client_id||!this.quote.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/quotes",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.quote)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"QuoteViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting quote:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting quote:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},Rp={class:"pt-2 pr-4"},Mp={class:"flex justify-between items-center mb-4"},Op={class:"card-title"},qp=r("div",{class:"divider mt-2"},null,-1),Np={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},Bp={class:"grid grid-cols-3 gap-4"},Vp={class:"ecwp-group form-group mb-4"},Fp={for:"quoteNumber",class:"ecwp-label"},Up={class:"ecwp-group form-group mb-4"},Lp={for:"quoteDate",class:"ecwp-label"},Wp={class:"ecwp-group form-group mb-4"},Xp={for:"quoteDatePr",class:"ecwp-label"},Hp={class:"grid grid-cols-2 gap-4"},zp={class:"mb-4"},Qp={class:"flex gap-2 items-end"},Gp=r("i",{class:"fas fa-plus"},null,-1),Jp=[Gp],Yp={class:"ecwp-group form-group w-full"},Kp={for:"client",class:"ecwp-label"},Zp={class:"ecwp-group form-group mb-4"},$p={for:"status",class:"ecwp-label"},e_={value:"draft",selected:""},t_={value:"pending"},n_={value:"approved"},s_={value:"rejected"},o_={class:"flex justify-between"},i_=["disabled"],r_={key:0,class:"loading loading-spinner loading-sm"};function a_(t,e,s,i,n,o){const a=O("VueDatePicker"),l=O("model-select"),f=O("Card"),d=O("AddClientModal");return u(),h("div",Rp,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_quote_new"},{default:me(()=>[r("div",Mp,[r("h2",Op,c(o.translations.new_quote),1)]),qp,n.loading?(u(),h("div",Np)):g("",!0),r("form",{onSubmit:e[7]||(e[7]=J((...m)=>o.submitQuote&&o.submitQuote(...m),["prevent"]))},[r("div",Bp,[r("div",Vp,[r("label",Fp,c(o.translations.quote_number),1),D(r("input",{type:"text",id:"quoteNumber","onUpdate:modelValue":e[0]||(e[0]=m=>n.quote.number=m),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[W,n.quote.number]])]),r("div",Up,[r("label",Lp,c(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.due_date&&n.showError?"input-error":""]]),id:"quoteDate",modelValue:n.quote.due_date,"onUpdate:modelValue":e[1]||(e[1]=m=>n.quote.due_date=m),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),r("div",Wp,[r("label",Xp,c(o.translations.provisional_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.quote.provisional_start_date&&n.showError?"input-error":""]]),id:"quoteDatePr",modelValue:n.quote.provisional_start_date,"onUpdate:modelValue":e[2]||(e[2]=m=>n.quote.provisional_start_date=m),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])])]),r("div",Hp,[r("div",zp,[r("div",Qp,[r("button",{type:"button",class:"btn btn-primary",onClick:e[3]||(e[3]=(...m)=>o.AddNew&&o.AddNew(...m))},Jp),r("div",Yp,[r("label",Kp,c(o.translations.company_name),1),P(l,{modelValue:n.quote.client_id,"onUpdate:modelValue":e[4]||(e[4]=m=>n.quote.client_id=m),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.quote.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])])])]),r("div",Zp,[r("label",$p,c(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[5]||(e[5]=m=>n.quote.status=m),class:I(["ecwp-input select select-bordered w-full",[!n.quote.status&&n.showError?"input-error":""]])},[r("option",e_,c(o.translations.draft),1),r("option",t_,c(o.translations.pending),1),r("option",n_,c(o.translations.approved),1),r("option",s_,c(o.translations.rejected),1)],2),[[ue,n.quote.status]])])]),r("div",o_,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[6]||(e[6]=(...m)=>o.cancelAction&&o.cancelAction(...m))},c(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.submit)+" ",1),n.loadingBtn?(u(),h("span",r_)):g("",!0)],8,i_)])],32)]),_:1}),P(d,{onClientAdded:o.fetchClients},null,8,["onClientAdded"])])}var l_=ne(jp,[["render",a_]]);const c_={name:"InvoicesList",components:{Card:Ze,RemoveModal:qt},data(){return{invoices:[],filteredInvoices:[],filters:{invoice_number:"",client:"",status:"",total_amount:"",due_date:"",created_at:""},showInvoiceDetailsModal:!1,editInvoiceModal:!1,selectedInvoice:null,currentPage:1,totalCount:0,totalPages:1,paginationButtons:[],loading:!0,loadingPrice:!0,loadingModal:!1,skeletonRows:5,perPage:10,perPageOptions:[5,10,20,50],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",settings:{},toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},created(){this.fetchInvoices(),this.fetchClients(),this.loadSettings()},methods:{fetchInvoices(t=1){this.loading=!0;const{perPage:e}=this;fetch(`/wp-json/my-easy-compta/v1/invoices?page=${t}&per_page=${e}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(s=>s.json()).then(s=>{this.invoices=s.invoices,this.totalCount=s.total_count,this.totalPages=s.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(s=>{console.error("Error fetching invoices:",s)}).finally(()=>{this.loading=!1})},fetchInvoicesWithFilters(t=1){this.loading=!0;const{perPage:e,filters:s}=this,i=new URLSearchParams({page:t,per_page:e,...s}).toString();fetch(`/wp-json/my-easy-compta/v1/invoices?${i}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(n=>n.json()).then(n=>{this.invoices=n.invoices,this.totalCount=n.total_count,this.totalPages=n.total_pages,this.currentPage=t,this.perPage=e,this.generatePaginationButtons()}).catch(n=>{console.error("Error fetching invoices with filters:",n)}).finally(()=>{this.loading=!1})},fetchClients(){fetch("/wp-json/my-easy-compta/v1/clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients}).catch(t=>{console.error("Error fetching clients:",t)})},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},calculateVAT(t){return so(t,this.default_vat.rate)},calculateWithoutVAT(t){return oo(t)},generatePaginationButtons(){this.paginationButtons=io(this.currentPage,this.totalPages)},goToPage(t){t!=="..."&&this.fetchInvoicesWithFilters(t)},perPageChanged(){this.fetchInvoicesWithFilters()},formatAmount(t,e){return ro(t,e,this.settings.currency_position)},showToast(t,e){ao(this.toast,t,e)},confirmDeleteInvoice(t){this.selectedInvoice=t,modal_invoice_remove.showModal(),this.showRemoveModal=!0},deleteInvoice(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/delete/${t}`,{method:"DELETE",headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{e.success?(this.fetchInvoices(),this.showToast(e.message,"alert-success")):(this.showToast(e.message,"alert-error"),console.error("Error deleting invoice:",e.statusText))}).catch(e=>{console.log(e.message);const s=e&&e.message?e.message:"Error deleting client";s==="This client cannot be deleted because it has associated data."?this.showToast(s,"alert-error"):console.error("Error deleting client:",e)})}},computed:{skeletonItems(){return Array.from({length:5},(t,e)=>e)},totalPages(){return Math.ceil(this.totalCount/this.perPage)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}}},d_={class:"pt-2 pr-4"},u_={class:"flex justify-between items-center"},h_={class:"card-title"},m_={class:"btn btn-primary rounded-full"},f_=r("i",{class:"fas fa-plus-circle"},null,-1),p_={key:0,class:"ms-2"},__={class:"btn btn-outline btn-accent rounded-full hover:text-white",href:"/wp-admin/admin.php?page=my-easy-compta-export#tab3"},g_=r("i",{class:"fas fa-file-export"},null,-1),y_=["data-tip"],b_={class:"btn btn-outline btn-accent rounded-full",disabled:""},v_=r("i",{class:"fas fa-file-export"},null,-1),w_=r("div",{class:"divider mt-2"},null,-1),x_={class:"flex items-center mb-4"},E_={for:"perPageSelect",class:"mr-2"},C_=["value"],T_={class:"overflow-x-auto"},I_={class:"table w-full"},k_={value:""},A_=["value"],S_={value:""},D_={value:"draft"},P_={value:"unpaid"},j_={value:"paid"},R_={class:"flex justify-center"},M_={key:0},O_={key:0,class:"badge badge-primary badge-outline badge-sm mr-2"},q_={key:0,class:"badge badge-scondary badge-outline badge-sm"},N_={key:1,class:"badge badge-warning badge-outline badge-sm"},B_={key:2,class:"badge badge-success badge-outline badge-sm"},V_={key:3,class:"badge badge-error badge-outline badge-sm ms-2"},F_={key:0},U_={key:0},L_={key:0},W_={key:1},X_={key:0},H_={key:1},z_={key:1},Q_=r("span",{class:"loading loading-bars loading-sm"},null,-1),G_=[Q_],J_={key:0},Y_={key:1},K_=r("span",{class:"loading loading-bars loading-sm"},null,-1),Z_=[K_],$_={key:0},eg={key:1},tg=r("span",{class:"loading loading-bars loading-sm"},null,-1),ng=[tg],sg={class:"flex justify-end"},og=["data-tip"],ig=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"far fa-eye"})],-1),rg=["data-tip"],ag=r("button",{class:"btn btn-circle mx-1"},[r("i",{class:"fas fa-pencil-alt"})],-1),lg=["data-tip"],cg=["onClick"],dg=r("i",{class:"far fa-trash-alt"},null,-1),ug=[dg],hg={key:0},mg=r("div",{class:"flex gap-4 items-center"},[r("div",{class:"skeleton w-16 h-16 rounded-full shrink-0"}),r("div",{class:"flex flex-col gap-4 w-full"},[r("div",{class:"skeleton h-4 w-full"}),r("div",{class:"skeleton h-4 w-full"})])],-1),fg=r("div",{class:"divider my-1"},null,-1),pg=[mg,fg],_g={class:"join ecwp_pagination mt-6 pt-4"},gg=["onClick"];function yg(t,e,s,i,n,o){const a=O("remove-modal"),l=O("router-link"),f=O("Card");return u(),h("div",d_,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),P(a,{"modal-id":"modal_invoice_remove","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=d=>this.deleteInvoice(n.selectedInvoice)),onCancel:e[1]||(e[1]=d=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(f,{topMargin:"mt-8"},{default:me(()=>[r("div",u_,[r("h2",h_,c(o.translations.invoices),1),r("div",null,[P(l,{to:{name:"InvoiceNew"}},{default:me(()=>[r("button",m_,[C(c(o.translations.add)+" ",1),f_])]),_:1}),n.settings.easy_compta_export_addon_active==1?(u(),h("span",p_,[r("a",__,[C(c(o.translations.export)+" ",1),g_])])):(u(),h("span",{key:1,class:"tooltip tooltip-left tooltip-warning ms-2","data-tip":o.translations.active_export_addon},[r("button",b_,[C(c(o.translations.export)+" ",1),v_])],8,y_))])]),w_,r("div",x_,[r("label",E_,c(o.translations.display_per_page),1),D(r("select",{id:"perPageSelect","onUpdate:modelValue":e[2]||(e[2]=d=>n.perPage=d),onChange:e[3]||(e[3]=(...d)=>o.perPageChanged&&o.perPageChanged(...d))},[(u(!0),h(F,null,U(n.perPageOptions,d=>(u(),h("option",{key:d,value:d},c(d),9,C_))),128))],544),[[ue,n.perPage]])]),r("div",T_,[r("table",I_,[r("thead",null,[r("tr",null,[r("th",null,[r("div",null,c(o.translations.invoice_number),1),D(r("input",{"onUpdate:modelValue":e[4]||(e[4]=d=>n.filters.invoice_number=d),onInput:e[5]||(e[5]=d=>o.fetchInvoicesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.invoice_number]])]),r("th",null,[r("div",null,c(o.translations.client),1),D(r("select",{"onUpdate:modelValue":e[6]||(e[6]=d=>n.filters.client=d),onChange:e[7]||(e[7]=d=>o.fetchInvoicesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",k_,c(o.translations.all),1),(u(!0),h(F,null,U(t.clients,d=>(u(),h("option",{key:d.id,value:d.company_name},c(d.company_name),9,A_))),128))],544),[[ue,n.filters.client]])]),r("th",null,[r("div",null,c(o.translations.status),1),D(r("select",{"onUpdate:modelValue":e[8]||(e[8]=d=>n.filters.status=d),onChange:e[9]||(e[9]=d=>o.fetchInvoicesWithFilters()),class:"ecwp-input input-xs input-bordered mt-2"},[r("option",S_,c(o.translations.all_statuses),1),r("option",D_,c(o.translations.draft),1),r("option",P_,c(o.translations.unpaid),1),r("option",j_,c(o.translations.paid),1)],544),[[ue,n.filters.status]])]),r("th",null,[r("div",null,c(o.translations.total),1),D(r("input",{"onUpdate:modelValue":e[10]||(e[10]=d=>n.filters.total_amount=d),onInput:e[11]||(e[11]=d=>o.fetchInvoicesWithFilters()),type:"text",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.total_amount]])]),r("th",null,[r("div",null,c(o.translations.due_date),1),D(r("input",{"onUpdate:modelValue":e[12]||(e[12]=d=>n.filters.due_date=d),onInput:e[13]||(e[13]=d=>o.fetchInvoicesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.due_date]])]),r("th",null,[r("div",null,c(o.translations.created_at),1),D(r("input",{"onUpdate:modelValue":e[14]||(e[14]=d=>n.filters.created_at=d),onInput:e[15]||(e[15]=d=>o.fetchInvoicesWithFilters()),type:"date",class:"ecwp-input input-xs input-bordered mt-2"},null,544),[[W,n.filters.created_at]])]),r("th",R_,c(o.translations.actions),1)])]),n.loading?g("",!0):(u(),h("tbody",M_,[(u(!0),h(F,null,U(n.invoices,d=>(u(),h("tr",{key:d.id},[r("td",null,[d.advance==1?(u(),h("span",O_,c(o.translations.advance),1)):g("",!0),C(c(d.invoice_number),1)]),r("td",null,c(d.client_name),1),r("td",null,[d.status=="draft"?(u(),h("span",q_,c(o.translations.draft),1)):g("",!0),d.status=="unpaid"?(u(),h("span",N_,c(o.translations.unpaid),1)):g("",!0),d.status=="paid"?(u(),h("span",B_,c(o.translations.paid),1)):g("",!0),d.credit=="1"?(u(),h("span",V_,c(o.translations.credit),1)):g("",!0)]),r("td",null,[n.loadingPrice?(u(),h("div",z_,G_)):(u(),h("div",F_,[n.settings.easy_compta_advance_addon_active&&d.advance==1?(u(),h("div",U_,c(o.formatAmount(d.advance_amount,d.client_currency||n.default_currency_symbol)),1)):g("",!0),n.settings.vat_active==1?(u(),h("div",{key:1,class:I({"text-xs":d.advance==1})},[n.default_currency_symbol==d.client_currency||d.client_currency==null?(u(),h("span",L_,c(o.formatAmount(d.total_amount,n.default_currency_symbol)),1)):(u(),h("span",W_,c(o.formatAmount(d.total_amount,d.client_currency)),1))],2)):(u(),h("div",{key:2,class:I({"text-xs":d.advance==1})},[n.default_currency_symbol==d.client_currency||d.client_currency==null?(u(),h("span",X_,c(o.formatAmount(d.total_amount,n.default_currency_symbol)),1)):(u(),h("span",H_,c(o.formatAmount(d.total_amount,d.client_currency)),1))],2))]))]),r("td",null,[n.loadingPrice?(u(),h("div",Y_,Z_)):(u(),h("div",J_,c(d.due_date),1))]),r("td",null,[n.loadingPrice?(u(),h("div",eg,ng)):(u(),h("div",$_,c(d.created),1))]),r("td",sg,[r("span",{class:"lg:tooltip","data-tip":o.translations.view},[P(l,{to:{name:"InvoiceViewDetail",params:{id:d.id}}},{default:me(()=>[ig]),_:2},1032,["to"])],8,og),d.status=="draft"?(u(),h("span",{key:0,class:"lg:tooltip","data-tip":o.translations.edit},[P(l,{to:{name:"InvoiceEdit",params:{id:d.id}}},{default:me(()=>[ag]),_:2},1032,["to"])],8,rg)):g("",!0),d.status=="draft"?(u(),h("span",{key:1,class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:m=>o.confirmDeleteInvoice(d.id),class:"btn btn-circle text-red-500 hover:text-red-700 mx-1"},ug,8,cg)],8,lg)):g("",!0)])]))),128))]))]),n.loading?(u(),h("div",hg,[(u(!0),h(F,null,U(n.skeletonRows,d=>(u(),h("div",{key:d,class:"flex flex-col gap-4 w-full"},pg))),128))])):g("",!0)]),r("div",_g,[(u(!0),h(F,null,U(n.paginationButtons,d=>(u(),h("button",{key:d,class:I(["join-item btn",{"btn-disabled":d==="..."||d===n.currentPage}]),onClick:m=>o.goToPage(d)},c(d),11,gg))),128))])]),_:1})])}var bg=ne(c_,[["render",yg]]);const vg={name:"sendInvoice",components:{VueEditor:mt.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"invoice",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},wg=["id","open"],xg={class:"modal-box"},Eg={class:"font-bold text-lg"},Cg={key:0},Tg={class:"grid grid-cols-1 gap-4"},Ig=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),kg=r("div",{class:"skeleton h-4 w-full"},null,-1),Ag=[Ig,kg],Sg={class:"grid grid-cols-1 gap-4"},Dg=["type"],Pg=["for"],jg=["id","value","disabled","onInput"],Rg={key:1},Mg=["for"],Og={class:"form-group mt-4 flex justify-end"},qg=["disabled"],Ng={key:0,class:"loading loading-spinner loading-sm"};function Bg(t,e,s,i,n,o){const a=O("vue-editor");return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",xg,[r("h3",Eg,c(o.translations.send_invoice),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=l=>o.closeModal())}," \u2715 "),n.loading?(u(),h("div",Cg,[r("div",Tg,[(u(!0),h(F,null,U(o.skeletonItems,l=>(u(),h("div",{key:l,class:"py-2"},Ag))),128))])])):(u(),h("form",{key:1,onSubmit:e[1]||(e[1]=J((...l)=>o.submitForm&&o.submitForm(...l),["prevent"])),class:"form"},[r("div",Sg,[(u(!0),h(F,null,U(n.fields,(l,f)=>(u(),h("div",{key:f,class:"ecwp-group form-group"},[l.type!=="textarea"?(u(),h("div",{key:0,type:l.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},c(l.label),9,Pg),r("input",{id:f,class:I(["ecwp-input input input-bordered",l.class||"w-full"]),value:l.value,disabled:l.disabled,onInput:d=>o.updateFieldValue(f,d.target.value)},null,42,jg)],8,Dg)):(u(),h("div",Rg,[r("label",{for:f,class:"form-label"},c(l.label),9,Mg),P(a,{modelValue:l.value,"onUpdate:modelValue":d=>l.value=d,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",Og,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.send)+" ",1),n.loadingBtn?(u(),h("span",Ng)):g("",!0)],8,qg)])],32))])],8,wg)])}var Vg=ne(vg,[["render",Bg]]);const Fg={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:"",paymentMethods:[],hasPaymentMethodError:!1}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},mounted(){this.fetchPaymentMethods()},methods:{async fetchPaymentMethods(){try{const t=await fetch("/wp-json/my-easy-compta/v1/payments/methods",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(!t.ok)throw new Error(`Erreur : ${t.status}`);const e=await t.json();this.paymentMethods=e}catch(t){console.error("Erreur lors de la r\xE9cup\xE9ration des m\xE9thodes de paiement :",t)}},onConfirm(){if(!this.selectedPaymentMethod){this.hasPaymentMethodError=!0;return}this.hasPaymentMethodError=!1,this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm_paid").close()}}},Ug=["open"],Lg={class:"modal-box"},Wg={class:"font-bold text-lg"},Xg=r("div",{class:"text-center text-red-400 mb-2"},[r("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),Hg={class:"text-lg font-semibold text-center"},zg={class:"my-4 text-center text-xl"},Qg={key:0,class:"mt-4 mb-4"},Gg={class:"ecwp-group form-group"},Jg={for:"payment_method",class:"ecwp-label form-label"},Yg={value:""},Kg=["value"],Zg={class:"flex justify-between space-x-4"};function $g(t,e,s,i,n,o){return u(),h("div",null,[r("dialog",{id:"modal_confirm_paid",class:"modal",open:t.showModal},[r("div",Lg,[r("h3",Wg,c(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...a)=>o.closeModal&&o.closeModal(...a))}," \u2715 "),Xg,r("h2",Hg,c(s.title),1),r("p",zg,c(s.message),1),s.status==="paid"?(u(),h("div",Qg,[r("div",Gg,[r("label",Jg,c(o.translations.payment_method),1),D(r("select",{id:"payment_method","onUpdate:modelValue":e[1]||(e[1]=a=>n.selectedPaymentMethod=a),class:I([{"input-error":n.hasPaymentMethodError},"ecwp-input input input-bordered w-full"])},[r("option",Yg,c(o.translations.select),1),(u(!0),h(F,null,U(n.paymentMethods,a=>(u(),h("option",{key:a.id,value:a.id},c(a.method_name),9,Kg))),128))],2),[[ue,n.selectedPaymentMethod]])])])):g("",!0),r("div",Zg,[r("button",{onClick:e[2]||(e[2]=(...a)=>o.onCancel&&o.onCancel(...a)),class:"btn btn-secondary rounded-full"},c(s.cancelText),1),r("button",{onClick:e[3]||(e[3]=(...a)=>o.onConfirm&&o.onConfirm(...a)),class:"btn rounded-full btn-error text-white"},c(s.confirmText),1)])])],8,Ug)])}var ey=ne(Fg,[["render",$g]]);const ty={props:{isVisible:{type:Boolean,default:!1},title:{type:String,default:"Confirmation"},message:{type:String,default:"Are you sure?"},confirmText:{type:String,default:"Confirm"},cancelText:{type:String,default:"Cancel"},status:{type:String}},data(){return{selectedPaymentMethod:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{onConfirm(){this.$emit("confirm",this.selectedPaymentMethod),this.closeModal()},onCancel(){this.$emit("cancel"),this.closeModal()},closeModal(){document.getElementById("modal_confirm_credit").close()}}},ny=["open"],sy={class:"modal-box"},oy={class:"font-bold text-lg"},iy=r("div",{class:"text-center text-red-400 mb-2"},[r("i",{class:"fas fa-exclamation-triangle text-4xl"})],-1),ry={class:"text-lg font-semibold text-center"},ay={class:"my-4 text-center text-xl"},ly={class:"flex justify-between space-x-4"};function cy(t,e,s,i,n,o){return u(),h("div",null,[r("dialog",{id:"modal_confirm_credit",class:"modal",open:t.showModal},[r("div",sy,[r("h3",oy,c(t.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=(...a)=>o.closeModal&&o.closeModal(...a))}," \u2715 "),iy,r("h2",ry,c(s.title),1),r("p",ay,c(s.message),1),r("div",ly,[r("button",{onClick:e[1]||(e[1]=(...a)=>o.onCancel&&o.onCancel(...a)),class:"btn btn-secondary rounded-full"},c(s.cancelText),1),r("button",{onClick:e[2]||(e[2]=(...a)=>o.onConfirm&&o.onConfirm(...a)),class:"btn rounded-full btn-error text-white"},c(s.confirmText),1)])])],8,ny)])}var dy=ne(ty,[["render",cy]]);const uy={name:"InvoiceNavBar",components:{SendInvoiceModal:Vg,RemoveModal:qt,ConfirmModal:ds,ConfirmModalPaid:ey,ConfirmModalCredit:dy},props:{invoiceInfo:Object,currencyDefault:Object,currencyClient:Object,emailActive:String,qrCodeActive:String,totalAmount:String,noItems:Boolean},data(){return{showConfirmModal:!1,showConfirmCreditModal:!1,loading:!1,sendInvoiceModal:!1,loadingModal:!1,loadingPdf:!1,client_detail:null,selectedStatus:null,subject:"",content:"",showQrCodeModal:!1,qrCodeSrc:""}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{changeInvoiceStatusWithPaymentMethod(t){const e=this.selectedStatus;this.changeInvoiceStatus(e,t),this.showConfirmModal=!1},async changeInvoiceStatus(t,e){this.loading=!0;try{const i=await(await fetch("/wp-json/my-easy-compta/v1/invoices/update-status",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id,status:t,method:e})})).json();i.success?(this.invoiceInfo.status=t,this.loading=!1):(console.error("Failed to update invoice status:",i.message),this.loading=!1)}catch(s){console.error("An error occurred while updating invoice status:",s)}},async addCreditInvoice(){this.loading=!0;try{const e=await(await fetch("/wp-json/my-easy-compta/v1/invoices/credit",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({id:this.invoiceInfo.id})})).json();e.success?(this.invoiceInfo.credit=1,this.loading=!1):(console.error("Failed to update invoice status:",e.message),this.loading=!1)}catch(t){console.error("An error occurred while updating invoice status:",t)}},exportToPDF(t){this.loadingPdf=!0;let s=`/wp-json/my-easy-compta/v1/invoices/pdf/${this.invoiceInfo.id}?currency_id=${t}`;fetch(s,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(i=>{if(!i.ok)throw this.loadingPdf=!1,new Error("Network response was not ok");return i.blob()}).then(i=>{const n=URL.createObjectURL(i);window.open(n),this.loadingPdf=!1}).catch(i=>{console.error("There was a problem with the fetch operation:",i),this.loadingPdf=!1})},sendInvoice(t){this.loadingModal=!0,this.sendInvoiceModal=!0,modal_send_invoice.showModal(),this.fetchClient(t),this.fetchSettings()},fetchClient(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e,this.loading=!1}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.subject=e.email_invoice_subject,this.content=e.email_invoice_content}else{const e=await t.json();this.showToast(e.message,"alert-error")}}catch(t){this.loading=!1,this.showToast(t.message,"alert-error")}},confirmValidateInvoice(t){this.selectedStatus=t,t=="unpaid"?modal_confirm.showModal():t=="paid"&&modal_confirm_paid.showModal(),this.showConfirmModal=!0},confirmCreditInvoice(){modal_confirm_credit.showModal(),this.showConfirmCreditModal=!0},async generateQRCode(){this.loading=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/generate-qrcode",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_ref:this.invoiceInfo.invoice_number||`Facture #${this.invoiceInfo.number}`,price:parseFloat(this.invoiceInfo.total_amount)})}),e=await t.json();t.ok&&e.qr_code?(this.qrCodeSrc=e.qr_code,this.showQrCodeModal=!0):console.error("Erreur lors de la g\xE9n\xE9ration du QR Code :",e.message)}catch(t){console.error("Erreur lors de l'appel \xE0 l'API pour g\xE9n\xE9rer le QR code :",t)}finally{this.loading=!1}},closeQrCodeModal(){this.showQrCodeModal=!1},downloadQRCode(){const t=document.createElement("a");t.href=this.qrCodeSrc,t.download=`qr_code_${this.invoiceInfo.invoice_number||this.invoiceInfo.number}.png`,t.click()}}},hy={key:0},my={key:1,class:"modal modal-open"},fy={class:"modal-box"},py={class:"font-bold text-lg"},_y={class:"mb-4"},gy=["src"],yy={class:"flex justify-end space-x-4"},by={key:2,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},vy=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),wy=[vy],xy={class:"navbar bg-base-100 mb-4 shadow-xl rounded-box flex justify-between"},Ey=r("div",{class:"dropdown"},[r("div",{tabindex:"0",role:"button",class:"btn btn-ghost lg:hidden"},[r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 6h16M4 12h8m-8 6h16"})])]),r("ul",{tabindex:"0",class:"menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"},[r("li",null,[r("a",null,"Item")]),r("li",null,[r("a",null,"Parent"),r("ul",{class:"p-2"},[r("li",null,[r("a",null,"Submenu")]),r("li",null,[r("a",null,"Submenu")])])]),r("li",null,[r("a",null,"Item")])])],-1),Cy={class:"hidden lg:flex gap-2"},Ty={class:"btn btn-sm"},Iy=r("i",{class:"far fa-edit"},null,-1),ky={key:1},Ay={class:"btn btn-sm",disabled:""},Sy=r("i",{class:"far fa-edit"},null,-1),Dy={key:2},Py=r("i",{class:"fa fa-check"},null,-1),jy={class:"btn btn-outline btn-success btn-sm hover:text-white",disabled:""},Ry=r("i",{class:"fa fa-check"},null,-1),My={key:0},Oy={class:"btn btn-sm ms-2",disabled:""},qy=r("i",{class:"fas fa-undo"},null,-1),Ny={key:1},By=r("i",{class:"fas fa-undo"},null,-1),Vy=["disabled"],Fy=r("i",{class:"far fa-file-pdf"},null,-1),Uy={key:0,class:"loading loading-spinner loading-sm"},Ly={class:"flex gap-2"},Wy=r("i",{class:"fas fa-paper-plane"},null,-1),Xy={key:0},Hy={key:1},zy={key:2,class:"far fa-envelope"},Qy=["data-tip"],Gy={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Jy=r("i",{class:"fas fa-paper-plane"},null,-1),Yy=["data-tip"],Ky={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Zy=r("i",{class:"fas fa-paper-plane"},null,-1),$y={key:3},eb=r("i",{class:"fas fa-qrcode"},null,-1),tb={key:1,click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},nb=r("i",{class:"fas fa-qrcode"},null,-1),sb=["data-tip"],ob={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},ib=r("i",{class:"fas fa-qrcode"},null,-1),rb={key:5},ab={key:0,class:"dropdown dropdown-end"},lb={tabindex:"0",role:"button",class:"btn btn-outline btn-success btn-sm"},cb=r("i",{class:"far fa-file-pdf"},null,-1),db={key:0,class:"loading loading-spinner loading-sm"},ub={tabindex:"0",class:"dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"},hb=["disabled"],mb=["disabled"],fb={key:6},pb=["disabled"],_b=r("i",{class:"far fa-file-pdf"},null,-1),gb={key:0},yb={key:1},bb={key:2,class:"loading loading-spinner loading-sm"},vb=r("i",{class:"fas fa-check"},null,-1),wb=["data-tip"],xb={click:"#",class:"btn btn-outline btn-primary btn-sm hover:text-white",disabled:""},Eb=r("i",{class:"fas fa-check"},null,-1);function Cb(t,e,s,i,n,o){const a=O("send-invoice-modal"),l=O("confirm-modal"),f=O("confirm-modal-paid"),d=O("confirm-modal-credit"),m=O("router-link");return u(),h("div",null,[s.emailActive==1?(u(),h("div",hy,[P(a,{loading:n.loadingModal,"show-modal":n.sendInvoiceModal,"modal-id":"modal_send_invoice",client:n.client_detail,"invoice-id":s.invoiceInfo.id,subject:n.subject,content:n.content,onClose:e[0]||(e[0]=p=>n.sendInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):g("",!0),P(l,{"show-modal":n.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,status:n.selectedStatus,onConfirm:e[1]||(e[1]=p=>o.changeInvoiceStatus("unpaid")),onCancel:e[2]||(e[2]=p=>n.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","status"]),P(f,{"show-modal":n.showConfirmModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,status:n.selectedStatus,onConfirm:o.changeInvoiceStatusWithPaymentMethod,onCancel:e[3]||(e[3]=p=>n.showConfirmModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText","status","onConfirm"]),P(d,{"show-modal":n.showConfirmCreditModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_confirm_it,cancelText:o.translations.cancel,onConfirm:e[4]||(e[4]=p=>this.addCreditInvoice()),onCancel:e[5]||(e[5]=p=>n.showConfirmCreditModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),s.qrCodeActive==1&&n.showQrCodeModal?(u(),h("div",my,[r("div",fy,[r("h3",py,c(o.translations.download_qr_code),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[6]||(e[6]=p=>o.closeQrCodeModal())}," \u2715 "),r("div",_y,[r("img",{src:n.qrCodeSrc,alt:"QR Code",class:"max-w-full h-auto mx-auto"},null,8,gy)]),r("div",yy,[r("button",{onClick:e[7]||(e[7]=(...p)=>o.downloadQRCode&&o.downloadQRCode(...p)),class:"btn btn-primary"},c(o.translations.download_qr_code),1)])])])):g("",!0),n.loading?(u(),h("div",by,wy)):g("",!0),r("div",xy,[r("div",null,[Ey,r("div",Cy,[s.invoiceInfo.status=="draft"?(u(),pi(m,{key:0,to:{name:"InvoiceEdit",params:{id:s.invoiceInfo.id}}},{default:me(()=>[r("button",Ty,[Iy,C(" "+c(o.translations.edit_invoice),1)])]),_:1},8,["to"])):(u(),h("div",ky,[r("button",Ay,[Sy,C(" "+c(o.translations.edit_invoice),1)])])),s.invoiceInfo.status=="unpaid"&&!s.noItems?(u(),h("div",Dy,[r("button",{class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[8]||(e[8]=p=>o.confirmValidateInvoice("paid"))},[Py,C(" "+c(o.translations.mark_as_paid),1)])])):(u(),h(F,{key:3},[r("div",null,[r("button",jy,[Ry,C(" "+c(o.translations.mark_as_paid),1)])]),s.invoiceInfo.credit!=0&&s.invoiceInfo.status=="paid"&&!s.noItems?(u(),h("div",My,[r("button",Oy,[qy,C(" "+c(o.translations.credit_invoice),1)])])):g("",!0),s.invoiceInfo.credit==0&&s.invoiceInfo.status=="paid"&&!s.noItems?(u(),h("div",Ny,[r("button",{class:"btn btn-sm ms-2",onClick:e[9]||(e[9]=p=>o.confirmCreditInvoice())},[By,C(" "+c(o.translations.credit_invoice),1)])])):g("",!0)],64))])]),s.invoiceInfo.status=="draft"?(u(),h("button",{key:0,onClick:e[10]||(e[10]=p=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-secondary btn-sm",disabled:n.loadingPdf},[Fy,r("span",null,c(o.translations.previewPDF),1),n.loadingPdf?(u(),h("span",Uy)):g("",!0)],8,Vy)):g("",!0),r("div",Ly,[s.emailActive==1&&s.invoiceInfo.status!="draft"?(u(),h("button",{key:0,onClick:e[11]||(e[11]=J(p=>o.sendInvoice(s.invoiceInfo.client_id),["prevent"])),class:"btn btn-outline btn-primary btn-sm hover:text-white"},[Wy,s.invoiceInfo.sent==1?(u(),h("span",Xy,c(o.translations.resend_invoice),1)):(u(),h("span",Hy,c(o.translations.send_invoice),1)),s.invoiceInfo.sent==1?(u(),h("i",zy)):g("",!0)])):s.emailActive==1&&s.invoiceInfo.status=="draft"?(u(),h("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.draft_cannot_send},[r("button",Gy,[Jy,C(" "+c(o.translations.send_invoice),1)])],8,Qy)):(u(),h("div",{key:2,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[r("button",Ky,[Zy,C(" "+c(o.translations.send_invoice),1)])],8,Yy)),s.qrCodeActive==1?(u(),h("div",$y,[s.invoiceInfo.status=="unpaid"?(u(),h("button",{key:0,class:"btn btn-outline btn-accent btn-sm",onClick:e[12]||(e[12]=(...p)=>o.generateQRCode&&o.generateQRCode(...p))},[eb,C(" "+c(o.translations.generate_qrcode),1)])):(u(),h("button",tb,[nb,C(" "+c(o.translations.generate_qrcode),1)]))])):(u(),h("div",{key:4,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_qrcode_addon},[r("button",ob,[ib,C(" "+c(o.translations.generate_qrcode),1)])],8,sb)),s.currencyDefault.currency_id!==s.currencyClient.currency_id?(u(),h("div",rb,[s.invoiceInfo.status!="draft"?(u(),h("div",ab,[r("div",lb,[cb,C(" "+c(o.translations.exportToPDF)+" ",1),n.loadingPdf?(u(),h("span",db)):g("",!0)]),r("ul",ub,[r("li",null,[r("a",{onClick:e[13]||(e[13]=p=>o.exportToPDF(s.currencyDefault.currency_id)),disabled:n.loadingPdf},c(o.translations.invoice_in)+" "+c(s.currencyDefault.currency_symbol),9,hb)]),r("li",null,[r("a",{onClick:e[14]||(e[14]=p=>o.exportToPDF(s.currencyClient.currency_id)),disabled:n.loadingPdf},c(o.translations.invoice_in)+" "+c(s.currencyClient.currency_symbol),9,mb)])])])):g("",!0)])):(u(),h("div",fb,[s.invoiceInfo.status!="draft"?(u(),h("button",{key:0,onClick:e[15]||(e[15]=p=>o.exportToPDF(s.currencyDefault.currency_id)),class:"btn btn-outline btn-success btn-sm",disabled:n.loadingPdf},[_b,s.invoiceInfo.status!="draft"?(u(),h("span",gb,c(o.translations.exportToPDF),1)):(u(),h("span",yb,c(o.translations.previewPDF),1)),n.loadingPdf?(u(),h("span",bb)):g("",!0)],8,pb)):g("",!0)])),s.invoiceInfo.status=="draft"&&!s.noItems?(u(),h("button",{key:7,class:"btn btn-outline btn-success btn-sm hover:text-white",onClick:e[16]||(e[16]=p=>o.confirmValidateInvoice("unpaid"))},[vb,C(" "+c(o.translations.validateInvoice),1)])):g("",!0),s.invoiceInfo.status=="draft"&&s.noItems?(u(),h("div",{key:8,class:"tooltip tooltip-left tooltip-warning","data-tip":o.translations.min_article},[r("button",xb,[Eb,C(" "+c(o.translations.validateInvoice),1)])],8,wb)):g("",!0)])])])}var Tb=ne(uy,[["render",Cb]]);const Ib={components:{VueEditor:mt.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,item:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedItem:{...this.item},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{item_name:{label:t.item_name},item_description:{label:t.item_description,type:"textarea"},quantity:{label:t.quantity,type:"number"},vat_rate:{label:t.vat,type:"number"},unit_price:{label:t.unit_price,type:"number"},discount:{label:t.discount,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/invoices/edit-item/${this.editedItem.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedItem)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("itemEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{item:{handler(t){this.editedItem={...t}},immediate:!0}}},kb=["id","open"],Ab={class:"modal-box"},Sb={class:"font-bold text-lg"},Db={key:0},Pb={class:"grid grid-cols-1 gap-4"},jb=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),Rb=r("div",{class:"skeleton h-4 w-full"},null,-1),Mb=[jb,Rb],Ob={class:"grid grid-cols-1 gap-4"},qb=["type"],Nb=["for"],Bb=["id","onUpdate:modelValue"],Vb={key:1},Fb=["for"],Ub={class:"form-group mt-4 flex justify-end"},Lb=["disabled"],Wb={key:0,class:"loading loading-spinner loading-sm"};function Xb(t,e,s,i,n,o){const a=O("vue-editor");return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",Ab,[r("h3",Sb,c(s.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=l=>o.closeModal())}," \u2715 "),n.loading?(u(),h("div",Db,[r("div",Pb,[(u(!0),h(F,null,U(o.skeletonItems,l=>(u(),h("div",{key:l,class:"py-2"},Mb))),128))])])):(u(),h("form",{key:1,onSubmit:e[1]||(e[1]=J((...l)=>o.submitForm&&o.submitForm(...l),["prevent"])),class:"form"},[r("div",Ob,[(u(!0),h(F,null,U(n.fields,(l,f)=>(u(),h("div",{key:f,class:"ecwp-group form-group"},[l.type!=="textarea"?(u(),h("div",{key:0,type:l.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},c(l.label),9,Nb),D(r("input",{id:f,"onUpdate:modelValue":d=>n.editedItem[f]=d,class:I(["ecwp-input input input-bordered",l.class||"w-full"])},null,10,Bb),[[W,n.editedItem[f]]])],8,qb)):(u(),h("div",Vb,[r("label",{for:f,class:"form-label"},c(l.label),9,Fb),P(a,{id:f,modelValue:n.editedItem[f],"onUpdate:modelValue":d=>n.editedItem[f]=d,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",Ub,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.save)+" ",1),n.loadingBtn?(u(),h("span",Wb)):g("",!0)],8,Lb)])],32))])],8,kb)])}var Hb=ne(Ib,[["render",Xb]]);const zb={components:{VueEditor:mt.exports.VueEditor},props:{loading:Boolean,showModal:Boolean,modalId:String,modalTitle:String,disb:Object},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{editedDisb:{...this.disb},loading:this.loading,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},fields:{title:{label:t.item_name},description:{label:t.item_description,type:"textarea"},unit_price:{label:t.unit_price,type:"number"}}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch(`/wp-json/my-easy-compta/v1/invoices/edit-disb/${this.editedDisb.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.editedDisb)});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success"),this.$emit("disbEdited")}else{const e=`Error editing item: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error editing item";this.showToast(e,"alert-error"),console.error("Error editing item:",t),this.loadingBtn=!1}},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--}},watch:{disb:{handler(t){this.editedDisb={...t}},immediate:!0}}},Qb=["id","open"],Gb={class:"modal-box"},Jb={class:"font-bold text-lg"},Yb={key:0},Kb={class:"grid grid-cols-1 gap-4"},Zb=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),$b=r("div",{class:"skeleton h-4 w-full"},null,-1),ev=[Zb,$b],tv={class:"grid grid-cols-1 gap-4"},nv=["type"],sv=["for"],ov=["id","onUpdate:modelValue"],iv={key:1},rv=["for"],av={class:"form-group mt-4 flex justify-end"},lv=["disabled"],cv={key:0,class:"loading loading-spinner loading-sm"};function dv(t,e,s,i,n,o){const a=O("vue-editor");return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",Gb,[r("h3",Jb,c(s.modalTitle),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=l=>o.closeModal())}," \u2715 "),n.loading?(u(),h("div",Yb,[r("div",Kb,[(u(!0),h(F,null,U(o.skeletonItems,l=>(u(),h("div",{key:l,class:"py-2"},ev))),128))])])):(u(),h("form",{key:1,onSubmit:e[1]||(e[1]=J((...l)=>o.submitForm&&o.submitForm(...l),["prevent"])),class:"form"},[r("div",tv,[(u(!0),h(F,null,U(n.fields,(l,f)=>(u(),h("div",{key:f,class:"ecwp-group form-group"},[l.type!=="textarea"?(u(),h("div",{key:0,type:l.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},c(l.label),9,sv),D(r("input",{id:f,"onUpdate:modelValue":d=>n.editedDisb[f]=d,class:I(["ecwp-input input input-bordered",l.class||"w-full"])},null,10,ov),[[W,n.editedDisb[f]]])],8,nv)):(u(),h("div",iv,[r("label",{for:f,class:"form-label"},c(l.label),9,rv),P(a,{id:f,modelValue:n.editedDisb[f],"onUpdate:modelValue":d=>n.editedDisb[f]=d,editorToolbar:t.toolbarOptions},null,8,["id","modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",av,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.save)+" ",1),n.loadingBtn?(u(),h("span",cv)):g("",!0)],8,lv)])],32))])],8,Qb)])}var uv=ne(zb,[["render",dv]]);const hv={name:"sendRemind",components:{VueEditor:mt.exports.VueEditor},props:{showModal:Boolean,modalId:String,client:Object,invoiceId:Number,loading:Boolean,subject:String,content:String},data(){const t=window.myEasyComptaAdmin.easyComptaTranslations;return{loading:!1,loadingBtn:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},toolbarOptions:[["bold","italic","underline","strike"],["link"],[{list:"ordered"},{list:"bullet"}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{align:[]}],[{align:"right"},{align:"center"},{align:"justify"}],["clean"]],fields:{client_email:{label:t.client,value:"",disabled:!0},email_subject:{label:t.email_subject,value:""},email_message:{label:t.email_content,value:"",type:"textarea"}}}},watch:{client:{immediate:!0,handler(t){this.fields.client_email.value=(t==null?void 0:t.email)||""}},subject:{immediate:!0,handler(t){this.fields.email_subject.value=t||""}},content:{immediate:!0,handler(t){this.fields.email_message.value=t||""}}},computed:{skeletonItems(){return Array.from({length:10},(t,e)=>e)},translations(){return window.myEasyComptaAdmin.easyComptaTranslations}},methods:{closeModal(){document.getElementById(this.modalId).close()},async submitForm(){this.loadingBtn=!0;try{const t=await fetch("/wp-json/my-easy-compta/v1/emails/send-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({type:"remind",id:this.invoiceId,client_email:this.client.email,email_subject:this.fields.email_subject.value,email_message:this.fields.email_message.value})});if(t.ok){const e=await t.json();this.loadingBtn=!1,this.closeModal(),this.showToast(e.message,"alert-success")}else{const e=`Error sending email: ${t.statusText}`;this.showToast(e,"alert-error"),console.error(e),this.loadingBtn=!1}}catch(t){const e=t.response&&t.response.data&&t.response.data.message?t.response.data.message:"Error sending email";this.showToast(e,"alert-error"),console.error("Error sending email:",t),this.loadingBtn=!1}},updateFieldValue(t,e){this.fields[t].value=e},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},mv=["id","open"],fv={class:"modal-box"},pv={class:"font-bold text-lg"},_v={key:0},gv={class:"grid grid-cols-1 gap-4"},yv=r("div",{class:"skeleton h-4 w-full mb-2"},null,-1),bv=r("div",{class:"skeleton h-4 w-full"},null,-1),vv=[yv,bv],wv={class:"grid grid-cols-1 gap-4"},xv=["type"],Ev=["for"],Cv=["id","value","disabled","onInput"],Tv={key:1},Iv=["for"],kv={class:"form-group mt-4 flex justify-end"},Av=["disabled"],Sv={key:0,class:"loading loading-spinner loading-sm"};function Dv(t,e,s,i,n,o){const a=O("vue-editor");return u(),h("div",null,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),r("dialog",{id:s.modalId,class:"modal",open:s.showModal},[r("div",fv,[r("h3",pv,c(o.translations.remind_invoice),1),r("button",{class:"btn btn-sm btn-circle btn-ghost absolute right-2 top-2",onClick:e[0]||(e[0]=l=>o.closeModal())}," \u2715 "),n.loading?(u(),h("div",_v,[r("div",gv,[(u(!0),h(F,null,U(o.skeletonItems,l=>(u(),h("div",{key:l,class:"py-2"},vv))),128))])])):(u(),h("form",{key:1,onSubmit:e[1]||(e[1]=J((...l)=>o.submitForm&&o.submitForm(...l),["prevent"])),class:"form"},[r("div",wv,[(u(!0),h(F,null,U(n.fields,(l,f)=>(u(),h("div",{key:f,class:"ecwp-group form-group"},[l.type!=="textarea"?(u(),h("div",{key:0,type:l.type||"text"},[r("label",{for:f,class:"ecwp-label form-label"},c(l.label),9,Ev),r("input",{id:f,class:I(["ecwp-input input input-bordered",l.class||"w-full"]),value:l.value,disabled:l.disabled,onInput:d=>o.updateFieldValue(f,d.target.value)},null,42,Cv)],8,xv)):(u(),h("div",Tv,[r("label",{for:f,class:"form-label"},c(l.label),9,Iv),P(a,{modelValue:l.value,"onUpdate:modelValue":d=>l.value=d,editorToolbar:n.toolbarOptions},null,8,["modelValue","onUpdate:modelValue","editorToolbar"])]))]))),128))]),r("div",kv,[r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.send)+" ",1),n.loadingBtn?(u(),h("span",Sv)):g("",!0)],8,Av)])],32))])],8,mv)])}var Pv=ne(hv,[["render",Dv]]);const jv={name:"InvoiceViewDetail",components:{Card:Ze,InvoiceNavBar:Tb,EditItemModal:Hb,EditDisbModal:uv,RemoveModal:qt,RemindInvoiceModal:Pv,ArticleModal:zo},data(){return{selectedItem:null,selectedDisb:null,SelectedInvoiceId:null,editItemsModal:!1,editDisbModal:!1,RemindInvoiceModal:!1,no_items:!0,loading:!1,loading_add:!1,invoice:[],invoiceItems:[],newItem:{loading_del:!1,item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:0,unit_price:0,discount:0,total_price:0,total_amount:0},settings:[],client_detail:[],list_vats:[],client_currency:"",default_vat:"",default_currency:"",default_currency_symbol:"",showArticlesModal:!1,articles:[],categories:[],refs:[],showDropdown:!1,showDropdownRef:!1,toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"},showDisbursements:!1,disbursementsExist:!1,disbursementsItem:{title:"",description:"",unit_price:""},loading_add_disbursements:!1,disbursementsList:[]}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},isInvoiceOverdue(){const t=new Date().getTime(),e=this.invoice.due_date?new Date(this.invoice.due_date).getTime():null;return e&&e<t},defaultCurrency(){return{currency_id:this.settings.default_currency,currency_symbol:this.default_currency_symbol}},clientCurrency(){return{currency_id:this.client_detail.currency_id,currency_symbol:this.client_currency}},totalAmountWithoutDiscount(){const t=this.invoiceItems.reduce((e,s)=>{const i=s.quantity*s.unit_price;return e+i},0);return this.formatCurrency(t)},totalAmount(){const t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_price),0);return this.formatCurrency(t)},totalAmountDefaultCurrency(){return(this.invoiceItems.reduce((i,n)=>i+parseFloat(n.total_amount),0)*this.invoice.exchange_rate).toFixed(2)},totalAmountWithVAT(){const t=parseFloat(this.totalAmount);if(this.settings.vat_active==1){const e=parseFloat(this.calculateVAT());return this.formatCurrency(t+e)}else return this.formatCurrency(t)}},methods:{getUniqueVATRates(){const t=new Set;return this.invoiceItems.forEach(e=>{e.vat_rate&&t.add(e.vat_rate)}),Array.from(t)},calculateVATForRate(t){let e=0;return this.invoiceItems.forEach(s=>{if(s.vat_rate===t){const i=s.quantity*s.unit_price,n=i*s.discount/100;e+=(i-n)*t/100}}),this.formatCurrency(e)},totalDisbursements(){let t=0;return this.disbursementsList&&this.disbursementsList.length>0&&(t+=this.disbursementsList.reduce((e,s)=>e+parseFloat(s.unit_price||0),0)),this.formatCurrency(t)},calculateTotalAmountWithVAT(){let t=this.invoiceItems.reduce((e,s)=>e+parseFloat(s.total_amount),0);return this.disbursementsList&&this.disbursementsList.length>0&&(t+=this.disbursementsList.reduce((e,s)=>e+parseFloat(s.unit_price||0),0)),this.settings.easy_compta_woo_addon_active==1&&(t+=parseFloat(this.invoice.shipping_amount||0)),this.formatCurrency(t)},formatShippingAmout(t){return this.formatShippingCurrency(t)},formatShippingCurrency(t){const s=(parseFloat(t)||0).toFixed(2),i=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${s}${i}`},fetchInvoice(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t?(this.invoice=t,this.fetchClientInfo(t.client_id)):console.error("Invoice not found")}).catch(t=>{console.error("Error fetching invoice:",t),this.loading=!1})},fetchClientInfo(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/clients/details/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw new Error("Client not found");return e.json()}).then(e=>{this.client_detail=e;const s=e.currency_id;s&&this.fetchCurrencyDetails(s)}).catch(e=>{console.error("Error fetching client info:",e),this.loading=!1})},fetchItems(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}/items`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code=="no_items_found"?(console.error("No items found"),this.invoiceItems=[],this.loading=!1,this.no_items=!0):(this.invoiceItems=t,this.loading=!1,this.no_items=!1)}).catch(t=>{console.error("Error fetching items:",t),this.loading=!1})},fetchDisbursements(){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/disbursements/${this.$route.params.id}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{t.code==="no_disbursements"?(console.error("No disbursements found"),this.disbursementsList=[],this.disbursementsExist=!1):(this.disbursementsList=t,this.disbursementsExist=!0),this.loading=!1}).catch(t=>{console.error("Error fetching disbursements:",t),this.loading=!1})},fetchCurrencyDetails(t){this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/settings/currency/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>{if(!e.ok)throw this.loading=!1,new Error("Currency details not found");return this.loading=!1,e.json()}).then(e=>{this.client_currency=e.symbol,this.loading=!1}).catch(e=>{this.loading=!1,console.error("Error fetching currency details:",e)})},updateTotal(){const t=this.newItem.quantity*this.newItem.unit_price,e=t*this.newItem.discount/100,s=t-e;var i=0;if(this.settings.vat_active==1){const n=s*this.newItem.vat_rate/100;i=s+n}else i=s;this.newItem.total_price=this.formatCurrency(s),this.newItem.total_amount=this.formatCurrency(i)},calculateTotalWithVat(t,e,s,i){const n=t*e,o=n*i/100,a=n-o,l=a*s/100,f=a+l;return this.formatCurrency(f)},calculateTotal(t,e,s){const i=t*e,n=i*s/100,a=i-n;return this.formatCurrency(a)},submitItems(){this.updateTotal();const t={...this.newItem,invoice_id:this.$route.params.id};this.loading_add=!0,fetch("/wp-json/my-easy-compta/v1/invoices/element-add",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{e.success?(this.loading_add=!1,this.fetchItems(),this.newItem={item_name:"",item_ref:"",item_category:"Type",item_description:"",quantity:1,vat_rate:this.default_vat.rate,unit_price:0,discount:0,total_price:0,total_amount:0}):(this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e.message),this.loading_add=!1)}).catch(e=>{this.showToast(e.message,"alert-error"),console.error("Error submitting item:",e),this.loading_add=!1})},increase(){this.newItem.quantity++},decrease(){this.newItem.quantity>1&&this.newItem.quantity--},confirmremoveItem(t,e){this.selectedItem=t,this.SelectedInvoiceId=e,modal_remove_item.showModal(),this.showRemoveModal=!0},removeItem(t,e){const s=this.invoiceItems.find(i=>i.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/element-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:e})}).then(i=>i.json()).then(i=>{i.success?(s.loading_del=!1,this.fetchItems()):(this.showToast(i.message,"alert-error"),console.error("Error removing item:",i.message),s.loading_del=!1)}).catch(i=>{this.showToast(i.message,"alert-error"),console.error("Error removing item:",i),s.loading_del=!1})},editItem(t){this.loadingModal=!0,this.editItemsModal=!0,modal_edit_item.showModal(),this.fetchItemDetails(t)},fetchItemDetails(t){fetch(`/wp-json/my-easy-compta/v1/invoices/item-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedItem=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},editDisb(t){this.loadingModal=!0,this.editDisbModal=!0,modal_edit_disb.showModal(),this.fetchDisbDetails(t)},fetchDisbDetails(t){fetch(`/wp-json/my-easy-compta/v1/invoices/disb-details/${t}`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.selectedDisb=e,this.loading=!1}).catch(e=>{console.error("Error fetching item details:",e),this.loading=!1})},confirmremoveDisb(t,e){this.selectedDisb=t,this.SelectedInvoiceId=e,modal_remove_disb.showModal(),this.showRemoveModalDisb=!0},removeDisb(t,e){const s=this.disbursementsList.find(i=>i.id===t);s.loading_del=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/disb-delete/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:e})}).then(i=>i.json()).then(i=>{i.success?(s.loading_del=!1,this.fetchDisbursements()):(this.showToast(i.message,"alert-error"),console.error("Error removing item:",i.message),s.loading_del=!1)}).catch(i=>{this.showToast(i.message,"alert-error"),console.error("Error removing item:",i),s.loading_del=!1})},formatCurrency(t){const e=t.toFixed(2),s=this.client_currency!==this.default_currency_symbol?this.client_currency:this.default_currency_symbol;return`${e}${s}`},calculateDiscountAmountWithVAT(t,e,s,i){const o=t*e*i/100,a=o*s/100,l=o+a;return this.formatCurrency(l)},calculateDiscountAmount(t,e,s){const o=t*e*s/100;return this.formatCurrency(o)},calculateVAT(){const t=parseFloat(this.totalAmount),e=parseFloat(this.default_vat.rate),s=t*(e/100);return this.formatCurrency(s)},onDragEnd(t){const e=this.invoiceItems[t.oldIndex];this.invoiceItems.splice(t.oldIndex,1),this.invoiceItems.splice(t.newIndex,0,e);const s=this.invoiceItems.map(i=>i.id);this.saveOrderToDatabase(s)},nl2br(t){return t?t.replace(/\n/g,"<br>"):""},resize(){let t=this.$refs.textarea;t.style.height="auto",t.style.height=t.scrollHeight+"px"},saveOrderToDatabase(t){fetch("/wp-json/my-easy-compta/v1/invoices/update-invoice-items-order",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({order:t})}).then(e=>{e.ok?console.log("Order saved successfully."):console.error("Failed to save order:",e.statusText)}).catch(e=>{console.error("Error saving order:",e)})},fetchCategoriesArticles(){fetch("/wp-json/my-easy-compta/v1/categories-articles",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.categories=t}).catch(t=>console.error("Error fetching categories:",t))},ShowModalArticles(){this.showArticlesModal=!0,modal_articles.showModal()},applySelectedArticle(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description||"",this.newItem.unit_price=t.unit_price||0},fetchArticles(){if(this.newItem.item_name.length<1){this.articles=[];return}const t=document.getElementById("loader_articles");t.classList.remove("hidden"),fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_name}&method=name`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{this.articles=e}).catch(e=>console.error("Error fetching articles:",e)).finally(()=>{t.classList.add("hidden")})},toggleDisbursements(){this.showDisbursements=!this.showDisbursements},addDisbursements(){this.loading_add_disbursements=!0,fetch("/wp-json/my-easy-compta/v1/invoices/disbursements",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify({invoice_id:this.invoice.id,title:this.disbursementsItem.title,description:this.disbursementsItem.description,unit_price:parseFloat(this.disbursementsItem.unit_price)})}).then(t=>{if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}).then(t=>{this.disbursementsItem={title:"",description:"",unit_price:""},this.disbursementsList.push(t),this.disbursementsExist=!0}).catch(t=>{console.error("Erreur lors de l'ajout du d\xE9bours :",t)}).finally(()=>{this.loading_add_disbursements=!1})},selectItem(t){this.newItem.item_ref=t.ref,this.newItem.item_name=t.name,this.newItem.item_description=t.description,this.newItem.unit_price=t.unit_price,this.showDropdown=!1,this.showDropdownRef=!1},fetchRefs(){if(this.newItem.item_ref.length<1){this.refs=[];return}fetch(`/wp-json/my-easy-compta/v1/articles?search=${this.newItem.item_ref}&method=ref`,{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.refs=t}).catch(t=>console.error("Error fetching refrences:",t))},async loadSettings(){try{this.loadingPrice=!0;const{settings:t,currencySymbol:e,vatData:s,listVatData:i}=await mn();this.settings=t,this.default_currency_symbol=e,this.default_vat=s,this.list_vats=i,this.newItem.vat_rate=this.default_vat.rate,this.loadingPrice=!1}catch(t){this.showToast(t.message,"alert-error"),this.loadingPrice=!1}},highlightMatch(t){if(!this.newItem.item_name)return t;const e=new RegExp(`(${this.escapeRegExp(this.newItem.item_name)})`,"gi");return t.replace(e,"<b>$1</b>")},escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},handleClickOutside(t){this.$el.contains(t.target)||(this.showDropdown=!1,this.showDropdownRef=!1)},sendRemind(t){this.loadingModal=!0,this.RemindInvoiceModal=!0,modal_send_remind.showModal(),this.fetchClientInfo(t),this.loadSettings()},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}},beforeDestroy(){document.removeEventListener("click",this.handleClickOutside)},mounted(){this.fetchInvoice(),this.fetchItems(),this.loadSettings(),this.fetchCategoriesArticles(),this.fetchDisbursements(),document.addEventListener("click",this.handleClickOutside);const t=document.querySelector("tbody");M.create(t,{animation:150,handle:".drag-handle",onEnd:this.onDragEnd})}},Rv={class:"pt-2 pr-4"},Mv={key:0},Ov={key:2,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},qv=r("span",{class:"loading loading-spinner text-primary loading-lg"},null,-1),Nv=[qv],Bv={key:3},Vv={role:"alert",class:"alert alert-warning"},Fv=r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),Uv={key:0},Lv=["data-tip"],Wv={class:"btn btn-sm btn-primary",disabled:""},Xv={class:"grid grid-cols-2"},Hv={class:"md:col-span-1"},zv=["src"],Qv={class:"md:col-span-1 text-right"},Gv={class:"text-lg font-semibold"},Jv={key:0,class:"badge badge-error text-white"},Yv={key:1,class:"badge badge-error text-white"},Kv={key:2,class:"badge badge-success text-white"},Zv={class:"bg-base-300 rounded-lg shadow-md flex justify-between p-4 mt-4 gap-4"},$v=r("br",null,null,-1),e1=r("br",null,null,-1),t1=r("br",null,null,-1),n1=["href"],s1=r("br",null,null,-1),o1=r("br",null,null,-1),i1=r("br",null,null,-1),r1=["href"],a1=r("br",null,null,-1),l1=["href"],c1={class:"table mt-8"},d1=r("th",null,null,-1),u1={width:"5%"},h1={width:"19%"},m1={width:"21%"},f1={width:"10%",class:"text-center"},p1={width:"8%",class:"text-center"},_1={key:0,width:"5%",class:"text-center"},g1={key:1,width:"5%"},y1={width:"10%",class:"text-center"},b1={width:"10%",class:"text-right"},v1=r("th",{width:"18%",class:"text-right inv-actions"},null,-1),w1={class:"draggable-item drag-handle px-2"},x1={key:0,class:"fas fa-sort"},E1={key:0,class:"badge badge-ghost badge-xs"},C1=["innerHTML"],T1={class:"text-center"},I1={class:"text-center"},k1={key:0},A1={key:1},S1={key:0,class:"text-center"},D1={key:1},P1={key:2,class:"text-center"},j1=r("br",null,null,-1),R1={key:3,class:"text-center"},M1=r("br",null,null,-1),O1={class:"text-right"},q1={key:0},N1={key:1},B1={key:0},V1=["data-tip"],F1=["onClick"],U1=r("i",{class:"far fa-edit"},null,-1),L1=[U1],W1=["data-tip"],X1=["onClick"],H1={key:0,class:"far fa-trash-alt"},z1={key:1,class:"loading loading-spinner loading-xs"},Q1={key:0},G1={class:"align-top px-2"},J1=r("i",{class:"fas fa-list-ul"},null,-1),Y1=[J1],K1={class:"align-top px-2"},Z1={class:"flex items-center border rounded-md relative"},$1=["placeholder"],ew={key:0,class:"autocomplete-dropdown bg-base-100"},tw=["onClick","innerHTML"],nw={class:"align-top px-2"},sw=r("option",{disabled:"",selected:""},"Type",-1),ow=["value"],iw={class:"flex items-center border rounded-md relative"},rw=r("span",{id:"loader_articles",class:"loading loading-spinner loading-xs absolute right-2 hidden"},null,-1),aw=["placeholder"],lw={key:0,class:"autocomplete-dropdown bg-base-100"},cw=["onClick","innerHTML"],dw={class:"align-top"},uw={class:"flex items-center rounded-md"},hw=["placeholder"],mw={class:"align-top"},fw={class:"flex items-center border rounded-lg"},pw={class:"inline-flex"},_w=["placeholder"],gw={class:"align-top"},yw={class:"flex items-center border rounded-md"},bw=["placeholder"],vw={key:0,class:"align-top"},ww=["value"],xw={key:1,class:"align-top"},Ew={class:"align-top"},Cw={class:"flex items-center border rounded-md"},Tw=["placeholder"],Iw=r("div",{class:"px-3 py-2.5 rounded-l-md bg-base-300 border-r"}," % ",-1),kw={key:2,class:"text-right"},Aw={key:3,class:"text-right"},Sw={key:0},Dw=["data-tip"],Pw={type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"},jw={key:0,class:"fa fa-plus"},Rw={key:1,class:"loading loading-spinner loading-xs"},Mw={key:1},Ow={colspan:"12",class:"font-bold text-lg pl-0 pt-10"},qw={key:1,class:"ml-2"},Nw={key:2},Bw={class:"p-2",colspan:"3"},Vw={class:"p-2"},Fw={class:"p-2",colspan:"1"},Uw={class:"p-2",colspan:"3"},Lw=["innerHTML"],Ww={class:"p-2"},Xw={class:"p-2",colspan:"2"},Hw=["data-tip"],zw=["onClick"],Qw=r("i",{class:"far fa-edit"},null,-1),Gw=[Qw],Jw=["data-tip"],Yw=["onClick"],Kw={key:0,class:"far fa-trash-alt"},Zw={key:1,class:"loading loading-spinner loading-xs"},$w={key:3},e0={class:"align-top px-2",colspan:"3"},t0={class:"flex items-center border rounded-md"},n0=["placeholder"],s0={class:"align-top px-2"},o0={class:"flex items-center rounded-md"},i0=["placeholder"],r0={class:"align-top"},a0={class:"flex items-center border rounded-md"},l0=["placeholder"],c0=r("td",{class:"align-top",colspan:"3"},null,-1),d0={class:"text-right"},u0=["data-tip"],h0={key:0,class:"fa fa-plus"},m0={key:1,class:"loading loading-spinner loading-xs"},f0={class:"border-t-4"},p0={colspan:"8",class:"text-right no-border"},_0={class:"text-right"},g0={key:0,class:"line-through"},y0=r("td",null,null,-1),b0={colspan:"8",class:"text-right no-border"},v0={class:"text-right"},w0=r("td",null,null,-1),x0={key:5},E0={colspan:"8",class:"text-right no-border"},C0={class:"text-right no-border"},T0={key:6},I0={colspan:"8",class:"text-right no-border"},k0={class:"text-right no-border"},A0=r("td",null,null,-1),S0={colspan:"8",class:"text-right no-border font-bold text-xl"},D0={class:"text-right no-border font-bold text-xl"},P0=r("td",null,null,-1),j0={key:7},R0={colspan:"8",class:"text-right no-border"},M0={class:"text-right no-border"},O0={key:8},q0={colspan:"8",class:"text-right no-border"},N0={class:"text-right no-border font-bold text-xl"};function B0(t,e,s,i,n,o){const a=O("InvoiceNavBar"),l=O("remove-modal"),f=O("article-modal"),d=O("remind-invoice-modal"),m=O("edit-item-modal"),p=O("edit-disb-modal"),y=O("Card");return u(),h("div",Rv,[P(a,{invoiceInfo:n.invoice,currencyDefault:o.defaultCurrency,currencyClient:o.clientCurrency,emailActive:n.settings.easy_compta_email_addon_active,qrCodeActive:n.settings.easy_compta_qrcode_addon_active,noItems:n.no_items},null,8,["invoiceInfo","currencyDefault","currencyClient","emailActive","qrCodeActive","noItems"]),P(l,{"modal-id":"modal_remove_item","show-modal":t.showRemoveModal,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[0]||(e[0]=_=>this.removeItem(n.selectedItem,n.SelectedInvoiceId)),onCancel:e[1]||(e[1]=_=>t.showRemoveModal=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(l,{"modal-id":"modal_remove_disb","show-modal":t.showRemoveModalDisb,title:o.translations.are_you_sure,message:o.translations.no_turning_back,confirmText:o.translations.yes_delete_it,cancelText:o.translations.cancel,onConfirm:e[2]||(e[2]=_=>this.removeDisb(n.selectedDisb,n.SelectedInvoiceId)),onCancel:e[3]||(e[3]=_=>t.showRemoveModalDisb=!1)},null,8,["show-modal","title","message","confirmText","cancelText"]),P(f,{"show-modal":n.showArticlesModal,"modal-id":"modal_articles","modal-title":o.translations.select,onSelectArticle:o.applySelectedArticle,onClose:e[4]||(e[4]=_=>n.showArticlesModal=!1)},null,8,["show-modal","modal-title","onSelectArticle"]),n.settings.easy_compta_email_addon_active==1?(u(),h("div",Mv,[P(d,{loading:t.loadingModal,"show-modal":n.RemindInvoiceModal,"modal-id":"modal_send_remind",client:n.client_detail,"invoice-id":n.invoice.id,subject:n.settings.remind_invoice_subject,content:n.settings.remind_invoice_content,onClose:e[5]||(e[5]=_=>n.RemindInvoiceModal=!1)},null,8,["loading","show-modal","client","invoice-id","subject","content"])])):g("",!0),n.toast.visible?(u(),h("div",{key:1,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),n.loading?(u(),h("div",Ov,Nv)):g("",!0),o.isInvoiceOverdue&&n.invoice.status=="unpaid"?(u(),h("div",Bv,[r("div",Vv,[Fv,r("span",null,c(o.translations.invoice_overdue),1),n.settings.easy_compta_email_addon_active==1?(u(),h("div",Uv,[r("button",{onClick:e[6]||(e[6]=J(_=>o.sendRemind(n.invoice.client_id),["prevent"])),class:"btn btn-sm btn-primary"},c(o.translations.remind_invoice),1)])):(u(),h("div",{key:1,class:"tooltip tooltip-bottom tooltip-warning","data-tip":o.translations.active_email_addon},[r("button",Wv,c(o.translations.remind_invoice),1)],8,Lv))])])):g("",!0),P(y,{topMargin:"mt-8",id:"invoice-content"},{default:me(()=>[r("div",Xv,[r("div",Hv,[r("div",null,[r("img",{src:n.settings.logo_url,style:no({width:n.settings.logo_width+"px"}),alt:"Logo"},null,12,zv)])]),r("div",Qv,[r("p",Gv,c(n.invoice.invoice_number),1),r("div",null,[C(c(o.translations.created_at)+": ",1),r("strong",null,c(n.invoice.created_at),1)]),r("div",null,[C(c(o.translations.due_date)+": ",1),r("strong",null,c(n.invoice.due_date),1)]),r("div",null,[C(c(o.translations.status)+": ",1),n.invoice.status=="draft"?(u(),h("span",Jv,c(o.translations.draft),1)):g("",!0),n.invoice.status=="unpaid"?(u(),h("span",Yv,c(o.translations.unpaid),1)):g("",!0),n.invoice.status=="paid"?(u(),h("span",Kv,c(o.translations.paid),1)):g("",!0)])])]),r("div",Zv,[r("div",null,[r("strong",null,c(o.translations.bill_to)+":",1),r("h4",null,[r("strong",null,c(n.client_detail.company_name),1)]),r("p",null,[C(c(n.client_detail.address),1),$v,C(" "+c(n.client_detail.postal_code)+", "+c(n.client_detail.city)+" ",1),e1,C(" "+c(n.client_detail.country),1),t1,n.client_detail.phone?(u(),h("a",{key:0,href:"tel:"+n.client_detail.phone},c(n.client_detail.phone),9,n1)):g("",!0)])]),r("div",null,[r("strong",null,c(o.translations.received_from)+":",1),r("h4",null,[r("strong",null,c(n.settings.company_name),1)]),r("p",null,[C(c(n.settings.company_address),1),s1,C(" "+c(n.settings.postal_code)+", "+c(n.settings.city)+" ",1),o1,C(" "+c(n.settings.country),1),i1,n.settings.company_phone?(u(),h("a",{key:0,href:"tel:"+n.settings.company_phone},c(n.settings.company_phone),9,r1)):g("",!0),a1,n.settings.mobile_phone?(u(),h("a",{key:1,href:"tel:"+n.settings.mobile_phone},c(n.settings.mobile_phone),9,l1)):g("",!0)])])]),P(m,{loading:t.loadingModal,"show-modal":n.editItemsModal,"modal-id":"modal_edit_item","modal-title":o.translations.edit_item,item:n.selectedItem,onClose:e[7]||(e[7]=_=>n.editItemsModal=!1),onItemEdited:o.fetchItems},null,8,["loading","show-modal","modal-title","item","onItemEdited"]),P(p,{loading:t.loadingModal,"show-modal":n.editDisbModal,"modal-id":"modal_edit_disb","modal-title":o.translations.edit_item,disb:n.selectedDisb,onClose:e[8]||(e[8]=_=>n.editDisbModal=!1),onDisbEdited:o.fetchDisbursements},null,8,["loading","show-modal","modal-title","disb","onDisbEdited"]),r("form",{onSubmit:e[34]||(e[34]=J((..._)=>o.submitItems&&o.submitItems(..._),["prevent"]))},[r("table",c1,[r("thead",null,[r("tr",null,[d1,r("th",u1,c(o.translations.item_ref),1),r("th",h1,c(o.translations.item_name),1),r("th",m1,c(o.translations.description),1),r("th",f1,c(o.translations.quantity),1),r("th",p1,c(o.translations.unit_price),1),n.settings.vat_active==1?(u(),h("th",_1,c(o.translations.vat),1)):(u(),h("th",g1)),r("th",y1,c(o.translations.discount),1),r("th",b1,c(o.translations.total),1),v1])]),r("tbody",null,[(u(!0),h(F,null,U(n.invoiceItems,(_,v)=>(u(),h("tr",{key:_.id||v},[r("td",w1,[n.invoice.status=="draft"?(u(),h("i",x1)):g("",!0)]),r("td",null,c(_.item_ref),1),r("td",null,[_.category_name?(u(),h("div",E1,c(_.category_name),1)):g("",!0),r("div",null,c(_.item_name),1)]),r("td",{innerHTML:o.nl2br(_.item_description)},null,8,C1),r("td",T1,c(_.quantity),1),r("td",I1,[C(c(_.unit_price),1),n.default_currency_symbol==n.client_currency?(u(),h("span",k1,c(n.default_currency_symbol),1)):(u(),h("span",A1,c(n.client_currency),1))]),n.settings.vat_active==1?(u(),h("td",S1,c(_.vat_rate)+"% ",1)):(u(),h("td",D1)),n.settings.vat_active==1?(u(),h("td",P1,[C(c(_.discount)+"% ",1),j1,C(" "+c(o.calculateDiscountAmountWithVAT(_.quantity,_.unit_price,_.vat_rate,_.discount)),1)])):(u(),h("td",R1,[C(c(_.discount)+"% ",1),M1,C(" "+c(o.calculateDiscountAmount(_.quantity,_.unit_price,_.discount)),1)])),r("td",O1,[C(c(_.total_amount)+" ",1),n.default_currency_symbol==n.client_currency?(u(),h("span",q1,c(n.default_currency_symbol),1)):(u(),h("span",N1,c(n.client_currency),1))]),r("td",null,[n.invoice.status=="draft"?(u(),h("div",B1,[r("span",{class:"lg:tooltip","data-tip":o.translations.edit},[r("button",{onClick:J(x=>o.editItem(_.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},L1,8,F1)],8,V1),r("span",{class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:J(x=>o.confirmremoveItem(_.id,n.invoice.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[_.loading_del?g("",!0):(u(),h("i",H1)),_.loading_del?(u(),h("span",z1)):g("",!0)],8,X1)],8,W1)])):g("",!0)])]))),128)),n.invoice.status=="draft"?(u(),h("tr",Q1,[r("td",G1,[r("span",{class:"cursor-pointer",onClick:e[9]||(e[9]=J((..._)=>o.ShowModalArticles&&o.ShowModalArticles(..._),["prevent"]))},Y1)]),r("td",K1,[r("div",Z1,[D(r("input",{type:"text","onUpdate:modelValue":e[10]||(e[10]=_=>n.newItem.item_ref=_),onInput:e[11]||(e[11]=(..._)=>o.fetchRefs&&o.fetchRefs(..._)),onFocus:e[12]||(e[12]=_=>n.showDropdownRef=!0),placeholder:o.translations.item_ref,class:"w-full p-2.5 input-xs outline-none"},null,40,$1),[[W,n.newItem.item_ref]]),n.showDropdownRef&&n.refs.length?(u(),h("ul",ew,[(u(!0),h(F,null,U(n.refs,_=>(u(),h("li",{key:_.ref,onClick:v=>o.selectItem(_),class:"autocomplete-item",innerHTML:o.highlightMatch(_.ref)},null,8,tw))),128))])):g("",!0)])]),r("td",nw,[D(r("select",{class:"select select-xs w-full mb-1 ecwp-select","onUpdate:modelValue":e[13]||(e[13]=_=>n.newItem.item_category=_)},[sw,(u(!0),h(F,null,U(n.categories,_=>(u(),h("option",{key:_.id,value:_.id},c(_.name),9,ow))),128))],512),[[ue,n.newItem.item_category]]),r("div",iw,[rw,D(r("input",{type:"text","onUpdate:modelValue":e[14]||(e[14]=_=>n.newItem.item_name=_),onInput:e[15]||(e[15]=(..._)=>o.fetchArticles&&o.fetchArticles(..._)),onFocus:e[16]||(e[16]=_=>n.showDropdown=!0),placeholder:o.translations.item_name,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,40,aw),[[W,n.newItem.item_name]]),n.showDropdown&&n.articles.length?(u(),h("ul",lw,[(u(!0),h(F,null,U(n.articles,_=>(u(),h("li",{key:_.name,onClick:v=>o.selectItem(_),class:"autocomplete-item bt-primary",innerHTML:o.highlightMatch(_.name)},null,8,cw))),128))])):g("",!0)])]),r("td",dw,[r("div",uw,[D(r("textarea",{"onUpdate:modelValue":e[17]||(e[17]=_=>n.newItem.item_description=_),placeholder:o.translations.item_description,class:"textarea textarea-bordered input-xs w-full",onInput:e[18]||(e[18]=_=>o.resize()),ref:"textarea"},null,40,hw),[[W,n.newItem.item_description]])])]),r("td",mw,[r("div",fw,[r("div",pw,[r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-l",onClick:e[19]||(e[19]=(..._)=>o.decrease&&o.decrease(..._))}," - "),D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[20]||(e[20]=_=>n.newItem.quantity=_),placeholder:o.translations.quantity,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[21]||(e[21]=(..._)=>o.updateTotal&&o.updateTotal(..._))},null,40,_w),[[W,n.newItem.quantity]]),r("div",{class:"select-none border py-3 px-2 cursor-pointer bg-base-300 hover:bg-gray-200 rounded-r",onClick:e[22]||(e[22]=(..._)=>o.increase&&o.increase(..._))}," + ")])])]),r("td",gw,[r("div",yw,[D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[23]||(e[23]=_=>n.newItem.unit_price=_),placeholder:o.translations.unit_price,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[24]||(e[24]=(..._)=>o.updateTotal&&o.updateTotal(..._))},null,40,bw),[[W,n.newItem.unit_price]])])]),n.settings.vat_active==1?(u(),h("td",vw,[D(r("select",{"onUpdate:modelValue":e[25]||(e[25]=_=>n.newItem.vat_rate=_),onChange:e[26]||(e[26]=(..._)=>o.updateTotal&&o.updateTotal(..._)),class:"select select-md w-full mb-1 ecwp-select min-w-20"},[(u(!0),h(F,null,U(n.list_vats,_=>(u(),h("option",{key:_,value:_.rate},c(_.rate)+"% ",9,ww))),128))],544),[[ue,n.newItem.vat_rate]])])):(u(),h("td",xw)),r("td",Ew,[r("div",Cw,[D(r("input",{type:"number","onUpdate:modelValue":e[27]||(e[27]=_=>n.newItem.discount=_),min:"0",max:"100",placeholder:o.translations.discount,class:"w-full p-2.5 bg-transparent outline-none max-w-40 min-w-10",onInput:e[28]||(e[28]=(..._)=>o.updateTotal&&o.updateTotal(..._))},null,40,Tw),[[W,n.newItem.discount]]),Iw])]),n.settings.vat_active==1?(u(),h("td",kw,c(o.calculateTotalWithVat(n.newItem.quantity,n.newItem.unit_price,n.newItem.vat_rate,n.newItem.discount)),1)):(u(),h("td",Aw,c(o.calculateTotal(n.newItem.quantity,n.newItem.unit_price,n.newItem.discount)),1)),r("td",null,[n.invoice.status=="draft"?(u(),h("div",Sw,[r("span",{class:"lg:tooltip","data-tip":o.translations.add},[r("button",Pw,[n.loading_add?g("",!0):(u(),h("i",jw)),n.loading_add?(u(),h("span",Rw)):g("",!0)])],8,Dw)])):g("",!0)])])):g("",!0),n.settings.active_disbursements==1?(u(),h("tr",Mw,[r("td",Ow,[n.invoice.status=="draft"?(u(),h("button",{key:0,onClick:e[29]||(e[29]=J((..._)=>o.toggleDisbursements&&o.toggleDisbursements(..._),["prevent"])),class:"btn btn-primary py-2 px-4 rounded text-white"},[r("i",{class:I({"fas fa-plus":!n.showDisbursements,"fas fa-minus":n.showDisbursements})},null,2)])):g("",!0),n.invoice.status=="draft"||n.disbursementsExist?(u(),h("span",qw,c(o.translations.disbursements),1)):g("",!0)])])):g("",!0),n.settings.active_disbursements==1&&n.disbursementsList&&n.disbursementsList.length>0?(u(),h("tr",Nw,[r("th",Bw,c(o.translations.item_name),1),r("th",Vw,c(o.translations.description),1),r("th",Fw,c(o.translations.unit_price),1)])):g("",!0),(u(!0),h(F,null,U(n.disbursementsList,_=>(u(),h("tr",{key:_.id},[r("td",Uw,c(_.title),1),r("td",{class:"p-2",innerHTML:o.nl2br(_.description)},null,8,Lw),r("td",Ww,c(o.calculateTotal(1,_.unit_price,0)),1),r("td",Xw,[r("span",{class:"lg:tooltip","data-tip":o.translations.edit},[r("button",{onClick:J(v=>o.editDisb(_.id),["prevent"]),class:"bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-3 rounded"},Gw,8,zw)],8,Hw),r("span",{class:"lg:tooltip","data-tip":o.translations.delete},[r("button",{onClick:J(v=>o.confirmremoveDisb(_.id,n.invoice.id),["prevent"]),class:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 mx-2 rounded"},[_.loading_del?g("",!0):(u(),h("i",Kw)),_.loading_del?(u(),h("span",Zw)):g("",!0)],8,Yw)],8,Jw)])]))),128)),n.settings.active_disbursements==1&&n.showDisbursements&&n.invoice.status=="draft"?(u(),h("tr",$w,[r("td",e0,[r("div",t0,[D(r("input",{type:"text","onUpdate:modelValue":e[30]||(e[30]=_=>n.disbursementsItem.title=_),placeholder:o.translations.title,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,8,n0),[[W,n.disbursementsItem.title]])])]),r("td",s0,[r("div",o0,[D(r("textarea",{"onUpdate:modelValue":e[31]||(e[31]=_=>n.disbursementsItem.description=_),placeholder:o.translations.description,class:"textarea textarea-bordered input-xs w-full"},null,8,i0),[[W,n.disbursementsItem.description]])])]),r("td",r0,[r("div",a0,[D(r("input",{type:"text",pattern:"([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]","onUpdate:modelValue":e[32]||(e[32]=_=>n.disbursementsItem.unit_price=_),placeholder:o.translations.price,class:"w-full p-2.5 bg-transparent input-xs outline-none"},null,8,l0),[[W,n.disbursementsItem.unit_price]])])]),c0,r("td",d0,c(o.calculateTotal(1,n.disbursementsItem.unit_price,0)),1),r("td",null,[r("span",{class:"lg:tooltip","data-tip":o.translations.add_disbursements},[r("button",{type:"submit",class:"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded",onClick:e[33]||(e[33]=J((..._)=>o.addDisbursements&&o.addDisbursements(..._),["prevent"]))},[n.loading_add_disbursements?g("",!0):(u(),h("i",h0)),n.loading_add_disbursements?(u(),h("span",m0)):g("",!0)])],8,u0)])])):g("",!0),r("tr",f0,[r("td",p0,[r("strong",null,c(o.translations.subtotal),1)]),r("td",_0,[o.totalAmount!==o.totalAmountWithoutDiscount?(u(),h("span",g0,c(o.totalAmountWithoutDiscount),1)):g("",!0),C(" "+c(o.totalAmount),1)]),y0]),n.settings.vat_active==1?(u(!0),h(F,{key:4},U(o.getUniqueVATRates(),(_,v)=>(u(),h("tr",{key:v},[r("td",b0,[r("strong",null,c(o.translations.tax)+" ("+c(_)+"%) ",1)]),r("td",v0,c(o.calculateVATForRate(_)),1),w0]))),128)):g("",!0),n.invoice.shipping_amount?(u(),h("tr",x0,[r("td",E0,[r("strong",null,c(o.translations.shipping_fees),1)]),r("td",C0,c(o.formatShippingAmout(n.invoice.shipping_amount)),1)])):g("",!0),n.settings.active_disbursements==1&&n.disbursementsExist?(u(),h("tr",T0,[r("td",I0,[r("strong",null,c(o.translations.total_disbursements),1)]),r("td",k0,c(o.totalDisbursements()),1),A0])):g("",!0),r("tr",null,[r("td",S0,[r("strong",null,c(o.translations.total),1)]),r("td",D0,c(o.calculateTotalAmountWithVAT()),1),P0]),n.client_currency!=n.default_currency_symbol?(u(),h("tr",j0,[r("td",R0,[r("strong",null,c(o.translations.exchange_rate),1)]),r("td",M0,c(n.invoice.exchange_rate),1)])):g("",!0),n.client_currency!=n.default_currency_symbol?(u(),h("tr",O0,[r("td",q0,[r("strong",null,c(o.translations.total)+" "+c(n.default_currency_symbol),1)]),r("td",N0,c(o.totalAmountDefaultCurrency)+c(n.default_currency_symbol),1)])):g("",!0)])])],32)]),_:1})])}var V0=ne(jv,[["render",B0]]);const F0={name:"InvoiceNew",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt,AddClientModal:jo},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],last_invoice_number:"",toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings()},methods:{AddNew(){modal_clients.showModal()},cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`}))}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e;const s=`${this.settings.invoice_prefix}_${String(this.settings.last_invoice_id).padStart(4,"0")}`;this.invoice.number=s}else{const e=await t.json()}}catch{this.loading=!1}},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch("/wp-json/my-easy-compta/v1/invoices",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"),this.loadingBtn=!1)}).catch(t=>{console.error("Error submitting invoice:",t),this.showToast(t,"alert-error"),this.loadingBtn=!1})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},U0={class:"pt-2 pr-4"},L0={class:"flex justify-between items-center mb-4"},W0={class:"card-title"},X0=r("div",{class:"divider mt-2"},null,-1),H0={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},z0={class:"grid grid-cols-2 gap-4"},Q0={class:"ecwp-group form-group mb-4"},G0={for:"invoiceNumber",class:"ecwp-label"},J0={class:"ecwp-group form-group mb-4"},Y0={for:"invoiceDate",class:"ecwp-label"},K0={class:"mb-4"},Z0={class:"flex gap-2 items-end"},$0=r("i",{class:"fas fa-plus"},null,-1),ex=[$0],tx={class:"ecwp-group form-group w-full"},nx={for:"client",class:"ecwp-label"},sx={class:"ecwp-group form-group mb-4"},ox={for:"status",class:"ecwp-label"},ix={value:"draft"},rx={key:0,class:"ecwp-group form-group mb-4"},ax={for:"exchangeRate",class:"ecwp-label"},lx={class:"flex justify-between"},cx=["disabled"],dx={key:0,class:"loading loading-spinner loading-sm"};function ux(t,e,s,i,n,o){const a=O("VueDatePicker"),l=O("model-select"),f=O("Card"),d=O("AddClientModal");return u(),h("div",U0,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:me(()=>[r("div",L0,[r("h2",W0,c(o.translations.new_invoice),1)]),X0,n.loading?(u(),h("div",H0)):g("",!0),r("form",{onSubmit:e[7]||(e[7]=J((...m)=>o.submitInvoice&&o.submitInvoice(...m),["prevent"]))},[r("div",z0,[r("div",Q0,[r("label",G0,c(o.translations.invoice_number),1),D(r("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=m=>n.invoice.number=m),class:"ecwp-input input input-bordered w-full",disabled:"disabled"},null,512),[[W,n.invoice.number]])]),r("div",J0,[r("label",Y0,c(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=m=>n.invoice.due_date=m),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),r("div",K0,[r("div",Z0,[r("button",{type:"button",class:"btn btn-primary",onClick:e[2]||(e[2]=(...m)=>o.AddNew&&o.AddNew(...m))},ex),r("div",tx,[r("label",nx,c(o.translations.company_name),1),P(l,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[3]||(e[3]=m=>n.invoice.client_id=m),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])])])]),r("div",sx,[r("label",ox,c(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[4]||(e[4]=m=>n.invoice.status=m),class:I(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[r("option",ix,c(o.translations.draft),1)],2),[[ue,n.invoice.status]])]),o.currencyMismatch?(u(),h("div",rx,[r("label",ax,c(o.translations.exchange_rate),1),D(r("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[5]||(e[5]=m=>n.invoice.exchange_rate=m),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[W,n.invoice.exchange_rate]])])):g("",!0)]),r("div",lx,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[6]||(e[6]=(...m)=>o.cancelAction&&o.cancelAction(...m))},c(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.submit)+" ",1),n.loadingBtn?(u(),h("span",dx)):g("",!0)],8,cx)])],32)]),_:1}),P(d,{onClientAdded:o.fetchClients},null,8,["onClientAdded"])])}var hx=ne(F0,[["render",ux]]);const mx={name:"invoiceEdit",components:{Card:Ze,ModelSelect:hn,VueDatePicker:Nt},data(){return{invoice:{invoice_number:"",due_date:"",client_id:"",client:null,status:"paid",exchange_rate:0},showError:!1,loading:!1,loadingBtn:!1,clients:[],clientOptions:[],settings:[],toast:{visible:!1,message:"",type:"alert-success",position:"toast-bottom toast-end"}}},computed:{translations(){return window.myEasyComptaAdmin.easyComptaTranslations},formattedDate(){return t=>{if(!t)return"";const e=t.getDate().toString().padStart(2,"0"),s=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getFullYear();return`${e}-${s}-${i}`}},currencyMismatch(){const t=this.clients.find(e=>e.id===this.invoice.client_id);return t&&this.settings.default_currency!==t.currency_id}},mounted(){this.fetchClients(),this.fetchSettings(),this.fetchInvoiceDetails()},methods:{cancelAction(){this.$router.push("/invoices")},fetchClients(){this.loading=!0,fetch("/wp-json/my-easy-compta/v1/list-clients",{headers:{"X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(t=>t.json()).then(t=>{this.clients=t.clients,this.clientOptions=this.clients.map(e=>({value:e.id,text:`${e.company_name} - ${e.email} (${e.currency_symbol})`})),this.invoice.client_id&&this.setClientById(this.invoice.client_id)}).catch(t=>{console.error("Error fetching clients:",t)}).finally(()=>{this.loading=!1})},async fetchSettings(){try{this.loading=!0;const t=await fetch("/wp-json/my-easy-compta/v1/settings/get",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}});if(this.loading=!1,t.ok){const e=await t.json();this.settings=e}else{const e=await t.json();console.error("Error fetching settings:",e)}}catch(t){this.loading=!1,console.error("Error fetching settings:",t)}},fetchInvoiceDetails(){const t=this.$route.params.id;!t||(this.loading=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${t}`,{headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce}}).then(e=>e.json()).then(e=>{e?this.invoice=e:(console.error("Error fetching invoice details:",e.message),this.showToast(e.message,"alert-error"))}).catch(e=>{console.error("Error fetching invoice details:",e),this.showToast(e,"alert-error")}).finally(()=>{this.loading=!1}))},setClientById(t){this.invoice.client=this.clients.find(e=>e.id===t)||null},handleClientChange(){const t=this.clients.find(e=>e.id===this.invoice.client_id);t&&this.settings.default_currency!==t.currency_id?this.invoice.exchange_rate=1:this.invoice.exchange_rate=0},submitInvoice(){if(!this.invoice.due_date||!this.invoice.client_id||!this.invoice.status){this.showError=!0,this.showToast("Veuillez remplir tous les champs obligatoires.","alert-error");return}this.loadingBtn=!0,fetch(`/wp-json/my-easy-compta/v1/invoices/${this.$route.params.id}`,{method:"PUT",headers:{"Content-Type":"application/json","X-WP-Nonce":myEasyComptaAdmin.nonce},body:JSON.stringify(this.invoice)}).then(t=>{if(!t.ok)throw this.loadingBtn=!1,new Error("Network response was not ok");return t.json()}).then(t=>{t.success?(this.loadingBtn=!1,this.showToast(t.message,"alert-success"),this.$router.push({name:"InvoiceViewDetail",params:{id:t.id}})):(this.loadingBtn=!1,console.error("Error submitting invoice:",t.message),this.showToast(t.message,"alert-error"))}).catch(t=>{this.loadingBtn=!1,console.error("Error submitting invoice:",t),this.showToast(t,"alert-error")})},showToast(t,e){this.toast.message=t,this.toast.type=e,this.toast.visible=!0,setTimeout(()=>{this.toast.visible=!1},3e3)}}},fx={class:"pt-2 pr-4"},px={class:"flex justify-between items-center mb-4"},_x={class:"card-title"},gx=r("div",{class:"divider mt-2"},null,-1),yx={key:0,class:"fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-900 bg-opacity-50 z-50"},bx={class:"grid grid-cols-2 gap-4"},vx={class:"ecwp-group form-group mb-4"},wx={for:"invoiceNumber",class:"ecwp-label"},xx={class:"ecwp-group form-group mb-4"},Ex={for:"invoiceDate",class:"ecwp-label"},Cx={class:"ecwp-group form-group mb-4"},Tx={for:"client",class:"ecwp-label"},Ix={class:"ecwp-group form-group mb-4"},kx={for:"status",class:"ecwp-label"},Ax={value:"draft",selected:""},Sx={value:"unpaid"},Dx={value:"paid"},Px={key:0,class:"ecwp-group form-group mb-4"},jx={for:"exchangeRate",class:"ecwp-label"},Rx={class:"flex justify-between"},Mx=["disabled"],Ox={key:0,class:"loading loading-spinner loading-sm"};function qx(t,e,s,i,n,o){const a=O("VueDatePicker"),l=O("model-select"),f=O("Card");return u(),h("div",fx,[n.toast.visible?(u(),h("div",{key:0,class:I(["toast",n.toast.position]),style:{zIndex:9999}},[r("div",{class:I(["alert",n.toast.type,"text-white"])},[r("span",null,c(n.toast.message),1)],2)],2)):g("",!0),P(f,{topMargin:"mt-8",modalType:"modal_invoice_new"},{default:me(()=>[r("div",px,[r("h2",_x,c(o.translations.edit_invoice),1)]),gx,n.loading?(u(),h("div",yx)):g("",!0),r("form",{onSubmit:e[6]||(e[6]=J((...d)=>o.submitInvoice&&o.submitInvoice(...d),["prevent"]))},[r("div",bx,[r("div",vx,[r("label",wx,c(o.translations.invoice_number),1),D(r("input",{type:"text",id:"invoiceNumber","onUpdate:modelValue":e[0]||(e[0]=d=>n.invoice.invoice_number=d),class:"ecwp-input input input-bordered w-full",disabled:"true"},null,512),[[W,n.invoice.invoice_number]])]),r("div",xx,[r("label",Ex,c(o.translations.due_date),1),P(a,{class:I(["ecwp-input ecwp-date input input-bordered w-full",[!n.invoice.due_date&&n.showError?"input-error":""]]),id:"invoiceDate",modelValue:n.invoice.due_date,"onUpdate:modelValue":e[1]||(e[1]=d=>n.invoice.due_date=d),"enable-time-picker":!1,"auto-apply":"",format:o.formattedDate,"min-date":new Date,locale:"fr"},null,8,["class","modelValue","format","min-date"])]),r("div",Cx,[r("label",Tx,c(o.translations.company_name),1),P(l,{modelValue:n.invoice.client_id,"onUpdate:modelValue":e[2]||(e[2]=d=>n.invoice.client_id=d),options:n.clientOptions,label:"text","track-by":"value",placeholder:o.translations.select,class:I(["ecwp-input input input-bordered w-full",[!n.invoice.client_id&&n.showError?"input-error":""]])},null,8,["modelValue","options","placeholder","class"])]),r("div",Ix,[r("label",kx,c(o.translations.status),1),D(r("select",{id:"status","onUpdate:modelValue":e[3]||(e[3]=d=>n.invoice.status=d),class:I(["ecwp-input select select-bordered w-full",[!n.invoice.status&&n.showError?"input-error":""]])},[r("option",Ax,c(o.translations.draft),1),r("option",Sx,c(o.translations.unpaid),1),r("option",Dx,c(o.translations.paid),1)],2),[[ue,n.invoice.status]])]),o.currencyMismatch?(u(),h("div",Px,[r("label",jx,c(o.translations.exchange_rate),1),D(r("input",{type:"text",id:"exchangeRate","onUpdate:modelValue":e[4]||(e[4]=d=>n.invoice.exchange_rate=d),class:"ecwp-input input input-bordered w-full",required:""},null,512),[[W,n.invoice.exchange_rate]])])):g("",!0)]),r("div",Rx,[r("button",{type:"button",class:"btn btn-secondary rounded-full",onClick:e[5]||(e[5]=(...d)=>o.cancelAction&&o.cancelAction(...d))},c(o.translations.cancel),1),r("button",{type:"submit",class:"btn btn-primary rounded-full",disabled:n.loadingBtn},[C(c(o.translations.save)+" ",1),n.loadingBtn?(u(),h("span",Ox)):g("",!0)],8,Mx)])],32)]),_:1})])}var Nx=ne(mx,[["render",qx]]);const je=un;(function(t,e){const s=un,i=t();for(;[];)try{if(-parseInt(s(388))/1+-parseInt(s(399))/2+parseInt(s(402))/3*(parseInt(s(395))/4)+parseInt(s(391))/5*(parseInt(s(390))/6)+parseInt(s(384))/7*(parseInt(s(398))/8)+parseInt(s(396))/9*(-parseInt(s(381))/10)+-parseInt(s(383))/11*(-parseInt(s(392))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(dn,780643);function dn(){const t=["24qXimAf","/invoice/new","/quotes","549964dluHzw","443367uwdKlU","InvoiceNew","15256xYralW","1560954OjeLLN","InvoiceViewDetail","/quote/new","9lEwjuS","190YMLdNZ","/quote/edit/:id","3000305yGGYhw","3913VkmcCa","/invoices","Invoice","/invoice/detail/:id","128860zarLXn","QuoteViewDetail","6jCBQZu","3009905JNrxkz"];return dn=function(){return t},dn()}function un(t,e){const s=dn();return un=function(i,n){return i=i-381,s[i]},un(t,e)}const Bx=[{path:je(394),name:"Quote",component:xd},{path:"/quote/detail/:id",name:je(389),component:Pp},{path:je(401),name:"QuoteNew",component:l_},{path:je(382),name:"QuoteEdit",component:Ho},{path:je(385),name:je(386),component:bg},{path:je(387),name:je(400),component:V0},{path:"/invoice/edit/:id",name:"InvoiceEdit",component:Nx},{path:je(393),name:je(397),component:hx}],Hx=Cl({history:Za(),routes:Bx});export{jo as A,Hx as r};
  • my-easy-compta/trunk/includes/Modules/Settings.php

    r3190628 r3195461  
    10391039
    10401040        $encrypted_license_key = get_option('ecwp_client_license_key');
     1041
     1042        $license_key = openssl_decrypt($encrypted_license_key, 'AES-128-ECB', ECWP_SECRET_KEY);
     1043
     1044        $license_data = $this->get_validate_license($license_key);
     1045
    10411046        if (empty($encrypted_license_key)) {
    10421047            return new \WP_REST_Response(['success' => false, 'message' => 'License key not found.'], 404);
    10431048        }
    1044 
    1045         $license_key = openssl_decrypt($encrypted_license_key, 'AES-128-ECB', ECWP_SECRET_KEY);
    1046 
    1047         $license_data = $this->get_validate_license($license_key);
    10481049
    10491050        if (!$license_data || !$license_data['valid']) {
  • my-easy-compta/trunk/my-easy-compta.php

    r3195078 r3195461  
    33 * Plugin Name: myEasyCompta
    44 * Description: Streamline your financial management with myEasyCompta, an all-in-one accounting plugin. Effortlessly handle quotes, invoices, expenses, and more, all within a sleek, user-friendly interface. Perfect for freelancers and small businesses looking to simplify their accounting processes.
    5  * Version: 1.4.3
     5 * Version: 1.4.4
    66 * Author: MELIOZ.dev
    77 * Author URI: https://myeasycompta.com
     
    2222 *
    2323 * @package myEasyCompta
    24  * @since 1.4.3
     24 * @since 1.4.4
    2525 */
    2626
     
    3737     * @var string
    3838     */
    39     public $version = '1.4.3';
     39    public $version = '1.4.4';
    4040    private $version_migration_db = false;
    4141
  • my-easy-compta/trunk/readme.txt

    r3195078 r3195461  
    22Tags: accounting, quotes, invoices, expenses, freelancers
    33Requires at least: 6.2
    4 Tested up to: 6.6.1
     4Tested up to: 6.7.1
    55Requires PHP: 8.0
    6 Stable tag: 1.4.3
     6Stable tag: 1.4.4
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8080== Changelog ==
    8181
     82### = 1.4.4 =
     83* Enhance: Added a modal to easily select and apply articles for new items.
     84* Enhance: Improved the user interface for the item addition process.
     85
    8286= 1.4.3 =
    8387* Enhance: Updated the design of error notifications with a modern, responsive look.
Note: See TracChangeset for help on using the changeset viewer.