package view

import (
    "stevenlr.com/locker/model"
    "fmt"
)

templ lock(t model.Lock) {
    <p class="lock-row">
        <a href={ templ.URL(fmt.Sprint("/lock/", t.Id)) }>{ t.Name }</a>
        -
        <a
            href="javascript:void(0);"
            hx-delete={ fmt.Sprint("/lock/", t.Id) }
            hx-target="closest .lock-row"
			hx-confirm={ fmt.Sprint("Are you sure you want to delete lock \"", t.Name , "\"?") }
        >Delete</a>
    </p>
}

templ LockCreateForm(lockName string, err string) {
    <form
        hx-put="/lock"
        hx-target="closest .locks-list"
        hx-target-error="this"
    >
        <p>
            <input type="text" name="lockName" value={ lockName } placeholder="Name" />
            <input type="number" name="days" placeholder="Days" />
            <input type="number" name="hours" placeholder="Hours" />
            <button type="submit">Create</button>
        </p>
        if err != "" {
            <p class="error">{ err }</p>
        }
    </form>
}

templ LocksList(locks []model.Lock, isSignedIn bool) {
    <div class="locks-list">
        if isSignedIn {
            <h1>Locks</h1>
		        for _, t := range locks {
		            @lock(t)
		        }
            <h4>Create lock</h4>
            @LockCreateForm("", "")
        }
    </div>
}