2024-06-02 23:41:46 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-10-29 12:45:03 +03:00
|
|
|
import clsx from 'clsx';
|
2024-06-02 23:41:46 +03:00
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { SelectorButton } from '@/components/Control';
|
|
|
|
import { Dropdown, DropdownButton, useDropdown } from '@/components/Dropdown';
|
2025-02-21 21:15:05 +03:00
|
|
|
import { type Styling } from '@/components/props';
|
2024-06-02 23:41:46 +03:00
|
|
|
import { prefixes } from '@/utils/constants';
|
|
|
|
|
2025-02-11 20:56:24 +03:00
|
|
|
import { describeLocationHead, labelLocationHead } from '../labels';
|
2025-02-10 01:32:55 +03:00
|
|
|
import { LocationHead } from '../models/library';
|
|
|
|
|
2025-02-26 00:16:41 +03:00
|
|
|
import { IconLocationHead } from './IconLocationHead';
|
|
|
|
|
2025-02-21 21:15:05 +03:00
|
|
|
interface SelectLocationHeadProps extends Styling {
|
2024-06-02 23:41:46 +03:00
|
|
|
value: LocationHead;
|
2024-06-21 19:27:36 +03:00
|
|
|
onChange: (newValue: LocationHead) => void;
|
2024-06-02 23:41:46 +03:00
|
|
|
excluded?: LocationHead[];
|
|
|
|
}
|
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
export function SelectLocationHead({
|
|
|
|
value,
|
|
|
|
excluded = [],
|
|
|
|
onChange,
|
|
|
|
className,
|
|
|
|
...restProps
|
|
|
|
}: SelectLocationHeadProps) {
|
2024-06-02 23:41:46 +03:00
|
|
|
const menu = useDropdown();
|
|
|
|
|
2025-02-05 01:27:52 +03:00
|
|
|
function handleChange(newValue: LocationHead) {
|
|
|
|
menu.hide();
|
|
|
|
onChange(newValue);
|
|
|
|
}
|
2024-06-02 23:41:46 +03:00
|
|
|
|
|
|
|
return (
|
2024-10-29 12:45:03 +03:00
|
|
|
<div ref={menu.ref} className={clsx('h-full text-right', className)} {...restProps}>
|
2024-06-02 23:41:46 +03:00
|
|
|
<SelectorButton
|
|
|
|
transparent
|
|
|
|
tabIndex={-1}
|
|
|
|
title={describeLocationHead(value)}
|
|
|
|
hideTitle={menu.isOpen}
|
|
|
|
className='h-full'
|
2025-02-26 00:16:41 +03:00
|
|
|
icon={<IconLocationHead value={value} size='1rem' />}
|
2024-06-02 23:41:46 +03:00
|
|
|
text={labelLocationHead(value)}
|
|
|
|
onClick={menu.toggle}
|
|
|
|
/>
|
|
|
|
|
2025-02-25 13:24:19 +03:00
|
|
|
<Dropdown isOpen={menu.isOpen} className='z-modal-tooltip'>
|
2024-06-02 23:41:46 +03:00
|
|
|
{Object.values(LocationHead)
|
|
|
|
.filter(head => !excluded.includes(head))
|
|
|
|
.map((head, index) => {
|
|
|
|
return (
|
|
|
|
<DropdownButton
|
|
|
|
className='w-[10rem]'
|
|
|
|
key={`${prefixes.location_head_list}${index}`}
|
|
|
|
onClick={() => handleChange(head)}
|
|
|
|
title={describeLocationHead(head)}
|
|
|
|
>
|
|
|
|
<div className='inline-flex items-center gap-3'>
|
2025-02-26 00:16:41 +03:00
|
|
|
<IconLocationHead value={head} size='1rem' />
|
2024-06-02 23:41:46 +03:00
|
|
|
{labelLocationHead(head)}
|
|
|
|
</div>
|
|
|
|
</DropdownButton>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|