import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { css } from "styled-components";
import React from "react";
import { useQuery } from "react-query";
import { useOpenK9Client } from "../components/client";
export function SortResultList({ setSortResult, background = "white", minHeight = "40px", color = "#7e7e7e", }) {
    const client = useOpenK9Client();
    const options = useQuery(["date-label-sort-options", {}], async () => {
        return await client.getLabelSort();
    });
    return (_jsx("span", { className: "openk9-container-sort-result-list-component", children: _jsxs("select", { className: "form-control openk9-sort-result-select", id: "regularSelectElement", css: css `
          border-radius: 34px;
          border: 1px solid #a292926b;
          height: 30px;
          width: 100%;
          padding-inline: 10px;
          cursor: pointer;
          :focus {
            border: 1px solid #a292926b;
            outline: none;
          }
          background: ${background};
          min-height: ${minHeight};
          color: ${color};
        `, onChange: (event) => {
                if (JSON.parse(event.currentTarget.value)?.label === "relevance") {
                    setSortResult({});
                }
                else {
                    setSortResult({
                        [JSON.parse(event.currentTarget.value)?.label]: {
                            sort: JSON.parse(event.currentTarget.value)?.sort,
                            missing: "_last",
                        },
                    });
                }
            }, children: [_jsx("option", { value: JSON.stringify({
                        label: "relevance",
                    }), children: "relevance" }), options.data?.map((option) => {
                    return (_jsxs(React.Fragment, { children: [_jsxs("option", { value: JSON.stringify({
                                    label: option.field,
                                    sort: "asc",
                                }), children: [option.label, " asc"] }, option.id + "asc"), _jsxs("option", { value: JSON.stringify({
                                    label: option.field,
                                    sort: "desc",
                                }), children: [option.label, " desc"] }, option.id + "desc")] }));
                })] }) }));
}
