import {
  type Meta,
  type StoryObj,
  applicationConfig,
  argsToTemplate,
} from '@storybook/angular';

import { InlineAddressComponent, Address } from '@isa/shared/address';
import { CountryResource } from '@isa/crm/data-access';

const meta: Meta<InlineAddressComponent> = {
  title: 'shared/address/InlineAddressComponent',
  component: InlineAddressComponent,
  decorators: [
    applicationConfig({
      providers: [
        {
          provide: CountryResource,
          useValue: {
            resource: {
              value: () => [
                { isO3166_A_3: 'DEU', name: 'Germany' },
                { isO3166_A_3: 'FRA', name: 'France' },
                { isO3166_A_3: 'AUT', name: 'Austria' },
                { isO3166_A_3: 'USA', name: 'United States' },
                { isO3166_A_3: 'CHE', name: 'Switzerland' },
                { isO3166_A_3: 'ITA', name: 'Italy' },
                { isO3166_A_3: 'ESP', name: 'Spain' },
              ],
            },
          },
        },
      ],
    }),
  ],
  argTypes: {
    address: {
      control: 'object',
      description: 'The address object to display in inline format',
    },
  },
  render: (args) => ({
    props: args,
    template: `<shared-inline-address ${argsToTemplate(args)}></shared-inline-address>`,
  }),
};

export default meta;

type Story = StoryObj<InlineAddressComponent>;

export const Default: Story = {
  args: {
    address: {
      street: 'Hauptstraße',
      streetNumber: '42',
      zipCode: '10115',
      city: 'Berlin',
      country: 'DEU',
    },
  },
};

export const GermanAddress: Story = {
  args: {
    address: {
      street: 'Maximilianstraße',
      streetNumber: '15',
      zipCode: '80539',
      city: 'München',
      country: 'DEU',
    },
  },
};

export const FrenchAddress: Story = {
  args: {
    address: {
      street: 'Rue de la Paix',
      streetNumber: '25',
      zipCode: '75002',
      city: 'Paris',
      country: 'FRA',
    },
  },
};

export const AustrianAddress: Story = {
  args: {
    address: {
      street: 'Stephansplatz',
      streetNumber: '1',
      zipCode: '1010',
      city: 'Wien',
      country: 'AUT',
    },
  },
};

export const SwissAddress: Story = {
  args: {
    address: {
      street: 'Bahnhofstrasse',
      streetNumber: '50',
      zipCode: '8001',
      city: 'Zürich',
      country: 'CHE',
    },
  },
};

export const USAddress: Story = {
  args: {
    address: {
      street: 'Fifth Avenue',
      streetNumber: '350',
      zipCode: '10118',
      city: 'New York',
      country: 'USA',
    },
  },
};

export const ShortAddress: Story = {
  args: {
    address: {
      street: 'Dorfstraße',
      streetNumber: '5',
      city: 'Neustadt',
    },
  },
};

export const StreetOnly: Story = {
  args: {
    address: {
      street: 'Hauptstraße',
      streetNumber: '10',
    },
  },
};

export const CityOnly: Story = {
  args: {
    address: {
      zipCode: '12345',
      city: 'Beispielstadt',
    },
  },
};

export const NoCountry: Story = {
  args: {
    address: {
      street: 'Teststraße',
      streetNumber: '99',
      zipCode: '54321',
      city: 'Musterstadt',
    },
  },
};

export const WithCountryLookup: Story = {
  args: {
    address: {
      street: 'Via Roma',
      streetNumber: '10',
      zipCode: '00100',
      city: 'Roma',
      country: 'ITA',
    },
  },
};

export const SpanishAddress: Story = {
  args: {
    address: {
      street: 'Calle Mayor',
      streetNumber: '1',
      zipCode: '28013',
      city: 'Madrid',
      country: 'ESP',
    },
  },
};

export const EmptyAddress: Story = {
  args: {
    address: {},
  },
};