import{ac as E,u as T,a as B,v as M,ce as F,cU as P,ah as I,aB as N,p as d,fe as R,E as $,j as s,ae as q,eG as w,C as A,c2 as i,Q as _,cY as D,dp as Y,ff as G,e8 as Q,c_ as S,c$ as f,F as j,r as U,e as O,ak as z,h as H}from"./bundle.CHKSNOJF.js";import{p as J}from"./atoms-jNEMAPkL.js";function W(){const{documentTitle:g}=E("new_project"),[r]=T(),m=B(),n=M(),[c]=F(),b=P(),y=I(),k=[{name:r("projects"),href:"/projects"},{name:r("new_project"),href:"/projects/create"}],[t,h]=N(J),[l,v]=d.useState(),[x,C]=d.useState(!1),a=(e,o)=>{h(u=>u&&{...u,[e]:o})},{data:p}=R({enabled:typeof t>"u"}),V=e=>{e.preventDefault(),!x&&(j.processing(),v(void 0),C(!0),U("POST",O("/api/v1/projects"),t).then(o=>{j.success("created_project"),z(["projects"]),y(H("/projects/:id/edit",{id:o.data.data.id}))}).catch(o=>{o.response?.status===422&&(j.dismiss(),v(o.response.data))}).finally(()=>{C(!1)}))};return d.useEffect(()=>{h(e=>{let o=e;if(c.get("action")!=="clone"&&(o=void 0),typeof p<"u"&&typeof o>"u"&&c.get("action")!=="clone"){const u=$.cloneDeep(p);u.task_rate=n?.settings.default_task_rate||0,c.get("client")&&(u.client_id=c.get("client")),o=u}return o})},[p]),d.useEffect(()=>{t?.client_id&&t.client_id.length>1&&b.find(t.client_id).then(e=>{e.settings.default_task_rate&&a("task_rate",e.settings.default_task_rate)})},[t?.client_id]),s.jsx(q,{title:g,breadcrumbs:k,disableSaveButton:!t||x,onSaveClick:V,children:s.jsx(w,{breadcrumbs:[],children:s.jsxs(A,{title:g,className:"shadow-sm",style:{borderColor:m.$24},headerStyle:{borderColor:m.$20},children:[s.jsx(i,{leftSide:r("project_name"),required:!0,children:s.jsx(_,{value:t?.name,onValueChange:e=>a("name",e),errorMessage:l?.errors.name,cypressRef:"name"})}),s.jsx(i,{leftSide:r("client"),required:!0,children:s.jsx(D,{value:t?.client_id,onChange:e=>a("client_id",e.id),clearButton:!!t?.client_id,onClearButtonClick:()=>a("client_id",""),errorMessage:l?.errors.client_id})}),s.jsx(i,{leftSide:r("assigned_user"),children:s.jsx(Y,{value:t?.assigned_user_id,onChange:e=>a("assigned_user_id",e.id),onClearButtonClick:()=>a("assigned_user_id",""),errorMessage:l?.errors.assigned_user_id})}),s.jsx(i,{leftSide:r("tags"),children:s.jsx(G,{entityType:Q.project,value:t?.tags||[],onChange:e=>a("tags",e),errorMessage:l?.errors.tags})}),s.jsx(i,{leftSide:r("due_date"),children:s.jsx(_,{type:"date",value:t?.due_date,onValueChange:e=>a("due_date",e),errorMessage:l?.errors.due_date})}),s.jsx(i,{leftSide:r("budgeted_hours"),children:s.jsx(S,{value:t?.budgeted_hours||"",onValueChange:e=>a("budgeted_hours",parseFloat(e)),errorMessage:l?.errors.budgeted_hours})}),s.jsx(i,{leftSide:r("task_rate"),children:s.jsx(S,{value:t?.task_rate||"",onValueChange:e=>a("task_rate",parseFloat(e)),errorMessage:l?.errors.task_rate})}),s.jsx(i,{leftSide:r("public_notes"),children:s.jsx(_,{element:"textarea",value:t?.public_notes,onValueChange:e=>a("public_notes",e),errorMessage:l?.errors.public_notes})}),s.jsx(i,{leftSide:r("private_notes"),children:s.jsx(_,{element:"textarea",value:t?.private_notes,onValueChange:e=>a("private_notes",e),errorMessage:l?.errors.private_notes})}),t&&n?.custom_fields?.project1&&s.jsx(f,{field:"project1",defaultValue:t.custom_value1||"",value:n.custom_fields.project1,onValueChange:e=>a("custom_value1",e.toString())}),t&&n?.custom_fields?.project2&&s.jsx(f,{field:"project2",defaultValue:t.custom_value2||"",value:n.custom_fields.project2,onValueChange:e=>a("custom_value2",e.toString())}),t&&n?.custom_fields?.project3&&s.jsx(f,{field:"project3",defaultValue:t.custom_value3||"",value:n.custom_fields.project3,onValueChange:e=>a("custom_value3",e.toString())}),t&&n?.custom_fields?.project4&&s.jsx(f,{field:"project4",defaultValue:t.custom_value4||"",value:n.custom_fields.project4,onValueChange:e=>a("custom_value4",e.toString())})]})})})}export{W as default};
