import{T as y,i as V,c as _,w as i,u as e,o as m,a as t,b as d,g as u,t as p,e as b,F as h,h as U,f as v}from"./app-WJL2kJBE.js";import{_ as g}from"./Button-Cw-sZQ7I.js";import{C as w}from"./CheckBox-DbNLzE9G.js";import{_ as f}from"./TextInput-DTKGEx4z.js";import{_ as B}from"./AppLayout-BWrI3d7K.js";import{_ as E}from"./InputError-idDGfizs.js";import{_ as C}from"./FormSection-VZbtMXdy.js";import{_ as N}from"./ActionMessage-CbAgcH97.js";import"./LoadingButton-H6RtHB1p.js";import"./Checkbox-WeIDo5uG.js";import"./v4-Ch9TGLTe.js";import"./Label-CBaaVbfI.js";import"./Input-C4-VG2dv.js";import"./Modal-B9NNWAdE.js";import"./SectionTitle-DsJypKOL.js";const S={class:"max-w-7xl mx-auto py-10 sm:px-6 lg:px-8"},$={class:"col-span-6 sm:col-span-3"},I={class:"col-span-6 sm:col-span-3"},P={class:"col-span-6 sm:col-span-3"},F={class:"col-span-6 sm:col-span-3"},A={class:"col-span-full"},L={key:0,class:"flex flex-wrap items-center gap-x-6 gap-y-3 mb-4"},T={class:"block w-full font-medium"},D={class:"font-bold mb-2"},R={class:"flex flex-col lg:flex-row gap-6"},le={__name:"Form",props:["edit","roles"],setup(c){const l=y({name:null,email:null,password:null,password_confirmation:null,roles:[],view_all:null,edit_all:null}),r=c;r.edit&&(l.name=r.edit.data.name,l.email=r.edit.data.email,l.password=r.edit.data.password,l.password_confirmation=r.edit.data.password_confirmation,l.roles=r.edit.data.roles.map(n=>n.name),l.view_all=r.edit.view_all,l.edit_all=r.edit.edit_all);const{t:s}=V({});function x(){let n=r.edit?"put":"post",o=r.edit?route("users.update",r.edit.data.id):route("users.store");l[n](o,{preserveScroll:!0,onSuccess:()=>{r.edit||l.reset()},onError:()=>{l.errors.name&&document.getElementById("name").focus(),l.errors.company&&document.getElementById("company").focus(),l.errors.email&&document.getElementById("email").focus(),l.errors.phone&&document.getElementById("phone").focus()}})}return(n,o)=>(m(),_(B,{title:r.edit?e(s)("Edit User"):e(s)("Add New User")},{default:i(()=>[t("div",S,[d(C,{onSubmitted:x,autocomplete:"off"},{title:i(()=>[u(p(r.edit?e(s)("Edit User"):e(s)("Add New User")),1)]),description:i(()=>[u(p(e(s)("Please fill the form below to {x} item.",{x:r.edit?e(s)("update"):e(s)("add")}))+" ",1),t("div",null,[d(g,{href:n.route("users.index"),class:"mt-4"},{default:i(()=>[u(p(e(s)("List Users")),1)]),_:1},8,["href"])])]),form:i(()=>[t("div",$,[d(f,{modelValue:e(l).name,"onUpdate:modelValue":o[0]||(o[0]=a=>e(l).name=a),id:"name",error:e(l).errors.name,label:e(s)("Name")},null,8,["modelValue","error","label"])]),t("div",I,[d(f,{modelValue:e(l).email,"onUpdate:modelValue":o[1]||(o[1]=a=>e(l).email=a),id:"email",type:"email",error:e(l).errors.email,label:e(s)("Email")},null,8,["modelValue","error","label"])]),t("div",P,[d(f,{modelValue:e(l).password,"onUpdate:modelValue":o[2]||(o[2]=a=>e(l).password=a),id:"password",type:"password",error:e(l).errors.password,label:e(s)("Password")},null,8,["modelValue","error","label"])]),t("div",F,[d(f,{type:"password",id:"password_confirmation",label:e(s)("Confirm Password"),modelValue:e(l).password_confirmation,"onUpdate:modelValue":o[3]||(o[3]=a=>e(l).password_confirmation=a),error:e(l).errors.password_confirmation},null,8,["label","modelValue","error"])]),t("div",A,[c.roles&&c.roles.length?(m(),b("div",L,[t("label",T,p(e(s)("Roles")),1),(m(!0),b(h,null,U(c.roles,a=>(m(),_(w,{key:a.name,id:a.name,value:a.name,label:e(s)(a.name),error:e(l).errors.roles,checked:e(l).roles,"onUpdate:checked":o[4]||(o[4]=k=>e(l).roles=k)},null,8,["id","value","label","error","checked"]))),128)),e(l).errors.roles?(m(),_(E,{key:0,message:e(l).errors.roles,class:"w-full -mt-1"},null,8,["message"])):v("",!0)])):v("",!0),t("h1",D,p(e(s)("Permissions")),1),t("div",R,[d(w,{id:"view_all",checked:e(l).view_all,"onUpdate:checked":o[5]||(o[5]=a=>e(l).view_all=a),label:e(s)("Can view all records")},null,8,["checked","label"]),d(w,{id:"edit_all",checked:e(l).edit_all,"onUpdate:checked":o[6]||(o[6]=a=>e(l).edit_all=a),label:e(s)("Can edit all records")},null,8,["checked","label"])])])]),actions:i(()=>[d(N,{on:e(l).recentlySuccessful,class:"mr-3"},{default:i(()=>o[7]||(o[7]=[u(" Saved. ")])),_:1},8,["on"]),d(g,{type:"submit",loading:e(l).processing},{default:i(()=>o[8]||(o[8]=[u(" Save ")])),_:1},8,["loading"])]),_:1})])]),_:1},8,["title"]))}};export{le as default};
