form!
title "Configure Calls"

field(
	var: "fwd[voicemail_enabled]",
	type: "boolean",
	label: "Voicemail enabled",
	value: @customer.fwd.voicemail_enabled?
)

if @customer.fwd.voicemail_enabled?
	field(
		var: "fwd[timeout]",
		type: "text-single",
		datatype: "xs:integer",
		label: "Seconds to ring before voicemail",
		description: "One ring is ~5 seconds",
		value: @customer.fwd.timeout.to_i.to_s,
		range: (0..300)
	)

	field(
		var: "voicemail_transcription",
		type: "boolean",
		label: "Voicemail transcription",
		value: @customer.transcription_enabled.to_s
	)
end

field(
	var: "fwd[uri]",
	type: "list-single",
	datatype: "xs:anyURI",
	open: true,
	label: "Forward calls to",
	description: "List item or any custom xmpp:, sip:, or tel: URI.",
	options: [
		{ label: "Jabber ID", value: "xmpp:#{@customer.jid}" },
		{ label: "SIP Account", value: @customer.sip_account.uri }
	],
	value: @customer.fwd.uri
)

if (lidb = @customer.tndetails.dig(:features, :lidb))
	field(
		var: "lidb_name",
		type: "fixed",
		label: "CNAM",
		value: "#{lidb[:subscriber_information]} (#{lidb[:status]})"
	)
elsif @customer.tndetails[:on_net_vendor]
	field(
		var: "lidb_name",
		type: "text-single",
		label: "CNAM Name",
		description: "or nothing/space to leave blank"
	)
end
