import{a as e,t}from"./rolldown-runtime-CNC7AqOf.js";import{t as n}from"./react-Augu_vA3.js";import{Cr as r,Dt as i,V as a,Vn as o,Vt as s,Wt as c,Y as l,_t as u,ai as d,ct as f,dt as p,et as m,lt as h,ot as g,qt as _,st as v,vn as y,wn as b,zt as x}from"./forms-CL2ODv4X.js";import{t as S}from"./useTranslation-B_YCgyrR.js";import{t as ee}from"./dayjs.min-wxmwWtJd.js";import{l as te}from"./dist-DWDqendd.js";import{t as ne}from"./jsx-runtime-CTknu7_t.js";import{a as re,c as ie,o as C}from"./cards-CR_9H_Xm.js";import{n as ae}from"./Combobox-BFkUVwV6.js";import{t as w}from"./Modal-C4GWc9Ry.js";import{t as T}from"./useHasPermission-CRA8mdHC.js";import{t as oe}from"./Plus-sxGnuR_5.js";import{n as se}from"./StatusColorTheme-C6Iyd2V-.js";import{n as E}from"./data-table-z0Fb_a7m.js";import{n as D,r as ce,t as le}from"./useAdjustColorDarkness-Ba6EO9yY.js";import{t as O}from"./Badge-BFQliKBR.js";import{t as k}from"./utc-Vb5zyARk.js";import{t as A}from"./ColorPicker-CDUktmxV.js";import{t as ue}from"./relativeTime-CCBsD5LK.js";var j=e(n()),M=e(ee(),1),N=e(ne());function P({size:e=`1.2rem`,filledColor:t=`#000`,borderColor:n=`#000`}){return(0,N.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,xmlnsXlink:`http://www.w3.org/1999/xlink`,x:`0px`,y:`0px`,style:{width:e,height:e},viewBox:`0 0 18 18`,children:[(0,N.jsx)(`path`,{d:`M9.00009 17C13.4184 17 17.0001 13.4183 17.0001 9C17.0001 4.58172 13.4184 1 9.00009 1C4.58181 1 1.00009 4.58172 1.00009 9C1.00009 13.4183 4.58181 17 9.00009 17Z`,fill:n}),(0,N.jsx)(`path`,{d:`M9.00009 13C11.2092 13 13.0001 11.2091 13.0001 9C13.0001 6.79086 11.2092 5 9.00009 5C6.79095 5 5.00009 6.79086 5.00009 9C5.00009 11.2091 6.79095 13 9.00009 13Z`,fill:t})]})}function F({color:e=`#000`,size:t=`1.2rem`}){return(0,N.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,xmlnsXlink:`http://www.w3.org/1999/xlink`,x:`0px`,y:`0px`,style:{width:t,height:t},viewBox:`0 0 18 18`,children:(0,N.jsx)(`path`,{d:`M9,17c-4.411,0-8-3.589-8-8S4.589,1,9,1s8,3.589,8,8-3.589,8-8,8Zm0-14.5c-3.584,0-6.5,2.916-6.5,6.5s2.916,6.5,6.5,6.5,6.5-2.916,6.5-6.5-2.916-6.5-6.5-6.5Z`,fill:e})})}var I=t(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self).dayjs_plugin_duration=r()})(e,(function(){var e,t,n=1e3,r=6e4,i=36e5,a=864e5,o=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,s=31536e6,c=2628e6,l=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,u={years:s,months:c,days:a,hours:i,minutes:r,seconds:n,milliseconds:1,weeks:6048e5},d=function(e){return e instanceof v},f=function(e,t,n){return new v(e,n,t.$l)},p=function(e){return t.p(e)+`s`},m=function(e){return e<0},h=function(e){return m(e)?Math.ceil(e):Math.floor(e)},g=function(e){return Math.abs(e)},_=function(e,t){return e?m(e)?{negative:!0,format:``+g(e)+t}:{negative:!1,format:``+e+t}:{negative:!1,format:``}},v=function(){function m(e,t,n){var r=this;if(this.$d={},this.$l=n,e===void 0&&(this.$ms=0,this.parseFromMilliseconds()),t)return f(e*u[p(t)],this);if(typeof e==`number`)return this.$ms=e,this.parseFromMilliseconds(),this;if(typeof e==`object`)return Object.keys(e).forEach((function(t){r.$d[p(t)]=e[t]})),this.calMilliseconds(),this;if(typeof e==`string`){var i=e.match(l);if(i){var a=i.slice(2).map((function(e){return e==null?0:Number(e)}));return this.$d.years=a[0],this.$d.months=a[1],this.$d.weeks=a[2],this.$d.days=a[3],this.$d.hours=a[4],this.$d.minutes=a[5],this.$d.seconds=a[6],this.calMilliseconds(),this}}return this}var g=m.prototype;return g.calMilliseconds=function(){var e=this;this.$ms=Object.keys(this.$d).reduce((function(t,n){return t+(e.$d[n]||0)*u[n]}),0)},g.parseFromMilliseconds=function(){var e=this.$ms;this.$d.years=h(e/s),e%=s,this.$d.months=h(e/c),e%=c,this.$d.days=h(e/a),e%=a,this.$d.hours=h(e/i),e%=i,this.$d.minutes=h(e/r),e%=r,this.$d.seconds=h(e/n),e%=n,this.$d.milliseconds=e},g.toISOString=function(){var e=_(this.$d.years,`Y`),t=_(this.$d.months,`M`),n=+this.$d.days||0;this.$d.weeks&&(n+=7*this.$d.weeks);var r=_(n,`D`),i=_(this.$d.hours,`H`),a=_(this.$d.minutes,`M`),o=this.$d.seconds||0;this.$d.milliseconds&&(o+=this.$d.milliseconds/1e3,o=Math.round(1e3*o)/1e3);var s=_(o,`S`),c=e.negative||t.negative||r.negative||i.negative||a.negative||s.negative,l=i.format||a.format||s.format?`T`:``,u=(c?`-`:``)+`P`+e.format+t.format+r.format+l+i.format+a.format+s.format;return u===`P`||u===`-P`?`P0D`:u},g.toJSON=function(){return this.toISOString()},g.format=function(e){var n=e||`YYYY-MM-DDTHH:mm:ss`,r={Y:this.$d.years,YY:t.s(this.$d.years,2,`0`),YYYY:t.s(this.$d.years,4,`0`),M:this.$d.months,MM:t.s(this.$d.months,2,`0`),D:this.$d.days,DD:t.s(this.$d.days,2,`0`),H:this.$d.hours,HH:t.s(this.$d.hours,2,`0`),m:this.$d.minutes,mm:t.s(this.$d.minutes,2,`0`),s:this.$d.seconds,ss:t.s(this.$d.seconds,2,`0`),SSS:t.s(this.$d.milliseconds,3,`0`)};return n.replace(o,(function(e,t){return t||String(r[e])}))},g.as=function(e){return this.$ms/u[p(e)]},g.get=function(e){var t=this.$ms,n=p(e);return n===`milliseconds`?t%=1e3:t=n===`weeks`?h(t/u[n]):this.$d[n],t||0},g.add=function(e,t,n){var r;return r=t?e*u[p(t)]:d(e)?e.$ms:f(e,this).$ms,f(this.$ms+r*(n?-1:1),this)},g.subtract=function(e,t){return this.add(e,t,!0)},g.locale=function(e){var t=this.clone();return t.$l=e,t},g.clone=function(){return f(this.$ms,this)},g.humanize=function(t){return e().add(this.$ms,`ms`).locale(this.$l).fromNow(!t)},g.valueOf=function(){return this.asMilliseconds()},g.milliseconds=function(){return this.get(`milliseconds`)},g.asMilliseconds=function(){return this.as(`milliseconds`)},g.seconds=function(){return this.get(`seconds`)},g.asSeconds=function(){return this.as(`seconds`)},g.minutes=function(){return this.get(`minutes`)},g.asMinutes=function(){return this.as(`minutes`)},g.hours=function(){return this.get(`hours`)},g.asHours=function(){return this.as(`hours`)},g.days=function(){return this.get(`days`)},g.asDays=function(){return this.as(`days`)},g.weeks=function(){return this.get(`weeks`)},g.asWeeks=function(){return this.as(`weeks`)},g.months=function(){return this.get(`months`)},g.asMonths=function(){return this.as(`months`)},g.years=function(){return this.get(`years`)},g.asYears=function(){return this.as(`years`)},m}(),y=function(e,t,n){return e.add(t.years()*n,`y`).add(t.months()*n,`M`).add(t.days()*n,`d`).add(t.hours()*n,`h`).add(t.minutes()*n,`m`).add(t.seconds()*n,`s`).add(t.milliseconds()*n,`ms`)};return function(n,r,i){e=i,t=i().$utils(),i.duration=function(e,t){return f(e,{$l:i.locale()},t)},i.isDuration=d;var a=r.prototype.add,o=r.prototype.subtract;r.prototype.add=function(e,t){return d(e)?y(this,e,1):a.bind(this)(e,t)},r.prototype.subtract=function(e,t){return d(e)?y(this,e,-1):o.bind(this)(e,t)}}}))})),L=e(I(),1),R=e(ue(),1);function z(e){if(e===``||e===`[]`)return[];let t=[[0,0,``,!0]],n=JSON.parse(e);return n.length?n:t}function B(e,t=!1){let n=z(e),r=0;for(let[e,i]of n){if(e>i&&!t)continue;let n=(i===0?Math.floor(Date.now()/1e3):typeof i==`number`?i:0)-(typeof e==`number`?e:0);r+=Math.max(n,0)}let i=Math.floor(r/3600),a=Math.floor(r%3600/60),o=r%60;return i<24?`${i}:${a.toString().padStart(2,`0`)}:${o.toString().padStart(2,`0`)}`:`${i}h`}function V(e,t){let n=z(e);M.default.extend(L.default),M.default.extend(R.default);let r=0;if(t?.calculateLastTimeLog){let e=n[n.length-1][0],t=e?M.default.unix(e):(0,M.default)();r+=(0,M.default)().diff(t,`seconds`)}else n.map(([e,t])=>{let n=e?M.default.unix(e):(0,M.default)(),i=t?M.default.unix(t):(0,M.default)();r+=i.diff(n,`seconds`)});return t?.inSeconds?r.toString():r>86400?M.default.duration(r,`seconds`).humanize():M.default.duration(r,`seconds`).format(`HH:mm:ss`)}function H(e,t){let n=z(e)[t],r=n?M.default.unix(n[0]):(0,M.default)(),i=(n?M.default.unix(n[1]):(0,M.default)()).diff(r,`seconds`);return new Date(i*1e3).toISOString().slice(11,19)}function U(e){let{isAdmin:t}=T();return c([`/api/v1/task_statuses`,`create`],()=>x(`GET`,i(`/api/v1/task_statuses/create`)).then(e=>e.data.data),{staleTime:1/0,enabled:t?e?.enabled??!0:!1})}function W(e){return c([`/api/v1/task_statuses`,e],()=>x(`GET`,i(`/api/v1/task_statuses?status=:status&sort=id|asc`,{status:e?.status||`all`})).then(e=>e.data),{staleTime:1/0})}function de(e){return c([`/api/v1/task_statuses`,e.id],()=>x(`GET`,i(`/api/v1/task_statuses/:id`,{id:e.id})),{staleTime:1/0})}function fe(){return(e,t)=>{y.processing(),x(`POST`,i(`/api/v1/task_statuses/bulk`),{action:t,ids:[e]}).then(()=>{y.success(`${t}d_task_status`),s([`task_statuses`])})}}function G(e){let t=!1,n=z(e.time_log).sort((e,t)=>e[0]-t[0]),r=0;return n.forEach(([e,i],a)=>{let o=n[a+1];i==0&&o&&(t=!0),o&&i>o[0]&&(t=!0),i!==0&&e>i&&(t=!0),i===0&&r++,r>1&&(t=!0)}),t}function K(e){let{isFormBusy:t,setErrors:n,setIsFormBusy:r}=e;return e=>{if(!t){if(r(!0),y.processing(),G(e))return r(!1),y.error(`task_errors`);x(`PUT`,i(`/api/v1/tasks/:id`,{id:e.id}),e).then(()=>{y.success(`updated_task`),s([`tasks`])}).catch(e=>{e.response?.status===422&&(y.dismiss(),n?.(e.response.data))}).finally(()=>r(!1))}}}function q(e){return(t,n)=>{e.setErrors(void 0),e.setTaskStatus(e=>e&&{...e,[t]:n})}}function pe(){let[e]=S(),t=fe();return[n=>n.archived_at===0&&(0,N.jsx)(C,{onClick:()=>t(n.id,`archive`),icon:(0,N.jsx)(m,{element:b}),children:e(`archive`)}),n=>n.archived_at>0&&(0,N.jsx)(C,{onClick:()=>t(n.id,`restore`),icon:(0,N.jsx)(m,{element:r}),children:e(`restore`)}),n=>!n.is_deleted&&(0,N.jsx)(C,{onClick:()=>t(n.id,`delete`),icon:(0,N.jsx)(m,{element:o}),children:e(`delete`)})]}function J(e){let[t]=S(),n=h(),{data:r}=U(),[o,c]=(0,j.useState)(),[l,u]=(0,j.useState)(!1),[d,f]=(0,j.useState)(),p=q({setErrors:c,setTaskStatus:f});return(0,j.useEffect)(()=>{r&&f(r)},[r]),(0,N.jsxs)(w,{title:t(`new_task_status`),visible:e.visible,onClose:()=>{e.setVisible(!1),f(r)},children:[(0,N.jsx)(a,{required:!0,label:t(`name`),value:d?.name,onValueChange:e=>p(`name`,e),errorMessage:o?.errors.name}),(0,N.jsx)(g,{children:t(`color`)}),(0,N.jsx)(A,{value:d?.color||n,onValueChange:e=>p(`color`,e)}),(0,N.jsx)(v,{className:`self-end`,behavior:`button`,disabled:l,onClick:()=>{l||(y.processing(),c(void 0),u(!0),x(`POST`,i(`/api/v1/task_statuses`),d).then(t=>{y.success(`created_task_status`),s([`task_statuses`]),f(r),e.onCreatedTaskStatus?.(t.data.data),e.setVisible(!1)}).catch(e=>{e.response?.status===422&&(c(e.response.data),y.dismiss())}).finally(()=>u(!1)))},children:t(`save`)})]})}var Y=f.div` &:hover { background-color: ${e=>e.theme.hoverColor}; } `;function X(e){let[t]=S(),n=u(),{isAdmin:r,isOwner:i}=T(),{visible:a,isFormBusy:o,setIsFormBusy:s,task:c,setVisible:l}=e,[d,f]=(0,j.useState)(!1),{data:p}=W({status:`active`}),m=K({isFormBusy:o,setIsFormBusy:s});return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(ie,{placement:`bottom`,interactive:!0,render:()=>(0,N.jsxs)(`div`,{className:`border box rounded-md shadow-lg focus:outline-none p-1`,style:{backgroundColor:n.$1,borderColor:n.$4,minWidth:`13rem`,maxWidth:`20rem`},children:[(0,N.jsx)(`div`,{className:`flex flex-col max-h-80 overflow-y-auto`,children:p?.data.map((e,t)=>(0,N.jsxs)(Y,{className:`flex items-center p-2 space-x-2 rounded-sm`,onClick:()=>{l(!1),m({...c,status_id:e.id})},theme:{hoverColor:n.$7},children:[(0,N.jsx)(`div`,{children:e.id===c.status_id?(0,N.jsx)(P,{size:`1.2rem`,filledColor:n.$1,borderColor:n.$3}):(0,N.jsx)(F,{size:`1.2rem`,color:n.$17})}),(0,N.jsx)(`span`,{className:`truncate`,children:e.name})]},t))}),!p?.data.length&&(0,N.jsx)(`div`,{className:`font-medium text-center py-2 text-xs`,children:t(`no_records_found`)}),(r||i)&&(0,N.jsx)(Y,{className:`flex items-center font-medium text-center p-2 rounded-sm`,onClick:()=>{f(!0),l(!1)},theme:{hoverColor:n.$7},children:(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(oe,{color:n.$17,size:`1.2rem`}),(0,N.jsx)(`span`,{children:t(`create_new`)})]})})]}),visible:a,children:(0,N.jsx)(`div`,{})}),(0,N.jsx)(J,{visible:d,setVisible:f,onCreatedTaskStatus:e=>m({...c,status_id:e.id})})]})}var Z=e(p(),1);function me(e){let[t]=S(),n=(0,j.useRef)(null);u();let r=ce(),i=se(),{invoice_id:a,archived_at:o,is_deleted:s,time_log:c,status:d}=e.entity,[f,p]=(0,j.useState)(!1),[m,h]=(0,j.useState)(!1);re(n,()=>{f&&p(!1)});let g=()=>{let e=z(c),t=e.length;return t?e[t-1][1]===0:!1};if(s)return(0,N.jsx)(O,{variant:`red`,children:t(`deleted`)});if(o)return(0,N.jsx)(O,{variant:`orange`,children:t(`archived`)});if(a)return(0,N.jsx)(O,{variant:`green`,style:{backgroundColor:i.$3},children:t(`invoiced`)});if(g())return(0,N.jsx)(O,{variant:`light-blue`,style:{backgroundColor:i.$2},children:t(`running`)});if(d){let{red:t,green:i,blue:a,hex:o}=le(d.color),s=D(t,i,a)?-220:220;return(0,N.jsxs)(`div`,{ref:n,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`flex items-center`,children:[(0,N.jsx)(`div`,{className:(0,Z.default)(`text-xs rounded-l px-2 py-1 border-r border-white font-medium`,{"rounded-r border-r-0":e.withoutDropdown}),style:{color:r(o,s),backgroundColor:d.color},children:d.name}),!e.withoutDropdown&&(0,N.jsx)(`div`,{className:`flex items-center justify-center rounded-r py-1 h-full`,style:{color:r(o,s),backgroundColor:d.color,width:`1.5rem`},onClick:()=>!m&&p(e=>!e),children:(0,N.jsx)(l,{color:r(o,s),size:`1rem`})})]}),(0,N.jsx)(X,{visible:f,isFormBusy:m,setIsFormBusy:h,task:e.entity,setVisible:p})]})}return(0,N.jsxs)(`div`,{ref:n,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`flex items-center`,children:[(0,N.jsx)(`div`,{className:(0,Z.default)(`text-xs rounded-l px-2 py-1 border-r border-white font-medium bg-gray-100 text-gray-800`,{"rounded-r border-r-0":e.withoutDropdown}),children:t(`logged`)}),!e.withoutDropdown&&(0,N.jsx)(`div`,{className:`flex items-center justify-center rounded-r py-1 h-full bg-gray-100`,onClick:()=>!m&&p(e=>!e),style:{width:`1.5rem`},children:(0,N.jsx)(l,{color:`#1f2937`,size:`1rem`})})]}),(0,N.jsx)(X,{visible:f,isFormBusy:m,setIsFormBusy:h,task:e.entity,setVisible:p})]})}var he=e(k(),1);function Q(e){let t=!1;return z(e.time_log).forEach(([,e])=>{e===0&&(t=!0)}),t}function $(e){return e.invoice_id?`invoiced`:Q(e)?`active`:`logged`}M.default.extend(he.default);function ge(e){if(e.invoice_id||Q(e))return!1;let t=z(e.time_log);if(!t.length)return!0;let n=M.default.utc().unix();return!t.some(([e,t])=>e>n||t>n)}function _e(){let e=_(),t=d(E),n=te();return r=>{y.processing(),x(`PUT`,i(`/api/v1/tasks/:id?start=true`,{id:r.id}),r).then(()=>{n.pathname.endsWith(`/create`)?y.dismiss():y.success(`started_task`),s([`tasks`]),t&&e.invalidateQueries([t])})}}function ve(){let e=_(),t=d(E);return n=>{y.processing();let r=z(n.time_log),a=r[r.length-1][0],o=(0,M.default)().unix();if(a&&a>o)r[r.length-1][1]=a+1,n.time_log=JSON.stringify(r);else if(G(n))return y.error(`task_errors`);x(`PUT`,i(`/api/v1/tasks/:id?stop=true`,{id:n.id}),n).then(()=>{y.success(`stopped_task`),s([`tasks`]),t&&e.invalidateQueries([t])})}}function ye(e){let[t]=S(),n=h(),{isAdmin:r,isOwner:o}=T(),[c,l]=(0,j.useState)(!1),[u,d]=(0,j.useState)(!1),[f,p]=(0,j.useState)(),[m,_]=(0,j.useState)(),{data:b}=U({enabled:c});return(0,j.useEffect)(()=>{b&&p(b)},[b]),(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(w,{title:t(`new_task_status`),visible:c,onClose:()=>{l(!1),p(b)},children:[(0,N.jsx)(a,{required:!0,label:t(`name`),value:f?.name,onValueChange:e=>p(t=>t&&{...t,name:e}),errorMessage:m?.errors.name}),(0,N.jsx)(g,{children:t(`color`)}),(0,N.jsx)(A,{value:f?.color||n,onValueChange:e=>p(t=>t&&{...t,color:e})}),(0,N.jsx)(v,{className:`self-end`,behavior:`button`,onClick:()=>{u||(y.processing(),_(void 0),d(!0),x(`POST`,i(`/api/v1/task_statuses`),f).then(t=>{y.success(`created_task_status`),s([`task_statuses`]),p(b),e.onChange(t.data.data),l(!1)}).catch(e=>{e.response?.status===422&&(_(e.response.data),y.dismiss())}).finally(()=>d(!1)))},children:t(`save`)})]}),(0,N.jsx)(ae,{endpoint:i(`/api/v1/task_statuses?status=active`),sortBy:`id|asc`,onChange:t=>t.resource&&e.onChange(t.resource),inputOptions:{label:e.inputLabel?.toString(),value:e.value||null},entryOptions:{id:`id`,label:`name`,value:`id`},action:{label:t(`new_task_status`),onClick:()=>l(!0),visible:(r||o)&&!e.withoutAction},onDismiss:e.onClearButtonClick,readonly:e.readonly,errorMessage:e.errorMessage})]})}export{P as S,B as _,$ as a,I as b,J as c,K as d,G as f,H as g,W as h,ge as i,pe as l,de as m,ve as n,Q as o,U as p,_e as r,me as s,ye as t,q as u,V as v,F as x,z as y};