import { SingleAutocomplete } from '@/manager/shared/components/SingleAutocomplete';
import { getFieldSetHost, getInputHostByLabel } from '@/manager/shared/utils/locator-utils';
import { BaseComponent } from '@/shared/base/BaseComponent';
import { Taxes } from '@/shared/types/tax-types';
import { formatPercentage } from '@/shared/utils/formatters';

export class TaxFieldSet extends BaseComponent {
  readonly main = getFieldSetHost(this.host, 'Taxes');
  readonly b2cTaxAutocomplete = new SingleAutocomplete(getInputHostByLabel(this.main, 'B2C'));
  readonly b2bTaxAutocomplete = new SingleAutocomplete(getInputHostByLabel(this.main, 'B2B'));

  async fill(taxes: Taxes): Promise<void> {
    await this.b2cTaxAutocomplete.select(formatPercentage(taxes.b2c.rate));
    await this.b2bTaxAutocomplete.select(formatPercentage(taxes.b2b.rate));
  }
}
