use leptos::*;
use crate::backend::user::CreateUser;
use crate::components::data_form::DataForm;
use crate::components::modal_box::DialogOpener;
use crate::locales::trl;

#[component]
pub fn user_edit(opener: DialogOpener) -> impl IntoView {
    let create_usr = create_server_action::<CreateUser>();
    view! {
        <DataForm opener=opener action=create_usr title="Create user">
                //<input type="hidden" value={move || company.get().id()} name="company[id]"/>
                <div class="row">
                    <div class="col mb-3">
                        <label  for="username" class="form-label">{trl("Username")}</label>
                        <input
                            type="text"
                            id="username"
                            class="form-control"
                            placeholder={trl("Enter username")}
                            prop:value={move || opener.empty()}
                            name="user[login]"
                        />
                    </div>
                </div>
                <div class="row">
                    <div class="col mb-3">
                        <label  for="password" class="form-label">{trl("Password")}</label>
                        <input
                            type="password"
                            id="password"
                            class="form-control"
                            prop:value={move || opener.empty()}
                            name="user[password]"
                        />
                    </div>
                </div>
                <div class="row">
                    <div class="col mb-3">
                        <label  for="passwordVer" class="form-label">{trl("Verify password")}</label>
                        <input
                            type="password"
                            id="passwordVer"
                            class="form-control"
                            prop:value={move || opener.empty()}
                            name="user[password_ver]"
                        />
                    </div>
                </div>
                <div class="row">
                    <div class="col mb-3">
                        <label  for="fullName" class="form-label">{trl("Full name")}</label>
                        <input
                            type="text"
                            id="fullName"
                            class="form-control"
                            placeholder="Enter full name"
                            prop:value={move || opener.empty()}
                            name="user[full_name]"
                        />
                    </div>
                </div>
                <div class="row">
                    <div class="col mb-3">
                        <label  for="email" class="form-label">"Email"</label>
                        <input
                            type="text"
                            id="email"
                            class="form-control"
                            placeholder="Enter email"
                            prop:value={move || opener.empty()}
                            name="user[email]"
                        />
                    </div>
                </div>
                <div class="row">
                    <div class="col mb-3">
                        <input
                            type="checkbox"
                            id="admin"
                            class="form-check-input"
                            prop:checked={move || opener.not_checked()}
                            name="user[admin]"
                        />
                        <label  for="admin" class="form-label">"Admin"</label>
                    </div>
                </div>
                <div class="row">
                    <div class="col mb-3">
                        <input
                            type="checkbox"
                            id="getEmails"
                            class="form-check-input"
                            prop:checked={move || opener.not_checked()}
                            name="user[get_emails]"
                        />
                        <label  for="geEmails" class="form-label">{trl("Get emails")}</label>
                    </div>
                </div>
            </DataForm>
    }
}