import Elementary import ElementaryHTMX import SharedModels import Vapor struct EmployeeSelect: HTML { let classString: String let name: String let employees: [Employee]? let context: Context var content: some HTML { if let employees { select(.name(name), .class(classString)) { for employee in employees { option(.value(employee.id.uuidString)) { employee.fullName } } } .attributes(.style("margin-left: 15px;"), when: context == .search) } else { div( .hx.get("/select/employee?context=\(context.rawValue)"), .hx.target("this"), .hx.swap(.outerHTML.transition(true).swap("0.5s")), .hx.indicator("next .hx-indicator"), .hx.trigger(.event(.revealed)), .style("display: inline;") ) { Img.spinner().attributes(.class("hx-indicator")) } } } static func purchaseOrderForm(employees: [Employee]? = nil) -> Self { .init(classString: "col-3", name: "createdForID", employees: employees, context: .form) } static func purchaseOrderSearch(employees: [Employee]? = nil) -> Self { .init(classString: "col-3", name: "employeeID", employees: employees, context: .search) } enum Context: String, Codable, Content { case form case search } }