use leptos::*;
use crate::backend::data::WeekHours;
use crate::backend::opening_hours::UpdateHours;
use crate::components::data_form::DataForm;
use crate::components::modal_box::DialogOpener;
use crate::locales::trl;

#[component]
pub fn EditHours(opener: DialogOpener, hours: ReadSignal<WeekHours>) -> impl IntoView {
    let update_hours = create_server_action::<UpdateHours>();

    view! {
        <DataForm opener=opener action=update_hours title="Edit hours">
            <input type="hidden" value={move || hours.get().day().to_string()} name="hours[day]"/>
            <div class="row">
                <div class="col mb-3">
                    <label  for="hours" class="form-label">{trl("Hours")}</label>
                    <input
                        type="text"
                        id="hours"
                        class="form-control"
                        placeholder="12:00 - 15:00, 17:00 - 21:00"
                        prop:value={move || hours.get().hours().to_string()}
                        name="hours[hours]"
                    />
                </div>
            </div>
        </DataForm>
    }
}