import{q as y,r as b,S as j,j as a,f as d}from"./app-Bup04Qnx.js";import{S}from"./Select-Cs0aMrtU.js";import{W as _}from"./WithModal-CbKxT3eW.js";import{l as k,k as g}from"./format-CisCU4Rs.js";import"./index-CtjruoRR.js";import"./floating-ui.dom-CwWDmSD9.js";import"./BaseForm-wkPKZ5Eg.js";const I=v=>{var m;const{props:n}=y(),o="company",i=b.useRef();let p=new URLSearchParams(new URL(n.location).search).get("company_id");const{data:s,setData:h,errors:u,processing:c}=j({company_id:((m=n.company)==null?void 0:m.id)??p});let l=null;n.companies.length>0&&(l=s.company_id?n.companies.findIndex(e=>e.value==s.company_id):null);const x=e=>{h(t=>({...t,company_id:e==null?void 0:e.value}))},f=e=>{e.preventDefault(),k("company_id",s.company_id,365,{onSuccess:()=>{var t;s.company_id?((t=i.current)==null||t.click(),d.visit("/admin/dashboard")):g("department_id",{onSuccess:()=>{var r;(r=i.current)==null||r.click(),d.visit("/admin/dashboard")}})}})};return a.jsx(_,{type:o,modalBoxSize:"max-w-2xl",children:a.jsxs("form",{action:"",children:[a.jsx("h1",{className:"text-lg font-bold",children:"Pilih Perusahaan Aktif"}),a.jsx("p",{children:"Semua aktivitas selama sesi ini akan terkait dengan perusahaan yang dipilih."}),a.jsx("div",{className:"mt-4",children:a.jsx(S,{isReactSelect:!0,isVirtualized:!0,isLabel:!1,name:"company_id",handleChange:x,data:s,errors:u,defaultValue:n.companies[l],options:n.companies})}),a.jsxs("div",{className:"modal-action",children:[a.jsx("label",{ref:i,htmlFor:`modal_${o}`,className:"btn btn-sm btn-neutral btn-outline",children:"Kembali"}),a.jsx("button",{onClick:f,className:"btn btn-sm btn-primary text-white ",disabled:c,children:a.jsx("span",{className:`${c&&"loading"}`,children:"Simpan"})})]})]})})};export{I as default};
